| author | bors <bors@rust-lang.org> 2026-06-25 14:59:15 UTC |
| committer | bors <bors@rust-lang.org> 2026-06-25 14:59:15 UTC |
| log | fa36a479e492137fdf473a891206da127f132910 |
| tree | 68526db09cc0407ba41d95c5d2b96945a90f47a7 |
| parent | 973ad0d0ab149bde2e96422833c1265c7a5be217 |
| parent | b20305bb330cc7692d35d277404e0c2c177f30ca |
Add rigid alias marker
This PR adds a rigidness marker to `TyKind::Alias` and `ConstKind::Unevaluated`. It's used to skip renormalization of rigid aliases. The tracking issue for this is rust-lang/rust#155345.
The difficulty is that rigid aliases are only valid in their own `TypingEnv` so we need to force them back to non-rigid when entering another `TypingEnv`, either because a change to the `ParamEnv` or because we enter another `TypingMode`.
Changes to the `ParamEnv` currently only happen by moving into a new context. We now make sure that `EarlyBinder` new contains any rigid aliases, this way we have to normalize all aliases contained in it after instantiating.
Changes to the `TypingMode` are rare, and have to be manually handled.
---
The main changes in this PR are as follows:
- we add `enum IsRigid { Yes, No }` as a field to `TyKind::Alias` and `ConstKind::Unevaluated`. It is always `No` with the old solver, this makes some of the code less nice than it will be with the old solver removed.
- if we keep an alias as rigid when proving `Projection` goals we equate the expected term with that alias with `IsRigid::Yes`
- `EarlyBinder::bind` now takes the `tcx` and eagerly sets all `IsRigid` to `No`, this is necessary as moving aliases into a different `TypingEnv` may cause them to no longer be rigid
- `EarlyBinder::bind_iter` asserts that there are no rigid aliases instead of replacing them
- type relations and generalization always structurally recurse into rigid aliases
- a lot of places in the new solver can ICE when matching on `TyKind::Alias` with `IsRigid::No`
---
There's a lot of future work here:
- coherence don't actually rely on lazy norm :<
- remove eq_structurally_relating_aliases, have a special type folder for canonical responses
- yeet `AliasRelate`, lazily replace non-rigid aliases with infer var + projection goal
- `ParamEnv` normalization hack to incorrectly mark things as rigid
- eagerly normalize when adding stuff to the fulfillment ctxt :>
- change `TypeOutlives` goal handling to only expect rigid aliases
- properly expect `IsRigid::Yes`in region handling (or `yes_if_next_solver`)
- probably change `EarlyBinder::bind` to also assert that there are no rigid aliases and manually replacing rigid aliases before then where necessary
---
This PR also adds a flag `-Zrenormalize-rigid-aliases` to test whether we properly handle typing mode change.
Currently only `tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-4.rs` fails this check.
r? lcnr267 files changed, 1944 insertions(+), 1434 deletions(-)
compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs+2-2| ... | ... | @@ -713,8 +713,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { |
| 713 | 713 | )); |
| 714 | 714 | let can_subst = |ty: Ty<'tcx>| { |
| 715 | 715 | // Normalize before comparing to see through type aliases and projections. |
| 716 | let old_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, generic_args); | |
| 717 | let new_ty = ty::EarlyBinder::bind(ty).instantiate(tcx, new_args); | |
| 716 | let old_ty = ty::EarlyBinder::bind(tcx, ty).instantiate(tcx, generic_args); | |
| 717 | let new_ty = ty::EarlyBinder::bind(tcx, ty).instantiate(tcx, new_args); | |
| 718 | 718 | if let Ok(old_ty) = tcx.try_normalize_erasing_regions( |
| 719 | 719 | self.infcx.typing_env(self.infcx.param_env), |
| 720 | 720 | old_ty, |
compiler/rustc_borrowck/src/diagnostics/opaque_types.rs+3-2| ... | ... | @@ -76,6 +76,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { |
| 76 | 76 | "non-defining use of `{}` in the defining scope", |
| 77 | 77 | Ty::new_opaque( |
| 78 | 78 | infcx.tcx, |
| 79 | ty::IsRigid::No, | |
| 79 | 80 | opaque_type_key.def_id.to_def_id(), |
| 80 | 81 | opaque_type_key.args |
| 81 | 82 | ) |
| ... | ... | @@ -220,7 +221,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> { |
| 220 | 221 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 221 | 222 | // If we find an opaque in a local ty, then for each of its captured regions, |
| 222 | 223 | // try to find a path between that captured regions and our borrow region... |
| 223 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind() | |
| 224 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind() | |
| 224 | 225 | && let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } = |
| 225 | 226 | self.tcx.opaque_ty_origin(def_id) |
| 226 | 227 | { |
| ... | ... | @@ -277,7 +278,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen |
| 277 | 278 | |
| 278 | 279 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 279 | 280 | match *ty.kind() { |
| 280 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 281 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 281 | 282 | if self.seen_opaques.insert(def_id) { |
| 282 | 283 | for (bound, _) in self |
| 283 | 284 | .tcx |
compiler/rustc_borrowck/src/diagnostics/region_errors.rs+1-1| ... | ... | @@ -603,7 +603,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { |
| 603 | 603 | let ErrorConstraintInfo { outlived_fr, span, .. } = errci; |
| 604 | 604 | |
| 605 | 605 | let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; |
| 606 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() { | |
| 606 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *output_ty.kind() { | |
| 607 | 607 | output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity().skip_norm_wip() |
| 608 | 608 | }; |
| 609 | 609 |
compiler/rustc_borrowck/src/lib.rs+2-2| ... | ... | @@ -1928,7 +1928,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { |
| 1928 | 1928 | | ty::Never |
| 1929 | 1929 | | ty::Tuple(_) |
| 1930 | 1930 | | ty::UnsafeBinder(_) |
| 1931 | | ty::Alias(_) | |
| 1931 | | ty::Alias(_, _) | |
| 1932 | 1932 | | ty::Param(_) |
| 1933 | 1933 | | ty::Bound(_, _) |
| 1934 | 1934 | | ty::Infer(_) |
| ... | ... | @@ -1970,7 +1970,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> { |
| 1970 | 1970 | | ty::CoroutineWitness(..) |
| 1971 | 1971 | | ty::Never |
| 1972 | 1972 | | ty::UnsafeBinder(_) |
| 1973 | | ty::Alias(_) | |
| 1973 | | ty::Alias(_, _) | |
| 1974 | 1974 | | ty::Param(_) |
| 1975 | 1975 | | ty::Bound(_, _) |
| 1976 | 1976 | | ty::Infer(_) |
compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs+1-1| ... | ... | @@ -176,7 +176,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CollectMemberConstraintsVisitor<'_, '_, |
| 176 | 176 | | ty::CoroutineClosure(def_id, args) |
| 177 | 177 | | ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args), |
| 178 | 178 | |
| 179 | ty::Alias(ty::AliasTy { kind, args, .. }) | |
| 179 | ty::Alias(_, ty::AliasTy { kind, args, .. }) | |
| 180 | 180 | if let Some(variances) = self.cx().opt_alias_variances(kind) => |
| 181 | 181 | { |
| 182 | 182 | // Skip lifetime parameters that are not captured, since they do |
compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs+4-4| ... | ... | @@ -367,7 +367,7 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>( |
| 367 | 367 | // usage of the opaque type and we can ignore it. This check is mirrored in typeck's |
| 368 | 368 | // writeback. |
| 369 | 369 | if !rcx.infcx.tcx.use_typing_mode_post_typeck_until_borrowck() { |
| 370 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 370 | if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 371 | 371 | hidden_type.ty.skip_binder().kind() |
| 372 | 372 | && def_id == opaque_type_key.def_id.to_def_id() |
| 373 | 373 | && args == opaque_type_key.args |
| ... | ... | @@ -500,7 +500,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { |
| 500 | 500 | Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?) |
| 501 | 501 | } |
| 502 | 502 | |
| 503 | ty::Alias(ty::AliasTy { kind, args, .. }) | |
| 503 | ty::Alias(_, ty::AliasTy { kind, args, .. }) | |
| 504 | 504 | if let Some(variances) = tcx.opt_alias_variances(kind) => |
| 505 | 505 | { |
| 506 | 506 | let args = tcx.mk_args_from_iter(std::iter::zip(variances, args.iter()).map( |
| ... | ... | @@ -512,7 +512,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> { |
| 512 | 512 | } |
| 513 | 513 | }, |
| 514 | 514 | ))?; |
| 515 | ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx) | |
| 515 | ty::AliasTy::new_from_args(tcx, kind, args).to_ty(tcx, ty::IsRigid::No) | |
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | _ => ty.try_super_fold_with(self)?, |
| ... | ... | @@ -541,7 +541,7 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>( |
| 541 | 541 | for &(key, hidden_type) in opaque_types { |
| 542 | 542 | let Some(expected) = hidden_types.get(&key.def_id) else { |
| 543 | 543 | if !tcx.use_typing_mode_post_typeck_until_borrowck() { |
| 544 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 544 | if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 545 | 545 | hidden_type.ty.kind() |
| 546 | 546 | && def_id == key.def_id.to_def_id() |
| 547 | 547 | && args == key.args |
compiler/rustc_borrowck/src/type_check/mod.rs+2-2| ... | ... | @@ -469,7 +469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { |
| 469 | 469 | // Necessary for non-trivial patterns whose user-type annotation is an opaque type, |
| 470 | 470 | // e.g. `let (_a,): Tait = whatever`, see #105897 |
| 471 | 471 | if !self.infcx.next_trait_solver() |
| 472 | && let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = | |
| 472 | && let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) = | |
| 473 | 473 | curr_projected_ty.ty.kind() |
| 474 | 474 | { |
| 475 | 475 | // There is nothing that we can compare here if we go through an opaque type. |
| ... | ... | @@ -1760,7 +1760,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 1760 | 1760 | let tcx = self.tcx(); |
| 1761 | 1761 | let maybe_uneval = match constant.const_ { |
| 1762 | 1762 | Const::Ty(_, ct) => match ct.kind() { |
| 1763 | ty::ConstKind::Unevaluated(uv) => match uv.kind { | |
| 1763 | ty::ConstKind::Unevaluated(_, uv) => match uv.kind { | |
| 1764 | 1764 | ty::UnevaluatedConstKind::Projection { def_id } |
| 1765 | 1765 | | ty::UnevaluatedConstKind::Inherent { def_id } |
| 1766 | 1766 | | ty::UnevaluatedConstKind::Free { def_id } |
compiler/rustc_borrowck/src/type_check/relate_tys.rs+6-6| ... | ... | @@ -150,10 +150,10 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { |
| 150 | 150 | }; |
| 151 | 151 | |
| 152 | 152 | let (a, b) = match (a.kind(), b.kind()) { |
| 153 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => { | |
| 153 | (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => { | |
| 154 | 154 | (a, enable_subtyping(b, true)?) |
| 155 | 155 | } |
| 156 | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | |
| 156 | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | |
| 157 | 157 | (enable_subtyping(a, false)?, b) |
| 158 | 158 | } |
| 159 | 159 | _ => unreachable!( |
| ... | ... | @@ -386,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | ( |
| 389 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 390 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 389 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 390 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 391 | 391 | ) if a_def_id == b_def_id || infcx.next_trait_solver() => { |
| 392 | 392 | super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| { |
| 393 | 393 | // This behavior is only there for the old solver, the new solver |
| ... | ... | @@ -401,8 +401,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> { |
| 401 | 401 | if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } |
| 402 | 402 | })?; |
| 403 | 403 | } |
| 404 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 405 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 404 | (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 405 | | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 406 | 406 | if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() => |
| 407 | 407 | { |
| 408 | 408 | self.relate_opaques(a, b)?; |
compiler/rustc_codegen_cranelift/src/common.rs+1-1| ... | ... | @@ -349,7 +349,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { |
| 349 | 349 | self.instance.instantiate_mir_and_normalize_erasing_regions( |
| 350 | 350 | self.tcx, |
| 351 | 351 | ty::TypingEnv::fully_monomorphized(), |
| 352 | ty::EarlyBinder::bind(value), | |
| 352 | ty::EarlyBinder::bind(self.tcx, value), | |
| 353 | 353 | ) |
| 354 | 354 | } |
| 355 | 355 |
compiler/rustc_codegen_ssa/src/mir/mod.rs+2-2| ... | ... | @@ -136,7 +136,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { |
| 136 | 136 | self.instance.instantiate_mir_and_normalize_erasing_regions( |
| 137 | 137 | self.cx.tcx(), |
| 138 | 138 | self.cx.typing_env(), |
| 139 | ty::EarlyBinder::bind(value), | |
| 139 | ty::EarlyBinder::bind(self.cx.tcx(), value), | |
| 140 | 140 | ) |
| 141 | 141 | } |
| 142 | 142 | } |
| ... | ... | @@ -219,7 +219,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( |
| 219 | 219 | let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions( |
| 220 | 220 | tcx, |
| 221 | 221 | ty::TypingEnv::fully_monomorphized(), |
| 222 | ty::EarlyBinder::bind(mir.clone()), | |
| 222 | ty::EarlyBinder::bind(tcx, mir.clone()), | |
| 223 | 223 | ); |
| 224 | 224 | mir = tcx.arena.alloc(optimize_use_clone::<Bx>(cx, monomorphized_mir)); |
| 225 | 225 | } |
compiler/rustc_codegen_ssa/src/mir/naked_asm.rs+3-3| ... | ... | @@ -67,7 +67,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL |
| 67 | 67 | .instantiate_mir_and_normalize_erasing_regions( |
| 68 | 68 | cx.tcx(), |
| 69 | 69 | cx.typing_env(), |
| 70 | ty::EarlyBinder::bind(value.const_), | |
| 70 | ty::EarlyBinder::bind(cx.tcx(), value.const_), | |
| 71 | 71 | ) |
| 72 | 72 | .eval(cx.tcx(), cx.typing_env(), value.span) |
| 73 | 73 | .expect("erroneous constant missed by mono item collection"); |
| ... | ... | @@ -75,7 +75,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL |
| 75 | 75 | let mono_type = instance.instantiate_mir_and_normalize_erasing_regions( |
| 76 | 76 | cx.tcx(), |
| 77 | 77 | cx.typing_env(), |
| 78 | ty::EarlyBinder::bind(value.ty()), | |
| 78 | ty::EarlyBinder::bind(cx.tcx(), value.ty()), | |
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | 81 | let string = common::asm_const_to_str( |
| ... | ... | @@ -91,7 +91,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL |
| 91 | 91 | let mono_type = instance.instantiate_mir_and_normalize_erasing_regions( |
| 92 | 92 | cx.tcx(), |
| 93 | 93 | cx.typing_env(), |
| 94 | ty::EarlyBinder::bind(value.ty()), | |
| 94 | ty::EarlyBinder::bind(cx.tcx(), value.ty()), | |
| 95 | 95 | ); |
| 96 | 96 | |
| 97 | 97 | let instance = match mono_type.kind() { |
compiler/rustc_const_eval/src/check_consts/qualifs.rs+1-1| ... | ... | @@ -345,7 +345,7 @@ where |
| 345 | 345 | Const::Ty(_, ct) => match ct.kind() { |
| 346 | 346 | ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None, |
| 347 | 347 | // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`). |
| 348 | ty::ConstKind::Unevaluated(_) => None, | |
| 348 | ty::ConstKind::Unevaluated(_, _) => None, | |
| 349 | 349 | // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly |
| 350 | 350 | // strict, and if instead we should be doing some kind of value-based analysis. |
| 351 | 351 | ty::ConstKind::Value(_) => None, |
compiler/rustc_const_eval/src/const_eval/eval_queries.rs+2-2| ... | ... | @@ -97,8 +97,8 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>( |
| 97 | 97 | body: &'tcx mir::Body<'tcx>, |
| 98 | 98 | ) -> InterpResult<'tcx, R> { |
| 99 | 99 | let tcx = *ecx.tcx; |
| 100 | let layout = | |
| 101 | ecx.layout_of(body.bound_return_ty().instantiate(tcx, cid.instance.args).skip_norm_wip())?; | |
| 100 | let layout = ecx | |
| 101 | .layout_of(body.bound_return_ty(tcx).instantiate(tcx, cid.instance.args).skip_norm_wip())?; | |
| 102 | 102 | let (intern_kind, ret) = setup_for_eval(ecx, cid, layout)?; |
| 103 | 103 | |
| 104 | 104 | trace!( |
compiler/rustc_const_eval/src/interpret/eval_context.rs+1-1| ... | ... | @@ -362,7 +362,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { |
| 362 | 362 | .try_instantiate_mir_and_normalize_erasing_regions( |
| 363 | 363 | *self.tcx, |
| 364 | 364 | self.typing_env, |
| 365 | ty::EarlyBinder::bind(value), | |
| 365 | ty::EarlyBinder::bind(self.tcx.tcx, value), | |
| 366 | 366 | ) |
| 367 | 367 | .map_err(|_| ErrorHandled::TooGeneric(self.cur_span())) |
| 368 | 368 | } |
compiler/rustc_const_eval/src/util/type_name.rs+8-7| ... | ... | @@ -53,20 +53,21 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> { |
| 53 | 53 | // Types with identity (print the module path). |
| 54 | 54 | ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args) |
| 55 | 55 | | ty::FnDef(def_id, args) |
| 56 | | ty::Alias(ty::AliasTy { | |
| 57 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, | |
| 58 | args, | |
| 59 | .. | |
| 60 | }) | |
| 56 | | ty::Alias( | |
| 57 | _, | |
| 58 | ty::AliasTy { | |
| 59 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, args, .. | |
| 60 | }, | |
| 61 | ) | |
| 61 | 62 | | ty::Closure(def_id, args) |
| 62 | 63 | | ty::CoroutineClosure(def_id, args) |
| 63 | 64 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), |
| 64 | 65 | ty::Foreign(def_id) => self.print_def_path(def_id, &[]), |
| 65 | 66 | |
| 66 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => { | |
| 67 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => { | |
| 67 | 68 | bug!("type_name: unexpected free alias") |
| 68 | 69 | } |
| 69 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 70 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 70 | 71 | bug!("type_name: unexpected inherent projection") |
| 71 | 72 | } |
| 72 | 73 | ty::CoroutineWitness(..) => bug!("type_name: unexpected `CoroutineWitness`"), |
compiler/rustc_hir_analysis/src/autoderef.rs+3-2| ... | ... | @@ -165,8 +165,9 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { |
| 165 | 165 | return None; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | let (normalized_ty, obligations) = self | |
| 169 | .normalize_ty(Unnormalized::new(Ty::new_projection(tcx, trait_target_def_id, [ty])))?; | |
| 168 | let (normalized_ty, obligations) = self.normalize_ty(Unnormalized::new( | |
| 169 | Ty::new_projection(tcx, ty::IsRigid::No, trait_target_def_id, [ty]), | |
| 170 | ))?; | |
| 170 | 171 | debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations); |
| 171 | 172 | self.state.obligations.extend(obligations); |
| 172 | 173 |
compiler/rustc_hir_analysis/src/check/always_applicable.rs+4-3| ... | ... | @@ -192,8 +192,9 @@ fn ensure_all_fields_are_const_destruct<'tcx>( |
| 192 | 192 | let ocx = ObligationCtxt::new_with_diagnostics(&infcx); |
| 193 | 193 | |
| 194 | 194 | let impl_span = tcx.def_span(impl_def_id.to_def_id()); |
| 195 | let env = | |
| 196 | ty::EarlyBinder::bind(tcx.param_env(impl_def_id)).instantiate_identity().skip_norm_wip(); | |
| 195 | let env = ty::EarlyBinder::bind(tcx, tcx.param_env(impl_def_id)) | |
| 196 | .instantiate_identity() | |
| 197 | .skip_norm_wip(); | |
| 197 | 198 | let args = ty::GenericArgs::identity_for_item(tcx, impl_def_id); |
| 198 | 199 | let destruct_trait = tcx.lang_items().destruct_trait().unwrap(); |
| 199 | 200 | for field in tcx.adt_def(adt_def_id).all_fields() { |
| ... | ... | @@ -281,7 +282,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>( |
| 281 | 282 | // reference the params from the ADT instead of from the impl which is bad UX. To resolve |
| 282 | 283 | // this we "rename" the ADT's params to be the impl's params which should not affect behaviour. |
| 283 | 284 | let impl_adt_ty = Ty::new_adt(tcx, tcx.adt_def(adt_def_id), adt_to_impl_args); |
| 284 | let adt_env = ty::EarlyBinder::bind(tcx.param_env(adt_def_id)) | |
| 285 | let adt_env = ty::EarlyBinder::bind(tcx, tcx.param_env(adt_def_id)) | |
| 285 | 286 | .instantiate(tcx, adt_to_impl_args) |
| 286 | 287 | .skip_norm_wip(); |
| 287 | 288 |
compiler/rustc_hir_analysis/src/check/check.rs+11-8| ... | ... | @@ -337,7 +337,7 @@ fn check_opaque_meets_bounds<'tcx>( |
| 337 | 337 | }), |
| 338 | 338 | }; |
| 339 | 339 | |
| 340 | let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); | |
| 340 | let opaque_ty = Ty::new_opaque(tcx, ty::IsRigid::No, def_id.to_def_id(), args); | |
| 341 | 341 | |
| 342 | 342 | // `ReErased` regions appear in the "parent_args" of closures/coroutines. |
| 343 | 343 | // We're ignoring them here and replacing them with fresh region variables. |
| ... | ... | @@ -534,7 +534,7 @@ fn sanity_check_found_hidden_type<'tcx>( |
| 534 | 534 | // Nothing was actually constrained. |
| 535 | 535 | return Ok(()); |
| 536 | 536 | } |
| 537 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = ty.ty.kind() { | |
| 537 | if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = ty.ty.kind() { | |
| 538 | 538 | if def_id == key.def_id.to_def_id() && args == key.args { |
| 539 | 539 | // Nothing was actually constrained, this is an opaque usage that was |
| 540 | 540 | // only discovered to be opaque after inference vars resolved. |
| ... | ... | @@ -778,7 +778,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), |
| 778 | 778 | if has_default { |
| 779 | 779 | // need to store default and type of default |
| 780 | 780 | let ct = tcx.const_param_default(param.def_id).skip_binder(); |
| 781 | if let ty::ConstKind::Unevaluated(uv) = ct.kind() | |
| 781 | if let ty::ConstKind::Unevaluated(_, uv) = ct.kind() | |
| 782 | 782 | && let Some(def_id) = uv.kind.opt_def_id() |
| 783 | 783 | { |
| 784 | 784 | tcx.ensure_ok().type_of(def_id); |
| ... | ... | @@ -2191,7 +2191,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG |
| 2191 | 2191 | impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector { |
| 2192 | 2192 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 2193 | 2193 | match *t.kind() { |
| 2194 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { | |
| 2194 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { | |
| 2195 | 2195 | self.opaques.push(def); |
| 2196 | 2196 | } |
| 2197 | 2197 | ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => { |
| ... | ... | @@ -2224,10 +2224,13 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG |
| 2224 | 2224 | let mut label_match = |ty: Ty<'_>, span| { |
| 2225 | 2225 | for arg in ty.walk() { |
| 2226 | 2226 | if let ty::GenericArgKind::Type(ty) = arg.kind() |
| 2227 | && let ty::Alias(ty::AliasTy { | |
| 2228 | kind: ty::Opaque { def_id: captured_def_id }, | |
| 2229 | .. | |
| 2230 | }) = *ty.kind() | |
| 2227 | && let ty::Alias( | |
| 2228 | _, | |
| 2229 | ty::AliasTy { | |
| 2230 | kind: ty::Opaque { def_id: captured_def_id }, | |
| 2231 | .. | |
| 2232 | }, | |
| 2233 | ) = *ty.kind() | |
| 2231 | 2234 | && captured_def_id == opaque_def_id.to_def_id() |
| 2232 | 2235 | { |
| 2233 | 2236 | err.span_label( |
compiler/rustc_hir_analysis/src/check/compare_impl_item.rs+15-12| ... | ... | @@ -761,7 +761,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( |
| 761 | 761 | Ok(ty) => ty, |
| 762 | 762 | Err(guar) => Ty::new_error(tcx, guar), |
| 763 | 763 | }; |
| 764 | remapped_types.insert(def_id, ty::EarlyBinder::bind(ty)); | |
| 764 | remapped_types.insert(def_id, ty::EarlyBinder::bind(tcx, ty)); | |
| 765 | 765 | } |
| 766 | 766 | Err(err) => { |
| 767 | 767 | // This code path is not reached in any tests, but may be |
| ... | ... | @@ -783,11 +783,14 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( |
| 783 | 783 | if !remapped_types.contains_key(assoc_item) { |
| 784 | 784 | remapped_types.insert( |
| 785 | 785 | *assoc_item, |
| 786 | ty::EarlyBinder::bind(Ty::new_error_with_message( | |
| 786 | ty::EarlyBinder::bind( | |
| 787 | 787 | tcx, |
| 788 | return_span, | |
| 789 | "missing synthetic item for RPITIT", | |
| 790 | )), | |
| 788 | Ty::new_error_with_message( | |
| 789 | tcx, | |
| 790 | return_span, | |
| 791 | "missing synthetic item for RPITIT", | |
| 792 | ), | |
| 793 | ), | |
| 791 | 794 | ); |
| 792 | 795 | } |
| 793 | 796 | } |
| ... | ... | @@ -826,7 +829,7 @@ where |
| 826 | 829 | } |
| 827 | 830 | |
| 828 | 831 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 829 | if let &ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args: proj_args, .. }) = | |
| 832 | if let &ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args: proj_args, .. }) = | |
| 830 | 833 | ty.kind() |
| 831 | 834 | && self.cx().is_impl_trait_in_trait(def_id) |
| 832 | 835 | { |
| ... | ... | @@ -930,10 +933,10 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> { |
| 930 | 933 | } else { |
| 931 | 934 | let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) { |
| 932 | 935 | Some(def_id) => { |
| 933 | let return_span = if let &ty::Alias(ty::AliasTy { | |
| 934 | kind: ty::Opaque { def_id: opaque_ty_def_id }, | |
| 935 | .. | |
| 936 | }) = self.ty.kind() | |
| 936 | let return_span = if let &ty::Alias( | |
| 937 | _, | |
| 938 | ty::AliasTy { kind: ty::Opaque { def_id: opaque_ty_def_id }, .. }, | |
| 939 | ) = self.ty.kind() | |
| 937 | 940 | { |
| 938 | 941 | self.tcx.def_span(opaque_ty_def_id) |
| 939 | 942 | } else { |
| ... | ... | @@ -2721,7 +2724,7 @@ fn param_env_with_gat_bounds<'tcx>( |
| 2721 | 2724 | let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); |
| 2722 | 2725 | |
| 2723 | 2726 | match normalize_impl_ty.kind() { |
| 2724 | &ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 2727 | &ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 2725 | 2728 | if def_id == trait_ty.def_id && args == rebased_args => |
| 2726 | 2729 | { |
| 2727 | 2730 | // Don't include this predicate if the projected type is |
| ... | ... | @@ -2764,7 +2767,7 @@ fn try_report_async_mismatch<'tcx>( |
| 2764 | 2767 | return Ok(()); |
| 2765 | 2768 | } |
| 2766 | 2769 | |
| 2767 | let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id: async_future_def_id }, .. }) = | |
| 2770 | let ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id: async_future_def_id }, .. }) = | |
| 2768 | 2771 | *tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind() |
| 2769 | 2772 | else { |
| 2770 | 2773 | bug!("expected `async fn` to return an RPITIT"); |
compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs+6-5| ... | ... | @@ -87,7 +87,7 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( |
| 87 | 87 | hidden_tys[&trait_projection.kind].instantiate(tcx, impl_opaque_args).skip_norm_wip(); |
| 88 | 88 | |
| 89 | 89 | // If the hidden type is not an opaque, then we have "refined" the trait signature. |
| 90 | let impl_opaque = if let ty::Alias(alias) = *hidden_ty.kind() | |
| 90 | let impl_opaque = if let ty::Alias(_, alias) = *hidden_ty.kind() | |
| 91 | 91 | && let Some(impl_opaque) = alias.try_to_opaque() |
| 92 | 92 | { |
| 93 | 93 | impl_opaque |
| ... | ... | @@ -267,7 +267,7 @@ struct ImplTraitInTraitCollector<'tcx> { |
| 267 | 267 | |
| 268 | 268 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> { |
| 269 | 269 | fn visit_ty(&mut self, ty: Ty<'tcx>) { |
| 270 | if let ty::Alias(alias) = *ty.kind() | |
| 270 | if let ty::Alias(_, alias) = *ty.kind() | |
| 271 | 271 | && let Some(proj) = alias.try_to_projection() |
| 272 | 272 | && self.tcx.is_impl_trait_in_trait(proj.kind) |
| 273 | 273 | { |
| ... | ... | @@ -318,9 +318,10 @@ fn report_mismatched_rpitit_signature<'tcx>( |
| 318 | 318 | let mut return_ty = trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping }); |
| 319 | 319 | |
| 320 | 320 | if tcx.asyncness(impl_m_def_id).is_async() && tcx.asyncness(trait_m_def_id).is_async() { |
| 321 | let &ty::Alias(ty::AliasTy { | |
| 322 | kind: ty::Projection { def_id: future_ty_def_id }, args, .. | |
| 323 | }) = return_ty.kind() | |
| 321 | let &ty::Alias( | |
| 322 | _, | |
| 323 | ty::AliasTy { kind: ty::Projection { def_id: future_ty_def_id }, args, .. }, | |
| 324 | ) = return_ty.kind() | |
| 324 | 325 | else { |
| 325 | 326 | span_bug!( |
| 326 | 327 | tcx.def_span(trait_m_def_id), |
compiler/rustc_hir_analysis/src/check/intrinsic.rs+1| ... | ... | @@ -631,6 +631,7 @@ pub(crate) fn check_intrinsic_type( |
| 631 | 631 | vec![Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0))], |
| 632 | 632 | Ty::new_projection_from_args( |
| 633 | 633 | tcx, |
| 634 | ty::IsRigid::No, | |
| 634 | 635 | discriminant_def_id, |
| 635 | 636 | tcx.mk_args(&[param(0).into()]), |
| 636 | 637 | ), |
compiler/rustc_hir_analysis/src/check/wfcheck.rs+3-3| ... | ... | @@ -782,7 +782,7 @@ impl<'tcx> GATArgsCollector<'tcx> { |
| 782 | 782 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> { |
| 783 | 783 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 784 | 784 | match t.kind() { |
| 785 | &ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 785 | &ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 786 | 786 | if def_id == self.gat => |
| 787 | 787 | { |
| 788 | 788 | for (idx, arg) in args.iter().enumerate() { |
| ... | ... | @@ -1509,7 +1509,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: |
| 1509 | 1509 | | ty::ConstKind::Bound(_, _) => unreachable!(), |
| 1510 | 1510 | ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue, |
| 1511 | 1511 | ty::ConstKind::Value(cv) => cv.ty, |
| 1512 | ty::ConstKind::Unevaluated(uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 1512 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 1513 | 1513 | ty::ConstKind::Param(param_ct) => { |
| 1514 | 1514 | param_ct.find_const_ty_from_env(wfcx.param_env) |
| 1515 | 1515 | } |
| ... | ... | @@ -1585,7 +1585,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: |
| 1585 | 1585 | } |
| 1586 | 1586 | let mut param_count = CountParams::default(); |
| 1587 | 1587 | let has_region = pred.visit_with(&mut param_count).is_break(); |
| 1588 | let instantiated_pred = ty::EarlyBinder::bind(pred).instantiate(tcx, args); | |
| 1588 | let instantiated_pred = ty::EarlyBinder::bind(tcx, pred).instantiate(tcx, args); | |
| 1589 | 1589 | // Don't check non-defaulted params, dependent defaults (including lifetimes) |
| 1590 | 1590 | // or preds with multiple params. |
| 1591 | 1591 | if instantiated_pred.skip_normalization().has_non_region_param() |
compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs+8-5| ... | ... | @@ -203,10 +203,13 @@ impl<'tcx> InherentCollect<'tcx> { |
| 203 | 203 | | ty::FnPtr(..) |
| 204 | 204 | | ty::Tuple(..) |
| 205 | 205 | | ty::UnsafeBinder(_) => self.check_primitive_impl(id, self_ty), |
| 206 | ty::Alias(ty::AliasTy { | |
| 207 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 208 | .. | |
| 209 | }) | |
| 206 | ty::Alias( | |
| 207 | _, | |
| 208 | ty::AliasTy { | |
| 209 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 210 | .. | |
| 211 | }, | |
| 212 | ) | |
| 210 | 213 | | ty::Param(_) => { |
| 211 | 214 | Err(self.tcx.dcx().emit_err(diagnostics::InherentNominal { span: item_span })) |
| 212 | 215 | } |
| ... | ... | @@ -215,7 +218,7 @@ impl<'tcx> InherentCollect<'tcx> { |
| 215 | 218 | | ty::CoroutineClosure(..) |
| 216 | 219 | | ty::Coroutine(..) |
| 217 | 220 | | ty::CoroutineWitness(..) |
| 218 | | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) | |
| 221 | | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) | |
| 219 | 222 | | ty::Bound(..) |
| 220 | 223 | | ty::Placeholder(_) |
| 221 | 224 | | ty::Infer(_) => { |
compiler/rustc_hir_analysis/src/coherence/orphan.rs+2-2| ... | ... | @@ -194,7 +194,7 @@ pub(crate) fn orphan_check_impl( |
| 194 | 194 | NonlocalImpl::DisallowOther, |
| 195 | 195 | ), |
| 196 | 196 | |
| 197 | ty::Alias(ty::AliasTy { kind, .. }) => { | |
| 197 | ty::Alias(_, ty::AliasTy { kind, .. }) => { | |
| 198 | 198 | let problematic_kind = match kind { |
| 199 | 199 | // trait Id { type This: ?Sized; } |
| 200 | 200 | // impl<T: ?Sized> Id for T { |
| ... | ... | @@ -440,7 +440,7 @@ fn emit_orphan_check_error<'tcx>( |
| 440 | 440 | }); |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 443 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 444 | 444 | diag.subdiagnostic(diagnostics::OnlyCurrentTraitsOpaque { span }); |
| 445 | 445 | } |
| 446 | 446 | ty::RawPtr(ptr_ty, mutbl) => { |
compiler/rustc_hir_analysis/src/collect.rs+12-7| ... | ... | @@ -1085,7 +1085,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn |
| 1085 | 1085 | bug!("unexpected sort of node in fn_sig(): {:?}", x); |
| 1086 | 1086 | } |
| 1087 | 1087 | }; |
| 1088 | ty::EarlyBinder::bind(output) | |
| 1088 | ty::EarlyBinder::bind(tcx, output) | |
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | fn lower_fn_sig_recovering_infer_ret_ty<'tcx>( |
| ... | ... | @@ -1363,7 +1363,12 @@ pub fn suggest_impl_trait<'tcx>( |
| 1363 | 1363 | let item_ty = ocx.normalize( |
| 1364 | 1364 | &ObligationCause::dummy(), |
| 1365 | 1365 | param_env, |
| 1366 | Unnormalized::new(Ty::new_projection_from_args(infcx.tcx, assoc_item_def_id, args)), | |
| 1366 | Unnormalized::new(Ty::new_projection_from_args( | |
| 1367 | infcx.tcx, | |
| 1368 | ty::IsRigid::No, | |
| 1369 | assoc_item_def_id, | |
| 1370 | args, | |
| 1371 | )), | |
| 1367 | 1372 | ); |
| 1368 | 1373 | // FIXME(compiler-errors): We may benefit from resolving regions here. |
| 1369 | 1374 | if ocx.try_evaluate_obligations().is_empty() |
| ... | ... | @@ -1405,7 +1410,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader |
| 1405 | 1410 | let trait_ref = icx.lowerer().lower_impl_trait_ref(&of_trait.trait_ref, selfty); |
| 1406 | 1411 | |
| 1407 | 1412 | ty::ImplTraitHeader { |
| 1408 | trait_ref: ty::EarlyBinder::bind(trait_ref), | |
| 1413 | trait_ref: ty::EarlyBinder::bind(tcx, trait_ref), | |
| 1409 | 1414 | safety: of_trait.safety, |
| 1410 | 1415 | polarity: polarity_of_impl(tcx, of_trait, is_rustc_reservation), |
| 1411 | 1416 | constness: impl_.constness, |
| ... | ... | @@ -1626,7 +1631,7 @@ fn const_param_default<'tcx>( |
| 1626 | 1631 | default_ct, |
| 1627 | 1632 | tcx.type_of(def_id).instantiate(tcx, identity_args).skip_norm_wip(), |
| 1628 | 1633 | ); |
| 1629 | ty::EarlyBinder::bind(ct) | |
| 1634 | ty::EarlyBinder::bind(tcx, ct) | |
| 1630 | 1635 | } |
| 1631 | 1636 | |
| 1632 | 1637 | fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKind { |
| ... | ... | @@ -1676,7 +1681,7 @@ fn const_of_item<'tcx>( |
| 1676 | 1681 | tcx.def_span(def_id), |
| 1677 | 1682 | "cannot call const_of_item on a non-type_const", |
| 1678 | 1683 | ); |
| 1679 | return ty::EarlyBinder::bind(Const::new_error(tcx, e)); | |
| 1684 | return ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e)); | |
| 1680 | 1685 | } |
| 1681 | 1686 | }; |
| 1682 | 1687 | let icx = ItemCtxt::new(tcx, def_id); |
| ... | ... | @@ -1688,8 +1693,8 @@ fn const_of_item<'tcx>( |
| 1688 | 1693 | if let Err(e) = icx.check_tainted_by_errors() |
| 1689 | 1694 | && !ct.references_error() |
| 1690 | 1695 | { |
| 1691 | ty::EarlyBinder::bind(Const::new_error(tcx, e)) | |
| 1696 | ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e)) | |
| 1692 | 1697 | } else { |
| 1693 | ty::EarlyBinder::bind(ct) | |
| 1698 | ty::EarlyBinder::bind(tcx, ct) | |
| 1694 | 1699 | } |
| 1695 | 1700 | } |
compiler/rustc_hir_analysis/src/collect/item_bounds.rs+15-11| ... | ... | @@ -33,6 +33,7 @@ fn associated_type_bounds<'tcx>( |
| 33 | 33 | ty::print::with_reduced_queries!({ |
| 34 | 34 | let item_ty = Ty::new_projection_from_args( |
| 35 | 35 | tcx, |
| 36 | ty::IsRigid::No, | |
| 36 | 37 | assoc_item_def_id.to_def_id(), |
| 37 | 38 | GenericArgs::identity_for_item(tcx, assoc_item_def_id), |
| 38 | 39 | ); |
| ... | ... | @@ -144,6 +145,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>( |
| 144 | 145 | |
| 145 | 146 | let gat_vars = loop { |
| 146 | 147 | if let ty::Alias( |
| 148 | _, | |
| 147 | 149 | alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_ty_def_id }, .. }, |
| 148 | 150 | ) = *clause_ty.kind() |
| 149 | 151 | { |
| ... | ... | @@ -430,7 +432,7 @@ pub(super) fn explicit_item_bounds_with_filter( |
| 430 | 432 | let opaque_ty = tcx.hir_node_by_def_id(opaque_def_id.expect_local()).expect_opaque_ty(); |
| 431 | 433 | let bounds = |
| 432 | 434 | associated_type_bounds(tcx, def_id, opaque_ty.bounds, opaque_ty.span, filter); |
| 433 | return ty::EarlyBinder::bind(bounds); | |
| 435 | return ty::EarlyBinder::bind_iter(bounds); | |
| 434 | 436 | } |
| 435 | 437 | Some(ty::ImplTraitInTraitData::Impl { .. }) => { |
| 436 | 438 | span_bug!(tcx.def_span(def_id), "RPITIT in impl should not have item bounds") |
| ... | ... | @@ -457,7 +459,7 @@ pub(super) fn explicit_item_bounds_with_filter( |
| 457 | 459 | in_trait_or_impl: Some(hir::RpitContext::Trait), |
| 458 | 460 | } => { |
| 459 | 461 | let args = GenericArgs::identity_for_item(tcx, def_id); |
| 460 | let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); | |
| 462 | let item_ty = Ty::new_opaque(tcx, ty::IsRigid::No, def_id.to_def_id(), args); | |
| 461 | 463 | let bounds = &*tcx.arena.alloc_slice( |
| 462 | 464 | &opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter) |
| 463 | 465 | .to_vec() |
| ... | ... | @@ -476,7 +478,7 @@ pub(super) fn explicit_item_bounds_with_filter( |
| 476 | 478 | } |
| 477 | 479 | | rustc_hir::OpaqueTyOrigin::TyAlias { parent: _, .. } => { |
| 478 | 480 | let args = GenericArgs::identity_for_item(tcx, def_id); |
| 479 | let item_ty = Ty::new_opaque(tcx, def_id.to_def_id(), args); | |
| 481 | let item_ty = Ty::new_opaque(tcx, ty::IsRigid::No, def_id.to_def_id(), args); | |
| 480 | 482 | let bounds = opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter); |
| 481 | 483 | assert_only_contains_predicates_from(filter, bounds, item_ty); |
| 482 | 484 | bounds |
| ... | ... | @@ -486,7 +488,7 @@ pub(super) fn explicit_item_bounds_with_filter( |
| 486 | 488 | node => bug!("item_bounds called on {def_id:?} => {node:?}"), |
| 487 | 489 | }; |
| 488 | 490 | |
| 489 | ty::EarlyBinder::bind(bounds) | |
| 491 | ty::EarlyBinder::bind_iter(bounds) | |
| 490 | 492 | } |
| 491 | 493 | |
| 492 | 494 | pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_, ty::Clauses<'_>> { |
| ... | ... | @@ -515,9 +517,12 @@ pub(super) fn item_non_self_bounds( |
| 515 | 517 | let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect(); |
| 516 | 518 | let own_bounds: FxIndexSet<_> = tcx.item_self_bounds(def_id).skip_binder().iter().collect(); |
| 517 | 519 | if all_bounds.len() == own_bounds.len() { |
| 518 | ty::EarlyBinder::bind(ty::ListWithCachedTypeInfo::empty()) | |
| 520 | ty::EarlyBinder::bind(tcx, ty::ListWithCachedTypeInfo::empty()) | |
| 519 | 521 | } else { |
| 520 | ty::EarlyBinder::bind(tcx.mk_clauses_from_iter(all_bounds.difference(&own_bounds).copied())) | |
| 522 | ty::EarlyBinder::bind( | |
| 523 | tcx, | |
| 524 | tcx.mk_clauses_from_iter(all_bounds.difference(&own_bounds).copied()), | |
| 525 | ) | |
| 521 | 526 | } |
| 522 | 527 | } |
| 523 | 528 | |
| ... | ... | @@ -549,11 +554,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> { |
| 549 | 554 | } |
| 550 | 555 | |
| 551 | 556 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 552 | if let &ty::Alias(ty::AliasTy { | |
| 553 | kind: ty::Projection { def_id: projection_ty_def_id }, | |
| 554 | args, | |
| 555 | .. | |
| 556 | }) = ty.kind() | |
| 557 | if let &ty::Alias( | |
| 558 | _, | |
| 559 | ty::AliasTy { kind: ty::Projection { def_id: projection_ty_def_id }, args, .. }, | |
| 560 | ) = ty.kind() | |
| 557 | 561 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = |
| 558 | 562 | self.tcx.opt_rpitit_info(projection_ty_def_id) |
| 559 | 563 | && fn_def_id == self.fn_def_id |
compiler/rustc_hir_analysis/src/collect/predicates_of.rs+8-9| ... | ... | @@ -433,7 +433,7 @@ fn const_evaluatable_predicates_of<'tcx>( |
| 433 | 433 | |
| 434 | 434 | impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> { |
| 435 | 435 | fn visit_const(&mut self, c: ty::Const<'tcx>) { |
| 436 | if let ty::ConstKind::Unevaluated(uv) = c.kind() { | |
| 436 | if let ty::ConstKind::Unevaluated(_, uv) = c.kind() { | |
| 437 | 437 | if is_const_param_default(self.tcx, uv.kind) { |
| 438 | 438 | // Do not look into const param defaults, |
| 439 | 439 | // these get checked when they are actually instantiated. |
| ... | ... | @@ -519,11 +519,10 @@ pub(super) fn explicit_predicates_of<'tcx>( |
| 519 | 519 | // identity args of the trait. |
| 520 | 520 | // * It must be an associated type for this trait (*not* a |
| 521 | 521 | // supertrait). |
| 522 | if let &ty::Alias(ty::AliasTy { | |
| 523 | kind: ty::Projection { def_id: projection_def_id }, | |
| 524 | args, | |
| 525 | .. | |
| 526 | }) = ty.kind() | |
| 522 | if let &ty::Alias( | |
| 523 | _, | |
| 524 | ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, args, .. }, | |
| 525 | ) = ty.kind() | |
| 527 | 526 | { |
| 528 | 527 | args == trait_identity_args |
| 529 | 528 | // FIXME(return_type_notation): This check should be more robust |
| ... | ... | @@ -745,7 +744,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( |
| 745 | 744 | |
| 746 | 745 | assert_only_contains_predicates_from(filter, implied_bounds, tcx.types.self_param); |
| 747 | 746 | |
| 748 | ty::EarlyBinder::bind(implied_bounds) | |
| 747 | ty::EarlyBinder::bind_iter(implied_bounds) | |
| 749 | 748 | } |
| 750 | 749 | |
| 751 | 750 | // Make sure when elaborating supertraits, probing for associated types, etc., |
| ... | ... | @@ -919,7 +918,7 @@ pub(super) fn type_param_predicates<'tcx>( |
| 919 | 918 | let icx = ItemCtxt::new(tcx, parent); |
| 920 | 919 | icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident) |
| 921 | 920 | } else { |
| 922 | ty::EarlyBinder::bind(&[] as &[_]) | |
| 921 | ty::EarlyBinder::bind_iter(&[] as &[_]) | |
| 923 | 922 | }; |
| 924 | 923 | let mut extend = None; |
| 925 | 924 | |
| ... | ... | @@ -967,7 +966,7 @@ pub(super) fn type_param_predicates<'tcx>( |
| 967 | 966 | self_ty, |
| 968 | 967 | ); |
| 969 | 968 | |
| 970 | ty::EarlyBinder::bind(bounds) | |
| 969 | ty::EarlyBinder::bind_iter(bounds) | |
| 971 | 970 | } |
| 972 | 971 | |
| 973 | 972 | impl<'tcx> ItemCtxt<'tcx> { |
compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs+4-4| ... | ... | @@ -2574,10 +2574,10 @@ fn is_late_bound_map( |
| 2574 | 2574 | ty::Param(param_ty) => { |
| 2575 | 2575 | self.arg_is_constrained[param_ty.index as usize] = true; |
| 2576 | 2576 | } |
| 2577 | ty::Alias(ty::AliasTy { | |
| 2578 | kind: ty::Projection { .. } | ty::Inherent { .. }, | |
| 2579 | .. | |
| 2580 | }) => return, | |
| 2577 | ty::Alias( | |
| 2578 | _, | |
| 2579 | ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }, | |
| 2580 | ) => return, | |
| 2581 | 2581 | _ => (), |
| 2582 | 2582 | } |
| 2583 | 2583 | t.super_visit_with(self) |
compiler/rustc_hir_analysis/src/collect/type_of.rs+17-10| ... | ... | @@ -33,21 +33,28 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ |
| 33 | 33 | return map[&trait_item_def_id]; |
| 34 | 34 | } |
| 35 | 35 | Err(_) => { |
| 36 | return ty::EarlyBinder::bind(Ty::new_error_with_message( | |
| 36 | return ty::EarlyBinder::bind( | |
| 37 | 37 | tcx, |
| 38 | DUMMY_SP, | |
| 39 | "Could not collect return position impl trait in trait tys", | |
| 40 | )); | |
| 38 | Ty::new_error_with_message( | |
| 39 | tcx, | |
| 40 | DUMMY_SP, | |
| 41 | "Could not collect return position impl trait in trait tys", | |
| 42 | ), | |
| 43 | ); | |
| 41 | 44 | } |
| 42 | 45 | } |
| 43 | 46 | } |
| 44 | 47 | // For an RPITIT in a trait, just return the corresponding opaque. |
| 45 | 48 | Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => { |
| 46 | return ty::EarlyBinder::bind(Ty::new_opaque( | |
| 49 | return ty::EarlyBinder::bind( | |
| 47 | 50 | tcx, |
| 48 | opaque_def_id, | |
| 49 | ty::GenericArgs::identity_for_item(tcx, opaque_def_id), | |
| 50 | )); | |
| 51 | Ty::new_opaque( | |
| 52 | tcx, | |
| 53 | ty::IsRigid::No, | |
| 54 | opaque_def_id, | |
| 55 | ty::GenericArgs::identity_for_item(tcx, opaque_def_id), | |
| 56 | ), | |
| 57 | ); | |
| 51 | 58 | } |
| 52 | 59 | None => {} |
| 53 | 60 | } |
| ... | ... | @@ -240,9 +247,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ |
| 240 | 247 | if let Err(e) = icx.check_tainted_by_errors() |
| 241 | 248 | && !output.references_error() |
| 242 | 249 | { |
| 243 | ty::EarlyBinder::bind(Ty::new_error(tcx, e)) | |
| 250 | ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)) | |
| 244 | 251 | } else { |
| 245 | ty::EarlyBinder::bind(output) | |
| 252 | ty::EarlyBinder::bind(tcx, output) | |
| 246 | 253 | } |
| 247 | 254 | } |
| 248 | 255 |
compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs+7-7| ... | ... | @@ -49,7 +49,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type( |
| 49 | 49 | name: tcx.item_ident(parent_def_id.to_def_id()), |
| 50 | 50 | what: "impl", |
| 51 | 51 | }); |
| 52 | EarlyBinder::bind(Ty::new_error(tcx, guar)) | |
| 52 | EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)) | |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| ... | ... | @@ -94,7 +94,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait( |
| 94 | 94 | name: tcx.item_ident(parent_def_id.to_def_id()), |
| 95 | 95 | what: "crate", |
| 96 | 96 | }); |
| 97 | EarlyBinder::bind(Ty::new_error(tcx, guar)) | |
| 97 | EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)) | |
| 98 | 98 | } |
| 99 | 99 | } |
| 100 | 100 | |
| ... | ... | @@ -247,14 +247,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>( |
| 247 | 247 | let guar = tcx |
| 248 | 248 | .dcx() |
| 249 | 249 | .span_delayed_bug(opaque_type_span, "cannot infer type for stranded opaque type"); |
| 250 | return EarlyBinder::bind(Ty::new_error(tcx, guar)); | |
| 250 | return EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)); | |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | match opaque_types_from { |
| 254 | 254 | DefiningScopeKind::HirTypeck => { |
| 255 | 255 | let tables = tcx.typeck(owner_def_id); |
| 256 | 256 | if let Some(guar) = tables.tainted_by_errors { |
| 257 | EarlyBinder::bind(Ty::new_error(tcx, guar)) | |
| 257 | EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)) | |
| 258 | 258 | } else if let Some(hidden_ty) = tables.hidden_types.get(&def_id) { |
| 259 | 259 | hidden_ty.ty |
| 260 | 260 | } else { |
| ... | ... | @@ -265,7 +265,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>( |
| 265 | 265 | // so we can just make the hidden type be `!`. |
| 266 | 266 | // For backwards compatibility reasons, we fall back to |
| 267 | 267 | // `()` until we the diverging default is changed. |
| 268 | EarlyBinder::bind(tcx.types.unit) | |
| 268 | EarlyBinder::bind(tcx, tcx.types.unit) | |
| 269 | 269 | } |
| 270 | 270 | } |
| 271 | 271 | DefiningScopeKind::MirBorrowck => match tcx.mir_borrowck(owner_def_id) { |
| ... | ... | @@ -275,14 +275,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>( |
| 275 | 275 | } else { |
| 276 | 276 | let hir_ty = tcx.type_of_opaque_hir_typeck(def_id); |
| 277 | 277 | if let Err(guar) = hir_ty.skip_binder().error_reported() { |
| 278 | EarlyBinder::bind(Ty::new_error(tcx, guar)) | |
| 278 | EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)) | |
| 279 | 279 | } else { |
| 280 | 280 | assert!(!tcx.next_trait_solver_globally()); |
| 281 | 281 | hir_ty |
| 282 | 282 | } |
| 283 | 283 | } |
| 284 | 284 | } |
| 285 | Err(guar) => EarlyBinder::bind(Ty::new_error(tcx, guar)), | |
| 285 | Err(guar) => EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)), | |
| 286 | 286 | }, |
| 287 | 287 | } |
| 288 | 288 | } |
compiler/rustc_hir_analysis/src/constrained_generic_params.rs+8-5| ... | ... | @@ -63,14 +63,17 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector { |
| 63 | 63 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 64 | 64 | match *t.kind() { |
| 65 | 65 | // Projections are not injective in general. |
| 66 | ty::Alias(ty::AliasTy { | |
| 67 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 68 | .. | |
| 69 | }) if !self.include_nonconstraining => { | |
| 66 | ty::Alias( | |
| 67 | _, | |
| 68 | ty::AliasTy { | |
| 69 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 70 | .. | |
| 71 | }, | |
| 72 | ) if !self.include_nonconstraining => { | |
| 70 | 73 | return; |
| 71 | 74 | } |
| 72 | 75 | // All free alias types should've been expanded beforehand. |
| 73 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) | |
| 76 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) | |
| 74 | 77 | if !self.include_nonconstraining => |
| 75 | 78 | { |
| 76 | 79 | bug!("unexpected free alias type") |
compiler/rustc_hir_analysis/src/delegation.rs+4-2| ... | ... | @@ -436,7 +436,9 @@ pub(crate) fn inherit_predicates_for_delegation_item<'tcx>( |
| 436 | 436 | |
| 437 | 437 | let new_pred = pred.0.fold_with(&mut self.folder); |
| 438 | 438 | self.preds.push(( |
| 439 | EarlyBinder::bind(new_pred).instantiate(self.tcx, args).skip_norm_wip(), | |
| 439 | EarlyBinder::bind(self.tcx, new_pred) | |
| 440 | .instantiate(self.tcx, args) | |
| 441 | .skip_norm_wip(), | |
| 440 | 442 | pred.1, |
| 441 | 443 | )); |
| 442 | 444 | } |
| ... | ... | @@ -539,7 +541,7 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>( |
| 539 | 541 | |
| 540 | 542 | let (parent_args, child_args) = tcx.delegation_user_specified_args(def_id); |
| 541 | 543 | let (mut folder, args) = create_folder_and_args(tcx, def_id, sig_id, parent_args, child_args); |
| 542 | let caller_sig = EarlyBinder::bind(caller_sig.skip_binder().fold_with(&mut folder)); | |
| 544 | let caller_sig = EarlyBinder::bind(tcx, caller_sig.skip_binder().fold_with(&mut folder)); | |
| 543 | 545 | |
| 544 | 546 | let sig = caller_sig.instantiate(tcx, args.as_slice()).skip_binder(); |
| 545 | 547 | let sig_iter = sig.inputs().iter().cloned().chain(std::iter::once(sig.output())); |
compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs+6-5| ... | ... | @@ -589,7 +589,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 589 | 589 | .map_bound(|projection_term| projection_term.expect_ty()); |
| 590 | 590 | // Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty` |
| 591 | 591 | // parameter to have a skipped binder. |
| 592 | let param_ty = Ty::new_alias(tcx, projection_ty.skip_binder()); | |
| 592 | let param_ty = | |
| 593 | Ty::new_alias(tcx, ty::IsRigid::No, projection_ty.skip_binder()); | |
| 593 | 594 | self.lower_bounds( |
| 594 | 595 | param_ty, |
| 595 | 596 | hir_bounds, |
| ... | ... | @@ -679,7 +680,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 679 | 680 | ty::Binder::bind_with_vars(trait_ref, tcx.late_bound_vars(item_segment.hir_id)); |
| 680 | 681 | |
| 681 | 682 | match self.lower_return_type_notation_ty(candidate, item_def_id, hir_ty.span) { |
| 682 | Ok(ty) => Ty::new_alias(tcx, ty), | |
| 683 | Ok(ty) => Ty::new_alias(tcx, ty::IsRigid::No, ty), | |
| 683 | 684 | Err(guar) => Ty::new_error(tcx, guar), |
| 684 | 685 | } |
| 685 | 686 | } |
| ... | ... | @@ -727,7 +728,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 727 | 728 | } |
| 728 | 729 | |
| 729 | 730 | match self.lower_return_type_notation_ty(bound, item_def_id, hir_ty.span) { |
| 730 | Ok(ty) => Ty::new_alias(tcx, ty), | |
| 731 | Ok(ty) => Ty::new_alias(tcx, ty::IsRigid::No, ty), | |
| 731 | 732 | Err(guar) => Ty::new_error(tcx, guar), |
| 732 | 733 | } |
| 733 | 734 | } |
| ... | ... | @@ -791,7 +792,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 791 | 792 | // Next, we need to check that the return-type notation is being used on |
| 792 | 793 | // an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait). |
| 793 | 794 | let output = tcx.fn_sig(item_def_id).skip_binder().output(); |
| 794 | let output = if let ty::Alias(alias_ty) = *output.skip_binder().kind() | |
| 795 | let output = if let ty::Alias(_, alias_ty) = *output.skip_binder().kind() | |
| 795 | 796 | && let ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, .. } = alias_ty |
| 796 | 797 | && tcx.is_impl_trait_in_trait(projection_def_id) |
| 797 | 798 | { |
| ... | ... | @@ -810,7 +811,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 810 | 811 | // `rustc_middle::ty::predicate::Clause::instantiate_supertrait` |
| 811 | 812 | // and it's no coincidence why. |
| 812 | 813 | let shifted_output = tcx.shift_bound_var_indices(num_bound_vars, output); |
| 813 | Ok(ty::EarlyBinder::bind(shifted_output).instantiate(tcx, args).skip_norm_wip()) | |
| 814 | Ok(ty::EarlyBinder::bind(tcx, shifted_output).instantiate(tcx, args).skip_norm_wip()) | |
| 814 | 815 | } |
| 815 | 816 | } |
| 816 | 817 |
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+23-12| ... | ... | @@ -1216,7 +1216,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1216 | 1216 | // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will |
| 1217 | 1217 | // then actually instantiate the where bounds of. |
| 1218 | 1218 | let alias_ty = ty::AliasTy::new_from_args(tcx, ty::Free { def_id }, args); |
| 1219 | Ty::new_alias(tcx, alias_ty) | |
| 1219 | Ty::new_alias(tcx, ty::IsRigid::No, alias_ty) | |
| 1220 | 1220 | } else { |
| 1221 | 1221 | tcx.at(span).type_of(def_id).instantiate(tcx, args).skip_norm_wip() |
| 1222 | 1222 | } |
| ... | ... | @@ -1361,7 +1361,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1361 | 1361 | ty::AliasTyKind::Inherent { def_id } => def_id, |
| 1362 | 1362 | kind => bug!("expected projection or inherent alias, got {kind:?}"), |
| 1363 | 1363 | }; |
| 1364 | let ty = alias_ty.to_ty(tcx); | |
| 1364 | let ty = alias_ty.to_ty(tcx, ty::IsRigid::No); | |
| 1365 | 1365 | let ty = self.check_param_uses_if_mcg(ty, span, false); |
| 1366 | 1366 | Ok((ty, tcx.def_kind(def_id), def_id)) |
| 1367 | 1367 | } |
| ... | ... | @@ -1400,7 +1400,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1400 | 1400 | if let Some(def_id) = alias_ct.kind.opt_def_id() { |
| 1401 | 1401 | self.require_type_const_attribute(def_id, span)?; |
| 1402 | 1402 | } |
| 1403 | let ct = Const::new_unevaluated(tcx, alias_ct); | |
| 1403 | let ct = Const::new_unevaluated(tcx, ty::IsRigid::No, alias_ct); | |
| 1404 | 1404 | let ct = self.check_param_uses_if_mcg(ct, span, false); |
| 1405 | 1405 | Ok(ct) |
| 1406 | 1406 | } |
| ... | ... | @@ -1837,7 +1837,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1837 | 1837 | ty::AssocTag::Type, |
| 1838 | 1838 | ) { |
| 1839 | 1839 | Ok((item_def_id, item_args)) => { |
| 1840 | Ty::new_projection_from_args(self.tcx(), item_def_id, item_args) | |
| 1840 | Ty::new_projection_from_args(self.tcx(), ty::IsRigid::No, item_def_id, item_args) | |
| 1841 | 1841 | } |
| 1842 | 1842 | Err(guar) => Ty::new_error(self.tcx(), guar), |
| 1843 | 1843 | } |
| ... | ... | @@ -1868,7 +1868,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 1868 | 1868 | ty::UnevaluatedConstKind::new_from_def_id(tcx, item_def_id), |
| 1869 | 1869 | item_args, |
| 1870 | 1870 | ); |
| 1871 | Ok(Const::new_unevaluated(tcx, uv)) | |
| 1871 | Ok(Const::new_unevaluated(tcx, ty::IsRigid::No, uv)) | |
| 1872 | 1872 | } |
| 1873 | 1873 | |
| 1874 | 1874 | /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path. |
| ... | ... | @@ -2122,7 +2122,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2122 | 2122 | GenericsArgsErrExtend::OpaqueTy, |
| 2123 | 2123 | ); |
| 2124 | 2124 | let args = self.lower_generic_args_of_path_segment(span, did, segment); |
| 2125 | Ty::new_opaque(tcx, did, args) | |
| 2125 | Ty::new_opaque(tcx, ty::IsRigid::No, did, args) | |
| 2126 | 2126 | } |
| 2127 | 2127 | Res::Def( |
| 2128 | 2128 | DefKind::Enum |
| ... | ... | @@ -2321,7 +2321,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2321 | 2321 | const_arg.span, |
| 2322 | 2322 | "anonymous constants with lifetimes in their type are not yet supported", |
| 2323 | 2323 | ); |
| 2324 | tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e))); | |
| 2324 | tcx.feed_anon_const_type( | |
| 2325 | anon.def_id, | |
| 2326 | ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)), | |
| 2327 | ); | |
| 2325 | 2328 | return ty::Const::new_error(tcx, e); |
| 2326 | 2329 | } |
| 2327 | 2330 | // We must error if the instantiated type has any inference variables as we will |
| ... | ... | @@ -2332,7 +2335,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2332 | 2335 | const_arg.span, |
| 2333 | 2336 | "anonymous constants with inferred types are not yet supported", |
| 2334 | 2337 | ); |
| 2335 | tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e))); | |
| 2338 | tcx.feed_anon_const_type( | |
| 2339 | anon.def_id, | |
| 2340 | ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)), | |
| 2341 | ); | |
| 2336 | 2342 | return ty::Const::new_error(tcx, e); |
| 2337 | 2343 | } |
| 2338 | 2344 | // We error when the type contains unsubstituted generics since we do not currently |
| ... | ... | @@ -2342,11 +2348,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2342 | 2348 | const_arg.span, |
| 2343 | 2349 | "anonymous constants referencing generics are not yet supported", |
| 2344 | 2350 | ); |
| 2345 | tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(Ty::new_error(tcx, e))); | |
| 2351 | tcx.feed_anon_const_type( | |
| 2352 | anon.def_id, | |
| 2353 | ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e)), | |
| 2354 | ); | |
| 2346 | 2355 | return ty::Const::new_error(tcx, e); |
| 2347 | 2356 | } |
| 2348 | 2357 | |
| 2349 | tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(ty)); | |
| 2358 | tcx.feed_anon_const_type(anon.def_id, ty::EarlyBinder::bind(tcx, ty)); | |
| 2350 | 2359 | } |
| 2351 | 2360 | |
| 2352 | 2361 | let hir_id = const_arg.hir_id; |
| ... | ... | @@ -2763,6 +2772,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2763 | 2772 | let args = self.lower_generic_args_of_path_segment(span, did, segment); |
| 2764 | 2773 | ty::Const::new_unevaluated( |
| 2765 | 2774 | tcx, |
| 2775 | ty::IsRigid::No, | |
| 2766 | 2776 | ty::UnevaluatedConst::new( |
| 2767 | 2777 | tcx, |
| 2768 | 2778 | ty::UnevaluatedConstKind::new_from_def_id(tcx, did), |
| ... | ... | @@ -2920,6 +2930,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 2920 | 2930 | Some(v) => v, |
| 2921 | 2931 | None => ty::Const::new_unevaluated( |
| 2922 | 2932 | tcx, |
| 2933 | ty::IsRigid::No, | |
| 2923 | 2934 | ty::UnevaluatedConst::new( |
| 2924 | 2935 | tcx, |
| 2925 | 2936 | ty::UnevaluatedConstKind::Anon { def_id: anon.def_id.to_def_id() }, |
| ... | ... | @@ -3543,9 +3554,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { |
| 3543 | 3554 | debug!(?args); |
| 3544 | 3555 | |
| 3545 | 3556 | if in_trait.is_some() { |
| 3546 | Ty::new_projection_from_args(tcx, def_id, args) | |
| 3557 | Ty::new_projection_from_args(tcx, ty::IsRigid::No, def_id, args) | |
| 3547 | 3558 | } else { |
| 3548 | Ty::new_opaque(tcx, def_id, args) | |
| 3559 | Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args) | |
| 3549 | 3560 | } |
| 3550 | 3561 | } |
| 3551 | 3562 |
compiler/rustc_hir_analysis/src/outlives/explicit.rs+1-1| ... | ... | @@ -59,7 +59,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { |
| 59 | 59 | } |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | ty::EarlyBinder::bind(required_predicates) | |
| 62 | ty::EarlyBinder::bind_iter(required_predicates) | |
| 63 | 63 | }) |
| 64 | 64 | } |
| 65 | 65 | } |
compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs+7-5| ... | ... | @@ -81,8 +81,10 @@ pub(super) fn infer_predicates( |
| 81 | 81 | .map_or(0, |p| p.as_ref().skip_binder().len()); |
| 82 | 82 | if item_required_predicates.len() > item_predicates_len { |
| 83 | 83 | predicates_added.push(item_did); |
| 84 | global_inferred_outlives | |
| 85 | .insert(item_did.to_def_id(), ty::EarlyBinder::bind(item_required_predicates)); | |
| 84 | global_inferred_outlives.insert( | |
| 85 | item_did.to_def_id(), | |
| 86 | ty::EarlyBinder::bind_iter(item_required_predicates), | |
| 87 | ); | |
| 86 | 88 | } |
| 87 | 89 | } |
| 88 | 90 | |
| ... | ... | @@ -154,7 +156,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 154 | 156 | ); |
| 155 | 157 | } |
| 156 | 158 | |
| 157 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { | |
| 159 | ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { | |
| 158 | 160 | // This corresponds to a type like `Type<'a, T>`. |
| 159 | 161 | // We check inferred and explicit predicates. |
| 160 | 162 | debug!("Free"); |
| ... | ... | @@ -204,7 +206,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 204 | 206 | } |
| 205 | 207 | } |
| 206 | 208 | |
| 207 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 209 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 208 | 210 | // This corresponds to a type like `<() as Trait<'a, T>>::Type`. |
| 209 | 211 | // We only use the explicit predicates of the trait but |
| 210 | 212 | // not the ones of the associated type itself. |
| ... | ... | @@ -220,7 +222,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( |
| 220 | 222 | } |
| 221 | 223 | |
| 222 | 224 | // FIXME(inherent_associated_types): Use the explicit predicates from the parent impl. |
| 223 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {} | |
| 225 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {} | |
| 224 | 226 | |
| 225 | 227 | _ => {} |
| 226 | 228 | } |
compiler/rustc_hir_analysis/src/outlives/utils.rs+1-1| ... | ... | @@ -102,7 +102,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>( |
| 102 | 102 | // |
| 103 | 103 | // Here we want to add an explicit `where <T as Iterator>::Item: 'a` |
| 104 | 104 | // or `Opaque<T>: 'a` depending on the alias kind. |
| 105 | let ty = alias_ty.to_ty(tcx); | |
| 105 | let ty = alias_ty.to_ty(tcx, ty::IsRigid::No); | |
| 106 | 106 | required_predicates |
| 107 | 107 | .entry(ty::OutlivesPredicate(ty.into(), outlived_region)) |
| 108 | 108 | .or_insert(span); |
compiler/rustc_hir_analysis/src/variance/constraints.rs+10-7| ... | ... | @@ -260,15 +260,18 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
| 260 | 260 | self.add_constraints_from_args(current, def.did(), args, variance); |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | ty::Alias(ty::AliasTy { | |
| 264 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 265 | args, | |
| 266 | .. | |
| 267 | }) => { | |
| 263 | ty::Alias( | |
| 264 | _, | |
| 265 | ty::AliasTy { | |
| 266 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 267 | args, | |
| 268 | .. | |
| 269 | }, | |
| 270 | ) => { | |
| 268 | 271 | self.add_constraints_from_invariant_args(current, args, variance); |
| 269 | 272 | } |
| 270 | 273 | |
| 271 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => { | |
| 274 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => { | |
| 272 | 275 | let ty = self.tcx().expand_free_alias_tys(ty); |
| 273 | 276 | self.add_constraints_from_ty(current, ty, variance); |
| 274 | 277 | } |
| ... | ... | @@ -405,7 +408,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { |
| 405 | 408 | debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance); |
| 406 | 409 | |
| 407 | 410 | match &c.kind() { |
| 408 | ty::ConstKind::Unevaluated(uv) => { | |
| 411 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 409 | 412 | self.add_constraints_from_invariant_args(current, uv.args, variance); |
| 410 | 413 | } |
| 411 | 414 | _ => {} |
compiler/rustc_hir_analysis/src/variance/mod.rs+1-1| ... | ... | @@ -139,7 +139,7 @@ fn variance_of_opaque( |
| 139 | 139 | #[instrument(level = "trace", skip(self), ret)] |
| 140 | 140 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 141 | 141 | match t.kind() { |
| 142 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 142 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 143 | 143 | self.visit_opaque(*def_id, args); |
| 144 | 144 | } |
| 145 | 145 | _ => t.super_visit_with(self), |
compiler/rustc_hir_typeck/src/_match.rs+2-2| ... | ... | @@ -245,7 +245,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 245 | 245 | self.may_coerce(arm_ty, ret_ty) |
| 246 | 246 | && prior_arm.is_none_or(|(_, ty, _)| self.may_coerce(ty, ret_ty)) |
| 247 | 247 | // The match arms need to unify for the case of `impl Trait`. |
| 248 | && !matches!(ret_ty.kind(), ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) | |
| 248 | && !matches!(ret_ty.kind(), ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) | |
| 249 | 249 | } |
| 250 | 250 | _ => false, |
| 251 | 251 | }; |
| ... | ... | @@ -532,7 +532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 532 | 532 | let expected_ty = expectation.to_option(self)?; |
| 533 | 533 | let (def_id, args) = match *expected_ty.kind() { |
| 534 | 534 | // FIXME: Could also check that the RPIT is not defined |
| 535 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 535 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 536 | 536 | (def_id.as_local()?, args) |
| 537 | 537 | } |
| 538 | 538 | // FIXME(-Znext-solver=no): Remove this branch once `replace_opaque_types_with_infer` is gone. |
compiler/rustc_hir_typeck/src/cast.rs+1-1| ... | ... | @@ -123,7 +123,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 123 | 123 | // Pointers to foreign types are thin, despite being unsized |
| 124 | 124 | ty::Foreign(..) => Some(PointerKind::Thin), |
| 125 | 125 | // We should really try to normalize here. |
| 126 | ty::Alias(pi) => Some(PointerKind::OfAlias(pi)), | |
| 126 | ty::Alias(_, pi) => Some(PointerKind::OfAlias(pi)), | |
| 127 | 127 | ty::Param(p) => Some(PointerKind::OfParam(p)), |
| 128 | 128 | // Insufficient type information. |
| 129 | 129 | ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None, |
compiler/rustc_hir_typeck/src/closure.rs+3-3| ... | ... | @@ -294,7 +294,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 294 | 294 | closure_kind: hir::ClosureKind, |
| 295 | 295 | ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) { |
| 296 | 296 | match *expected_ty.kind() { |
| 297 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self | |
| 297 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self | |
| 298 | 298 | .deduce_closure_signature_from_predicates( |
| 299 | 299 | expected_ty, |
| 300 | 300 | closure_kind, |
| ... | ... | @@ -990,14 +990,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 990 | 990 | get_future_output(obligation.predicate, obligation.cause.span) |
| 991 | 991 | })? |
| 992 | 992 | } |
| 993 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 993 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 994 | 994 | return Some(Ty::new_error_with_message( |
| 995 | 995 | self.tcx, |
| 996 | 996 | closure_span, |
| 997 | 997 | "this projection should have been projected to an opaque type", |
| 998 | 998 | )); |
| 999 | 999 | } |
| 1000 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self | |
| 1000 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self | |
| 1001 | 1001 | .tcx |
| 1002 | 1002 | .explicit_item_self_bounds(def_id) |
| 1003 | 1003 | .iter_instantiated_copied(self.tcx, args) |
compiler/rustc_hir_typeck/src/expr.rs+2-1| ... | ... | @@ -2976,7 +2976,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2976 | 2976 | err.span_label(ident.span, "unknown field"); |
| 2977 | 2977 | self.point_at_param_definition(&mut err, param_ty); |
| 2978 | 2978 | } |
| 2979 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 2979 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 2980 | 2980 | self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); |
| 2981 | 2981 | } |
| 2982 | 2982 | _ => { |
| ... | ... | @@ -3578,6 +3578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3578 | 3578 | self.param_env, |
| 3579 | 3579 | Unnormalized::new(Ty::new_projection_from_args( |
| 3580 | 3580 | self.tcx, |
| 3581 | ty::IsRigid::No, | |
| 3581 | 3582 | index_trait_output_def_id, |
| 3582 | 3583 | impl_trait_ref.args, |
| 3583 | 3584 | )), |
compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs+4-3| ... | ... | @@ -1178,9 +1178,10 @@ fn find_param_in_ty<'tcx>( |
| 1178 | 1178 | return true; |
| 1179 | 1179 | } |
| 1180 | 1180 | if let ty::GenericArgKind::Type(ty) = arg.kind() |
| 1181 | && let ty::Alias(ty::AliasTy { | |
| 1182 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 1183 | }) = ty.kind() | |
| 1181 | && let ty::Alias( | |
| 1182 | _, | |
| 1183 | ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }, | |
| 1184 | ) = ty.kind() | |
| 1184 | 1185 | { |
| 1185 | 1186 | // This logic may seem a bit strange, but typically when |
| 1186 | 1187 | // we have a projection type in a function signature, the |
compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs+2-2| ... | ... | @@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 161 | 161 | ty::ConstKind::Param(_) |
| 162 | 162 | | ty::ConstKind::Expr(_) |
| 163 | 163 | | ty::ConstKind::Placeholder(_) |
| 164 | | ty::ConstKind::Unevaluated(_) => enforce_copy_bound(element, element_ty), | |
| 164 | | ty::ConstKind::Unevaluated(_, _) => enforce_copy_bound(element, element_ty), | |
| 165 | 165 | |
| 166 | 166 | ty::ConstKind::Bound(_, _) | ty::ConstKind::Infer(_) | ty::ConstKind::Error(_) => { |
| 167 | 167 | unreachable!() |
| ... | ... | @@ -1396,7 +1396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 1396 | 1396 | } |
| 1397 | 1397 | } |
| 1398 | 1398 | } |
| 1399 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: new_def_id }, .. }) | |
| 1399 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: new_def_id }, .. }) | |
| 1400 | 1400 | | ty::Closure(new_def_id, _) |
| 1401 | 1401 | | ty::FnDef(new_def_id, _) => { |
| 1402 | 1402 | def_id = new_def_id; |
compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs+12-10| ... | ... | @@ -294,7 +294,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 294 | 294 | // HACK(eddyb) should get the original `Span`. |
| 295 | 295 | let span = tcx.def_span(def_id); |
| 296 | 296 | |
| 297 | ty::EarlyBinder::bind(tcx.arena.alloc_from_iter( | |
| 297 | ty::EarlyBinder::bind_iter(tcx.arena.alloc_from_iter( | |
| 298 | 298 | self.param_env.caller_bounds().iter().filter_map(|predicate| { |
| 299 | 299 | match predicate.kind().skip_binder() { |
| 300 | 300 | ty::ClauseKind::Trait(data) if data.self_ty().is_param(index) => { |
| ... | ... | @@ -399,10 +399,13 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 399 | 399 | match ty.kind() { |
| 400 | 400 | ty::Adt(adt_def, _) => Some(*adt_def), |
| 401 | 401 | // FIXME(#104767): Should we handle bound regions here? |
| 402 | ty::Alias(ty::AliasTy { | |
| 403 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 404 | .. | |
| 405 | }) if !ty.has_escaping_bound_vars() => { | |
| 402 | ty::Alias( | |
| 403 | _, | |
| 404 | ty::AliasTy { | |
| 405 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 406 | .. | |
| 407 | }, | |
| 408 | ) if !ty.has_escaping_bound_vars() => { | |
| 406 | 409 | self.normalize(span, Unnormalized::new_wip(ty)).ty_adt_def() |
| 407 | 410 | } |
| 408 | 411 | _ => None, |
| ... | ... | @@ -416,11 +419,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { |
| 416 | 419 | // WF obligations that are registered elsewhere, but they have a |
| 417 | 420 | // better cause code assigned to them in `add_required_obligations_for_hir`. |
| 418 | 421 | // This means that they should shadow obligations with worse spans. |
| 419 | if let ty::Alias(ty::AliasTy { | |
| 420 | kind: ty::Projection { def_id } | ty::Free { def_id }, | |
| 421 | args, | |
| 422 | .. | |
| 423 | }) = ty.kind() | |
| 422 | if let ty::Alias( | |
| 423 | _, | |
| 424 | ty::AliasTy { kind: ty::Projection { def_id } | ty::Free { def_id }, args, .. }, | |
| 425 | ) = ty.kind() | |
| 424 | 426 | { |
| 425 | 427 | self.add_required_obligations_for_hir(span, *def_id, args, hir_id); |
| 426 | 428 | } |
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs+1-1| ... | ... | @@ -294,7 +294,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 294 | 294 | return false; |
| 295 | 295 | }; |
| 296 | 296 | |
| 297 | let item_type = Ty::new_projection(tcx, iterator_item_id, [found]); | |
| 297 | let item_type = Ty::new_projection(tcx, ty::IsRigid::No, iterator_item_id, [found]); | |
| 298 | 298 | let item_type = |
| 299 | 299 | self.normalize(expr.span, rustc_middle::ty::Unnormalized::new_wip(item_type)); |
| 300 | 300 |
compiler/rustc_hir_typeck/src/method/probe.rs+1-1| ... | ... | @@ -2050,7 +2050,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { |
| 2050 | 2050 | // HACK: opaque types will match anything for which their bounds hold. |
| 2051 | 2051 | // Thus we need to prevent them from trying to match the `&_` autoref |
| 2052 | 2052 | // candidates that get created for `&self` trait methods. |
| 2053 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 2053 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 2054 | 2054 | if !self.next_trait_solver() |
| 2055 | 2055 | && self.infcx.can_define_opaque_ty(def_id) |
| 2056 | 2056 | && !xform_self_ty.is_ty_var() => |
compiler/rustc_hir_typeck/src/method/suggest.rs+7-5| ... | ... | @@ -178,7 +178,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 178 | 178 | } |
| 179 | 179 | ty::Slice(..) |
| 180 | 180 | | ty::Adt(..) |
| 181 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 181 | | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 182 | 182 | for unsatisfied in unsatisfied_predicates.iter() { |
| 183 | 183 | if is_iterator_predicate(unsatisfied.0) { |
| 184 | 184 | return true; |
| ... | ... | @@ -3759,10 +3759,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 3759 | 3759 | | ty::Float(_) |
| 3760 | 3760 | | ty::Adt(_, _) |
| 3761 | 3761 | | ty::Str |
| 3762 | | ty::Alias(ty::AliasTy { | |
| 3763 | kind: ty::Projection { .. } | ty::Inherent { .. }, | |
| 3764 | .. | |
| 3765 | }) | |
| 3762 | | ty::Alias( | |
| 3763 | _, | |
| 3764 | ty::AliasTy { | |
| 3765 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 3766 | }, | |
| 3767 | ) | |
| 3766 | 3768 | | ty::Param(_) => format!("{deref_ty}"), |
| 3767 | 3769 | // we need to test something like <&[_]>::len or <(&[u32])>::len |
| 3768 | 3770 | // and Vec::function(); |
compiler/rustc_hir_typeck/src/pat.rs+1| ... | ... | @@ -2745,6 +2745,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 2745 | 2745 | // The expected type for the deref pat's inner pattern is `<expected as Deref>::Target`. |
| 2746 | 2746 | let target_ty = Ty::new_projection( |
| 2747 | 2747 | tcx, |
| 2748 | ty::IsRigid::No, | |
| 2748 | 2749 | tcx.require_lang_item(hir::LangItem::DerefTarget, span), |
| 2749 | 2750 | [source_ty], |
| 2750 | 2751 | ); |
compiler/rustc_hir_typeck/src/writeback.rs+2-2| ... | ... | @@ -567,7 +567,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { |
| 567 | 567 | for (opaque_type_key, hidden_type) in opaque_types { |
| 568 | 568 | let hidden_type = self.resolve(hidden_type, &hidden_type.span); |
| 569 | 569 | let opaque_type_key = self.resolve(opaque_type_key, &hidden_type.span); |
| 570 | if let &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 570 | if let &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = | |
| 571 | 571 | hidden_type.ty.kind() |
| 572 | 572 | && def_id == opaque_type_key.def_id.to_def_id() |
| 573 | 573 | && args == opaque_type_key.args |
| ... | ... | @@ -1055,7 +1055,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> { |
| 1055 | 1055 | type Result = ControlFlow<()>; |
| 1056 | 1056 | |
| 1057 | 1057 | fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { |
| 1058 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() | |
| 1058 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() | |
| 1059 | 1059 | && let Some(def_id) = def_id.as_local() |
| 1060 | 1060 | { |
| 1061 | 1061 | if self.def_id == def_id { |
compiler/rustc_infer/src/infer/canonical/query_response.rs+1-1| ... | ... | @@ -519,7 +519,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 519 | 519 | self.at(cause, param_env) |
| 520 | 520 | .eq( |
| 521 | 521 | DefineOpaqueTypes::Yes, |
| 522 | Ty::new_opaque(self.tcx, a.def_id.to_def_id(), a.args), | |
| 522 | Ty::new_opaque(self.tcx, ty::IsRigid::No, a.def_id.to_def_id(), a.args), | |
| 523 | 523 | b, |
| 524 | 524 | )? |
| 525 | 525 | .obligations, |
compiler/rustc_infer/src/infer/mod.rs+16-5| ... | ... | @@ -960,10 +960,20 @@ impl<'tcx> InferCtxt<'tcx> { |
| 960 | 960 | ty::Region::new_var(self.tcx, region_var) |
| 961 | 961 | } |
| 962 | 962 | |
| 963 | pub fn next_term_var_of_kind(&self, term: ty::Term<'tcx>, span: Span) -> ty::Term<'tcx> { | |
| 964 | match term.kind() { | |
| 965 | ty::TermKind::Ty(_) => self.next_ty_var(span).into(), | |
| 966 | ty::TermKind::Const(_) => self.next_const_var(span).into(), | |
| 963 | pub fn next_term_var_of_alias_kind( | |
| 964 | &self, | |
| 965 | alias_term: ty::AliasTerm<'tcx>, | |
| 966 | span: Span, | |
| 967 | ) -> ty::Term<'tcx> { | |
| 968 | match alias_term.kind { | |
| 969 | ty::AliasTermKind::ProjectionTy { .. } | |
| 970 | | ty::AliasTermKind::InherentTy { .. } | |
| 971 | | ty::AliasTermKind::OpaqueTy { .. } | |
| 972 | | ty::AliasTermKind::FreeTy { .. } => self.next_ty_var(span).into(), | |
| 973 | ty::AliasTermKind::FreeConst { .. } | |
| 974 | | ty::AliasTermKind::InherentConst { .. } | |
| 975 | | ty::AliasTermKind::AnonConst { .. } | |
| 976 | | ty::AliasTermKind::ProjectionConst { .. } => self.next_const_var(span).into(), | |
| 967 | 977 | } |
| 968 | 978 | } |
| 969 | 979 | |
| ... | ... | @@ -1252,10 +1262,11 @@ impl<'tcx> InferCtxt<'tcx> { |
| 1252 | 1262 | .unwrap_or(ct), |
| 1253 | 1263 | InferConst::Fresh(_) => ct, |
| 1254 | 1264 | }, |
| 1265 | ||
| 1255 | 1266 | ty::ConstKind::Param(_) |
| 1256 | 1267 | | ty::ConstKind::Bound(_, _) |
| 1257 | 1268 | | ty::ConstKind::Placeholder(_) |
| 1258 | | ty::ConstKind::Unevaluated(_) | |
| 1269 | | ty::ConstKind::Unevaluated(_, _) | |
| 1259 | 1270 | | ty::ConstKind::Value(_) |
| 1260 | 1271 | | ty::ConstKind::Error(_) |
| 1261 | 1272 | | ty::ConstKind::Expr(_) => ct, |
compiler/rustc_infer/src/infer/opaque_types/mod.rs+8-8| ... | ... | @@ -45,7 +45,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 45 | 45 | lt_op: |lt| lt, |
| 46 | 46 | ct_op: |ct| ct, |
| 47 | 47 | ty_op: |ty| match *ty.kind() { |
| 48 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 48 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 49 | 49 | if self.can_define_opaque_ty(def_id) && !ty.has_escaping_bound_vars() => |
| 50 | 50 | { |
| 51 | 51 | let def_span = self.tcx.def_span(def_id); |
| ... | ... | @@ -85,7 +85,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 85 | 85 | ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, TypeError<'tcx>> { |
| 86 | 86 | debug_assert!(!self.next_trait_solver()); |
| 87 | 87 | let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { |
| 88 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) | |
| 88 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) | |
| 89 | 89 | if def_id.is_local() => |
| 90 | 90 | { |
| 91 | 91 | let def_id = def_id.expect_local(); |
| ... | ... | @@ -136,7 +136,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 136 | 136 | return None; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }) = | |
| 139 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }) = | |
| 140 | 140 | *b.kind() |
| 141 | 141 | { |
| 142 | 142 | // We could accept this, but there are various ways to handle this situation, |
| ... | ... | @@ -324,6 +324,7 @@ impl<'tcx> InferCtxt<'tcx> { |
| 324 | 324 | // FIXME(RPITIT): Don't replace RPITITs with inference vars. |
| 325 | 325 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. |
| 326 | 326 | ty::Alias( |
| 327 | _, | |
| 327 | 328 | projection_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }, |
| 328 | 329 | ) if !projection_ty.has_escaping_bound_vars() |
| 329 | 330 | && !tcx.is_impl_trait_in_trait(def_id) |
| ... | ... | @@ -342,11 +343,10 @@ impl<'tcx> InferCtxt<'tcx> { |
| 342 | 343 | } |
| 343 | 344 | // Replace all other mentions of the same opaque type with the hidden type, |
| 344 | 345 | // as the bounds must hold on the hidden type after all. |
| 345 | ty::Alias(ty::AliasTy { | |
| 346 | kind: ty::Opaque { def_id: def_id2 }, | |
| 347 | args: args2, | |
| 348 | .. | |
| 349 | }) if def_id == def_id2 && args == args2 => hidden_ty, | |
| 346 | ty::Alias( | |
| 347 | _, | |
| 348 | ty::AliasTy { kind: ty::Opaque { def_id: def_id2 }, args: args2, .. }, | |
| 349 | ) if def_id == def_id2 && args == args2 => hidden_ty, | |
| 350 | 350 | _ => ty, |
| 351 | 351 | }, |
| 352 | 352 | lt_op: |lt| lt, |
compiler/rustc_infer/src/infer/outlives/for_liveness.rs+6-2| ... | ... | @@ -56,7 +56,7 @@ where |
| 56 | 56 | // either `'static` or a unique outlives region, and if one is |
| 57 | 57 | // found, we just need to prove that that region is still live. |
| 58 | 58 | // If one is not found, then we continue to walk through the alias. |
| 59 | ty::Alias(ty::AliasTy { kind, args, .. }) => { | |
| 59 | ty::Alias(_, alias_ty @ ty::AliasTy { kind, args, .. }) => { | |
| 60 | 60 | let tcx = self.tcx; |
| 61 | 61 | let param_env = self.param_env; |
| 62 | 62 | let def_id = match kind { |
| ... | ... | @@ -82,7 +82,11 @@ where |
| 82 | 82 | &outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| { |
| 83 | 83 | VerifyIfEq { ty, bound } |
| 84 | 84 | }), |
| 85 | ty, | |
| 85 | // FIXME(#155345): Region handling should generally only | |
| 86 | // deal with rigid aliases, making sure we do so correctly | |
| 87 | // everywhere is effort, so we're just using `No` everywhere | |
| 88 | // for now. This should change soon. | |
| 89 | alias_ty.to_ty(tcx, ty::IsRigid::No), | |
| 86 | 90 | ) |
| 87 | 91 | } |
| 88 | 92 | }) |
compiler/rustc_infer/src/infer/outlives/test_type_match.rs+12-1| ... | ... | @@ -44,7 +44,13 @@ pub fn extract_verify_if_eq<'tcx>( |
| 44 | 44 | assert!(!verify_if_eq_b.has_escaping_bound_vars()); |
| 45 | 45 | let mut m = MatchAgainstHigherRankedOutlives::new(tcx); |
| 46 | 46 | let verify_if_eq = verify_if_eq_b.skip_binder(); |
| 47 | m.relate(verify_if_eq.ty, test_ty).ok()?; | |
| 47 | // FIXME(#155345): Region handling should generally only | |
| 48 | // deal with rigid aliases, making sure we do so correctly | |
| 49 | // everywhere is effort, so we're just using `No` everywhere | |
| 50 | // for now. This should change soon. | |
| 51 | let (verify_ty, test_ty) = | |
| 52 | ty::set_aliases_to_non_rigid(tcx, (verify_if_eq.ty, test_ty)).skip_norm_wip(); | |
| 53 | m.relate(verify_ty, test_ty).ok()?; | |
| 48 | 54 | |
| 49 | 55 | if let ty::RegionKind::ReBound(index_kind, br) = verify_if_eq.bound.kind() { |
| 50 | 56 | assert!(matches!(index_kind, ty::BoundVarIndexKind::Bound(ty::INNERMOST))); |
| ... | ... | @@ -80,6 +86,11 @@ pub(super) fn can_match_erased_ty<'tcx>( |
| 80 | 86 | assert!(!outlives_predicate.has_escaping_bound_vars()); |
| 81 | 87 | let erased_outlives_predicate = tcx.erase_and_anonymize_regions(outlives_predicate); |
| 82 | 88 | let outlives_ty = erased_outlives_predicate.skip_binder().0; |
| 89 | // FIXME(#155345): Region handling should generally only | |
| 90 | // deal with rigid aliases, making sure we do so correctly | |
| 91 | // everywhere is effort, so we're just using `No` everywhere | |
| 92 | // for now. This should change soon. | |
| 93 | let outlives_ty = ty::set_aliases_to_non_rigid(tcx, outlives_ty).skip_normalization(); | |
| 83 | 94 | if outlives_ty == erased_ty { |
| 84 | 95 | // pointless micro-optimization |
| 85 | 96 | true |
compiler/rustc_infer/src/infer/outlives/verify.rs+20-4| ... | ... | @@ -96,7 +96,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 96 | 96 | &self, |
| 97 | 97 | alias_ty: ty::AliasTy<'tcx>, |
| 98 | 98 | ) -> Vec<ty::PolyTypeOutlivesPredicate<'tcx>> { |
| 99 | let erased_alias_ty = self.tcx.erase_and_anonymize_regions(alias_ty.to_ty(self.tcx)); | |
| 99 | // FIXME(#155345): Region handling should generally only | |
| 100 | // deal with rigid aliases, making sure we do so correctly | |
| 101 | // everywhere is effort, so we're just using `No` everywhere | |
| 102 | // for now. This should change soon. | |
| 103 | let erased_alias_ty = self.tcx.erase_and_anonymize_regions( | |
| 104 | ty::set_aliases_to_non_rigid(self.tcx, alias_ty) | |
| 105 | .skip_norm_wip() | |
| 106 | .to_ty(self.tcx, ty::IsRigid::No), | |
| 107 | ); | |
| 100 | 108 | self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty) |
| 101 | 109 | } |
| 102 | 110 | |
| ... | ... | @@ -104,8 +112,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 104 | 112 | pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> { |
| 105 | 113 | // Search the env for where clauses like `P: 'a`. |
| 106 | 114 | let env_bounds = self.approx_declared_bounds_from_env(alias_ty).into_iter().map(|binder| { |
| 115 | // FIXME(#155345): We probably want to assert the alias is rigid here. | |
| 107 | 116 | if let Some(ty::OutlivesPredicate(ty, r)) = binder.no_bound_vars() |
| 108 | && let ty::Alias(alias_ty_from_bound) = *ty.kind() | |
| 117 | && let ty::Alias(_, alias_ty_from_bound) = *ty.kind() | |
| 109 | 118 | && alias_ty_from_bound == alias_ty |
| 110 | 119 | { |
| 111 | 120 | // Micro-optimize if this is an exact match (this |
| ... | ... | @@ -236,12 +245,19 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { |
| 236 | 245 | // And therefore we can safely use structural equality for alias types. |
| 237 | 246 | (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {} |
| 238 | 247 | (GenericKind::Placeholder(p1), ty::Placeholder(p2)) if p1 == p2 => {} |
| 239 | (GenericKind::Alias(a1), ty::Alias(a2)) if a1.kind == a2.kind => {} | |
| 248 | // FIXME(#155345): We probably want to assert that the rhs is rigid. | |
| 249 | (GenericKind::Alias(a1), ty::Alias(_, a2)) if a1.kind == a2.kind => {} | |
| 240 | 250 | _ => return None, |
| 241 | 251 | } |
| 242 | 252 | |
| 243 | 253 | let p_ty = p.to_ty(tcx); |
| 244 | let erased_p_ty = self.tcx.erase_and_anonymize_regions(p_ty); | |
| 254 | // FIXME(#155345): Region handling should generally only | |
| 255 | // deal with rigid aliases, making sure we do so correctly | |
| 256 | // everywhere is effort, so we're just using `No` everywhere | |
| 257 | // for now. This should change soon. | |
| 258 | let erased_p_ty = self.tcx.erase_and_anonymize_regions( | |
| 259 | ty::set_aliases_to_non_rigid(self.tcx, p_ty).skip_norm_wip(), | |
| 260 | ); | |
| 245 | 261 | (erased_p_ty == erased_ty).then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r))) |
| 246 | 262 | })); |
| 247 | 263 |
compiler/rustc_infer/src/infer/region_constraints/mod.rs+5-1| ... | ... | @@ -805,7 +805,11 @@ impl<'tcx> GenericKind<'tcx> { |
| 805 | 805 | match *self { |
| 806 | 806 | GenericKind::Param(ref p) => p.to_ty(tcx), |
| 807 | 807 | GenericKind::Placeholder(ref p) => Ty::new_placeholder(tcx, *p), |
| 808 | GenericKind::Alias(ref p) => p.to_ty(tcx), | |
| 808 | // FIXME(#155345): Region handling should generally only | |
| 809 | // deal with rigid aliases, making sure we do so correctly | |
| 810 | // everywhere is effort, so we're just using `No` everywhere | |
| 811 | // for now. This should change soon. | |
| 812 | GenericKind::Alias(ref p) => p.to_ty(tcx, ty::IsRigid::No), | |
| 809 | 813 | } |
| 810 | 814 | } |
| 811 | 815 | } |
compiler/rustc_infer/src/infer/relate/generalize.rs+36-22| ... | ... | @@ -433,13 +433,16 @@ impl<'tcx> Generalizer<'_, 'tcx> { |
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | |
| 436 | /// We only handle potentially normalizable aliases via this method. For rigid alias, | |
| 437 | /// we always generalize structurally. | |
| 438 | /// | |
| 436 | 439 | /// An occurs check failure inside of an alias does not mean |
| 437 | 440 | /// that the types definitely don't unify. We may be able |
| 438 | 441 | /// to normalize the alias after all. |
| 439 | 442 | /// |
| 440 | /// We handle this by lazily equating the alias and generalizing | |
| 441 | /// it to an inference variable. In the new solver, we always | |
| 442 | /// generalize to an infer var unless the alias contains escaping | |
| 443 | /// We handle this by lazily equating the normalizable alias | |
| 444 | /// and generalizing it to an inference variable. In the new solver, | |
| 445 | /// we always generalize to an infer var unless the alias contains escaping | |
| 443 | 446 | /// bound variables. |
| 444 | 447 | /// |
| 445 | 448 | /// Correctly handling aliases with escaping bound variables is |
| ... | ... | @@ -467,7 +470,7 @@ impl<'tcx> Generalizer<'_, 'tcx> { |
| 467 | 470 | |
| 468 | 471 | let is_nested_alias = mem::replace(&mut self.in_alias, true); |
| 469 | 472 | let result = match self.relate(alias, alias) { |
| 470 | Ok(alias) => Ok(alias.to_term(self.cx())), | |
| 473 | Ok(alias) => Ok(alias.to_term(self.cx(), ty::IsRigid::No)), | |
| 471 | 474 | Err(e) => { |
| 472 | 475 | if is_nested_alias { |
| 473 | 476 | return Err(e); |
| ... | ... | @@ -636,7 +639,9 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { |
| 636 | 639 | } |
| 637 | 640 | } |
| 638 | 641 | |
| 639 | ty::Alias(data) => match self.structurally_relate_aliases { | |
| 642 | // We only need to be careful with potentially normalizeable | |
| 643 | // aliases here. See `generalize_alias_term` for more information. | |
| 644 | ty::Alias(ty::IsRigid::No, data) => match self.structurally_relate_aliases { | |
| 640 | 645 | StructurallyRelateAliases::No => { |
| 641 | 646 | self.generalize_alias_term(data.into()).map(|v| v.expect_type()) |
| 642 | 647 | } |
| ... | ... | @@ -752,24 +757,33 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> { |
| 752 | 757 | // |
| 753 | 758 | // FIXME: replace the StructurallyRelateAliases::Yes branch with |
| 754 | 759 | // `structurally_relate_consts` once it is fully structural. |
| 755 | ty::ConstKind::Unevaluated(uv) => match self.structurally_relate_aliases { | |
| 756 | // Hack: Fall back to old behavior if GCE is enabled (it used to just be the Yes | |
| 757 | // path), as doing this new No path breaks some GCE things. I expect GCE to be | |
| 758 | // ripped out soon so this shouldn't matter soon. | |
| 759 | StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => { | |
| 760 | self.generalize_alias_term(uv.into()).map(|v| v.expect_const()) | |
| 761 | } | |
| 762 | _ => { | |
| 763 | let ty::UnevaluatedConst { kind, args, .. } = uv; | |
| 764 | let args = self.relate_with_variance( | |
| 765 | ty::Invariant, | |
| 766 | ty::VarianceDiagInfo::default(), | |
| 767 | args, | |
| 768 | args, | |
| 769 | )?; | |
| 770 | Ok(ty::Const::new_unevaluated(tcx, ty::UnevaluatedConst::new(tcx, kind, args))) | |
| 760 | // | |
| 761 | // We only need to be careful with potentially normalizeable | |
| 762 | // aliases here. See `generalize_alias_term` for more information. | |
| 763 | ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { | |
| 764 | match self.structurally_relate_aliases { | |
| 765 | // Hack: Fall back to old behavior if GCE is enabled (it used to just be the Yes | |
| 766 | // path), as doing this new No path breaks some GCE things. I expect GCE to be | |
| 767 | // ripped out soon so this shouldn't matter soon. | |
| 768 | StructurallyRelateAliases::No if !tcx.features().generic_const_exprs() => { | |
| 769 | self.generalize_alias_term(uv.into()).map(|v| v.expect_const()) | |
| 770 | } | |
| 771 | _ => { | |
| 772 | let ty::UnevaluatedConst { kind, args, .. } = uv; | |
| 773 | let args = self.relate_with_variance( | |
| 774 | ty::Invariant, | |
| 775 | ty::VarianceDiagInfo::default(), | |
| 776 | args, | |
| 777 | args, | |
| 778 | )?; | |
| 779 | Ok(ty::Const::new_unevaluated( | |
| 780 | tcx, | |
| 781 | ty::IsRigid::No, | |
| 782 | ty::UnevaluatedConst::new(tcx, kind, args), | |
| 783 | )) | |
| 784 | } | |
| 771 | 785 | } |
| 772 | }, | |
| 786 | } | |
| 773 | 787 | ty::ConstKind::Placeholder(placeholder) => { |
| 774 | 788 | if self.for_universe.can_name(placeholder.universe) { |
| 775 | 789 | Ok(c) |
compiler/rustc_infer/src/infer/relate/lattice.rs+4-4| ... | ... | @@ -161,12 +161,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> { |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | ( |
| 164 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 165 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 164 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 165 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 166 | 166 | ) if a_def_id == b_def_id => super_combine_tys(infcx, self, a, b), |
| 167 | 167 | |
| 168 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 169 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 168 | (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 169 | | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 170 | 170 | if def_id.is_local() && !infcx.next_trait_solver() => |
| 171 | 171 | { |
| 172 | 172 | self.register_goals(infcx.handle_opaque_type( |
compiler/rustc_infer/src/infer/relate/type_relating.rs+13-5| ... | ... | @@ -2,7 +2,7 @@ use rustc_hir::def_id::DefId; |
| 2 | 2 | use rustc_middle::traits::solve::Goal; |
| 3 | 3 | use rustc_middle::ty::relate::combine::{combine_ty_args, super_combine_consts, super_combine_tys}; |
| 4 | 4 | use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation, relate_args_invariantly}; |
| 5 | use rustc_middle::ty::{self, DelayedSet, Ty, TyCtxt, TyVar}; | |
| 5 | use rustc_middle::ty::{self, DelayedSet, Ty, TyCtxt, TyVar, TypeVisitableExt}; | |
| 6 | 6 | use rustc_span::Span; |
| 7 | 7 | use tracing::{debug, instrument}; |
| 8 | 8 | |
| ... | ... | @@ -118,6 +118,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> { |
| 118 | 118 | |
| 119 | 119 | #[instrument(skip(self), level = "trace")] |
| 120 | 120 | fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> { |
| 121 | // We don't use the rigid marker in the old solver. | |
| 122 | debug_assert!(!a.has_rigid_aliases()); | |
| 123 | debug_assert!(!b.has_rigid_aliases()); | |
| 124 | ||
| 121 | 125 | if a == b { |
| 122 | 126 | return Ok(a); |
| 123 | 127 | } |
| ... | ... | @@ -184,14 +188,14 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> { |
| 184 | 188 | } |
| 185 | 189 | |
| 186 | 190 | ( |
| 187 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 188 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 191 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: a_def_id }, .. }), | |
| 192 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: b_def_id }, .. }), | |
| 189 | 193 | ) if a_def_id == b_def_id => { |
| 190 | 194 | super_combine_tys(infcx, self, a, b)?; |
| 191 | 195 | } |
| 192 | 196 | |
| 193 | (&ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 194 | | (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 197 | (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) | |
| 198 | | (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 195 | 199 | if self.define_opaque_types == DefineOpaqueTypes::Yes && def_id.is_local() => |
| 196 | 200 | { |
| 197 | 201 | self.register_goals(infcx.handle_opaque_type( |
| ... | ... | @@ -261,6 +265,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> { |
| 261 | 265 | a: ty::Const<'tcx>, |
| 262 | 266 | b: ty::Const<'tcx>, |
| 263 | 267 | ) -> RelateResult<'tcx, ty::Const<'tcx>> { |
| 268 | // We don't use the rigid marker in the old solver. | |
| 269 | debug_assert!(!a.has_rigid_aliases()); | |
| 270 | debug_assert!(!b.has_rigid_aliases()); | |
| 271 | ||
| 264 | 272 | super_combine_consts(self.infcx, self, a, b) |
| 265 | 273 | } |
| 266 | 274 |
compiler/rustc_lint/src/context.rs+1-1| ... | ... | @@ -831,7 +831,7 @@ impl<'tcx> LateContext<'tcx> { |
| 831 | 831 | tcx.associated_items(trait_id) |
| 832 | 832 | .find_by_ident_and_kind(tcx, Ident::with_dummy_span(name), ty::AssocTag::Type, trait_id) |
| 833 | 833 | .and_then(|assoc| { |
| 834 | let proj = Ty::new_projection(tcx, assoc.def_id, [self_ty]); | |
| 834 | let proj = Ty::new_projection(tcx, ty::IsRigid::No, assoc.def_id, [self_ty]); | |
| 835 | 835 | tcx.try_normalize_erasing_regions(self.typing_env(), Unnormalized::new_wip(proj)) |
| 836 | 836 | .ok() |
| 837 | 837 | }) |
compiler/rustc_lint/src/foreign_modules.rs+6-6| ... | ... | @@ -355,16 +355,16 @@ fn structurally_same_type_impl<'tcx>( |
| 355 | 355 | | (ty::Coroutine(..), ty::Coroutine(..)) |
| 356 | 356 | | (ty::CoroutineWitness(..), ty::CoroutineWitness(..)) |
| 357 | 357 | | ( |
| 358 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }), | |
| 359 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }), | |
| 358 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }), | |
| 359 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }), | |
| 360 | 360 | ) |
| 361 | 361 | | ( |
| 362 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }), | |
| 363 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }), | |
| 362 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }), | |
| 363 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }), | |
| 364 | 364 | ) |
| 365 | 365 | | ( |
| 366 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 367 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 366 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 367 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 368 | 368 | ) => false, |
| 369 | 369 | |
| 370 | 370 | // These definitely should have been caught above. |
compiler/rustc_lint/src/gpukernel_abi.rs+1-1| ... | ... | @@ -115,7 +115,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for CheckGpuKernelTypes<'tcx> { |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | ty::Adt(_, _) |
| 118 | | ty::Alias(_) | |
| 118 | | ty::Alias(_, _) | |
| 119 | 119 | | ty::Array(_, _) |
| 120 | 120 | | ty::Bound(_, _) |
| 121 | 121 | | ty::Closure(_, _) |
compiler/rustc_lint/src/impl_trait_overcaptures.rs+2-2| ... | ... | @@ -243,12 +243,12 @@ where |
| 243 | 243 | return; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | if let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) = *t.kind() | |
| 246 | if let ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) = *t.kind() | |
| 247 | 247 | && self.tcx.is_impl_trait_in_trait(def_id) |
| 248 | 248 | { |
| 249 | 249 | // visit the opaque of the RPITIT |
| 250 | 250 | self.tcx.type_of(def_id).instantiate(self.tcx, args).skip_norm_wip().visit_with(self) |
| 251 | } else if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args: opaque_ty_args, .. }) = *t.kind() | |
| 251 | } else if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args: opaque_ty_args, .. }) = *t.kind() | |
| 252 | 252 | && let Some(opaque_def_id) = def_id.as_local() |
| 253 | 253 | // Don't recurse infinitely on an opaque |
| 254 | 254 | && self.seen.insert(opaque_def_id) |
compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs+4-3| ... | ... | @@ -103,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 103 | 103 | let Some(proj_term) = proj.term.as_type() else { return }; |
| 104 | 104 | |
| 105 | 105 | // HACK: `impl Trait<Assoc = impl Trait2>` from an RPIT is "ok"... |
| 106 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: opaque_def_id }, .. }) = | |
| 106 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: opaque_def_id }, .. }) = | |
| 107 | 107 | *proj_term.kind() |
| 108 | 108 | && cx.tcx.parent(opaque_def_id) == def_id |
| 109 | 109 | && matches!( |
| ... | ... | @@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | let proj_ty = proj.projection_term.expect_ty().to_ty(cx.tcx); | |
| 133 | let proj_ty = proj.projection_term.expect_ty().to_ty(cx.tcx,ty::IsRigid::No); | |
| 134 | 134 | // For every instance of the projection type in the bounds, |
| 135 | 135 | // replace them with the term we're assigning to the associated |
| 136 | 136 | // type in our opaque type. |
| ... | ... | @@ -177,7 +177,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 177 | 177 | // then we can emit a suggestion to add the bound. |
| 178 | 178 | let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { |
| 179 | 179 | ( |
| 180 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), | |
| 180 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), | |
| 181 | 181 | ty::ClauseKind::Trait(trait_pred), |
| 182 | 182 | ) => Some(AddBound { |
| 183 | 183 | suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), |
| ... | ... | @@ -192,6 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { |
| 192 | 192 | OpaqueHiddenInferredBoundLint { |
| 193 | 193 | ty: Ty::new_opaque( |
| 194 | 194 | cx.tcx, |
| 195 | ty::IsRigid::No, | |
| 195 | 196 | def_id, |
| 196 | 197 | ty::GenericArgs::identity_for_item(cx.tcx, def_id), |
| 197 | 198 | ), |
compiler/rustc_lint/src/types/improper_ctypes.rs+14-9| ... | ... | @@ -889,16 +889,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 889 | 889 | |
| 890 | 890 | // While opaque types are checked for earlier, if a projection in a struct field |
| 891 | 891 | // normalizes to an opaque type, then it will reach this branch. |
| 892 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 892 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 893 | 893 | FfiUnsafe { ty, reason: msg!("opaque types have no C equivalent"), help: None } |
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe, |
| 897 | 897 | // so they are currently ignored for the purposes of this lint. |
| 898 | 898 | ty::Param(..) |
| 899 | | ty::Alias(ty::AliasTy { | |
| 900 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 901 | }) if state.can_expect_ty_params() => FfiSafe, | |
| 899 | | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }) | |
| 900 | if state.can_expect_ty_params() => | |
| 901 | { | |
| 902 | FfiSafe | |
| 903 | } | |
| 902 | 904 | |
| 903 | 905 | ty::UnsafeBinder(_) => FfiUnsafe { |
| 904 | 906 | ty, |
| ... | ... | @@ -920,10 +922,13 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 920 | 922 | }, |
| 921 | 923 | |
| 922 | 924 | ty::Param(..) |
| 923 | | ty::Alias(ty::AliasTy { | |
| 924 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 925 | .. | |
| 926 | }) | |
| 925 | | ty::Alias( | |
| 926 | _, | |
| 927 | ty::AliasTy { | |
| 928 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 929 | .. | |
| 930 | }, | |
| 931 | ) | |
| 927 | 932 | | ty::Infer(..) |
| 928 | 933 | | ty::Bound(..) |
| 929 | 934 | | ty::Error(_) |
| ... | ... | @@ -942,7 +947,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { |
| 942 | 947 | return ControlFlow::Continue(()); |
| 943 | 948 | } |
| 944 | 949 | |
| 945 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { | |
| 950 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { | |
| 946 | 951 | ControlFlow::Break(ty) |
| 947 | 952 | } else { |
| 948 | 953 | ty.super_visit_with(self) |
compiler/rustc_lint/src/unused/must_use.rs+7-5| ... | ... | @@ -176,10 +176,12 @@ pub fn is_ty_must_use<'tcx>( |
| 176 | 176 | ty::Adt(def, _) => { |
| 177 | 177 | is_def_must_use(cx, def.did(), expr.span).map_or(IsTyMustUse::No, IsTyMustUse::Yes) |
| 178 | 178 | } |
| 179 | ty::Alias(ty::AliasTy { | |
| 180 | kind: ty::Opaque { def_id: def } | ty::Projection { def_id: def }, | |
| 181 | .. | |
| 182 | }) => { | |
| 179 | ty::Alias( | |
| 180 | _, | |
| 181 | ty::AliasTy { | |
| 182 | kind: ty::Opaque { def_id: def } | ty::Projection { def_id: def }, .. | |
| 183 | }, | |
| 184 | ) => { | |
| 183 | 185 | elaborate( |
| 184 | 186 | cx.tcx, |
| 185 | 187 | cx.tcx |
| ... | ... | @@ -296,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { |
| 296 | 298 | |
| 297 | 299 | if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind |
| 298 | 300 | && let ty = cx.typeck_results().expr_ty(await_expr) |
| 299 | && let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: future_def_id }, .. }) = ty.kind() | |
| 301 | && let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: future_def_id }, .. }) = ty.kind() | |
| 300 | 302 | && cx.tcx.ty_is_opaque_future(ty) |
| 301 | 303 | && let async_fn_def_id = cx.tcx.parent(*future_def_id) |
| 302 | 304 | && matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn) |
compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs+4-3| ... | ... | @@ -14,7 +14,7 @@ use rustc_middle::middle::stability::DeprecationEntry; |
| 14 | 14 | use rustc_middle::queries::ExternProviders; |
| 15 | 15 | use rustc_middle::query::LocalCrate; |
| 16 | 16 | use rustc_middle::ty::fast_reject::SimplifiedType; |
| 17 | use rustc_middle::ty::{self, TyCtxt}; | |
| 17 | use rustc_middle::ty::{self, TyCtxt, TypeVisitable}; | |
| 18 | 18 | use rustc_middle::util::Providers; |
| 19 | 19 | use rustc_serialize::Decoder; |
| 20 | 20 | use rustc_session::StableCrateId; |
| ... | ... | @@ -39,10 +39,11 @@ impl<T> ProcessQueryValue<'_, T> for T { |
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | impl<'tcx, T> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T { | |
| 42 | // The `TypeVisitable` bound here is merely for `EarlyBinder`'s rigidness check. | |
| 43 | impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T { | |
| 43 | 44 | #[inline(always)] |
| 44 | 45 | fn process_decoded(self, _tcx: TyCtxt<'_>, _err: impl Fn() -> !) -> ty::EarlyBinder<'tcx, T> { |
| 45 | ty::EarlyBinder::bind(self) | |
| 46 | ty::EarlyBinder::bind_no_rigid_aliases(self) | |
| 46 | 47 | } |
| 47 | 48 | } |
| 48 | 49 |
compiler/rustc_middle/src/mir/consts.rs+14-9| ... | ... | @@ -239,14 +239,17 @@ impl<'tcx> Const<'tcx> { |
| 239 | 239 | tcx: TyCtxt<'tcx>, |
| 240 | 240 | def_id: DefId, |
| 241 | 241 | ) -> ty::EarlyBinder<'tcx, Const<'tcx>> { |
| 242 | ty::EarlyBinder::bind(Const::Unevaluated( | |
| 243 | UnevaluatedConst { | |
| 244 | def: def_id, | |
| 245 | args: ty::GenericArgs::identity_for_item(tcx, def_id), | |
| 246 | promoted: None, | |
| 247 | }, | |
| 248 | tcx.type_of(def_id).skip_binder(), | |
| 249 | )) | |
| 242 | ty::EarlyBinder::bind( | |
| 243 | tcx, | |
| 244 | Const::Unevaluated( | |
| 245 | UnevaluatedConst { | |
| 246 | def: def_id, | |
| 247 | args: ty::GenericArgs::identity_for_item(tcx, def_id), | |
| 248 | promoted: None, | |
| 249 | }, | |
| 250 | tcx.type_of(def_id).skip_binder(), | |
| 251 | ), | |
| 252 | ) | |
| 250 | 253 | } |
| 251 | 254 | |
| 252 | 255 | #[inline(always)] |
| ... | ... | @@ -317,7 +320,9 @@ impl<'tcx> Const<'tcx> { |
| 317 | 320 | ) -> Result<ConstValue, ErrorHandled> { |
| 318 | 321 | match self { |
| 319 | 322 | Const::Ty(_, c) => { |
| 320 | if c.has_non_region_param() { | |
| 323 | // FIXME(generic_const_exprs): We shouldn't encounter placeholders here | |
| 324 | // and could change this to ICE when encountering them instead. | |
| 325 | if c.has_non_region_param() || c.has_non_region_placeholders() { | |
| 321 | 326 | return Err(ErrorHandled::TooGeneric(span)); |
| 322 | 327 | } |
| 323 | 328 |
compiler/rustc_middle/src/mir/mod.rs+3-3| ... | ... | @@ -530,8 +530,8 @@ impl<'tcx> Body<'tcx> { |
| 530 | 530 | |
| 531 | 531 | /// Returns the return type; it always return first element from `local_decls` array. |
| 532 | 532 | #[inline] |
| 533 | pub fn bound_return_ty(&self) -> ty::EarlyBinder<'tcx, Ty<'tcx>> { | |
| 534 | ty::EarlyBinder::bind(self.local_decls[RETURN_PLACE].ty) | |
| 533 | pub fn bound_return_ty(&self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<'tcx, Ty<'tcx>> { | |
| 534 | ty::EarlyBinder::bind(tcx, self.local_decls[RETURN_PLACE].ty) | |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | /// Gets the location of the terminator for the given block. |
| ... | ... | @@ -624,7 +624,7 @@ impl<'tcx> Body<'tcx> { |
| 624 | 624 | let mono_literal = instance.instantiate_mir_and_normalize_erasing_regions( |
| 625 | 625 | tcx, |
| 626 | 626 | typing_env, |
| 627 | crate::ty::EarlyBinder::bind(constant.const_), | |
| 627 | crate::ty::EarlyBinder::bind(tcx, constant.const_), | |
| 628 | 628 | ); |
| 629 | 629 | mono_literal.try_eval_bits(tcx, typing_env) |
| 630 | 630 | }; |
compiler/rustc_middle/src/mir/pretty.rs+1-1| ... | ... | @@ -1491,7 +1491,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { |
| 1491 | 1491 | let val = match const_ { |
| 1492 | 1492 | Const::Ty(_, ct) => match ct.kind() { |
| 1493 | 1493 | ty::ConstKind::Param(p) => format!("ty::Param({p})"), |
| 1494 | ty::ConstKind::Unevaluated(uv) => { | |
| 1494 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 1495 | 1495 | let kind = match uv.kind { |
| 1496 | 1496 | ty::UnevaluatedConstKind::Projection { def_id } |
| 1497 | 1497 | | ty::UnevaluatedConstKind::Inherent { def_id } |
compiler/rustc_middle/src/query/keys.rs+1-1| ... | ... | @@ -391,7 +391,7 @@ fn def_id_of_type_cached<'a>(ty: Ty<'a>, visited: &mut SsoHashSet<Ty<'a>>) -> Op |
| 391 | 391 | | ty::CoroutineWitness(def_id, _) |
| 392 | 392 | | ty::Foreign(def_id) => Some(def_id), |
| 393 | 393 | |
| 394 | ty::Alias(alias) => match alias.kind { | |
| 394 | ty::Alias(_, alias) => match alias.kind { | |
| 395 | 395 | ty::AliasTyKind::Projection { def_id } |
| 396 | 396 | | ty::AliasTyKind::Inherent { def_id } |
| 397 | 397 | | ty::AliasTyKind::Opaque { def_id } |
compiler/rustc_middle/src/ty/abstract_const.rs+3-1| ... | ... | @@ -52,7 +52,9 @@ impl<'tcx> TyCtxt<'tcx> { |
| 52 | 52 | } |
| 53 | 53 | fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> { |
| 54 | 54 | let ct = match c.kind() { |
| 55 | ty::ConstKind::Unevaluated(uv) if let Some(def_id) = uv.kind.opt_def_id() => { | |
| 55 | ty::ConstKind::Unevaluated(_, uv) | |
| 56 | if let Some(def_id) = uv.kind.opt_def_id() => | |
| 57 | { | |
| 56 | 58 | match self.tcx.thir_abstract_const(def_id) { |
| 57 | 59 | Err(e) => ty::Const::new_error(self.tcx, e), |
| 58 | 60 | Ok(Some(bac)) => { |
compiler/rustc_middle/src/ty/adt.rs+1-1| ... | ... | @@ -292,7 +292,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> { |
| 292 | 292 | self, |
| 293 | 293 | tcx: TyCtxt<'tcx>, |
| 294 | 294 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = Ty<'tcx>>> { |
| 295 | ty::EarlyBinder::bind( | |
| 295 | ty::EarlyBinder::bind_iter( | |
| 296 | 296 | self.all_fields().map(move |field| tcx.type_of(field.did).skip_binder()), |
| 297 | 297 | ) |
| 298 | 298 | } |
compiler/rustc_middle/src/ty/consts.rs+12-4| ... | ... | @@ -107,8 +107,12 @@ impl<'tcx> Const<'tcx> { |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | #[inline] |
| 110 | pub fn new_unevaluated(tcx: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Const<'tcx> { | |
| 111 | Const::new(tcx, ty::ConstKind::Unevaluated(uv)) | |
| 110 | pub fn new_unevaluated( | |
| 111 | tcx: TyCtxt<'tcx>, | |
| 112 | is_rigid: ty::IsRigid, | |
| 113 | uv: ty::UnevaluatedConst<'tcx>, | |
| 114 | ) -> Const<'tcx> { | |
| 115 | Const::new(tcx, ty::ConstKind::Unevaluated(is_rigid, uv)) | |
| 112 | 116 | } |
| 113 | 117 | |
| 114 | 118 | #[inline] |
| ... | ... | @@ -190,8 +194,12 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> { |
| 190 | 194 | Const::new_placeholder(tcx, placeholder) |
| 191 | 195 | } |
| 192 | 196 | |
| 193 | fn new_unevaluated(interner: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Self { | |
| 194 | Const::new_unevaluated(interner, uv) | |
| 197 | fn new_unevaluated( | |
| 198 | interner: TyCtxt<'tcx>, | |
| 199 | is_rigid: ty::IsRigid, | |
| 200 | uv: ty::UnevaluatedConst<'tcx>, | |
| 201 | ) -> Self { | |
| 202 | Const::new_unevaluated(interner, is_rigid, uv) | |
| 195 | 203 | } |
| 196 | 204 | |
| 197 | 205 | fn new_expr(interner: TyCtxt<'tcx>, expr: ty::Expr<'tcx>) -> Self { |
compiler/rustc_middle/src/ty/context.rs+7-3| ... | ... | @@ -2058,7 +2058,7 @@ impl<'tcx> TyCtxt<'tcx> { |
| 2058 | 2058 | |
| 2059 | 2059 | /// Given a `ty`, return whether it's an `impl Future<...>`. |
| 2060 | 2060 | pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { |
| 2061 | let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *ty.kind() else { | |
| 2061 | let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = *ty.kind() else { | |
| 2062 | 2062 | return false; |
| 2063 | 2063 | }; |
| 2064 | 2064 | let future_trait = self.require_lang_item(LangItem::Future, DUMMY_SP); |
| ... | ... | @@ -2690,6 +2690,10 @@ impl<'tcx> TyCtxt<'tcx> { |
| 2690 | 2690 | self.sess.opts.unstable_opts.disable_fast_paths |
| 2691 | 2691 | } |
| 2692 | 2692 | |
| 2693 | pub fn renormalize_rigid_aliases(self) -> bool { | |
| 2694 | self.sess.opts.unstable_opts.renormalize_rigid_aliases | |
| 2695 | } | |
| 2696 | ||
| 2693 | 2697 | #[allow(rustc::bad_opt_access)] |
| 2694 | 2698 | pub fn use_typing_mode_post_typeck_until_borrowck(self) -> bool { |
| 2695 | 2699 | self.next_trait_solver_globally() |
| ... | ... | @@ -2706,8 +2710,8 @@ impl<'tcx> TyCtxt<'tcx> { |
| 2706 | 2710 | |
| 2707 | 2711 | pub fn get_impl_future_output_ty(self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> { |
| 2708 | 2712 | let (def_id, args) = match *ty.kind() { |
| 2709 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => (def_id, args), | |
| 2710 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 2713 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => (def_id, args), | |
| 2714 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) | |
| 2711 | 2715 | if self.is_impl_trait_in_trait(def_id) => |
| 2712 | 2716 | { |
| 2713 | 2717 | (def_id, args) |
compiler/rustc_middle/src/ty/context/impl_interner.rs+12-5| ... | ... | @@ -340,6 +340,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 340 | 340 | self.assumptions_on_binders() |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | fn renormalize_rigid_aliases(self) -> bool { | |
| 344 | self.renormalize_rigid_aliases() | |
| 345 | } | |
| 346 | ||
| 343 | 347 | fn coroutine_hidden_types( |
| 344 | 348 | self, |
| 345 | 349 | def_id: DefId, |
| ... | ... | @@ -388,7 +392,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 388 | 392 | self, |
| 389 | 393 | def_id: DefId, |
| 390 | 394 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> { |
| 391 | ty::EarlyBinder::bind( | |
| 395 | ty::EarlyBinder::bind_iter( | |
| 392 | 396 | self.predicates_of(def_id) |
| 393 | 397 | .instantiate_identity(self) |
| 394 | 398 | .predicates |
| ... | ... | @@ -401,7 +405,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 401 | 405 | self, |
| 402 | 406 | def_id: DefId, |
| 403 | 407 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> { |
| 404 | ty::EarlyBinder::bind( | |
| 408 | ty::EarlyBinder::bind_iter( | |
| 405 | 409 | self.predicates_of(def_id) |
| 406 | 410 | .instantiate_own_identity() |
| 407 | 411 | .map(|(clause, _)| clause.skip_normalization()), |
| ... | ... | @@ -456,7 +460,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 456 | 460 | self, |
| 457 | 461 | def_id: DefId, |
| 458 | 462 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> { |
| 459 | ty::EarlyBinder::bind( | |
| 463 | ty::EarlyBinder::bind_iter( | |
| 460 | 464 | self.const_conditions(def_id) |
| 461 | 465 | .instantiate_identity(self) |
| 462 | 466 | .into_iter() |
| ... | ... | @@ -468,7 +472,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 468 | 472 | self, |
| 469 | 473 | def_id: DefId, |
| 470 | 474 | ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> { |
| 471 | ty::EarlyBinder::bind( | |
| 475 | ty::EarlyBinder::bind_iter( | |
| 472 | 476 | self.explicit_implied_const_bounds(def_id) |
| 473 | 477 | .iter_identity_copied() |
| 474 | 478 | .map(Unnormalized::skip_normalization) |
| ... | ... | @@ -645,7 +649,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> { |
| 645 | 649 | // |
| 646 | 650 | // Impls which apply to an alias after normalization are handled by |
| 647 | 651 | // `assemble_candidates_after_normalizing_self_ty`. |
| 648 | ty::Alias(_) | ty::Placeholder(..) | ty::Error(_) => (), | |
| 652 | ty::Alias(ty::IsRigid::Yes, _) | ty::Placeholder(..) | ty::Error(_) => (), | |
| 653 | // FIXME(-Znext-solver=no): Need to support aliases not marked as | |
| 654 | // rigid for the old solver. | |
| 655 | ty::Alias(ty::IsRigid::No, _) => (), | |
| 649 | 656 | |
| 650 | 657 | // FIXME: These should ideally not exist as a self type. It would be nice for |
| 651 | 658 | // the builtin auto trait impls of coroutines to instead directly recurse |
compiler/rustc_middle/src/ty/diagnostics.rs+5-5| ... | ... | @@ -627,11 +627,11 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { |
| 627 | 627 | return ControlFlow::Break(()); |
| 628 | 628 | } |
| 629 | 629 | |
| 630 | Alias(AliasTy { kind: Opaque { def_id }, .. }) => { | |
| 630 | Alias(_, AliasTy { kind: Opaque { def_id }, .. }) => { | |
| 631 | 631 | let parent = self.tcx.parent(def_id); |
| 632 | 632 | let parent_ty = self.tcx.type_of(parent).instantiate_identity().skip_norm_wip(); |
| 633 | 633 | if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) |
| 634 | && let Alias(AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = | |
| 634 | && let Alias(_, AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = | |
| 635 | 635 | *parent_ty.kind() |
| 636 | 636 | && parent_opaque_def_id == def_id |
| 637 | 637 | { |
| ... | ... | @@ -641,7 +641,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> { |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | |
| 644 | Alias(AliasTy { kind: Projection { def_id }, .. }) | |
| 644 | Alias(_, AliasTy { kind: Projection { def_id }, .. }) | |
| 645 | 645 | if self.tcx.def_kind(def_id) != DefKind::AssocTy => |
| 646 | 646 | { |
| 647 | 647 | return ControlFlow::Break(()); |
| ... | ... | @@ -715,12 +715,12 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> { |
| 715 | 715 | placeholder |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | Alias(AliasTy { kind: Opaque { def_id }, .. }) => { | |
| 718 | Alias(_, AliasTy { kind: Opaque { def_id }, .. }) => { | |
| 719 | 719 | let parent = self.tcx.parent(def_id); |
| 720 | 720 | let parent_ty = self.tcx.type_of(parent).instantiate_identity().skip_norm_wip(); |
| 721 | 721 | if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = |
| 722 | 722 | self.tcx.def_kind(parent) |
| 723 | && let Alias(AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = | |
| 723 | && let Alias(_, AliasTy { kind: Opaque { def_id: parent_opaque_def_id }, .. }) = | |
| 724 | 724 | *parent_ty.kind() |
| 725 | 725 | && parent_opaque_def_id == def_id |
| 726 | 726 | { |
compiler/rustc_middle/src/ty/error.rs+9-9| ... | ... | @@ -148,11 +148,11 @@ impl<'tcx> Ty<'tcx> { |
| 148 | 148 | ty::Infer(ty::FreshTy(_)) => "fresh type".into(), |
| 149 | 149 | ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), |
| 150 | 150 | ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), |
| 151 | ty::Alias(ty::AliasTy { | |
| 152 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 153 | }) => "associated type".into(), | |
| 151 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }) => { | |
| 152 | "associated type".into() | |
| 153 | } | |
| 154 | 154 | ty::Param(p) => format!("type parameter `{p}`").into(), |
| 155 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 155 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => { | |
| 156 | 156 | if tcx.ty_is_opaque_future(self) { "future".into() } else { "opaque type".into() } |
| 157 | 157 | } |
| 158 | 158 | ty::Error(_) => "type error".into(), |
| ... | ... | @@ -207,12 +207,12 @@ impl<'tcx> Ty<'tcx> { |
| 207 | 207 | ty::Tuple(..) => "tuple".into(), |
| 208 | 208 | ty::Placeholder(..) => "higher-ranked type".into(), |
| 209 | 209 | ty::Bound(..) => "bound type variable".into(), |
| 210 | ty::Alias(ty::AliasTy { | |
| 211 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 212 | }) => "associated type".into(), | |
| 213 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => "type alias".into(), | |
| 210 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }) => { | |
| 211 | "associated type".into() | |
| 212 | } | |
| 213 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => "type alias".into(), | |
| 214 | 214 | ty::Param(_) => "type parameter".into(), |
| 215 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => "opaque type".into(), | |
| 215 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => "opaque type".into(), | |
| 216 | 216 | } |
| 217 | 217 | } |
| 218 | 218 | } |
compiler/rustc_middle/src/ty/generics.rs+16-10| ... | ... | @@ -402,8 +402,9 @@ impl<'tcx> GenericPredicates<'tcx> { |
| 402 | 402 | args: GenericArgsRef<'tcx>, |
| 403 | 403 | ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)> |
| 404 | 404 | + DoubleEndedIterator |
| 405 | + ExactSizeIterator { | |
| 406 | EarlyBinder::bind(self.predicates).iter_instantiated_copied(tcx, args).map(|u| { | |
| 405 | + ExactSizeIterator | |
| 406 | + Clone { | |
| 407 | EarlyBinder::bind_iter(self.predicates).iter_instantiated_copied(tcx, args).map(|u| { | |
| 407 | 408 | let (clause, span) = u.unzip(); |
| 408 | 409 | (clause, span.skip_normalization()) |
| 409 | 410 | }) |
| ... | ... | @@ -413,8 +414,9 @@ impl<'tcx> GenericPredicates<'tcx> { |
| 413 | 414 | self, |
| 414 | 415 | ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)> |
| 415 | 416 | + DoubleEndedIterator |
| 416 | + ExactSizeIterator { | |
| 417 | EarlyBinder::bind(self.predicates).iter_identity_copied().map(|u| { | |
| 417 | + ExactSizeIterator | |
| 418 | + Clone { | |
| 419 | EarlyBinder::bind_iter(self.predicates).iter_identity_copied().map(|u| { | |
| 418 | 420 | let (clause, span) = u.unzip(); |
| 419 | 421 | (clause, span.skip_normalization()) |
| 420 | 422 | }) |
| ... | ... | @@ -431,7 +433,7 @@ impl<'tcx> GenericPredicates<'tcx> { |
| 431 | 433 | tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, args); |
| 432 | 434 | } |
| 433 | 435 | instantiated.predicates.extend( |
| 434 | self.predicates.iter().map(|(p, _)| EarlyBinder::bind(*p).instantiate(tcx, args)), | |
| 436 | self.predicates.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)), | |
| 435 | 437 | ); |
| 436 | 438 | instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp)); |
| 437 | 439 | } |
| ... | ... | @@ -482,8 +484,9 @@ impl<'tcx> ConstConditions<'tcx> { |
| 482 | 484 | args: GenericArgsRef<'tcx>, |
| 483 | 485 | ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> |
| 484 | 486 | + DoubleEndedIterator |
| 485 | + ExactSizeIterator { | |
| 486 | EarlyBinder::bind(self.predicates).iter_instantiated_copied(tcx, args).map(|u| { | |
| 487 | + ExactSizeIterator | |
| 488 | + Clone { | |
| 489 | EarlyBinder::bind_iter(self.predicates).iter_instantiated_copied(tcx, args).map(|u| { | |
| 487 | 490 | let (trait_ref, span) = u.unzip(); |
| 488 | 491 | (trait_ref, span.skip_normalization()) |
| 489 | 492 | }) |
| ... | ... | @@ -493,8 +496,9 @@ impl<'tcx> ConstConditions<'tcx> { |
| 493 | 496 | self, |
| 494 | 497 | ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)> |
| 495 | 498 | + DoubleEndedIterator |
| 496 | + ExactSizeIterator { | |
| 497 | EarlyBinder::bind(self.predicates).iter_identity_copied().map(|u| { | |
| 499 | + ExactSizeIterator | |
| 500 | + Clone { | |
| 501 | EarlyBinder::bind_iter(self.predicates).iter_identity_copied().map(|u| { | |
| 498 | 502 | let (trait_ref, span) = u.unzip(); |
| 499 | 503 | (trait_ref, span.skip_normalization()) |
| 500 | 504 | }) |
| ... | ... | @@ -511,7 +515,9 @@ impl<'tcx> ConstConditions<'tcx> { |
| 511 | 515 | tcx.const_conditions(def_id).instantiate_into(tcx, instantiated, args); |
| 512 | 516 | } |
| 513 | 517 | instantiated.extend( |
| 514 | self.predicates.iter().map(|&(p, s)| (EarlyBinder::bind(p).instantiate(tcx, args), s)), | |
| 518 | self.predicates | |
| 519 | .iter() | |
| 520 | .map(|&(p, s)| (EarlyBinder::bind(tcx, p).instantiate(tcx, args), s)), | |
| 515 | 521 | ); |
| 516 | 522 | } |
| 517 | 523 |
compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs+2-2| ... | ... | @@ -243,7 +243,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { |
| 243 | 243 | fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> { |
| 244 | 244 | match self { |
| 245 | 245 | Self::ConstIsZero(c) => { |
| 246 | let c = ty::EarlyBinder::bind(c).instantiate(tcx, args).skip_norm_wip(); | |
| 246 | let c = ty::EarlyBinder::bind(tcx, c).instantiate(tcx, args).skip_norm_wip(); | |
| 247 | 247 | let pred = match c.try_to_target_usize(tcx) { |
| 248 | 248 | Some(0) => Self::True, |
| 249 | 249 | Some(1..) => Self::False, |
| ... | ... | @@ -252,7 +252,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { |
| 252 | 252 | Some(pred) |
| 253 | 253 | } |
| 254 | 254 | Self::GenericType(t) => Some( |
| 255 | ty::EarlyBinder::bind(t) | |
| 255 | ty::EarlyBinder::bind(tcx, t) | |
| 256 | 256 | .instantiate(tcx, args) |
| 257 | 257 | .skip_norm_wip() |
| 258 | 258 | .inhabited_predicate(tcx), |
compiler/rustc_middle/src/ty/inhabitedness/mod.rs+9-5| ... | ... | @@ -113,12 +113,16 @@ impl<'tcx> Ty<'tcx> { |
| 113 | 113 | InhabitedPredicate::True |
| 114 | 114 | } |
| 115 | 115 | Never => InhabitedPredicate::False, |
| 116 | // FIXME(#155345): This should only encounter rigid aliases with the new solver. | |
| 116 | 117 | Param(_) |
| 117 | | Alias(ty::AliasTy { | |
| 118 | kind: ty::Inherent { .. } | ty::Projection { .. } | ty::Free { .. }, | |
| 119 | .. | |
| 120 | }) => InhabitedPredicate::GenericType(self), | |
| 121 | &Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 118 | | Alias( | |
| 119 | _, | |
| 120 | ty::AliasTy { | |
| 121 | kind: ty::Inherent { .. } | ty::Projection { .. } | ty::Free { .. }, | |
| 122 | .. | |
| 123 | }, | |
| 124 | ) => InhabitedPredicate::GenericType(self), | |
| 125 | &Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 122 | 126 | match def_id.as_local() { |
| 123 | 127 | // Foreign opaque is considered inhabited. |
| 124 | 128 | None => InhabitedPredicate::True, |
compiler/rustc_middle/src/ty/instance.rs+1-2| ... | ... | @@ -916,11 +916,10 @@ impl<'tcx> Instance<'tcx> { |
| 916 | 916 | self.def.has_polymorphic_mir_body().then_some(self.args) |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, &T>) -> T | |
| 919 | pub fn instantiate_mir<T>(&self, tcx: TyCtxt<'tcx>, v: EarlyBinder<'tcx, T>) -> T | |
| 920 | 920 | where |
| 921 | 921 | T: TypeFoldable<TyCtxt<'tcx>> + Copy, |
| 922 | 922 | { |
| 923 | let v = v.map_bound(|v| *v); | |
| 924 | 923 | if let Some(args) = self.args_for_mir_body() { |
| 925 | 924 | v.instantiate(tcx, args).skip_norm_wip() |
| 926 | 925 | } else { |
compiler/rustc_middle/src/ty/layout.rs+12-5| ... | ... | @@ -408,11 +408,13 @@ impl<'tcx> SizeSkeleton<'tcx> { |
| 408 | 408 | ); |
| 409 | 409 | |
| 410 | 410 | match tail.kind() { |
| 411 | // FIXME(#155345): This should only handle rigid aliases if we're using | |
| 412 | // the new solver. | |
| 411 | 413 | ty::Param(_) |
| 412 | | ty::Alias(ty::AliasTy { | |
| 413 | kind: ty::Projection { .. } | ty::Inherent { .. }, | |
| 414 | .. | |
| 415 | }) => { | |
| 414 | | ty::Alias( | |
| 415 | _, | |
| 416 | ty::AliasTy { kind: ty::Projection { .. } | ty::Inherent { .. }, .. }, | |
| 417 | ) => { | |
| 416 | 418 | debug_assert!(tail.has_non_region_param()); |
| 417 | 419 | Ok(SizeSkeleton::Pointer { |
| 418 | 420 | non_zero, |
| ... | ... | @@ -915,7 +917,12 @@ where |
| 915 | 917 | { |
| 916 | 918 | let metadata = tcx.normalize_erasing_regions( |
| 917 | 919 | cx.typing_env(), |
| 918 | Unnormalized::new(Ty::new_projection(tcx, metadata_def_id, [pointee])), | |
| 920 | Unnormalized::new(Ty::new_projection( | |
| 921 | tcx, | |
| 922 | ty::IsRigid::No, | |
| 923 | metadata_def_id, | |
| 924 | [pointee], | |
| 925 | )), | |
| 919 | 926 | ); |
| 920 | 927 | |
| 921 | 928 | // Map `Metadata = DynMetadata<dyn Trait>` back to a vtable, since it |
compiler/rustc_middle/src/ty/mod.rs+17-4| ... | ... | @@ -688,16 +688,29 @@ impl<'tcx> Term<'tcx> { |
| 688 | 688 | pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> { |
| 689 | 689 | match self.kind() { |
| 690 | 690 | TermKind::Ty(ty) => match *ty.kind() { |
| 691 | ty::Alias(alias_ty) => Some(alias_ty.into()), | |
| 691 | ty::Alias(_, alias_ty) => Some(alias_ty.into()), | |
| 692 | 692 | _ => None, |
| 693 | 693 | }, |
| 694 | 694 | TermKind::Const(ct) => match ct.kind() { |
| 695 | ConstKind::Unevaluated(uv) => Some(uv.into()), | |
| 695 | ConstKind::Unevaluated(_, uv) => Some(uv.into()), | |
| 696 | 696 | _ => None, |
| 697 | 697 | }, |
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | 700 | |
| 701 | pub fn is_non_rigid_alias(self) -> bool { | |
| 702 | match self.kind() { | |
| 703 | ty::TermKind::Ty(ty) => match ty.kind() { | |
| 704 | ty::Alias(ty::IsRigid::No, _) => true, | |
| 705 | _ => false, | |
| 706 | }, | |
| 707 | ty::TermKind::Const(ct) => match ct.kind() { | |
| 708 | ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => true, | |
| 709 | _ => false, | |
| 710 | }, | |
| 711 | } | |
| 712 | } | |
| 713 | ||
| 701 | 714 | pub fn is_infer(&self) -> bool { |
| 702 | 715 | match self.kind() { |
| 703 | 716 | TermKind::Ty(ty) => ty.is_ty_var(), |
| ... | ... | @@ -926,7 +939,7 @@ impl<'tcx> ProvisionalHiddenType<'tcx> { |
| 926 | 939 | if cfg!(debug_assertions) && matches!(defining_scope_kind, DefiningScopeKind::HirTypeck) { |
| 927 | 940 | assert_eq!(result_ty, fold_regions(tcx, result_ty, |_, _| tcx.lifetimes.re_erased)); |
| 928 | 941 | } |
| 929 | DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(result_ty) } | |
| 942 | DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(tcx, result_ty) } | |
| 930 | 943 | } |
| 931 | 944 | } |
| 932 | 945 | |
| ... | ... | @@ -954,7 +967,7 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> { |
| 954 | 967 | pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> DefinitionSiteHiddenType<'tcx> { |
| 955 | 968 | DefinitionSiteHiddenType { |
| 956 | 969 | span: DUMMY_SP, |
| 957 | ty: ty::EarlyBinder::bind(Ty::new_error(tcx, guar)), | |
| 970 | ty: ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)), | |
| 958 | 971 | } |
| 959 | 972 | } |
| 960 | 973 |
compiler/rustc_middle/src/ty/offload_meta.rs+2-1| ... | ... | @@ -119,7 +119,8 @@ impl MappingFlags { |
| 119 | 119 | MappingFlags::LITERAL | MappingFlags::IMPLICIT |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Alias(_) | ty::Param(_) => { | |
| 122 | // FIXME: This should not treat aliases this way. | |
| 123 | ty::Adt(_, _) | ty::Tuple(_) | ty::Array(_, _) | ty::Alias(_, _) | ty::Param(_) => { | |
| 123 | 124 | MappingFlags::TO |
| 124 | 125 | } |
| 125 | 126 |
compiler/rustc_middle/src/ty/predicate.rs+1-1| ... | ... | @@ -419,7 +419,7 @@ impl<'tcx> Clause<'tcx> { |
| 419 | 419 | let shifted_pred = |
| 420 | 420 | tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder()); |
| 421 | 421 | // 2) Self: Bar1<'a, '^0.1> -> T: Bar1<'^0.0, '^0.1> |
| 422 | let new = EarlyBinder::bind(shifted_pred) | |
| 422 | let new = EarlyBinder::bind(tcx, shifted_pred) | |
| 423 | 423 | .instantiate(tcx, trait_ref.skip_binder().args) |
| 424 | 424 | .skip_norm_wip(); |
| 425 | 425 | // 3) ['x] + ['b] -> ['x, 'b] |
compiler/rustc_middle/src/ty/print/pretty.rs+11-9| ... | ... | @@ -820,13 +820,14 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 820 | 820 | } |
| 821 | 821 | ty::Foreign(def_id) => self.print_def_path(def_id, &[])?, |
| 822 | 822 | ty::Alias( |
| 823 | _, | |
| 823 | 824 | ref data @ ty::AliasTy { |
| 824 | 825 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, |
| 825 | 826 | .. |
| 826 | 827 | }, |
| 827 | 828 | ) => data.print(self)?, |
| 828 | 829 | ty::Placeholder(placeholder) => placeholder.print(self)?, |
| 829 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 830 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 830 | 831 | // We use verbose printing in 'NO_QUERIES' mode, to |
| 831 | 832 | // avoid needing to call `predicates_of`. This should |
| 832 | 833 | // only affect certain debug messages (e.g. messages printed |
| ... | ... | @@ -846,12 +847,13 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 846 | 847 | DefKind::TyAlias | DefKind::AssocTy => { |
| 847 | 848 | // NOTE: I know we should check for NO_QUERIES here, but it's alright. |
| 848 | 849 | // `type_of` on a type alias or assoc type should never cause a cycle. |
| 849 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: d }, .. }) = *self | |
| 850 | .tcx() | |
| 851 | .type_of(parent) | |
| 852 | .instantiate_identity() | |
| 853 | .skip_norm_wip() | |
| 854 | .kind() | |
| 850 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: d }, .. }) = | |
| 851 | *self | |
| 852 | .tcx() | |
| 853 | .type_of(parent) | |
| 854 | .instantiate_identity() | |
| 855 | .skip_norm_wip() | |
| 856 | .kind() | |
| 855 | 857 | { |
| 856 | 858 | if d == def_id { |
| 857 | 859 | // If the type alias directly starts with the `impl` of the |
| ... | ... | @@ -1367,7 +1369,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 1367 | 1369 | let fn_args = if self.tcx().features().return_type_notation() |
| 1368 | 1370 | && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) = |
| 1369 | 1371 | self.tcx().opt_rpitit_info(def_id) |
| 1370 | && let ty::Alias(alias_ty) = | |
| 1372 | && let ty::Alias(_, alias_ty) = | |
| 1371 | 1373 | self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind() |
| 1372 | 1374 | && let Some(projection_ty) = alias_ty.try_to_projection() |
| 1373 | 1375 | && projection_ty.kind == def_id |
| ... | ... | @@ -1566,7 +1568,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { |
| 1566 | 1568 | } |
| 1567 | 1569 | |
| 1568 | 1570 | match ct.kind() { |
| 1569 | ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, args, .. }) => { | |
| 1571 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => { | |
| 1570 | 1572 | match kind { |
| 1571 | 1573 | ty::UnevaluatedConstKind::Projection { def_id } |
| 1572 | 1574 | | ty::UnevaluatedConstKind::Inherent { def_id } |
compiler/rustc_middle/src/ty/significant_drop_order.rs+1-1| ... | ... | @@ -133,7 +133,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> { |
| 133 | 133 | | ty::FnPtr(_, _) |
| 134 | 134 | | ty::Tuple(_) |
| 135 | 135 | | ty::Dynamic(_, _) |
| 136 | | ty::Alias(_) | |
| 136 | | ty::Alias(_, _) | |
| 137 | 137 | | ty::Bound(_, _) |
| 138 | 138 | | ty::Pat(_, _) |
| 139 | 139 | | ty::Placeholder(_) |
compiler/rustc_middle/src/ty/structural_impls.rs+10-6| ... | ... | @@ -372,7 +372,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 372 | 372 | ty::CoroutineClosure(did, args) => { |
| 373 | 373 | ty::CoroutineClosure(did, args.try_fold_with(folder)?) |
| 374 | 374 | } |
| 375 | ty::Alias(data) => ty::Alias(data.try_fold_with(folder)?), | |
| 375 | ty::Alias(is_rigid, data) => ty::Alias(is_rigid, data.try_fold_with(folder)?), | |
| 376 | 376 | ty::Pat(ty, pat) => ty::Pat(ty.try_fold_with(folder)?, pat.try_fold_with(folder)?), |
| 377 | 377 | |
| 378 | 378 | ty::Bool |
| ... | ... | @@ -411,7 +411,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 411 | 411 | ty::CoroutineWitness(did, args) => ty::CoroutineWitness(did, args.fold_with(folder)), |
| 412 | 412 | ty::Closure(did, args) => ty::Closure(did, args.fold_with(folder)), |
| 413 | 413 | ty::CoroutineClosure(did, args) => ty::CoroutineClosure(did, args.fold_with(folder)), |
| 414 | ty::Alias(data) => ty::Alias(data.fold_with(folder)), | |
| 414 | ty::Alias(is_rigid, data) => ty::Alias(is_rigid, data.fold_with(folder)), | |
| 415 | 415 | ty::Pat(ty, pat) => ty::Pat(ty.fold_with(folder), pat.fold_with(folder)), |
| 416 | 416 | |
| 417 | 417 | ty::Bool |
| ... | ... | @@ -459,7 +459,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> { |
| 459 | 459 | ty::CoroutineWitness(_did, args) => args.visit_with(visitor), |
| 460 | 460 | ty::Closure(_did, args) => args.visit_with(visitor), |
| 461 | 461 | ty::CoroutineClosure(_did, args) => args.visit_with(visitor), |
| 462 | ty::Alias(data) => data.visit_with(visitor), | |
| 462 | ty::Alias(_, data) => data.visit_with(visitor), | |
| 463 | 463 | |
| 464 | 464 | ty::Pat(ty, pat) => { |
| 465 | 465 | try_visit!(ty.visit_with(visitor)); |
| ... | ... | @@ -634,7 +634,9 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 634 | 634 | folder: &mut F, |
| 635 | 635 | ) -> Result<Self, F::Error> { |
| 636 | 636 | let kind = match self.kind() { |
| 637 | ConstKind::Unevaluated(uv) => ConstKind::Unevaluated(uv.try_fold_with(folder)?), | |
| 637 | ConstKind::Unevaluated(is_rigid, uv) => { | |
| 638 | ConstKind::Unevaluated(is_rigid, uv.try_fold_with(folder)?) | |
| 639 | } | |
| 638 | 640 | ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?), |
| 639 | 641 | ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?), |
| 640 | 642 | |
| ... | ... | @@ -649,7 +651,9 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 649 | 651 | |
| 650 | 652 | fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self { |
| 651 | 653 | let kind = match self.kind() { |
| 652 | ConstKind::Unevaluated(uv) => ConstKind::Unevaluated(uv.fold_with(folder)), | |
| 654 | ConstKind::Unevaluated(is_rigid, uv) => { | |
| 655 | ConstKind::Unevaluated(is_rigid, uv.fold_with(folder)) | |
| 656 | } | |
| 653 | 657 | ConstKind::Value(v) => ConstKind::Value(v.fold_with(folder)), |
| 654 | 658 | ConstKind::Expr(e) => ConstKind::Expr(e.fold_with(folder)), |
| 655 | 659 | |
| ... | ... | @@ -666,7 +670,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 666 | 670 | impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> { |
| 667 | 671 | fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result { |
| 668 | 672 | match self.kind() { |
| 669 | ConstKind::Unevaluated(uv) => uv.visit_with(visitor), | |
| 673 | ConstKind::Unevaluated(_, uv) => uv.visit_with(visitor), | |
| 670 | 674 | ConstKind::Value(v) => v.visit_with(visitor), |
| 671 | 675 | ConstKind::Expr(e) => e.visit_with(visitor), |
| 672 | 676 | ConstKind::Error(e) => e.visit_with(visitor), |
compiler/rustc_middle/src/ty/sty.rs+36-11| ... | ... | @@ -166,7 +166,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> { |
| 166 | 166 | if tcx.is_async_drop_in_place_coroutine(def_id) { |
| 167 | 167 | layout.field_tys[*field].ty |
| 168 | 168 | } else { |
| 169 | ty::EarlyBinder::bind(layout.field_tys[*field].ty) | |
| 169 | ty::EarlyBinder::bind(tcx, layout.field_tys[*field].ty) | |
| 170 | 170 | .instantiate(tcx, self.args) |
| 171 | 171 | .skip_norm_wip() |
| 172 | 172 | } |
| ... | ... | @@ -481,7 +481,11 @@ impl<'tcx> Ty<'tcx> { |
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | #[inline] |
| 484 | pub fn new_alias(tcx: TyCtxt<'tcx>, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { | |
| 484 | pub fn new_alias( | |
| 485 | tcx: TyCtxt<'tcx>, | |
| 486 | is_rigid: ty::IsRigid, | |
| 487 | alias_ty: ty::AliasTy<'tcx>, | |
| 488 | ) -> Ty<'tcx> { | |
| 485 | 489 | if cfg!(debug_assertions) { |
| 486 | 490 | match alias_ty.kind { |
| 487 | 491 | ty::AliasTyKind::Projection { def_id } => { |
| ... | ... | @@ -498,7 +502,7 @@ impl<'tcx> Ty<'tcx> { |
| 498 | 502 | } |
| 499 | 503 | } |
| 500 | 504 | } |
| 501 | Ty::new(tcx, Alias(alias_ty)) | |
| 505 | Ty::new(tcx, Alias(is_rigid, alias_ty)) | |
| 502 | 506 | } |
| 503 | 507 | |
| 504 | 508 | #[inline] |
| ... | ... | @@ -537,8 +541,13 @@ impl<'tcx> Ty<'tcx> { |
| 537 | 541 | |
| 538 | 542 | #[inline] |
| 539 | 543 | #[instrument(level = "debug", skip(tcx))] |
| 540 | pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> { | |
| 541 | Ty::new_alias(tcx, AliasTy::new_from_args(tcx, ty::Opaque { def_id }, args)) | |
| 544 | pub fn new_opaque( | |
| 545 | tcx: TyCtxt<'tcx>, | |
| 546 | is_rigid: ty::IsRigid, | |
| 547 | def_id: DefId, | |
| 548 | args: GenericArgsRef<'tcx>, | |
| 549 | ) -> Ty<'tcx> { | |
| 550 | Ty::new_alias(tcx, is_rigid, AliasTy::new_from_args(tcx, ty::Opaque { def_id }, args)) | |
| 542 | 551 | } |
| 543 | 552 | |
| 544 | 553 | /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` |
| ... | ... | @@ -791,11 +800,13 @@ impl<'tcx> Ty<'tcx> { |
| 791 | 800 | #[inline] |
| 792 | 801 | pub fn new_projection_from_args( |
| 793 | 802 | tcx: TyCtxt<'tcx>, |
| 803 | is_rigid: ty::IsRigid, | |
| 794 | 804 | item_def_id: DefId, |
| 795 | 805 | args: ty::GenericArgsRef<'tcx>, |
| 796 | 806 | ) -> Ty<'tcx> { |
| 797 | 807 | Ty::new_alias( |
| 798 | 808 | tcx, |
| 809 | is_rigid, | |
| 799 | 810 | AliasTy::new_from_args(tcx, ty::Projection { def_id: item_def_id }, args), |
| 800 | 811 | ) |
| 801 | 812 | } |
| ... | ... | @@ -803,10 +814,15 @@ impl<'tcx> Ty<'tcx> { |
| 803 | 814 | #[inline] |
| 804 | 815 | pub fn new_projection( |
| 805 | 816 | tcx: TyCtxt<'tcx>, |
| 817 | is_rigid: ty::IsRigid, | |
| 806 | 818 | item_def_id: DefId, |
| 807 | 819 | args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, |
| 808 | 820 | ) -> Ty<'tcx> { |
| 809 | Ty::new_alias(tcx, AliasTy::new(tcx, ty::Projection { def_id: item_def_id }, args)) | |
| 821 | Ty::new_alias( | |
| 822 | tcx, | |
| 823 | is_rigid, | |
| 824 | AliasTy::new(tcx, ty::Projection { def_id: item_def_id }, args), | |
| 825 | ) | |
| 810 | 826 | } |
| 811 | 827 | |
| 812 | 828 | #[inline] |
| ... | ... | @@ -982,8 +998,12 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> { |
| 982 | 998 | Ty::new_canonical_bound(tcx, var) |
| 983 | 999 | } |
| 984 | 1000 | |
| 985 | fn new_alias(interner: TyCtxt<'tcx>, alias_ty: ty::AliasTy<'tcx>) -> Self { | |
| 986 | Ty::new_alias(interner, alias_ty) | |
| 1001 | fn new_alias( | |
| 1002 | interner: TyCtxt<'tcx>, | |
| 1003 | is_rigid: ty::IsRigid, | |
| 1004 | alias_ty: ty::AliasTy<'tcx>, | |
| 1005 | ) -> Self { | |
| 1006 | Ty::new_alias(interner, is_rigid, alias_ty) | |
| 987 | 1007 | } |
| 988 | 1008 | |
| 989 | 1009 | fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self { |
| ... | ... | @@ -1622,7 +1642,7 @@ impl<'tcx> Ty<'tcx> { |
| 1622 | 1642 | |
| 1623 | 1643 | #[inline] |
| 1624 | 1644 | pub fn is_opaque(self) -> bool { |
| 1625 | matches!(self.kind(), Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) | |
| 1645 | matches!(self.kind(), Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) | |
| 1626 | 1646 | } |
| 1627 | 1647 | |
| 1628 | 1648 | #[inline] |
| ... | ... | @@ -1704,7 +1724,12 @@ impl<'tcx> Ty<'tcx> { |
| 1704 | 1724 | let assoc_items = tcx.associated_item_def_ids( |
| 1705 | 1725 | tcx.require_lang_item(hir::LangItem::DiscriminantKind, DUMMY_SP), |
| 1706 | 1726 | ); |
| 1707 | Ty::new_projection_from_args(tcx, assoc_items[0], tcx.mk_args(&[self.into()])) | |
| 1727 | Ty::new_projection_from_args( | |
| 1728 | tcx, | |
| 1729 | ty::IsRigid::No, | |
| 1730 | assoc_items[0], | |
| 1731 | tcx.mk_args(&[self.into()]), | |
| 1732 | ) | |
| 1708 | 1733 | } |
| 1709 | 1734 | |
| 1710 | 1735 | ty::Pat(ty, _) => ty.discriminant_ty(tcx), |
| ... | ... | @@ -1837,7 +1862,7 @@ impl<'tcx> Ty<'tcx> { |
| 1837 | 1862 | Ok(metadata_ty) => metadata_ty, |
| 1838 | 1863 | Err(tail_ty) => { |
| 1839 | 1864 | let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, DUMMY_SP); |
| 1840 | Ty::new_projection(tcx, metadata_def_id, [tail_ty]) | |
| 1865 | Ty::new_projection(tcx, ty::IsRigid::No, metadata_def_id, [tail_ty]) | |
| 1841 | 1866 | } |
| 1842 | 1867 | } |
| 1843 | 1868 | } |
compiler/rustc_middle/src/ty/util.rs+6-4| ... | ... | @@ -894,12 +894,14 @@ impl<'tcx> TyCtxt<'tcx> { |
| 894 | 894 | /// [free]: ty::Free |
| 895 | 895 | /// [expand_free_alias_tys]: Self::expand_free_alias_tys |
| 896 | 896 | pub fn peel_off_free_alias_tys(self, mut ty: Ty<'tcx>) -> Ty<'tcx> { |
| 897 | let ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) = ty.kind() else { return ty }; | |
| 897 | let ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) = ty.kind() else { | |
| 898 | return ty; | |
| 899 | }; | |
| 898 | 900 | |
| 899 | 901 | let limit = self.recursion_limit(); |
| 900 | 902 | let mut depth = 0; |
| 901 | 903 | |
| 902 | while let &ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() { | |
| 904 | while let &ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() { | |
| 903 | 905 | if !limit.value_within_limit(depth) { |
| 904 | 906 | let guar = self.dcx().delayed_bug("overflow expanding free alias type"); |
| 905 | 907 | return Ty::new_error(self, guar); |
| ... | ... | @@ -993,7 +995,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> { |
| 993 | 995 | } |
| 994 | 996 | |
| 995 | 997 | fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { |
| 996 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() { | |
| 998 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *t.kind() { | |
| 997 | 999 | self.expand_opaque_ty(def_id, args).unwrap_or(t) |
| 998 | 1000 | } else if t.has_opaque_types() { |
| 999 | 1001 | t.super_fold_with(self) |
| ... | ... | @@ -1037,7 +1039,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> { |
| 1037 | 1039 | if !ty.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) { |
| 1038 | 1040 | return ty; |
| 1039 | 1041 | } |
| 1040 | let &ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() else { | |
| 1042 | let &ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) = ty.kind() else { | |
| 1041 | 1043 | return ty.super_fold_with(self); |
| 1042 | 1044 | }; |
| 1043 | 1045 | if !self.tcx.recursion_limit().value_within_limit(self.depth) { |
compiler/rustc_middle/src/ty/visit.rs+9-9| ... | ... | @@ -181,15 +181,15 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for LateBoundRegionsCollector<'tcx> { |
| 181 | 181 | match t.kind() { |
| 182 | 182 | // If we are only looking for "constrained" regions, we have to ignore the |
| 183 | 183 | // inputs to a projection as they may not appear in the normalized form. |
| 184 | ty::Alias(ty::AliasTy { | |
| 185 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. }, | |
| 186 | .. | |
| 187 | }) => { | |
| 188 | return; | |
| 189 | } | |
| 190 | // All free alias types should've been expanded beforehand. | |
| 191 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => { | |
| 192 | bug!("unexpected free alias type") | |
| 184 | ty::Alias(_, alias_ty) => { | |
| 185 | match alias_ty.kind { | |
| 186 | ty::Projection { .. } | ty::Inherent { .. } | ty::Opaque { .. } => return, | |
| 187 | ||
| 188 | // All free alias types should've been expanded beforehand. | |
| 189 | ty::Free { .. } => { | |
| 190 | bug!("unexpected free alias type") | |
| 191 | } | |
| 192 | } | |
| 193 | 193 | } |
| 194 | 194 | _ => {} |
| 195 | 195 | } |
compiler/rustc_mir_build/src/builder/block.rs+1-1| ... | ... | @@ -335,7 +335,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
| 335 | 335 | if destination_ty.is_unit() |
| 336 | 336 | || matches!( |
| 337 | 337 | destination_ty.kind(), |
| 338 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 338 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 339 | 339 | ) |
| 340 | 340 | { |
| 341 | 341 | // We only want to assign an implicit `()` as the return value of the block if the |
compiler/rustc_mir_build/src/builder/expr/as_constant.rs+1-1| ... | ... | @@ -77,7 +77,7 @@ pub(crate) fn as_constant_inner<'tcx>( |
| 77 | 77 | ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), |
| 78 | 78 | args, |
| 79 | 79 | ); |
| 80 | let ct = ty::Const::new_unevaluated(tcx, uneval); | |
| 80 | let ct = ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval); | |
| 81 | 81 | |
| 82 | 82 | let const_ = Const::Ty(ty, ct); |
| 83 | 83 | return ConstOperand { span, user_ty, const_ }; |
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs+3-3| ... | ... | @@ -49,7 +49,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { |
| 49 | 49 | let mut convert = ConstToPat::new(self, id, span, c); |
| 50 | 50 | |
| 51 | 51 | match c.kind() { |
| 52 | ty::ConstKind::Unevaluated(uv) => convert.unevaluated_to_pat(uv, ty), | |
| 52 | ty::ConstKind::Unevaluated(_, uv) => convert.unevaluated_to_pat(uv, ty), | |
| 53 | 53 | ty::ConstKind::Value(value) => convert.valtree_to_pat(value), |
| 54 | 54 | _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c), |
| 55 | 55 | } |
| ... | ... | @@ -77,7 +77,7 @@ impl<'tcx> ConstToPat<'tcx> { |
| 77 | 77 | |
| 78 | 78 | /// We errored. Signal that in the pattern, so that follow up errors can be silenced. |
| 79 | 79 | fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> { |
| 80 | if let ty::ConstKind::Unevaluated(uv) = self.c.kind() { | |
| 80 | if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() { | |
| 81 | 81 | if let ty::UnevaluatedConstKind::Projection { def_id } |
| 82 | 82 | | ty::UnevaluatedConstKind::Inherent { def_id } = uv.kind |
| 83 | 83 | && let Some(def_id) = def_id.as_local() |
| ... | ... | @@ -140,7 +140,7 @@ impl<'tcx> ConstToPat<'tcx> { |
| 140 | 140 | self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span }); |
| 141 | 141 | // We've emitted an error on the original const, it would be redundant to complain |
| 142 | 142 | // on its use as well. |
| 143 | if let ty::ConstKind::Unevaluated(uv) = self.c.kind() | |
| 143 | if let ty::ConstKind::Unevaluated(_, uv) = self.c.kind() | |
| 144 | 144 | && let ty::UnevaluatedConstKind::Projection { .. } |
| 145 | 145 | | ty::UnevaluatedConstKind::Inherent { .. } |
| 146 | 146 | | ty::UnevaluatedConstKind::Free { .. } = uv.kind |
compiler/rustc_mir_build/src/thir/pattern/mod.rs+1| ... | ... | @@ -659,6 +659,7 @@ impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> { |
| 659 | 659 | // generic args, instead of how we represent them in body expressions. |
| 660 | 660 | let c = ty::Const::new_unevaluated( |
| 661 | 661 | self.tcx, |
| 662 | ty::IsRigid::No, | |
| 662 | 663 | ty::UnevaluatedConst::new( |
| 663 | 664 | self.tcx, |
| 664 | 665 | ty::UnevaluatedConstKind::new_from_def_id(self.tcx, def_id), |
compiler/rustc_mir_dataflow/src/move_paths/builder.rs+2-2| ... | ... | @@ -165,7 +165,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { |
| 165 | 165 | | ty::Never |
| 166 | 166 | | ty::Tuple(_) |
| 167 | 167 | | ty::UnsafeBinder(_) |
| 168 | | ty::Alias(_) | |
| 168 | | ty::Alias(_, _) | |
| 169 | 169 | | ty::Param(_) |
| 170 | 170 | | ty::Bound(_, _) |
| 171 | 171 | | ty::Infer(_) |
| ... | ... | @@ -205,7 +205,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> { |
| 205 | 205 | | ty::CoroutineWitness(..) |
| 206 | 206 | | ty::Never |
| 207 | 207 | | ty::UnsafeBinder(_) |
| 208 | | ty::Alias(_) | |
| 208 | | ty::Alias(_, _) | |
| 209 | 209 | | ty::Param(_) |
| 210 | 210 | | ty::Bound(_, _) |
| 211 | 211 | | ty::Infer(_) |
compiler/rustc_mir_transform/src/coroutine/by_move_body.rs+1-1| ... | ... | @@ -247,7 +247,7 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>( |
| 247 | 247 | body_def.explicit_predicates_of(tcx.explicit_predicates_of(coroutine_def_id)); |
| 248 | 248 | |
| 249 | 249 | // The type of the coroutine is the `by_move_coroutine_ty`. |
| 250 | body_def.type_of(ty::EarlyBinder::bind(by_move_coroutine_ty)); | |
| 250 | body_def.type_of(ty::EarlyBinder::bind(tcx, by_move_coroutine_ty)); | |
| 251 | 251 | |
| 252 | 252 | body_def.mir_built(tcx.arena.alloc(Steal::new(by_move_body))); |
| 253 | 253 |
compiler/rustc_mir_transform/src/coroutine/layout.rs+1-1| ... | ... | @@ -612,7 +612,7 @@ fn check_must_not_suspend_ty<'tcx>( |
| 612 | 612 | } |
| 613 | 613 | ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data), |
| 614 | 614 | // FIXME: support adding the attribute to TAITs |
| 615 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { | |
| 615 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: def }, .. }) => { | |
| 616 | 616 | let mut has_emitted = false; |
| 617 | 617 | for &(predicate, _) in tcx.explicit_item_bounds(def).skip_binder() { |
| 618 | 618 | // We only look at the `DefId`, so it is safe to skip the binder here. |
compiler/rustc_mir_transform/src/cost_checker.rs+1-1| ... | ... | @@ -52,7 +52,7 @@ impl<'b, 'tcx> CostChecker<'b, 'tcx> { |
| 52 | 52 | |
| 53 | 53 | fn instantiate_ty(&self, v: Ty<'tcx>) -> Ty<'tcx> { |
| 54 | 54 | if let Some(instance) = self.instance { |
| 55 | instance.instantiate_mir(self.tcx, ty::EarlyBinder::bind(&v)) | |
| 55 | instance.instantiate_mir(self.tcx, ty::EarlyBinder::bind(self.tcx, v)) | |
| 56 | 56 | } else { |
| 57 | 57 | v |
| 58 | 58 | } |
compiler/rustc_mir_transform/src/function_item_references.rs+1-1| ... | ... | @@ -83,7 +83,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> { |
| 83 | 83 | // If the inner type matches the type bound by `Pointer` |
| 84 | 84 | if inner_ty == bound_ty { |
| 85 | 85 | // Do an instantiation using the parameters from the callsite |
| 86 | let instantiated_ty = EarlyBinder::bind(inner_ty) | |
| 86 | let instantiated_ty = EarlyBinder::bind(self.tcx, inner_ty) | |
| 87 | 87 | .instantiate(self.tcx, args_ref) |
| 88 | 88 | .skip_norm_wip(); |
| 89 | 89 | if let Some((fn_id, fn_args)) = |
compiler/rustc_mir_transform/src/inline.rs+5-4| ... | ... | @@ -420,9 +420,10 @@ impl<'tcx> Inliner<'tcx> for NormalInliner<'tcx> { |
| 420 | 420 | work_list.push(target); |
| 421 | 421 | |
| 422 | 422 | // If the place doesn't actually need dropping, treat it like a regular goto. |
| 423 | let ty = callsite | |
| 424 | .callee | |
| 425 | .instantiate_mir(tcx, ty::EarlyBinder::bind(&place.ty(callee_body, tcx).ty)); | |
| 423 | let ty = callsite.callee.instantiate_mir( | |
| 424 | tcx, | |
| 425 | ty::EarlyBinder::bind(tcx, place.ty(callee_body, tcx).ty), | |
| 426 | ); | |
| 426 | 427 | if ty.needs_drop(tcx, self.typing_env()) |
| 427 | 428 | && let UnwindAction::Cleanup(unwind) = unwind |
| 428 | 429 | { |
| ... | ... | @@ -638,7 +639,7 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>( |
| 638 | 639 | let Ok(callee_body) = callsite.callee.try_instantiate_mir_and_normalize_erasing_regions( |
| 639 | 640 | tcx, |
| 640 | 641 | inliner.typing_env(), |
| 641 | ty::EarlyBinder::bind(callee_body.clone()), | |
| 642 | ty::EarlyBinder::bind(tcx, callee_body.clone()), | |
| 642 | 643 | ) else { |
| 643 | 644 | debug!("failed to normalize callee body"); |
| 644 | 645 | return Err("implementation limitation -- could not normalize callee body"); |
compiler/rustc_mir_transform/src/inline/cycle.rs+1-1| ... | ... | @@ -76,7 +76,7 @@ fn process<'tcx>( |
| 76 | 76 | let Ok(args) = caller.try_instantiate_mir_and_normalize_erasing_regions( |
| 77 | 77 | tcx, |
| 78 | 78 | typing_env, |
| 79 | ty::EarlyBinder::bind(args), | |
| 79 | ty::EarlyBinder::bind(tcx, args), | |
| 80 | 80 | ) else { |
| 81 | 81 | trace!(?caller, ?typing_env, ?args, "cannot normalize, skipping"); |
| 82 | 82 | continue; |
compiler/rustc_mir_transform/src/liveness.rs+6-1| ... | ... | @@ -235,6 +235,11 @@ fn maybe_drop_guard<'tcx>( |
| 235 | 235 | ) -> bool { |
| 236 | 236 | if ever_dropped.contains(index) { |
| 237 | 237 | let ty = checked_places.places[index].ty(&body.local_decls, tcx).ty; |
| 238 | // FIXME(#155345): Liveness uses `TypingMode::PostAnalysis` | |
| 239 | // even though it's run on `mir_promoted` which is still | |
| 240 | // in an earlier `TypingMode`. This is odd and we have to | |
| 241 | // manually mark aliases as non-rigid here. | |
| 242 | let ty = ty::set_aliases_to_non_rigid(tcx, ty).skip_norm_wip(); | |
| 238 | 243 | matches!( |
| 239 | 244 | ty.kind(), |
| 240 | 245 | ty::Closure(..) |
| ... | ... | @@ -244,7 +249,7 @@ fn maybe_drop_guard<'tcx>( |
| 244 | 249 | | ty::Dynamic(..) |
| 245 | 250 | | ty::Array(..) |
| 246 | 251 | | ty::Slice(..) |
| 247 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 252 | | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 248 | 253 | ) && ty.needs_drop(tcx, typing_env) |
| 249 | 254 | } else { |
| 250 | 255 | false |
compiler/rustc_mir_transform/src/post_analysis_normalize.rs+19-8| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | |
| 5 | 5 | use rustc_middle::mir::visit::*; |
| 6 | 6 | use rustc_middle::mir::*; |
| 7 | use rustc_middle::ty::{self, Ty, TyCtxt, Unnormalized}; | |
| 7 | use rustc_middle::ty::{self, Ty, TyCtxt}; | |
| 8 | 8 | |
| 9 | 9 | pub(super) struct PostAnalysisNormalize; |
| 10 | 10 | |
| ... | ... | @@ -63,10 +63,10 @@ impl<'tcx> MutVisitor<'tcx> for PostAnalysisNormalizeVisitor<'tcx> { |
| 63 | 63 | // We have to use `try_normalize_erasing_regions` here, since it's |
| 64 | 64 | // possible that we visit impossible-to-satisfy where clauses here, |
| 65 | 65 | // see #91745 |
| 66 | if let Ok(c) = self | |
| 67 | .tcx | |
| 68 | .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(constant.const_)) | |
| 69 | { | |
| 66 | if let Ok(c) = self.tcx.try_normalize_erasing_regions( | |
| 67 | self.typing_env, | |
| 68 | ty::set_aliases_to_non_rigid(self.tcx, constant.const_), | |
| 69 | ) { | |
| 70 | 70 | constant.const_ = c; |
| 71 | 71 | } |
| 72 | 72 | self.super_const_operand(constant, location); |
| ... | ... | @@ -77,10 +77,21 @@ impl<'tcx> MutVisitor<'tcx> for PostAnalysisNormalizeVisitor<'tcx> { |
| 77 | 77 | // We have to use `try_normalize_erasing_regions` here, since it's |
| 78 | 78 | // possible that we visit impossible-to-satisfy where clauses here, |
| 79 | 79 | // see #91745 |
| 80 | if let Ok(t) = | |
| 81 | self.tcx.try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(*ty)) | |
| 82 | { | |
| 80 | if let Ok(t) = self.tcx.try_normalize_erasing_regions( | |
| 81 | self.typing_env, | |
| 82 | ty::set_aliases_to_non_rigid(self.tcx, *ty), | |
| 83 | ) { | |
| 83 | 84 | *ty = t; |
| 84 | 85 | } |
| 85 | 86 | } |
| 87 | ||
| 88 | #[inline] | |
| 89 | fn visit_args(&mut self, args: &mut ty::GenericArgsRef<'tcx>, _: Location) { | |
| 90 | if let Ok(a) = self.tcx.try_normalize_erasing_regions( | |
| 91 | self.typing_env, | |
| 92 | ty::set_aliases_to_non_rigid(self.tcx, *args), | |
| 93 | ) { | |
| 94 | *args = a; | |
| 95 | } | |
| 96 | } | |
| 86 | 97 | } |
compiler/rustc_mir_transform/src/shim.rs+1-1| ... | ... | @@ -107,7 +107,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, shim: ty::ShimKind<'tcx>) -> Body<'tcx> { |
| 107 | 107 | }; |
| 108 | 108 | |
| 109 | 109 | let mut body = |
| 110 | EarlyBinder::bind(body.clone()).instantiate(tcx, args).skip_norm_wip(); | |
| 110 | EarlyBinder::bind(tcx, body.clone()).instantiate(tcx, args).skip_norm_wip(); | |
| 111 | 111 | debug!("make_shim({:?}) = {:?}", shim, body); |
| 112 | 112 | |
| 113 | 113 | pm::run_passes( |
compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs+3-2| ... | ... | @@ -23,7 +23,8 @@ pub(super) fn build_async_destructor_ctor_shim<'tcx>( |
| 23 | 23 | debug_assert_eq!(Some(def_id), tcx.lang_items().async_drop_in_place_fn()); |
| 24 | 24 | let generic_body = tcx.optimized_mir(def_id); |
| 25 | 25 | let args = tcx.mk_args(&[ty.into()]); |
| 26 | let mut body = EarlyBinder::bind(generic_body.clone()).instantiate(tcx, args).skip_norm_wip(); | |
| 26 | let mut body = | |
| 27 | EarlyBinder::bind(tcx, generic_body.clone()).instantiate(tcx, args).skip_norm_wip(); | |
| 27 | 28 | |
| 28 | 29 | // Minimal shim passes except MentionedItems, |
| 29 | 30 | // it causes error "mentioned_items for DefId(...async_drop_in_place...) have already been set |
| ... | ... | @@ -206,7 +207,7 @@ fn build_adrop_for_coroutine_shim<'tcx>( |
| 206 | 207 | let source_info = SourceInfo::outermost(span); |
| 207 | 208 | let body = tcx.optimized_mir(*coroutine_def_id).future_drop_poll().unwrap(); |
| 208 | 209 | let mut body: Body<'tcx> = |
| 209 | EarlyBinder::bind(body.clone()).instantiate(tcx, impl_args).skip_norm_wip(); | |
| 210 | EarlyBinder::bind(tcx, body.clone()).instantiate(tcx, impl_args).skip_norm_wip(); | |
| 210 | 211 | body.source.instance = ty::InstanceKind::Shim(shim); |
| 211 | 212 | body.phase = MirPhase::Runtime(RuntimePhase::Initial); |
| 212 | 213 | body.var_debug_info.clear(); |
compiler/rustc_mir_transform/src/validate.rs+3-3| ... | ... | @@ -679,7 +679,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 679 | 679 | }; |
| 680 | 680 | |
| 681 | 681 | let kind = match parent_ty.ty.kind() { |
| 682 | &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 682 | &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 683 | 683 | self.tcx.type_of(def_id).instantiate(self.tcx, args).skip_norm_wip().kind() |
| 684 | 684 | } |
| 685 | 685 | kind => kind, |
| ... | ... | @@ -783,7 +783,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 783 | 783 | return; |
| 784 | 784 | }; |
| 785 | 785 | |
| 786 | ty::EarlyBinder::bind(f_ty.ty) | |
| 786 | ty::EarlyBinder::bind(self.tcx, f_ty.ty) | |
| 787 | 787 | .instantiate(self.tcx, args) |
| 788 | 788 | .skip_norm_wip() |
| 789 | 789 | } else { |
| ... | ... | @@ -1551,7 +1551,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { |
| 1551 | 1551 | pty.kind(), |
| 1552 | 1552 | ty::Adt(..) |
| 1553 | 1553 | | ty::Coroutine(..) |
| 1554 | | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 1554 | | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 1555 | 1555 | ) { |
| 1556 | 1556 | self.fail( |
| 1557 | 1557 | location, |
compiler/rustc_monomorphize/src/collector.rs+2-2| ... | ... | @@ -633,7 +633,7 @@ fn check_normalization_error<'tcx>( |
| 633 | 633 | match self.instance.try_instantiate_mir_and_normalize_erasing_regions( |
| 634 | 634 | self.tcx, |
| 635 | 635 | ty::TypingEnv::fully_monomorphized(), |
| 636 | ty::EarlyBinder::bind(t), | |
| 636 | ty::EarlyBinder::bind(self.tcx, t), | |
| 637 | 637 | ) { |
| 638 | 638 | Ok(_) => ControlFlow::Continue(()), |
| 639 | 639 | Err(_) => ControlFlow::Break(()), |
| ... | ... | @@ -697,7 +697,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { |
| 697 | 697 | self.instance.instantiate_mir_and_normalize_erasing_regions( |
| 698 | 698 | self.tcx, |
| 699 | 699 | ty::TypingEnv::fully_monomorphized(), |
| 700 | ty::EarlyBinder::bind(value), | |
| 700 | ty::EarlyBinder::bind(self.tcx, value), | |
| 701 | 701 | ) |
| 702 | 702 | } |
| 703 | 703 |
compiler/rustc_monomorphize/src/mono_checks/abi_check.rs+1-1| ... | ... | @@ -242,7 +242,7 @@ fn check_callees_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>, body: &m |
| 242 | 242 | let callee_ty = instance.instantiate_mir_and_normalize_erasing_regions( |
| 243 | 243 | tcx, |
| 244 | 244 | ty::TypingEnv::fully_monomorphized(), |
| 245 | ty::EarlyBinder::bind(callee_ty), | |
| 245 | ty::EarlyBinder::bind(tcx, callee_ty), | |
| 246 | 246 | ); |
| 247 | 247 | check_call_site_abi(tcx, callee_ty, body.source.instance, || { |
| 248 | 248 | let loc = Location { |
compiler/rustc_monomorphize/src/mono_checks/move_check.rs+1-1| ... | ... | @@ -60,7 +60,7 @@ impl<'tcx> MoveCheckVisitor<'tcx> { |
| 60 | 60 | self.instance.instantiate_mir_and_normalize_erasing_regions( |
| 61 | 61 | self.tcx, |
| 62 | 62 | ty::TypingEnv::fully_monomorphized(), |
| 63 | ty::EarlyBinder::bind(value), | |
| 63 | ty::EarlyBinder::bind(self.tcx, value), | |
| 64 | 64 | ) |
| 65 | 65 | } |
| 66 | 66 |
compiler/rustc_monomorphize/src/util.rs+2-2| ... | ... | @@ -30,12 +30,12 @@ pub(crate) fn dump_closure_profile<'tcx>(tcx: TyCtxt<'tcx>, closure_instance: In |
| 30 | 30 | let before_feature_tys = tcx.instantiate_and_normalize_erasing_regions( |
| 31 | 31 | closure_instance.args, |
| 32 | 32 | typing_env, |
| 33 | ty::EarlyBinder::bind(before_feature_tys), | |
| 33 | ty::EarlyBinder::bind(tcx, before_feature_tys), | |
| 34 | 34 | ); |
| 35 | 35 | let after_feature_tys = tcx.instantiate_and_normalize_erasing_regions( |
| 36 | 36 | closure_instance.args, |
| 37 | 37 | typing_env, |
| 38 | ty::EarlyBinder::bind(after_feature_tys), | |
| 38 | ty::EarlyBinder::bind(tcx, after_feature_tys), | |
| 39 | 39 | ); |
| 40 | 40 | |
| 41 | 41 | let new_size = tcx |
compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs+2-2| ... | ... | @@ -391,7 +391,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> { |
| 391 | 391 | | ty::CoroutineWitness(..) |
| 392 | 392 | | ty::Never |
| 393 | 393 | | ty::Tuple(_) |
| 394 | | ty::Alias(_) | |
| 394 | | ty::Alias(_, _) | |
| 395 | 395 | | ty::Bound(_, _) |
| 396 | 396 | | ty::Error(_) => { |
| 397 | 397 | return ensure_sufficient_stack(|| t.super_fold_with(self)); |
| ... | ... | @@ -565,7 +565,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz |
| 565 | 565 | }, |
| 566 | 566 | // FIXME: See comment above -- we could fold the region separately or something. |
| 567 | 567 | ty::ConstKind::Bound(_, _) |
| 568 | | ty::ConstKind::Unevaluated(_) | |
| 568 | | ty::ConstKind::Unevaluated(_, _) | |
| 569 | 569 | | ty::ConstKind::Value(_) |
| 570 | 570 | | ty::ConstKind::Error(_) |
| 571 | 571 | | ty::ConstKind::Expr(_) => return c.super_fold_with(self), |
compiler/rustc_next_trait_solver/src/canonical/mod.rs+1-1| ... | ... | @@ -333,7 +333,7 @@ where |
| 333 | 333 | { |
| 334 | 334 | let var_values = CanonicalVarValues { var_values: delegate.cx().mk_args(var_values) }; |
| 335 | 335 | let state = inspect::State { var_values, data }; |
| 336 | let state = eager_resolve_vars(delegate, state); | |
| 336 | let state = eager_resolve_vars(&**delegate, state); | |
| 337 | 337 | Canonicalizer::canonicalize_response(delegate, max_input_universe, state) |
| 338 | 338 | } |
| 339 | 339 |
compiler/rustc_next_trait_solver/src/coherence.rs+1-1| ... | ... | @@ -362,7 +362,7 @@ where |
| 362 | 362 | // normalize to that, so we have to treat it as an uncovered ty param. |
| 363 | 363 | // * Otherwise it may normalize to any non-type-generic type |
| 364 | 364 | // be it local or non-local. |
| 365 | ty::Alias(ty::AliasTy { kind, .. }) => { | |
| 365 | ty::Alias(_, ty::AliasTy { kind, .. }) => { | |
| 366 | 366 | if ty.has_type_flags( |
| 367 | 367 | ty::TypeFlags::HAS_TY_PLACEHOLDER |
| 368 | 368 | | ty::TypeFlags::HAS_TY_BOUND |
compiler/rustc_next_trait_solver/src/normalize.rs+74-44| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | use std::fmt::Debug; | |
| 2 | ||
| 1 | 3 | use rustc_type_ir::data_structures::ensure_sufficient_stack; |
| 2 | 4 | use rustc_type_ir::inherent::*; |
| 3 | use rustc_type_ir::solve::{Goal, NoSolution}; | |
| 4 | 5 | use rustc_type_ir::{ |
| 5 | 6 | self as ty, AliasTerm, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy, |
| 6 | 7 | Interner, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, |
| ... | ... | @@ -21,7 +22,6 @@ where |
| 21 | 22 | { |
| 22 | 23 | infcx: &'a Infcx, |
| 23 | 24 | universes: Vec<Option<UniverseIndex>>, |
| 24 | stalled_goals: Vec<Goal<I, I::Predicate>>, | |
| 25 | 25 | normalize: F, |
| 26 | 26 | } |
| 27 | 27 | |
| ... | ... | @@ -31,6 +31,12 @@ enum HasEscapingBoundVars { |
| 31 | 31 | No, |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | #[derive(PartialEq, Eq)] | |
| 35 | pub enum NormalizationWasAmbiguous { | |
| 36 | Yes, | |
| 37 | No, | |
| 38 | } | |
| 39 | ||
| 34 | 40 | /// Finds the max universe present in infer vars. |
| 35 | 41 | struct MaxUniverse<'a, Infcx, I> |
| 36 | 42 | where |
| ... | ... | @@ -97,64 +103,53 @@ where |
| 97 | 103 | } |
| 98 | 104 | } |
| 99 | 105 | |
| 100 | impl<'a, Infcx, I, F> NormalizationFolder<'a, Infcx, I, F> | |
| 106 | impl<'a, Infcx, I, F, E> NormalizationFolder<'a, Infcx, I, F> | |
| 101 | 107 | where |
| 102 | 108 | Infcx: InferCtxtLike<Interner = I>, |
| 103 | 109 | I: Interner, |
| 104 | F: FnMut(AliasTerm<I>) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>, | |
| 110 | F: FnMut(AliasTerm<I>) -> Result<(I::Term, NormalizationWasAmbiguous), E>, | |
| 105 | 111 | { |
| 106 | pub fn new( | |
| 107 | infcx: &'a Infcx, | |
| 108 | universes: Vec<Option<UniverseIndex>>, | |
| 109 | stalled_goals: Vec<Goal<I, I::Predicate>>, | |
| 110 | normalize: F, | |
| 111 | ) -> Self { | |
| 112 | Self { infcx, universes, stalled_goals, normalize } | |
| 113 | } | |
| 114 | ||
| 115 | pub fn stalled_goals(self) -> Vec<Goal<I, I::Predicate>> { | |
| 116 | self.stalled_goals | |
| 112 | pub fn new(infcx: &'a Infcx, universes: Vec<Option<UniverseIndex>>, normalize: F) -> Self { | |
| 113 | Self { infcx, universes, normalize } | |
| 117 | 114 | } |
| 118 | 115 | |
| 119 | 116 | fn normalize_alias_term( |
| 120 | 117 | &mut self, |
| 121 | 118 | alias_term: AliasTerm<I>, |
| 122 | 119 | has_escaping: HasEscapingBoundVars, |
| 123 | ) -> Result<Option<I::Term>, NoSolution> { | |
| 124 | let current_universe = self.infcx.universe(); | |
| 125 | self.infcx.create_next_universe(); | |
| 126 | ||
| 127 | let (normalized, ambig_goal) = (self.normalize)(alias_term)?; | |
| 120 | ) -> Result<Option<I::Term>, E> { | |
| 121 | let (normalized, normalization_was_ambiguous) = (self.normalize)(alias_term)?; | |
| 128 | 122 | |
| 129 | 123 | // Return ambiguous higher ranked alias as is, if |
| 130 | 124 | // - it contains escaping vars, and |
| 131 | // - the normalized term contains infer vars newly created | |
| 132 | // in the normalization above. | |
| 133 | // The problem is that they may be resolved to types | |
| 134 | // referencing the temporary placeholders. | |
| 125 | // - the normalized term contains infer vars which may mention | |
| 126 | // temporary placeholders after we've already mapped them back | |
| 127 | // to bound vars. | |
| 135 | 128 | // |
| 136 | 129 | // We can normalize the ambiguous alias again after the binder is instantiated. |
| 137 | if ambig_goal.is_some() && has_escaping == HasEscapingBoundVars::Yes { | |
| 130 | if normalization_was_ambiguous == NormalizationWasAmbiguous::Yes | |
| 131 | && has_escaping == HasEscapingBoundVars::Yes | |
| 132 | { | |
| 138 | 133 | let mut visitor = MaxUniverse::new(self.infcx); |
| 139 | 134 | normalized.visit_with(&mut visitor); |
| 140 | 135 | let max_universe = visitor.max_universe(); |
| 141 | if current_universe.cannot_name(max_universe) { | |
| 136 | if max_universe.can_name(self.universes.first().unwrap().unwrap()) { | |
| 142 | 137 | return Ok(None); |
| 143 | 138 | } |
| 144 | 139 | } |
| 145 | 140 | |
| 146 | self.stalled_goals.extend(ambig_goal); | |
| 147 | 141 | Ok(Some(normalized)) |
| 148 | 142 | } |
| 149 | 143 | } |
| 150 | 144 | |
| 151 | impl<'a, Infcx, I, F> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I, F> | |
| 145 | impl<'a, Infcx, I, F, E> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I, F> | |
| 152 | 146 | where |
| 153 | 147 | Infcx: InferCtxtLike<Interner = I>, |
| 154 | 148 | I: Interner, |
| 155 | F: FnMut(AliasTerm<I>) -> Result<(I::Term, Option<Goal<I, I::Predicate>>), NoSolution>, | |
| 149 | F: FnMut(AliasTerm<I>) -> Result<(I::Term, NormalizationWasAmbiguous), E>, | |
| 150 | E: Debug, | |
| 156 | 151 | { |
| 157 | type Error = NoSolution; | |
| 152 | type Error = E; | |
| 158 | 153 | |
| 159 | 154 | fn cx(&self) -> I { |
| 160 | 155 | self.infcx.cx() |
| ... | ... | @@ -173,16 +168,23 @@ where |
| 173 | 168 | #[instrument(level = "trace", skip(self), ret)] |
| 174 | 169 | fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Self::Error> { |
| 175 | 170 | let infcx = self.infcx; |
| 176 | if !ty.has_aliases() { | |
| 171 | let original = ty; | |
| 172 | ||
| 173 | if !self.cx().renormalize_rigid_aliases() && !ty.has_non_rigid_aliases() { | |
| 177 | 174 | return Ok(ty); |
| 178 | 175 | } |
| 179 | 176 | |
| 180 | 177 | // With eager normalization, we should normalize the args of alias before |
| 181 | 178 | // normalizing the alias itself. |
| 182 | 179 | let ty = ty.try_super_fold_with(self)?; |
| 183 | let ty::Alias(alias_ty) = ty.kind() else { return Ok(ty) }; | |
| 180 | let ty::Alias(orig_is_rigid, alias_ty) = ty.kind() else { return Ok(ty) }; | |
| 181 | // We support ambiguous aliases inside rigid alias. So we still recognize | |
| 182 | // the rigidness of the outer alias. | |
| 183 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 184 | return Ok(ty); | |
| 185 | } | |
| 184 | 186 | |
| 185 | if ty.has_escaping_bound_vars() { | |
| 187 | let normalized = if ty.has_escaping_bound_vars() { | |
| 186 | 188 | let (alias_ty, mapped_regions, mapped_types, mapped_consts) = |
| 187 | 189 | BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_ty); |
| 188 | 190 | let Some(result) = ensure_sufficient_stack(|| { |
| ... | ... | @@ -192,36 +194,51 @@ where |
| 192 | 194 | return Ok(ty); |
| 193 | 195 | }; |
| 194 | 196 | |
| 195 | Ok(PlaceholderReplacer::replace_placeholders( | |
| 197 | PlaceholderReplacer::replace_placeholders( | |
| 196 | 198 | infcx, |
| 197 | 199 | mapped_regions, |
| 198 | 200 | mapped_types, |
| 199 | 201 | mapped_consts, |
| 200 | 202 | &self.universes, |
| 201 | 203 | result.expect_ty(), |
| 202 | )) | |
| 204 | ) | |
| 203 | 205 | } else { |
| 204 | Ok(ensure_sufficient_stack(|| { | |
| 206 | ensure_sufficient_stack(|| { | |
| 205 | 207 | self.normalize_alias_term(alias_ty.into(), HasEscapingBoundVars::No) |
| 206 | 208 | })? |
| 207 | 209 | .map(|term| term.expect_ty()) |
| 208 | .unwrap_or(ty)) | |
| 210 | .unwrap_or(ty) | |
| 211 | }; | |
| 212 | ||
| 213 | if self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 214 | // find out missing typing env change. | |
| 215 | let original = crate::resolve::eager_resolve_vars(infcx, original); | |
| 216 | let normalized = crate::resolve::eager_resolve_vars(infcx, normalized); | |
| 217 | assert_eq!(original, normalized, "rigid alias is further normalized"); | |
| 209 | 218 | } |
| 219 | Ok(normalized) | |
| 210 | 220 | } |
| 211 | 221 | |
| 212 | 222 | #[instrument(level = "trace", skip(self), ret)] |
| 213 | 223 | fn try_fold_const(&mut self, ct: I::Const) -> Result<I::Const, Self::Error> { |
| 214 | 224 | let infcx = self.infcx; |
| 215 | if !ct.has_aliases() { | |
| 225 | let original = ct; | |
| 226 | ||
| 227 | if !self.cx().renormalize_rigid_aliases() && !ct.has_non_rigid_aliases() { | |
| 216 | 228 | return Ok(ct); |
| 217 | 229 | } |
| 218 | 230 | |
| 219 | 231 | // With eager normalization, we should normalize the args of alias before |
| 220 | 232 | // normalizing the alias itself. |
| 221 | 233 | let ct = ct.try_super_fold_with(self)?; |
| 222 | let ty::ConstKind::Unevaluated(uv) = ct.kind() else { return Ok(ct) }; | |
| 234 | let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return Ok(ct) }; | |
| 235 | // We support ambiguous aliases inside rigid alias. So we still recognize | |
| 236 | // the rigidness of the outer alias. | |
| 237 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 238 | return Ok(ct); | |
| 239 | } | |
| 223 | 240 | |
| 224 | if ct.has_escaping_bound_vars() { | |
| 241 | let normalized = if ct.has_escaping_bound_vars() { | |
| 225 | 242 | let (uv, mapped_regions, mapped_types, mapped_consts) = |
| 226 | 243 | BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv); |
| 227 | 244 | let Some(result) = ensure_sufficient_stack(|| { |
| ... | ... | @@ -230,20 +247,33 @@ where |
| 230 | 247 | else { |
| 231 | 248 | return Ok(ct); |
| 232 | 249 | }; |
| 233 | Ok(PlaceholderReplacer::replace_placeholders( | |
| 250 | PlaceholderReplacer::replace_placeholders( | |
| 234 | 251 | infcx, |
| 235 | 252 | mapped_regions, |
| 236 | 253 | mapped_types, |
| 237 | 254 | mapped_consts, |
| 238 | 255 | &self.universes, |
| 239 | 256 | result.expect_const(), |
| 240 | )) | |
| 257 | ) | |
| 241 | 258 | } else { |
| 242 | Ok(ensure_sufficient_stack(|| { | |
| 259 | ensure_sufficient_stack(|| { | |
| 243 | 260 | self.normalize_alias_term(uv.into(), HasEscapingBoundVars::No) |
| 244 | 261 | })? |
| 245 | 262 | .map(|term| term.expect_const()) |
| 246 | .unwrap_or(ct)) | |
| 263 | .unwrap_or(ct) | |
| 264 | }; | |
| 265 | ||
| 266 | if self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 267 | // find out missing typing env change. | |
| 268 | let original = crate::resolve::eager_resolve_vars(infcx, original); | |
| 269 | let normalized = crate::resolve::eager_resolve_vars(infcx, normalized); | |
| 270 | assert_eq!(original, normalized, "rigid alias is further normalized"); | |
| 247 | 271 | } |
| 272 | ||
| 273 | Ok(normalized) | |
| 274 | } | |
| 275 | ||
| 276 | fn try_fold_predicate(&mut self, p: I::Predicate) -> Result<I::Predicate, Self::Error> { | |
| 277 | if p.allow_normalization() { p.try_super_fold_with(self) } else { Ok(p) } | |
| 248 | 278 | } |
| 249 | 279 | } |
compiler/rustc_next_trait_solver/src/resolve.rs+8-10| ... | ... | @@ -5,15 +5,13 @@ use rustc_type_ir::{ |
| 5 | 5 | TypeVisitableExt, |
| 6 | 6 | }; |
| 7 | 7 | |
| 8 | use crate::delegate::SolverDelegate; | |
| 9 | ||
| 10 | 8 | /////////////////////////////////////////////////////////////////////////// |
| 11 | 9 | // EAGER RESOLUTION |
| 12 | 10 | |
| 13 | 11 | /// Resolves ty, region, and const vars to their inferred values or their root vars. |
| 14 | struct EagerResolver<'a, D, I = <D as SolverDelegate>::Interner> | |
| 12 | struct EagerResolver<'a, D, I = <D as InferCtxtLike>::Interner> | |
| 15 | 13 | where |
| 16 | D: SolverDelegate<Interner = I>, | |
| 14 | D: InferCtxtLike<Interner = I>, | |
| 17 | 15 | I: Interner, |
| 18 | 16 | { |
| 19 | 17 | delegate: &'a D, |
| ... | ... | @@ -22,25 +20,25 @@ where |
| 22 | 20 | cache: DelayedMap<I::Ty, I::Ty>, |
| 23 | 21 | } |
| 24 | 22 | |
| 25 | pub fn eager_resolve_vars<D: SolverDelegate, T: TypeFoldable<D::Interner>>( | |
| 26 | delegate: &D, | |
| 23 | pub fn eager_resolve_vars<Infcx: InferCtxtLike, T: TypeFoldable<Infcx::Interner>>( | |
| 24 | infcx: &Infcx, | |
| 27 | 25 | value: T, |
| 28 | 26 | ) -> T { |
| 29 | 27 | if value.has_infer() { |
| 30 | let mut folder = EagerResolver::new(delegate); | |
| 28 | let mut folder = EagerResolver::new(infcx); | |
| 31 | 29 | value.fold_with(&mut folder) |
| 32 | 30 | } else { |
| 33 | 31 | value |
| 34 | 32 | } |
| 35 | 33 | } |
| 36 | 34 | |
| 37 | impl<'a, D: SolverDelegate> EagerResolver<'a, D> { | |
| 38 | fn new(delegate: &'a D) -> Self { | |
| 35 | impl<'a, Infcx: InferCtxtLike> EagerResolver<'a, Infcx> { | |
| 36 | fn new(delegate: &'a Infcx) -> Self { | |
| 39 | 37 | EagerResolver { delegate, cache: Default::default() } |
| 40 | 38 | } |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, D> { | |
| 41 | impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, Infcx> { | |
| 44 | 42 | fn cx(&self) -> I { |
| 45 | 43 | self.delegate.cx() |
| 46 | 44 | } |
compiler/rustc_next_trait_solver/src/solve/alias_relate.rs+6-29| ... | ... | @@ -49,11 +49,11 @@ where |
| 49 | 49 | |
| 50 | 50 | // Structurally normalize the lhs. |
| 51 | 51 | let lhs = if let Some(alias) = lhs.to_alias_term() { |
| 52 | let term = self.next_term_infer_of_kind(lhs); | |
| 52 | let term = self.next_term_infer_of_alias_kind(alias); | |
| 53 | 53 | self.add_goal( |
| 54 | 54 | GoalSource::TypeRelating, |
| 55 | 55 | goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }), |
| 56 | ); | |
| 56 | )?; | |
| 57 | 57 | term |
| 58 | 58 | } else { |
| 59 | 59 | lhs |
| ... | ... | @@ -61,11 +61,11 @@ where |
| 61 | 61 | |
| 62 | 62 | // Structurally normalize the rhs. |
| 63 | 63 | let rhs = if let Some(alias) = rhs.to_alias_term() { |
| 64 | let term = self.next_term_infer_of_kind(rhs); | |
| 64 | let term = self.next_term_infer_of_alias_kind(alias); | |
| 65 | 65 | self.add_goal( |
| 66 | 66 | GoalSource::TypeRelating, |
| 67 | 67 | goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }), |
| 68 | ); | |
| 68 | )?; | |
| 69 | 69 | term |
| 70 | 70 | } else { |
| 71 | 71 | rhs |
| ... | ... | @@ -87,30 +87,7 @@ where |
| 87 | 87 | ty::AliasRelationDirection::Equate => ty::Invariant, |
| 88 | 88 | ty::AliasRelationDirection::Subtype => ty::Covariant, |
| 89 | 89 | }; |
| 90 | match (lhs.to_alias_term(), rhs.to_alias_term()) { | |
| 91 | (None, None) => { | |
| 92 | self.relate(param_env, lhs, variance, rhs)?; | |
| 93 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 94 | } | |
| 95 | ||
| 96 | (Some(alias), None) => { | |
| 97 | self.relate_rigid_alias_non_alias(param_env, alias, variance, rhs)?; | |
| 98 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 99 | } | |
| 100 | (None, Some(alias)) => { | |
| 101 | self.relate_rigid_alias_non_alias( | |
| 102 | param_env, | |
| 103 | alias, | |
| 104 | variance.xform(ty::Contravariant), | |
| 105 | lhs, | |
| 106 | )?; | |
| 107 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 108 | } | |
| 109 | ||
| 110 | (Some(alias_lhs), Some(alias_rhs)) => { | |
| 111 | self.relate(param_env, alias_lhs, variance, alias_rhs)?; | |
| 112 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 113 | } | |
| 114 | } | |
| 90 | self.relate(param_env, lhs, variance, rhs)?; | |
| 91 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 115 | 92 | } |
| 116 | 93 | } |
compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs+18-9| ... | ... | @@ -68,7 +68,7 @@ where |
| 68 | 68 | ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> { |
| 69 | 69 | Self::probe_and_match_goal_against_assumption(ecx, parent_source, goal, assumption, |ecx| { |
| 70 | 70 | for (nested_source, goal) in requirements { |
| 71 | ecx.add_goal(nested_source, goal); | |
| 71 | ecx.add_goal(nested_source, goal)?; | |
| 72 | 72 | } |
| 73 | 73 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 74 | 74 | }) |
| ... | ... | @@ -113,7 +113,7 @@ where |
| 113 | 113 | bounds, |
| 114 | 114 | ) { |
| 115 | 115 | Ok(requirements) => { |
| 116 | ecx.add_goals(GoalSource::ImplWhereBound, requirements); | |
| 116 | ecx.add_goals(GoalSource::ImplWhereBound, requirements)?; | |
| 117 | 117 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 118 | 118 | } |
| 119 | 119 | Err(_) => { |
| ... | ... | @@ -789,13 +789,21 @@ where |
| 789 | 789 | return Ok(()); |
| 790 | 790 | } |
| 791 | 791 | |
| 792 | ty::Alias(alias_ty @ AliasTy { kind: ty::Projection { def_id }, .. }) => { | |
| 793 | (alias_ty, def_id.into()) | |
| 794 | } | |
| 795 | ty::Alias(alias_ty @ AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 792 | ty::Alias( | |
| 793 | ty::IsRigid::Yes, | |
| 794 | alias_ty @ AliasTy { kind: ty::Projection { def_id }, .. }, | |
| 795 | ) => (alias_ty, def_id.into()), | |
| 796 | ||
| 797 | ty::Alias(ty::IsRigid::Yes, alias_ty @ AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 796 | 798 | (alias_ty, def_id.into()) |
| 797 | 799 | } |
| 798 | ty::Alias(AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }) => { | |
| 800 | ||
| 801 | ty::Alias(ty::IsRigid::No, _) => unreachable!("non-rigid self type: {self_ty:?}"), | |
| 802 | ||
| 803 | ty::Alias( | |
| 804 | ty::IsRigid::Yes, | |
| 805 | AliasTy { kind: ty::Inherent { .. } | ty::Free { .. }, .. }, | |
| 806 | ) => { | |
| 799 | 807 | self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF")); |
| 800 | 808 | return Ok(()); |
| 801 | 809 | } |
| ... | ... | @@ -971,7 +979,7 @@ where |
| 971 | 979 | elaborate::elaborate(cx, [predicate]) |
| 972 | 980 | .skip(1) |
| 973 | 981 | .map(|predicate| goal.with(cx, predicate)), |
| 974 | ); | |
| 982 | )?; | |
| 975 | 983 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) |
| 976 | 984 | } |
| 977 | 985 | }) |
| ... | ... | @@ -1088,9 +1096,10 @@ where |
| 1088 | 1096 | self.cx |
| 1089 | 1097 | } |
| 1090 | 1098 | fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { |
| 1091 | if let ty::Alias(alias_ty) = ty.kind() | |
| 1099 | if let ty::Alias(is_rigid, alias_ty) = ty.kind() | |
| 1092 | 1100 | && let Some(opaque_ty) = alias_ty.try_to_opaque() |
| 1093 | 1101 | { |
| 1102 | debug_assert_eq!(is_rigid, ty::IsRigid::No); | |
| 1094 | 1103 | if opaque_ty == self.opaque_ty { |
| 1095 | 1104 | return self.self_ty; |
| 1096 | 1105 | } |
compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs+33-23| ... | ... | @@ -49,11 +49,14 @@ where |
| 49 | 49 | |
| 50 | 50 | ty::Dynamic(..) |
| 51 | 51 | | ty::Param(..) |
| 52 | | ty::Alias(ty::AliasTy { | |
| 53 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 54 | .. | |
| 55 | }) | |
| 52 | | ty::Alias( | |
| 53 | ty::IsRigid::Yes, | |
| 54 | ty::AliasTy { | |
| 55 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, .. | |
| 56 | }, | |
| 57 | ) | |
| 56 | 58 | | ty::Placeholder(..) |
| 59 | | ty::Alias(ty::IsRigid::No, _) | |
| 57 | 60 | | ty::Bound(..) |
| 58 | 61 | | ty::Infer(_) => { |
| 59 | 62 | panic!("unexpected type `{ty:?}`") |
| ... | ... | @@ -102,7 +105,7 @@ where |
| 102 | 105 | .collect(), |
| 103 | 106 | )), |
| 104 | 107 | |
| 105 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 108 | ty::Alias(ty::IsRigid::Yes, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 106 | 109 | // We can resolve the `impl Trait` to its concrete type, |
| 107 | 110 | // which enforces a DAG between the functions requiring |
| 108 | 111 | // the auto trait bounds in question. |
| ... | ... | @@ -227,15 +230,10 @@ where |
| 227 | 230 | | ty::Foreign(..) |
| 228 | 231 | | ty::Ref(_, _, Mutability::Mut) |
| 229 | 232 | | ty::Adt(_, _) |
| 230 | | ty::Alias(_) | |
| 233 | | ty::Alias(ty::IsRigid::Yes, _) | |
| 231 | 234 | | ty::Param(_) |
| 232 | 235 | | ty::Placeholder(..) => Err(NoSolution), |
| 233 | 236 | |
| 234 | ty::Bound(..) | |
| 235 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | |
| 236 | panic!("unexpected type `{ty:?}`") | |
| 237 | } | |
| 238 | ||
| 239 | 237 | // impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone |
| 240 | 238 | ty::Tuple(tys) => Ok(ty::Binder::dummy(tys.to_vec())), |
| 241 | 239 | |
| ... | ... | @@ -272,6 +270,12 @@ where |
| 272 | 270 | .instantiate(ecx.cx(), args) |
| 273 | 271 | .skip_norm_wip() |
| 274 | 272 | .map_bound(|bound| bound.types.to_vec())), |
| 273 | ||
| 274 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | |
| 275 | | ty::Alias(ty::IsRigid::No, _) | |
| 276 | | ty::Bound(..) => { | |
| 277 | panic!("unexpected type `{ty:?}`") | |
| 278 | } | |
| 275 | 279 | } |
| 276 | 280 | } |
| 277 | 281 | |
| ... | ... | @@ -401,14 +405,15 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern |
| 401 | 405 | | ty::Tuple(_) |
| 402 | 406 | | ty::Pat(_, _) |
| 403 | 407 | | ty::UnsafeBinder(_) |
| 404 | | ty::Alias(_) | |
| 408 | | ty::Alias(ty::IsRigid::Yes, _) | |
| 405 | 409 | | ty::Param(_) |
| 406 | 410 | | ty::Placeholder(..) |
| 407 | 411 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| 408 | 412 | | ty::Error(_) => Err(NoSolution), |
| 409 | 413 | |
| 410 | ty::Bound(..) | |
| 411 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | |
| 414 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | |
| 415 | | ty::Alias(ty::IsRigid::No, _) | |
| 416 | | ty::Bound(..) => { | |
| 412 | 417 | panic!("unexpected type `{self_ty:?}`") |
| 413 | 418 | } |
| 414 | 419 | } |
| ... | ... | @@ -545,7 +550,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: |
| 545 | 550 | |
| 546 | 551 | let future_output_def_id = |
| 547 | 552 | cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput); |
| 548 | let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]); | |
| 553 | let future_output_ty = | |
| 554 | Ty::new_projection(cx, ty::IsRigid::No, future_output_def_id, [sig.output()]); | |
| 549 | 555 | Ok(( |
| 550 | 556 | bound_sig.rebind(AsyncCallableRelevantTypes { |
| 551 | 557 | tupled_inputs_ty: sig.inputs().get(0).unwrap(), |
| ... | ... | @@ -575,14 +581,15 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: |
| 575 | 581 | | ty::Never |
| 576 | 582 | | ty::UnsafeBinder(_) |
| 577 | 583 | | ty::Tuple(_) |
| 578 | | ty::Alias(_) | |
| 584 | | ty::Alias(ty::IsRigid::Yes, _) | |
| 579 | 585 | | ty::Param(_) |
| 580 | 586 | | ty::Placeholder(..) |
| 581 | 587 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| 582 | 588 | | ty::Error(_) => Err(NoSolution), |
| 583 | 589 | |
| 584 | ty::Bound(..) | |
| 585 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | |
| 590 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | |
| 591 | | ty::Alias(ty::IsRigid::No, _) | |
| 592 | | ty::Bound(..) => { | |
| 586 | 593 | panic!("unexpected type `{self_ty:?}`") |
| 587 | 594 | } |
| 588 | 595 | } |
| ... | ... | @@ -601,7 +608,8 @@ fn fn_item_to_async_callable<I: Interner>( |
| 601 | 608 | ]; |
| 602 | 609 | let future_output_def_id = |
| 603 | 610 | cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput); |
| 604 | let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]); | |
| 611 | let future_output_ty = | |
| 612 | Ty::new_projection(cx, ty::IsRigid::No, future_output_def_id, [sig.output()]); | |
| 605 | 613 | Ok(( |
| 606 | 614 | bound_sig.rebind(AsyncCallableRelevantTypes { |
| 607 | 615 | tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()), |
| ... | ... | @@ -650,6 +658,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>( |
| 650 | 658 | cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars); |
| 651 | 659 | let tupled_upvars_ty = Ty::new_projection( |
| 652 | 660 | cx, |
| 661 | ty::IsRigid::No, | |
| 653 | 662 | upvars_projection_def_id, |
| 654 | 663 | [ |
| 655 | 664 | I::GenericArg::from(args.kind_ty()), |
| ... | ... | @@ -739,15 +748,16 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>( |
| 739 | 748 | | ty::Never |
| 740 | 749 | | ty::Tuple(_) |
| 741 | 750 | | ty::Pat(_, _) |
| 742 | | ty::Alias(_) | |
| 751 | | ty::Alias(ty::IsRigid::Yes, _) | |
| 743 | 752 | | ty::Param(_) |
| 744 | 753 | | ty::Placeholder(..) |
| 745 | 754 | | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) |
| 746 | 755 | | ty::Error(_) |
| 747 | 756 | | ty::UnsafeBinder(_) => return Err(NoSolution), |
| 748 | 757 | |
| 749 | ty::Bound(..) | |
| 750 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { | |
| 758 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) | |
| 759 | | ty::Alias(ty::IsRigid::No, _) | |
| 760 | | ty::Bound(..) => { | |
| 751 | 761 | panic!("unexpected type `{self_ty:?}`") |
| 752 | 762 | } |
| 753 | 763 | } |
| ... | ... | @@ -1035,7 +1045,7 @@ where |
| 1035 | 1045 | } |
| 1036 | 1046 | |
| 1037 | 1047 | fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> { |
| 1038 | if let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { .. }, .. }) = ty.kind() | |
| 1048 | if let ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Projection { .. }, .. }) = ty.kind() | |
| 1039 | 1049 | && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? |
| 1040 | 1050 | { |
| 1041 | 1051 | Ok(term.expect_ty()) |
compiler/rustc_next_trait_solver/src/solve/effect_goals.rs+8-8| ... | ... | @@ -124,7 +124,7 @@ where |
| 124 | 124 | ) |
| 125 | 125 | }, |
| 126 | 126 | ), |
| 127 | ); | |
| 127 | )?; | |
| 128 | 128 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 129 | 129 | }, |
| 130 | 130 | )); |
| ... | ... | @@ -176,7 +176,7 @@ where |
| 176 | 176 | .iter_instantiated(cx, impl_args) |
| 177 | 177 | .map(Unnormalized::skip_norm_wip) |
| 178 | 178 | .map(|pred| goal.with(cx, pred)); |
| 179 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); | |
| 179 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; | |
| 180 | 180 | |
| 181 | 181 | // For this impl to be `const`, we need to check its `[const]` bounds too. |
| 182 | 182 | let const_conditions = cx |
| ... | ... | @@ -190,7 +190,7 @@ where |
| 190 | 190 | .skip_norm_wip(), |
| 191 | 191 | ) |
| 192 | 192 | }); |
| 193 | ecx.add_goals(GoalSource::ImplWhereBound, const_conditions); | |
| 193 | ecx.add_goals(GoalSource::ImplWhereBound, const_conditions)?; | |
| 194 | 194 | |
| 195 | 195 | then(ecx, certainty) |
| 196 | 196 | }) |
| ... | ... | @@ -242,8 +242,8 @@ where |
| 242 | 242 | // `GoalSource::ImplWhereClause` here would be incorrect, as we also |
| 243 | 243 | // impl them, which means we're "stepping out of the impl constructor" |
| 244 | 244 | // again. To handle this, we treat these cycles as ambiguous for now. |
| 245 | ecx.add_goals(GoalSource::Misc, where_clause_bounds); | |
| 246 | ecx.add_goals(GoalSource::Misc, const_conditions); | |
| 245 | ecx.add_goals(GoalSource::Misc, where_clause_bounds)?; | |
| 246 | ecx.add_goals(GoalSource::Misc, const_conditions)?; | |
| 247 | 247 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 248 | 248 | }) |
| 249 | 249 | } |
| ... | ... | @@ -278,8 +278,8 @@ where |
| 278 | 278 | ), |
| 279 | 279 | ) |
| 280 | 280 | }), |
| 281 | ); | |
| 282 | }); | |
| 281 | ) | |
| 282 | })?; | |
| 283 | 283 | |
| 284 | 284 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 285 | 285 | }) |
| ... | ... | @@ -432,7 +432,7 @@ where |
| 432 | 432 | .to_host_effect_clause(cx, goal.predicate.constness), |
| 433 | 433 | ) |
| 434 | 434 | }), |
| 435 | ); | |
| 435 | )?; | |
| 436 | 436 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 437 | 437 | }) |
| 438 | 438 | } |
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+70-205| ... | ... | @@ -3,7 +3,7 @@ use std::ops::ControlFlow; |
| 3 | 3 | |
| 4 | 4 | #[cfg(feature = "nightly")] |
| 5 | 5 | use rustc_macros::StableHash; |
| 6 | use rustc_type_ir::data_structures::{HashMap, HashSet}; | |
| 6 | use rustc_type_ir::data_structures::HashSet; | |
| 7 | 7 | use rustc_type_ir::inherent::*; |
| 8 | 8 | use rustc_type_ir::region_constraint::RegionConstraint; |
| 9 | 9 | use rustc_type_ir::relate::Relate; |
| ... | ... | @@ -16,8 +16,8 @@ use rustc_type_ir::solve::{ |
| 16 | 16 | }; |
| 17 | 17 | use rustc_type_ir::{ |
| 18 | 18 | self as ty, CanonicalVarValues, ClauseKind, InferCtxtLike, Interner, MayBeErased, |
| 19 | OpaqueTypeKey, PredicateKind, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, | |
| 20 | TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, | |
| 19 | OpaqueTypeKey, PredicateKind, TypeFoldable, TypeSuperVisitable, TypeVisitable, | |
| 20 | TypeVisitableExt, TypeVisitor, TypingMode, | |
| 21 | 21 | }; |
| 22 | 22 | use tracing::{Level, debug, instrument, trace, warn}; |
| 23 | 23 | |
| ... | ... | @@ -28,6 +28,7 @@ use crate::canonical::{ |
| 28 | 28 | }; |
| 29 | 29 | use crate::coherence; |
| 30 | 30 | use crate::delegate::SolverDelegate; |
| 31 | use crate::normalize::{NormalizationFolder, NormalizationWasAmbiguous}; | |
| 31 | 32 | use crate::placeholder::BoundVarReplacer; |
| 32 | 33 | use crate::resolve::eager_resolve_vars; |
| 33 | 34 | use crate::solve::search_graph::SearchGraph; |
| ... | ... | @@ -604,7 +605,7 @@ where |
| 604 | 605 | // so we only canonicalize the lookup table and ignore |
| 605 | 606 | // duplicate entries. |
| 606 | 607 | let opaque_types = self.delegate.clone_opaque_types_lookup_table(); |
| 607 | let (goal, opaque_types) = eager_resolve_vars(self.delegate, (goal, opaque_types)); | |
| 608 | let (goal, opaque_types) = eager_resolve_vars(&**self.delegate, (goal, opaque_types)); | |
| 608 | 609 | let typing_mode = self.typing_mode(); |
| 609 | 610 | let step_kind = self.step_kind_for_source(source); |
| 610 | 611 | |
| ... | ... | @@ -1049,15 +1050,20 @@ where |
| 1049 | 1050 | self.delegate.cx() |
| 1050 | 1051 | } |
| 1051 | 1052 | |
| 1052 | pub(super) fn add_goal(&mut self, source: GoalSource, mut goal: Goal<I, I::Predicate>) { | |
| 1053 | goal.predicate = self.replace_alias_with_infer(goal.predicate, source, goal.param_env); | |
| 1054 | self.add_goal_raw(source, goal); | |
| 1055 | } | |
| 1056 | ||
| 1057 | 1053 | #[instrument(level = "debug", skip(self))] |
| 1058 | fn add_goal_raw(&mut self, source: GoalSource, goal: Goal<I, I::Predicate>) { | |
| 1054 | pub(super) fn add_goal( | |
| 1055 | &mut self, | |
| 1056 | source: GoalSource, | |
| 1057 | mut goal: Goal<I, I::Predicate>, | |
| 1058 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1059 | goal.predicate = self.normalize( | |
| 1060 | GoalSource::NormalizeGoal(self.step_kind_for_source(source)), | |
| 1061 | goal.param_env, | |
| 1062 | ty::Unnormalized::new_wip(goal.predicate), | |
| 1063 | )?; | |
| 1059 | 1064 | self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal); |
| 1060 | 1065 | self.nested_goals.push((source, goal, None)); |
| 1066 | Ok(()) | |
| 1061 | 1067 | } |
| 1062 | 1068 | |
| 1063 | 1069 | #[instrument(level = "trace", skip(self, goals))] |
| ... | ... | @@ -1065,19 +1071,11 @@ where |
| 1065 | 1071 | &mut self, |
| 1066 | 1072 | source: GoalSource, |
| 1067 | 1073 | goals: impl IntoIterator<Item = Goal<I, I::Predicate>>, |
| 1068 | ) { | |
| 1074 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1069 | 1075 | for goal in goals { |
| 1070 | self.add_goal(source, goal); | |
| 1076 | self.add_goal(source, goal)?; | |
| 1071 | 1077 | } |
| 1072 | } | |
| 1073 | ||
| 1074 | pub(super) fn replace_alias_with_infer<T: TypeFoldable<I>>( | |
| 1075 | &mut self, | |
| 1076 | value: T, | |
| 1077 | source: GoalSource, | |
| 1078 | param_env: I::ParamEnv, | |
| 1079 | ) -> T { | |
| 1080 | value.fold_with(&mut ReplaceAliasWithInfer::new(self, source, param_env)) | |
| 1078 | Ok(()) | |
| 1081 | 1079 | } |
| 1082 | 1080 | |
| 1083 | 1081 | pub(super) fn next_region_var(&mut self) -> I::Region { |
| ... | ... | @@ -1100,10 +1098,19 @@ where |
| 1100 | 1098 | |
| 1101 | 1099 | /// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`. |
| 1102 | 1100 | /// If `kind` is an integer inference variable this will still return a ty infer var. |
| 1103 | pub(super) fn next_term_infer_of_kind(&mut self, term: I::Term) -> I::Term { | |
| 1104 | match term.kind() { | |
| 1105 | ty::TermKind::Ty(_) => self.next_ty_infer().into(), | |
| 1106 | ty::TermKind::Const(_) => self.next_const_infer().into(), | |
| 1101 | pub(super) fn next_term_infer_of_alias_kind( | |
| 1102 | &mut self, | |
| 1103 | alias_term: ty::AliasTerm<I>, | |
| 1104 | ) -> I::Term { | |
| 1105 | match alias_term.kind { | |
| 1106 | ty::AliasTermKind::ProjectionTy { .. } | |
| 1107 | | ty::AliasTermKind::InherentTy { .. } | |
| 1108 | | ty::AliasTermKind::OpaqueTy { .. } | |
| 1109 | | ty::AliasTermKind::FreeTy { .. } => self.next_ty_infer().into(), | |
| 1110 | ty::AliasTermKind::FreeConst { .. } | |
| 1111 | | ty::AliasTermKind::InherentConst { .. } | |
| 1112 | | ty::AliasTermKind::AnonConst { .. } | |
| 1113 | | ty::AliasTermKind::ProjectionConst { .. } => self.next_const_infer().into(), | |
| 1107 | 1114 | } |
| 1108 | 1115 | } |
| 1109 | 1116 | |
| ... | ... | @@ -1240,88 +1247,17 @@ where |
| 1240 | 1247 | param_env: I::ParamEnv, |
| 1241 | 1248 | lhs: T, |
| 1242 | 1249 | rhs: T, |
| 1243 | ) -> Result<(), NoSolution> { | |
| 1250 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1244 | 1251 | self.relate(param_env, lhs, ty::Variance::Invariant, rhs) |
| 1245 | 1252 | } |
| 1246 | 1253 | |
| 1247 | /// This should be used when relating a rigid alias with another type. | |
| 1248 | /// | |
| 1249 | /// Normally we emit a nested `AliasRelate` when equating an inference | |
| 1250 | /// variable and an alias. This causes us to instead constrain the inference | |
| 1251 | /// variable to the alias without emitting a nested alias relate goals. | |
| 1252 | #[instrument(level = "trace", skip(self, param_env), ret)] | |
| 1253 | pub(super) fn relate_rigid_alias_non_alias( | |
| 1254 | &mut self, | |
| 1255 | param_env: I::ParamEnv, | |
| 1256 | alias: ty::AliasTerm<I>, | |
| 1257 | variance: ty::Variance, | |
| 1258 | term: I::Term, | |
| 1259 | ) -> Result<(), NoSolution> { | |
| 1260 | // NOTE: this check is purely an optimization, the structural eq would | |
| 1261 | // always fail if the term is not an inference variable. | |
| 1262 | if term.is_infer() { | |
| 1263 | let cx = self.cx(); | |
| 1264 | // We need to relate `alias` to `term` treating only the outermost | |
| 1265 | // constructor as rigid, relating any contained generic arguments as | |
| 1266 | // normal. We do this by first structurally equating the `term` | |
| 1267 | // with the alias constructor instantiated with unconstrained infer vars, | |
| 1268 | // and then relate this with the whole `alias`. | |
| 1269 | // | |
| 1270 | // Alternatively we could modify `Equate` for this case by adding another | |
| 1271 | // variant to `StructurallyRelateAliases`. | |
| 1272 | let def_id = match alias.kind { | |
| 1273 | ty::AliasTermKind::ProjectionTy { def_id } => def_id.into(), | |
| 1274 | ty::AliasTermKind::InherentTy { def_id } => def_id.into(), | |
| 1275 | ty::AliasTermKind::OpaqueTy { def_id } => def_id.into(), | |
| 1276 | ty::AliasTermKind::FreeTy { def_id } => def_id.into(), | |
| 1277 | ty::AliasTermKind::AnonConst { def_id } => def_id.into(), | |
| 1278 | ty::AliasTermKind::ProjectionConst { def_id } => def_id.into(), | |
| 1279 | ty::AliasTermKind::FreeConst { def_id } => def_id.into(), | |
| 1280 | ty::AliasTermKind::InherentConst { def_id } => def_id.into(), | |
| 1281 | }; | |
| 1282 | let identity_args = self.fresh_args_for_item(def_id); | |
| 1283 | let rigid_ctor = alias.with_args(cx, identity_args); | |
| 1284 | let ctor_term = rigid_ctor.to_term(cx); | |
| 1285 | let obligations = self.delegate.eq_structurally_relating_aliases( | |
| 1286 | param_env, | |
| 1287 | term, | |
| 1288 | ctor_term, | |
| 1289 | self.origin_span, | |
| 1290 | )?; | |
| 1291 | debug_assert!(obligations.is_empty()); | |
| 1292 | self.relate(param_env, alias, variance, rigid_ctor) | |
| 1293 | } else { | |
| 1294 | Err(NoSolution) | |
| 1295 | } | |
| 1296 | } | |
| 1297 | ||
| 1298 | /// This should only be used when we're either instantiating a previously | |
| 1299 | /// unconstrained "return value" or when we're sure that all aliases in | |
| 1300 | /// the types are rigid. | |
| 1301 | #[instrument(level = "trace", skip(self, param_env), ret)] | |
| 1302 | pub(super) fn eq_structurally_relating_aliases<T: Relate<I>>( | |
| 1303 | &mut self, | |
| 1304 | param_env: I::ParamEnv, | |
| 1305 | lhs: T, | |
| 1306 | rhs: T, | |
| 1307 | ) -> Result<(), NoSolution> { | |
| 1308 | let result = self.delegate.eq_structurally_relating_aliases( | |
| 1309 | param_env, | |
| 1310 | lhs, | |
| 1311 | rhs, | |
| 1312 | self.origin_span, | |
| 1313 | )?; | |
| 1314 | assert_eq!(result, vec![]); | |
| 1315 | Ok(()) | |
| 1316 | } | |
| 1317 | ||
| 1318 | 1254 | #[instrument(level = "trace", skip(self, param_env), ret)] |
| 1319 | 1255 | pub(super) fn sub<T: Relate<I>>( |
| 1320 | 1256 | &mut self, |
| 1321 | 1257 | param_env: I::ParamEnv, |
| 1322 | 1258 | sub: T, |
| 1323 | 1259 | sup: T, |
| 1324 | ) -> Result<(), NoSolution> { | |
| 1260 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1325 | 1261 | self.relate(param_env, sub, ty::Variance::Covariant, sup) |
| 1326 | 1262 | } |
| 1327 | 1263 | |
| ... | ... | @@ -1332,7 +1268,7 @@ where |
| 1332 | 1268 | lhs: T, |
| 1333 | 1269 | variance: ty::Variance, |
| 1334 | 1270 | rhs: T, |
| 1335 | ) -> Result<(), NoSolution> { | |
| 1271 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1336 | 1272 | let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?; |
| 1337 | 1273 | for &goal in goals.iter() { |
| 1338 | 1274 | let source = match goal.predicate.kind().skip_binder() { |
| ... | ... | @@ -1343,7 +1279,7 @@ where |
| 1343 | 1279 | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc, |
| 1344 | 1280 | p => unreachable!("unexpected nested goal in `relate`: {p:?}"), |
| 1345 | 1281 | }; |
| 1346 | self.add_goal(source, goal); | |
| 1282 | self.add_goal(source, goal)?; | |
| 1347 | 1283 | } |
| 1348 | 1284 | Ok(()) |
| 1349 | 1285 | } |
| ... | ... | @@ -1484,7 +1420,7 @@ where |
| 1484 | 1420 | opaque_args: I::GenericArgs, |
| 1485 | 1421 | param_env: I::ParamEnv, |
| 1486 | 1422 | hidden_ty: I::Ty, |
| 1487 | ) { | |
| 1423 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 1488 | 1424 | let mut goals = Vec::new(); |
| 1489 | 1425 | self.delegate.add_item_bounds_for_hidden_type( |
| 1490 | 1426 | opaque_def_id, |
| ... | ... | @@ -1493,7 +1429,8 @@ where |
| 1493 | 1429 | hidden_ty, |
| 1494 | 1430 | &mut goals, |
| 1495 | 1431 | ); |
| 1496 | self.add_goals(GoalSource::AliasWellFormed, goals); | |
| 1432 | self.add_goals(GoalSource::AliasWellFormed, goals)?; | |
| 1433 | Ok(()) | |
| 1497 | 1434 | } |
| 1498 | 1435 | |
| 1499 | 1436 | // Try to evaluate a const, or return `None` if the const is too generic. |
| ... | ... | @@ -1540,10 +1477,9 @@ where |
| 1540 | 1477 | // however, we want to structurally instantiate to the original, non-rebased, |
| 1541 | 1478 | // trait `Self` form of the constant (with generic arguments being the trait |
| 1542 | 1479 | // `Self` type). |
| 1543 | self.relate_rigid_alias_non_alias( | |
| 1480 | self.eq( | |
| 1544 | 1481 | param_env, |
| 1545 | projection_term, | |
| 1546 | ty::Invariant, | |
| 1482 | projection_term.to_term(self.cx(), ty::IsRigid::Yes), | |
| 1547 | 1483 | expected_term, |
| 1548 | 1484 | )?; |
| 1549 | 1485 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| ... | ... | @@ -1695,7 +1631,7 @@ where |
| 1695 | 1631 | let external_constraints = |
| 1696 | 1632 | self.compute_external_query_constraints(certainty, normalization_nested_goals); |
| 1697 | 1633 | let (var_values, mut external_constraints) = |
| 1698 | eager_resolve_vars(self.delegate, (self.var_values, external_constraints)); | |
| 1634 | eager_resolve_vars(&**self.delegate, (self.var_values, external_constraints)); | |
| 1699 | 1635 | |
| 1700 | 1636 | // Remove any trivial or duplicated region constraints once we've resolved regions |
| 1701 | 1637 | let mut unique = HashSet::default(); |
| ... | ... | @@ -1781,110 +1717,39 @@ where |
| 1781 | 1717 | |
| 1782 | 1718 | ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals } |
| 1783 | 1719 | } |
| 1784 | } | |
| 1785 | ||
| 1786 | // FIXME: This should be eventually removed in favor of proper normalization. | |
| 1787 | // cc #156742 | |
| 1788 | /// Eagerly replace aliases with inference variables, emitting `AliasRelate` | |
| 1789 | /// goals, used when adding goals to the `EvalCtxt`. We compute the | |
| 1790 | /// `AliasRelate` goals before evaluating the actual goal to get all the | |
| 1791 | /// constraints we can. | |
| 1792 | /// | |
| 1793 | /// This is a performance optimization to more eagerly detect cycles during trait | |
| 1794 | /// solving. See tests/ui/traits/next-solver/cycles/cycle-modulo-ambig-aliases.rs. | |
| 1795 | /// | |
| 1796 | /// The emitted goals get evaluated in the context of the parent goal; by | |
| 1797 | /// replacing aliases in nested goals we essentially pull the normalization out of | |
| 1798 | /// the nested goal. We want to treat the goal as if the normalization still happens | |
| 1799 | /// inside of the nested goal by inheriting the `step_kind` of the nested goal and | |
| 1800 | /// storing it in the `GoalSource` of the emitted `AliasRelate` goals. | |
| 1801 | /// This is necessary for tests/ui/sized/coinductive-1.rs to compile. | |
| 1802 | struct ReplaceAliasWithInfer<'me, 'a, D, I> | |
| 1803 | where | |
| 1804 | D: SolverDelegate<Interner = I>, | |
| 1805 | I: Interner, | |
| 1806 | { | |
| 1807 | ecx: &'me mut EvalCtxt<'a, D>, | |
| 1808 | param_env: I::ParamEnv, | |
| 1809 | normalization_goal_source: GoalSource, | |
| 1810 | cache: HashMap<I::Ty, I::Ty>, | |
| 1811 | } | |
| 1812 | 1720 | |
| 1813 | impl<'me, 'a, D, I> ReplaceAliasWithInfer<'me, 'a, D, I> | |
| 1814 | where | |
| 1815 | D: SolverDelegate<Interner = I>, | |
| 1816 | I: Interner, | |
| 1817 | { | |
| 1818 | fn new( | |
| 1819 | ecx: &'me mut EvalCtxt<'a, D>, | |
| 1820 | for_goal_source: GoalSource, | |
| 1721 | pub(super) fn normalize<T: TypeFoldable<I>>( | |
| 1722 | &mut self, | |
| 1723 | source: GoalSource, | |
| 1821 | 1724 | param_env: I::ParamEnv, |
| 1822 | ) -> Self { | |
| 1823 | let step_kind = ecx.step_kind_for_source(for_goal_source); | |
| 1824 | ReplaceAliasWithInfer { | |
| 1825 | ecx, | |
| 1826 | param_env, | |
| 1827 | normalization_goal_source: GoalSource::NormalizeGoal(step_kind), | |
| 1828 | cache: Default::default(), | |
| 1829 | } | |
| 1830 | } | |
| 1831 | } | |
| 1725 | value: ty::Unnormalized<I, T>, | |
| 1726 | ) -> Result<T, NoSolutionOrRerunNonErased> { | |
| 1727 | let value = self.delegate.resolve_vars_if_possible(value.skip_normalization()); | |
| 1832 | 1728 | |
| 1833 | impl<D, I> TypeFolder<I> for ReplaceAliasWithInfer<'_, '_, D, I> | |
| 1834 | where | |
| 1835 | D: SolverDelegate<Interner = I>, | |
| 1836 | I: Interner, | |
| 1837 | { | |
| 1838 | fn cx(&self) -> I { | |
| 1839 | self.ecx.cx() | |
| 1840 | } | |
| 1841 | ||
| 1842 | fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { | |
| 1843 | match ty.kind() { | |
| 1844 | ty::Alias(alias) if !ty.has_escaping_bound_vars() => { | |
| 1845 | let infer_ty = self.ecx.next_ty_infer(); | |
| 1846 | let projection = ty::ProjectionPredicate { | |
| 1847 | projection_term: alias.into(), | |
| 1848 | term: infer_ty.into(), | |
| 1849 | }; | |
| 1850 | self.ecx.add_goal_raw( | |
| 1851 | self.normalization_goal_source, | |
| 1852 | Goal::new(self.cx(), self.param_env, projection), | |
| 1853 | ); | |
| 1854 | infer_ty | |
| 1855 | } | |
| 1856 | _ => { | |
| 1857 | if !ty.has_aliases() { | |
| 1858 | ty | |
| 1859 | } else if let Some(&entry) = self.cache.get(&ty) { | |
| 1860 | return entry; | |
| 1861 | } else { | |
| 1862 | let res = ty.super_fold_with(self); | |
| 1863 | assert!(self.cache.insert(ty, res).is_none()); | |
| 1864 | res | |
| 1865 | } | |
| 1866 | } | |
| 1729 | if !self.cx().renormalize_rigid_aliases() && !value.has_non_rigid_aliases() { | |
| 1730 | return Ok(value); | |
| 1867 | 1731 | } |
| 1868 | } | |
| 1869 | 1732 | |
| 1870 | fn fold_const(&mut self, ct: I::Const) -> I::Const { | |
| 1871 | match ct.kind() { | |
| 1872 | ty::ConstKind::Unevaluated(uv) if !ct.has_escaping_bound_vars() => { | |
| 1873 | let infer_ct = self.ecx.next_const_infer(); | |
| 1874 | let projection = | |
| 1875 | ty::ProjectionPredicate { projection_term: uv.into(), term: infer_ct.into() }; | |
| 1876 | self.ecx.add_goal_raw( | |
| 1877 | self.normalization_goal_source, | |
| 1878 | Goal::new(self.cx(), self.param_env, projection), | |
| 1879 | ); | |
| 1880 | infer_ct | |
| 1881 | } | |
| 1882 | _ => ct.super_fold_with(self), | |
| 1883 | } | |
| 1884 | } | |
| 1733 | // To drop the mutable borrow of self early. | |
| 1734 | let infcx = self.delegate.deref(); | |
| 1735 | let mut folder = NormalizationFolder::new(infcx, vec![], |alias_term| { | |
| 1736 | let infer_term = self.next_term_infer_of_alias_kind(alias_term); | |
| 1737 | let pred = ty::ProjectionPredicate { projection_term: alias_term, term: infer_term }; | |
| 1738 | let goal = Goal::new(self.cx(), param_env, pred); | |
| 1739 | self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal); | |
| 1740 | let GoalEvaluation { goal, certainty, has_changed: _, stalled_on } = | |
| 1741 | self.evaluate_goal(source, goal, None)?; | |
| 1742 | let normalization_was_ambiguous = match certainty { | |
| 1743 | Certainty::Yes => NormalizationWasAmbiguous::No, | |
| 1744 | Certainty::Maybe(_) => { | |
| 1745 | self.nested_goals.push((source, goal, stalled_on)); | |
| 1746 | NormalizationWasAmbiguous::Yes | |
| 1747 | } | |
| 1748 | }; | |
| 1885 | 1749 | |
| 1886 | fn fold_predicate(&mut self, predicate: I::Predicate) -> I::Predicate { | |
| 1887 | if predicate.allow_normalization() { predicate.super_fold_with(self) } else { predicate } | |
| 1750 | Ok((self.resolve_vars_if_possible(infer_term), normalization_was_ambiguous)) | |
| 1751 | }); | |
| 1752 | value.try_fold_with(&mut folder) | |
| 1888 | 1753 | } |
| 1889 | 1754 | } |
| 1890 | 1755 | |
| ... | ... | @@ -1919,7 +1784,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>, |
| 1919 | 1784 | origin_span: I::Span, |
| 1920 | 1785 | ) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) { |
| 1921 | 1786 | let opaque_types = delegate.clone_opaque_types_lookup_table(); |
| 1922 | let (goal, opaque_types) = eager_resolve_vars(delegate, (goal, opaque_types)); | |
| 1787 | let (goal, opaque_types) = eager_resolve_vars(&**delegate, (goal, opaque_types)); | |
| 1923 | 1788 | let typing_mode = delegate.typing_mode_raw().assert_not_erased(); |
| 1924 | 1789 | |
| 1925 | 1790 | let (orig_values, canonical_goal) = |
compiler/rustc_next_trait_solver/src/solve/mod.rs+27-30| ... | ... | @@ -24,7 +24,7 @@ mod trait_goals; |
| 24 | 24 | use derive_where::derive_where; |
| 25 | 25 | use rustc_type_ir::inherent::*; |
| 26 | 26 | pub use rustc_type_ir::solve::*; |
| 27 | use rustc_type_ir::{self as ty, Interner, TyVid, TypingMode}; | |
| 27 | use rustc_type_ir::{self as ty, Interner, TyVid}; | |
| 28 | 28 | use tracing::instrument; |
| 29 | 29 | |
| 30 | 30 | pub use self::eval_ctxt::{ |
| ... | ... | @@ -171,7 +171,7 @@ where |
| 171 | 171 | ) -> QueryResultOrRerunNonErased<I> { |
| 172 | 172 | match self.well_formed_goals(goal.param_env, goal.predicate) { |
| 173 | 173 | Some(goals) => { |
| 174 | self.add_goals(GoalSource::Misc, goals); | |
| 174 | self.add_goals(GoalSource::Misc, goals)?; | |
| 175 | 175 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 176 | 176 | } |
| 177 | 177 | None => self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS), |
| ... | ... | @@ -196,7 +196,18 @@ where |
| 196 | 196 | Goal { param_env, predicate: ct }: Goal<I, I::Const>, |
| 197 | 197 | ) -> QueryResultOrRerunNonErased<I> { |
| 198 | 198 | match ct.kind() { |
| 199 | ty::ConstKind::Unevaluated(uv) => { | |
| 199 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _) | |
| 200 | | ty::ConstKind::Placeholder(_) | |
| 201 | | ty::ConstKind::Value(_) | |
| 202 | | ty::ConstKind::Error(_) => { | |
| 203 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 204 | } | |
| 205 | ||
| 206 | ty::ConstKind::Infer(_) => { | |
| 207 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) | |
| 208 | } | |
| 209 | ||
| 210 | ty::ConstKind::Unevaluated(ty::IsRigid::No, uv) => { | |
| 200 | 211 | // We never return `NoSolution` here as `evaluate_const` emits an |
| 201 | 212 | // error itself when failing to evaluate, so emitting an additional fulfillment |
| 202 | 213 | // error in that case is unnecessary noise. This may change in the future once |
| ... | ... | @@ -211,12 +222,7 @@ where |
| 211 | 222 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) |
| 212 | 223 | } |
| 213 | 224 | } |
| 214 | ty::ConstKind::Infer(_) => { | |
| 215 | self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS) | |
| 216 | } | |
| 217 | ty::ConstKind::Placeholder(_) | ty::ConstKind::Value(_) | ty::ConstKind::Error(_) => { | |
| 218 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) | |
| 219 | } | |
| 225 | ||
| 220 | 226 | // We can freely ICE here as: |
| 221 | 227 | // - `Param` gets replaced with a placeholder during canonicalization |
| 222 | 228 | // - `Bound` cannot exist as we don't have a binder around the self Type |
| ... | ... | @@ -246,7 +252,12 @@ where |
| 246 | 252 | .evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 247 | 253 | .map_err(Into::into); |
| 248 | 254 | } |
| 249 | ty::ConstKind::Unevaluated(uv) => uv.type_of(self.cx()).skip_norm_wip(), | |
| 255 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { | |
| 256 | uv.type_of(self.cx()).skip_norm_wip() | |
| 257 | } | |
| 258 | ty::ConstKind::Unevaluated(ty::IsRigid::No, _) => unimplemented!( | |
| 259 | "non-rigid unevaluated constant for compute_const_arg_has_type_goal: {ct:?}" | |
| 260 | ), | |
| 250 | 261 | ty::ConstKind::Expr(_) => unimplemented!( |
| 251 | 262 | "`feature(generic_const_exprs)` is not supported in the new trait solver" |
| 252 | 263 | ), |
| ... | ... | @@ -366,8 +377,12 @@ where |
| 366 | 377 | param_env: I::ParamEnv, |
| 367 | 378 | term: I::Term, |
| 368 | 379 | ) -> Result<I::Term, NoSolutionOrRerunNonErased> { |
| 380 | if !self.cx().renormalize_rigid_aliases() && !term.is_non_rigid_alias() { | |
| 381 | return Ok(term); | |
| 382 | } | |
| 383 | ||
| 369 | 384 | if let Some(alias) = term.to_alias_term() { |
| 370 | let normalized_term = self.next_term_infer_of_kind(term); | |
| 385 | let normalized_term = self.next_term_infer_of_alias_kind(alias); | |
| 371 | 386 | let projection_goal = Goal::new( |
| 372 | 387 | self.cx(), |
| 373 | 388 | param_env, |
| ... | ... | @@ -375,31 +390,13 @@ where |
| 375 | 390 | ); |
| 376 | 391 | // We normalize the self type to be able to relate it with |
| 377 | 392 | // types from candidates. |
| 378 | self.add_goal(GoalSource::TypeRelating, projection_goal); | |
| 393 | self.add_goal(GoalSource::TypeRelating, projection_goal)?; | |
| 379 | 394 | self.try_evaluate_added_goals()?; |
| 380 | 395 | Ok(self.resolve_vars_if_possible(normalized_term)) |
| 381 | 396 | } else { |
| 382 | 397 | Ok(term) |
| 383 | 398 | } |
| 384 | 399 | } |
| 385 | ||
| 386 | fn opaque_type_is_rigid(&self, def_id: I::OpaqueTyId) -> bool { | |
| 387 | match self | |
| 388 | .typing_mode() | |
| 389 | // Caller should handle erased mode | |
| 390 | .assert_not_erased() | |
| 391 | { | |
| 392 | // Opaques are never rigid outside of analysis mode. | |
| 393 | TypingMode::Coherence | TypingMode::PostAnalysis | TypingMode::Codegen => false, | |
| 394 | // During analysis, opaques are rigid unless they may be defined by | |
| 395 | // the current body. | |
| 396 | TypingMode::Typeck { defining_opaque_types_and_generators: non_rigid_opaques } | |
| 397 | | TypingMode::PostTypeckUntilBorrowck { defining_opaque_types: non_rigid_opaques } | |
| 398 | | TypingMode::PostBorrowck { defined_opaque_types: non_rigid_opaques } => { | |
| 399 | !def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id.into())) | |
| 400 | } | |
| 401 | } | |
| 402 | } | |
| 403 | 400 | } |
| 404 | 401 | |
| 405 | 402 | /// The result of evaluating a goal. |
compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs+66-38| ... | ... | @@ -101,7 +101,7 @@ where |
| 101 | 101 | param_env: I::ParamEnv, |
| 102 | 102 | alias: ty::AliasTerm<I>, |
| 103 | 103 | term: I::Term, |
| 104 | ) { | |
| 104 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 105 | 105 | if let Some(ct) = term.as_const() { |
| 106 | 106 | let cx = self.cx(); |
| 107 | 107 | let expected_ty = alias.expect_ct().type_of(cx).skip_norm_wip(); |
| ... | ... | @@ -111,8 +111,9 @@ where |
| 111 | 111 | param_env, |
| 112 | 112 | predicate: ty::ClauseKind::ConstArgHasType(ct, expected_ty).upcast(cx), |
| 113 | 113 | }, |
| 114 | ); | |
| 114 | )?; | |
| 115 | 115 | } |
| 116 | Ok(()) | |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | /// When normalizing an associated item, constrain the expected term to `term`. |
| ... | ... | @@ -141,10 +142,15 @@ where |
| 141 | 142 | /// fires a `span_bug!`. Registering the obligation here ensures the type |
| 142 | 143 | /// mismatch is reported during normalization itself, tainting the MIR |
| 143 | 144 | /// before validation runs. |
| 144 | fn instantiate_normalizes_to_term(&mut self, goal: Goal<I, NormalizesTo<I>>, term: I::Term) { | |
| 145 | self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.alias, term); | |
| 145 | fn instantiate_normalizes_to_term( | |
| 146 | &mut self, | |
| 147 | goal: Goal<I, NormalizesTo<I>>, | |
| 148 | term: I::Term, | |
| 149 | ) -> Result<(), NoSolutionOrRerunNonErased> { | |
| 150 | self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.alias, term)?; | |
| 146 | 151 | self.eq(goal.param_env, goal.predicate.term, term) |
| 147 | 152 | .expect("expected goal term to be fully unconstrained"); |
| 153 | Ok(()) | |
| 148 | 154 | } |
| 149 | 155 | |
| 150 | 156 | /// Unlike `instantiate_normalizes_to_term` this instantiates the expected term |
| ... | ... | @@ -154,8 +160,13 @@ where |
| 154 | 160 | goal: Goal<I, NormalizesTo<I>>, |
| 155 | 161 | term: ty::AliasTerm<I>, |
| 156 | 162 | ) { |
| 157 | self.relate_rigid_alias_non_alias(goal.param_env, term, ty::Invariant, goal.predicate.term) | |
| 158 | .expect("expected goal term to be fully unconstrained"); | |
| 163 | self.relate( | |
| 164 | goal.param_env, | |
| 165 | term.to_term(self.cx(), ty::IsRigid::Yes), | |
| 166 | ty::Invariant, | |
| 167 | goal.predicate.term, | |
| 168 | ) | |
| 169 | .expect("expected goal term to be fully unconstrained"); | |
| 159 | 170 | } |
| 160 | 171 | } |
| 161 | 172 | |
| ... | ... | @@ -214,7 +225,7 @@ where |
| 214 | 225 | let assumption_projection_pred = ecx.instantiate_binder_with_infer(projection_pred); |
| 215 | 226 | ecx.eq(goal.param_env, goal.predicate.alias, assumption_projection_pred.projection_term)?; |
| 216 | 227 | |
| 217 | ecx.instantiate_normalizes_to_term(goal, assumption_projection_pred.term); | |
| 228 | ecx.instantiate_normalizes_to_term(goal, assumption_projection_pred.term)?; | |
| 218 | 229 | |
| 219 | 230 | // Add GAT where clauses from the trait's definition |
| 220 | 231 | // FIXME: We don't need these, since these are the type's own WF obligations. |
| ... | ... | @@ -224,7 +235,7 @@ where |
| 224 | 235 | .iter_instantiated(cx, goal.predicate.alias.args) |
| 225 | 236 | .map(Unnormalized::skip_norm_wip) |
| 226 | 237 | .map(|pred| goal.with(cx, pred)), |
| 227 | ); | |
| 238 | )?; | |
| 228 | 239 | |
| 229 | 240 | then(ecx) |
| 230 | 241 | } |
| ... | ... | @@ -290,7 +301,7 @@ where |
| 290 | 301 | .iter_instantiated(cx, impl_args) |
| 291 | 302 | .map(Unnormalized::skip_norm_wip) |
| 292 | 303 | .map(|pred| goal.with(cx, pred)); |
| 293 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); | |
| 304 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; | |
| 294 | 305 | |
| 295 | 306 | // Bail if the nested goals don't hold here. This is to avoid unnecessarily |
| 296 | 307 | // computing the `type_of` query for associated types that never apply, as |
| ... | ... | @@ -307,7 +318,7 @@ where |
| 307 | 318 | .iter_instantiated(cx, goal.predicate.alias.args) |
| 308 | 319 | .map(Unnormalized::skip_norm_wip) |
| 309 | 320 | .map(|pred| goal.with(cx, pred)), |
| 310 | ); | |
| 321 | )?; | |
| 311 | 322 | |
| 312 | 323 | let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| { |
| 313 | 324 | let error_term = match goal.predicate.alias.kind { |
| ... | ... | @@ -315,7 +326,7 @@ where |
| 315 | 326 | ty::AliasTermKind::ProjectionConst { .. } => Const::new_error(cx, guar).into(), |
| 316 | 327 | kind => panic!("expected projection, found {kind:?}"), |
| 317 | 328 | }; |
| 318 | ecx.instantiate_normalizes_to_term(goal, error_term); | |
| 329 | ecx.instantiate_normalizes_to_term(goal, error_term)?; | |
| 319 | 330 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 320 | 331 | }; |
| 321 | 332 | |
| ... | ... | @@ -339,7 +350,7 @@ where |
| 339 | 350 | ecx.add_goal( |
| 340 | 351 | GoalSource::Misc, |
| 341 | 352 | goal.with(cx, PredicateKind::Ambiguous), |
| 342 | ); | |
| 353 | )?; | |
| 343 | 354 | return ecx |
| 344 | 355 | .evaluate_added_goals_and_make_canonical_response( |
| 345 | 356 | Certainty::Yes, |
| ... | ... | @@ -389,7 +400,7 @@ where |
| 389 | 400 | // would be relevant if any of the nested goals refer to the `term`. |
| 390 | 401 | // This is not the case here and we only prefer adding an ambiguous |
| 391 | 402 | // nested goal for consistency. |
| 392 | ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous)); | |
| 403 | ecx.add_goal(GoalSource::Misc, goal.with(cx, PredicateKind::Ambiguous))?; | |
| 393 | 404 | return then(ecx, Certainty::Yes).map_err(Into::into); |
| 394 | 405 | } else { |
| 395 | 406 | ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias); |
| ... | ... | @@ -429,18 +440,18 @@ where |
| 429 | 440 | |
| 430 | 441 | // Finally we construct the actual value of the associated type. |
| 431 | 442 | let term = match goal.predicate.alias.kind { |
| 432 | ty::AliasTermKind::ProjectionTy { .. } => cx | |
| 433 | .type_of(target_item_def_id.into()) | |
| 434 | .instantiate(cx, target_args) | |
| 435 | .skip_norm_wip() | |
| 436 | .into(), | |
| 443 | ty::AliasTermKind::ProjectionTy { .. } => { | |
| 444 | let t = cx.type_of(target_item_def_id.into()).instantiate(cx, target_args); | |
| 445 | let t = ecx.normalize(GoalSource::Misc, goal.param_env, t)?; | |
| 446 | t.into() | |
| 447 | } | |
| 437 | 448 | ty::AliasTermKind::ProjectionConst { .. } |
| 438 | 449 | if cx.is_type_const(target_item_def_id.into()) => |
| 439 | 450 | { |
| 440 | cx.const_of_item(target_item_def_id.into()) | |
| 441 | .instantiate(cx, target_args) | |
| 442 | .skip_norm_wip() | |
| 443 | .into() | |
| 451 | let c = | |
| 452 | cx.const_of_item(target_item_def_id.into()).instantiate(cx, target_args); | |
| 453 | let c = ecx.normalize(GoalSource::Misc, goal.param_env, c)?; | |
| 454 | c.into() | |
| 444 | 455 | } |
| 445 | 456 | ty::AliasTermKind::ProjectionConst { .. } => { |
| 446 | 457 | let uv = ty::UnevaluatedConst::new( |
| ... | ... | @@ -460,7 +471,7 @@ where |
| 460 | 471 | kind => panic!("expected projection, found {kind:?}"), |
| 461 | 472 | }; |
| 462 | 473 | |
| 463 | ecx.instantiate_normalizes_to_term(goal, term); | |
| 474 | ecx.instantiate_normalizes_to_term(goal, term)?; | |
| 464 | 475 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into) |
| 465 | 476 | }) |
| 466 | 477 | } |
| ... | ... | @@ -480,7 +491,7 @@ where |
| 480 | 491 | }; |
| 481 | 492 | |
| 482 | 493 | ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 483 | ecx.instantiate_normalizes_to_term(goal, error_term); | |
| 494 | ecx.instantiate_normalizes_to_term(goal, error_term)?; | |
| 484 | 495 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 485 | 496 | }) |
| 486 | 497 | } |
| ... | ... | @@ -690,7 +701,7 @@ where |
| 690 | 701 | ); |
| 691 | 702 | |
| 692 | 703 | ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 693 | ecx.instantiate_normalizes_to_term(goal, upvars_ty.into()); | |
| 704 | ecx.instantiate_normalizes_to_term(goal, upvars_ty.into())?; | |
| 694 | 705 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 695 | 706 | }) |
| 696 | 707 | } |
| ... | ... | @@ -743,7 +754,7 @@ where |
| 743 | 754 | .skip_norm_wip() |
| 744 | 755 | } |
| 745 | 756 | |
| 746 | ty::Alias(_) | ty::Param(_) | ty::Placeholder(..) => { | |
| 757 | ty::Alias(ty::IsRigid::Yes, _) | ty::Param(_) | ty::Placeholder(..) => { | |
| 747 | 758 | // This is the "fallback impl" for type parameters, unnormalizable projections |
| 748 | 759 | // and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`. |
| 749 | 760 | // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't |
| ... | ... | @@ -755,8 +766,8 @@ where |
| 755 | 766 | cx.require_trait_lang_item(SolverTraitLangItem::Sized), |
| 756 | 767 | [I::GenericArg::from(goal.predicate.self_ty())], |
| 757 | 768 | ); |
| 758 | ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate)); | |
| 759 | ecx.instantiate_normalizes_to_term(goal, Ty::new_unit(cx).into()); | |
| 769 | ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate))?; | |
| 770 | ecx.instantiate_normalizes_to_term(goal, Ty::new_unit(cx).into())?; | |
| 760 | 771 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 761 | 772 | }); |
| 762 | 773 | |
| ... | ... | @@ -782,6 +793,7 @@ where |
| 782 | 793 | None => Ty::new_unit(cx), |
| 783 | 794 | Some(tail_ty) => Ty::new_projection( |
| 784 | 795 | cx, |
| 796 | ty::IsRigid::No, | |
| 785 | 797 | metadata_def_id, |
| 786 | 798 | [tail_ty.instantiate(cx, args).skip_norm_wip()], |
| 787 | 799 | ), |
| ... | ... | @@ -790,7 +802,9 @@ where |
| 790 | 802 | |
| 791 | 803 | ty::Tuple(elements) => match elements.last() { |
| 792 | 804 | None => Ty::new_unit(cx), |
| 793 | Some(tail_ty) => Ty::new_projection(cx, metadata_def_id, [tail_ty]), | |
| 805 | Some(tail_ty) => { | |
| 806 | Ty::new_projection(cx, ty::IsRigid::No, metadata_def_id, [tail_ty]) | |
| 807 | } | |
| 794 | 808 | }, |
| 795 | 809 | |
| 796 | 810 | ty::UnsafeBinder(_) => { |
| ... | ... | @@ -799,6 +813,7 @@ where |
| 799 | 813 | } |
| 800 | 814 | |
| 801 | 815 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) |
| 816 | | ty::Alias(ty::IsRigid::No, _) | |
| 802 | 817 | | ty::Bound(..) => panic!( |
| 803 | 818 | "unexpected self ty `{:?}` when normalizing `<T as Pointee>::Metadata`", |
| 804 | 819 | goal.predicate.self_ty() |
| ... | ... | @@ -806,7 +821,7 @@ where |
| 806 | 821 | }; |
| 807 | 822 | |
| 808 | 823 | ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 809 | ecx.instantiate_normalizes_to_term(goal, metadata_ty.into()); | |
| 824 | ecx.instantiate_normalizes_to_term(goal, metadata_ty.into())?; | |
| 810 | 825 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 811 | 826 | }) |
| 812 | 827 | } |
| ... | ... | @@ -833,7 +848,13 @@ where |
| 833 | 848 | CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), |
| 834 | 849 | goal, |
| 835 | 850 | ty::ProjectionPredicate { |
| 836 | projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.alias.kind, [self_ty]), | |
| 851 | projection_term: ty::AliasTerm::new( | |
| 852 | ecx.cx(), | |
| 853 | cx.alias_term_kind_from_def_id( | |
| 854 | goal.predicate.alias.expect_projection_def_id().into(), | |
| 855 | ), | |
| 856 | [self_ty], | |
| 857 | ), | |
| 837 | 858 | term, |
| 838 | 859 | } |
| 839 | 860 | .upcast(cx), |
| ... | ... | @@ -865,7 +886,13 @@ where |
| 865 | 886 | CandidateSource::BuiltinImpl(BuiltinImplSource::Misc), |
| 866 | 887 | goal, |
| 867 | 888 | ty::ProjectionPredicate { |
| 868 | projection_term: ty::AliasTerm::new(ecx.cx(), goal.predicate.alias.kind, [self_ty]), | |
| 889 | projection_term: ty::AliasTerm::new( | |
| 890 | ecx.cx(), | |
| 891 | cx.alias_term_kind_from_def_id( | |
| 892 | goal.predicate.alias.expect_projection_def_id().into(), | |
| 893 | ), | |
| 894 | [self_ty], | |
| 895 | ), | |
| 869 | 896 | term, |
| 870 | 897 | } |
| 871 | 898 | .upcast(cx), |
| ... | ... | @@ -914,7 +941,7 @@ where |
| 914 | 941 | ); |
| 915 | 942 | let yield_ty = args.as_coroutine().yield_ty(); |
| 916 | 943 | ecx.eq(goal.param_env, wrapped_expected_ty, yield_ty)?; |
| 917 | ecx.instantiate_normalizes_to_term(goal, expected_ty.into()); | |
| 944 | ecx.instantiate_normalizes_to_term(goal, expected_ty.into())?; | |
| 918 | 945 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 919 | 946 | }) |
| 920 | 947 | } |
| ... | ... | @@ -1011,7 +1038,7 @@ where |
| 1011 | 1038 | // Given an alias, parameter, or placeholder we add an impl candidate normalizing to a rigid |
| 1012 | 1039 | // alias. In case there's a where-bound further constraining this alias it is preferred over |
| 1013 | 1040 | // this impl candidate anyways. It's still a bit scuffed. |
| 1014 | ty::Alias(_) | ty::Param(_) | ty::Placeholder(..) => { | |
| 1041 | ty::Alias(ty::IsRigid::Yes, _) | ty::Param(_) | ty::Placeholder(..) => { | |
| 1015 | 1042 | return ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 1016 | 1043 | ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias); |
| 1017 | 1044 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| ... | ... | @@ -1019,6 +1046,7 @@ where |
| 1019 | 1046 | } |
| 1020 | 1047 | |
| 1021 | 1048 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) |
| 1049 | | ty::Alias(ty::IsRigid::No, _) | |
| 1022 | 1050 | | ty::Bound(..) => panic!( |
| 1023 | 1051 | "unexpected self ty `{:?}` when normalizing `<T as DiscriminantKind>::Discriminant`", |
| 1024 | 1052 | goal.predicate.self_ty() |
| ... | ... | @@ -1026,7 +1054,7 @@ where |
| 1026 | 1054 | }; |
| 1027 | 1055 | |
| 1028 | 1056 | ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 1029 | ecx.instantiate_normalizes_to_term(goal, discriminant_ty.into()); | |
| 1057 | ecx.instantiate_normalizes_to_term(goal, discriminant_ty.into())?; | |
| 1030 | 1058 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 1031 | 1059 | }) |
| 1032 | 1060 | } |
| ... | ... | @@ -1071,7 +1099,7 @@ where |
| 1071 | 1099 | _ => panic!("unexpected associated type {:?} in `Field`", goal.predicate), |
| 1072 | 1100 | }; |
| 1073 | 1101 | ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { |
| 1074 | ecx.instantiate_normalizes_to_term(goal, ty.into()); | |
| 1102 | ecx.instantiate_normalizes_to_term(goal, ty.into())?; | |
| 1075 | 1103 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 1076 | 1104 | }) |
| 1077 | 1105 | } |
| ... | ... | @@ -1089,7 +1117,7 @@ where |
| 1089 | 1117 | impl_args: I::GenericArgs, |
| 1090 | 1118 | impl_trait_ref: rustc_type_ir::TraitRef<I>, |
| 1091 | 1119 | target_container_def_id: I::DefId, |
| 1092 | ) -> Result<I::GenericArgs, NoSolution> { | |
| 1120 | ) -> Result<I::GenericArgs, NoSolutionOrRerunNonErased> { | |
| 1093 | 1121 | let cx = self.cx(); |
| 1094 | 1122 | Ok(if target_container_def_id == impl_trait_ref.def_id.into() { |
| 1095 | 1123 | // Default value from the trait definition. No need to rebase. |
| ... | ... | @@ -1114,7 +1142,7 @@ where |
| 1114 | 1142 | .iter_instantiated(cx, target_args) |
| 1115 | 1143 | .map(Unnormalized::skip_norm_wip) |
| 1116 | 1144 | .map(|pred| goal.with(cx, pred)), |
| 1117 | ); | |
| 1145 | )?; | |
| 1118 | 1146 | goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), target_args) |
| 1119 | 1147 | }) |
| 1120 | 1148 | } |
compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs+11-8| ... | ... | @@ -29,17 +29,20 @@ where |
| 29 | 29 | .iter_instantiated(cx, free_alias.args) |
| 30 | 30 | .map(Unnormalized::skip_norm_wip) |
| 31 | 31 | .map(|pred| goal.with(cx, pred)), |
| 32 | ); | |
| 32 | )?; | |
| 33 | 33 | |
| 34 | 34 | let actual = match free_alias.kind { |
| 35 | 35 | ty::AliasTermKind::FreeTy { def_id } => { |
| 36 | cx.type_of(def_id.into()).instantiate(cx, free_alias.args).skip_norm_wip().into() | |
| 36 | let free = cx.type_of(def_id.into()).instantiate(cx, free_alias.args); | |
| 37 | let free = self.normalize(GoalSource::Misc, goal.param_env, free)?; | |
| 38 | free.into() | |
| 39 | } | |
| 40 | ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => { | |
| 41 | let free = cx.const_of_item(def_id.into()).instantiate(cx, free_alias.args); | |
| 42 | let free = self.normalize(GoalSource::Misc, goal.param_env, free)?; | |
| 43 | ||
| 44 | free.into() | |
| 37 | 45 | } |
| 38 | ty::AliasTermKind::FreeConst { def_id } if cx.is_type_const(def_id.into()) => cx | |
| 39 | .const_of_item(def_id.into()) | |
| 40 | .instantiate(cx, free_alias.args) | |
| 41 | .skip_norm_wip() | |
| 42 | .into(), | |
| 43 | 46 | ty::AliasTermKind::FreeConst { .. } => { |
| 44 | 47 | return self.evaluate_const_and_instantiate_projection_term( |
| 45 | 48 | goal.param_env, |
| ... | ... | @@ -51,7 +54,7 @@ where |
| 51 | 54 | kind => panic!("expected free alias, found {kind:?}"), |
| 52 | 55 | }; |
| 53 | 56 | |
| 54 | self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.projection_term, actual); | |
| 57 | self.push_const_arg_has_type_goal(goal.param_env, goal.predicate.projection_term, actual)?; | |
| 55 | 58 | self.eq(goal.param_env, goal.predicate.term, actual)?; |
| 56 | 59 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 57 | 60 | } |
compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs+10-8| ... | ... | @@ -51,17 +51,19 @@ where |
| 51 | 51 | .iter_instantiated(cx, inherent_args) |
| 52 | 52 | .map(Unnormalized::skip_norm_wip) |
| 53 | 53 | .map(|pred| goal.with(cx, pred)), |
| 54 | ); | |
| 54 | )?; | |
| 55 | 55 | |
| 56 | 56 | let normalized: I::Term = match inherent.kind { |
| 57 | 57 | ty::AliasTermKind::InherentTy { def_id } => { |
| 58 | cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into() | |
| 58 | let inherent = cx.type_of(def_id.into()).instantiate(cx, inherent_args); | |
| 59 | let inherent = self.normalize(GoalSource::Misc, goal.param_env, inherent)?; | |
| 60 | inherent.into() | |
| 61 | } | |
| 62 | ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => { | |
| 63 | let inherent = cx.const_of_item(def_id.into()).instantiate(cx, inherent_args); | |
| 64 | let inherent = self.normalize(GoalSource::Misc, goal.param_env, inherent)?; | |
| 65 | inherent.into() | |
| 59 | 66 | } |
| 60 | ty::AliasTermKind::InherentConst { def_id } if cx.is_type_const(def_id.into()) => cx | |
| 61 | .const_of_item(def_id.into()) | |
| 62 | .instantiate(cx, inherent_args) | |
| 63 | .skip_norm_wip() | |
| 64 | .into(), | |
| 65 | 67 | ty::AliasTermKind::InherentConst { .. } => { |
| 66 | 68 | // FIXME(gca): This is dead code at the moment. It should eventually call |
| 67 | 69 | // self.evaluate_const like projected consts do in consider_impl_candidate in |
| ... | ... | @@ -78,7 +80,7 @@ where |
| 78 | 80 | goal.param_env, |
| 79 | 81 | goal.predicate.projection_term, |
| 80 | 82 | normalized, |
| 81 | ); | |
| 83 | )?; | |
| 82 | 84 | self.eq(goal.param_env, goal.predicate.term, normalized)?; |
| 83 | 85 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 84 | 86 | } |
compiler/rustc_next_trait_solver/src/solve/project_goals/mod.rs+3-26| ... | ... | @@ -44,7 +44,7 @@ where |
| 44 | 44 | goal: Goal<I, ProjectionPredicate<I>>, |
| 45 | 45 | ) -> QueryResultOrRerunNonErased<I> { |
| 46 | 46 | let ty::ProjectionPredicate { projection_term: alias, term } = goal.predicate; |
| 47 | let unconstrained_term = self.next_term_infer_of_kind(term); | |
| 47 | let unconstrained_term = self.next_term_infer_of_alias_kind(alias); | |
| 48 | 48 | let normalizes_to = |
| 49 | 49 | goal.with(self.cx(), ty::NormalizesTo { alias, term: unconstrained_term }); |
| 50 | 50 | |
| ... | ... | @@ -77,34 +77,11 @@ where |
| 77 | 77 | // since equating the normalized terms will lead to additional constraints. |
| 78 | 78 | self.inspect.make_canonical_response(Certainty::AMBIGUOUS); |
| 79 | 79 | |
| 80 | // FIXME: We shouldn't be doing this in the long term in favor of eager | |
| 81 | // normalization. | |
| 82 | // Normalize alias types in rhs. This is done in `EvalCtxt::add_goal` for nested | |
| 83 | // goals, but we might be evaluating the root goal. | |
| 84 | let term = self.replace_alias_with_infer(term, GoalSource::TypeRelating, goal.param_env); | |
| 85 | ||
| 86 | // Apply the constraints. | |
| 87 | self.try_evaluate_added_goals()?; | |
| 88 | ||
| 89 | // Finally, equate the goal's RHS with the unconstrained var. | |
| 90 | // | |
| 91 | // SUBTLE: | |
| 92 | // We structurally relate aliases here. This is necessary | |
| 93 | // as we otherwise emit a nested `AliasRelate` goal in case the | |
| 94 | // returned term is a rigid alias, resulting in overflow. | |
| 95 | // | |
| 96 | // It is correct as both `goal.predicate.term` and `unconstrained_rhs` | |
| 97 | // start out as an unconstrained inference variable so any aliases get | |
| 98 | // fully normalized when instantiating it. | |
| 99 | // | |
| 100 | // FIXME: Strictly speaking this may be incomplete if the normalized-to | |
| 101 | // type contains an ambiguous alias referencing bound regions. We should | |
| 102 | // consider changing this to only use "shallow structural equality". | |
| 103 | self.eq_structurally_relating_aliases(goal.param_env, term, unconstrained_term)?; | |
| 80 | self.eq(goal.param_env, term, unconstrained_term)?; | |
| 104 | 81 | |
| 105 | 82 | // Add the nested goals from normalization to our own nested goals. |
| 106 | 83 | for (s, g) in nested_goals { |
| 107 | self.add_goal(s, g); | |
| 84 | self.add_goal(s, g)?; | |
| 108 | 85 | } |
| 109 | 86 | |
| 110 | 87 | self.evaluate_added_goals_and_make_canonical_response(certainty) |
compiler/rustc_next_trait_solver/src/solve/project_goals/opaque_types.rs+26-24| ... | ... | @@ -32,12 +32,12 @@ where |
| 32 | 32 | opaque_ty.args, |
| 33 | 33 | goal.param_env, |
| 34 | 34 | expected, |
| 35 | ); | |
| 35 | )?; | |
| 36 | 36 | // Trying to normalize an opaque type during coherence is always ambiguous. |
| 37 | 37 | // We add a nested ambiguous goal here instead of using `Certainty::AMBIGUOUS`. |
| 38 | 38 | // This allows us to return the nested goals to the parent `AliasRelate` goal. |
| 39 | 39 | // This can then allow nested goals to fail after we've constrained the `term`. |
| 40 | self.add_goal(GoalSource::Misc, goal.with(cx, ty::PredicateKind::Ambiguous)); | |
| 40 | self.add_goal(GoalSource::Misc, goal.with(cx, ty::PredicateKind::Ambiguous))?; | |
| 41 | 41 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 42 | 42 | .map_err(Into::into) |
| 43 | 43 | } |
| ... | ... | @@ -48,10 +48,9 @@ where |
| 48 | 48 | .filter(|&def_id| defining_opaque_types.contains(&def_id.into())) |
| 49 | 49 | else { |
| 50 | 50 | // If we're not in the defining scope, treat the alias as rigid. |
| 51 | self.relate_rigid_alias_non_alias( | |
| 51 | self.eq( | |
| 52 | 52 | goal.param_env, |
| 53 | opaque_ty, | |
| 54 | ty::Invariant, | |
| 53 | opaque_ty.to_term(cx, ty::IsRigid::Yes), | |
| 55 | 54 | goal.predicate.term, |
| 56 | 55 | )?; |
| 57 | 56 | return self |
| ... | ... | @@ -93,12 +92,15 @@ where |
| 93 | 92 | TypingMode::PostTypeckUntilBorrowck { .. } => { |
| 94 | 93 | let actual = cx |
| 95 | 94 | .type_of_opaque_hir_typeck(def_id) |
| 96 | .instantiate(cx, opaque_ty.args) | |
| 97 | .skip_norm_wip(); | |
| 98 | let actual = fold_regions(cx, actual, |re, _dbi| match re.kind() { | |
| 99 | ty::ReErased => self.next_region_var(), | |
| 100 | _ => re, | |
| 95 | .instantiate(cx, opaque_ty.args); | |
| 96 | let actual = actual.map(|v| { | |
| 97 | fold_regions(cx, v, |re, _dbi| match re.kind() { | |
| 98 | ty::ReErased => self.next_region_var(), | |
| 99 | _ => re, | |
| 100 | }) | |
| 101 | 101 | }); |
| 102 | let actual = | |
| 103 | self.normalize(GoalSource::Misc, goal.param_env, actual)?; | |
| 102 | 104 | self.eq(goal.param_env, expected, actual)?; |
| 103 | 105 | } |
| 104 | 106 | TypingMode::Coherence |
| ... | ... | @@ -113,7 +115,7 @@ where |
| 113 | 115 | normalized_args, |
| 114 | 116 | goal.param_env, |
| 115 | 117 | expected, |
| 116 | ); | |
| 118 | )?; | |
| 117 | 119 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 118 | 120 | .map_err(Into::into) |
| 119 | 121 | } |
| ... | ... | @@ -122,10 +124,9 @@ where |
| 122 | 124 | .as_local() |
| 123 | 125 | .filter(|&def_id| defined_opaque_types.contains(&def_id.into())) |
| 124 | 126 | else { |
| 125 | self.relate_rigid_alias_non_alias( | |
| 127 | self.eq( | |
| 126 | 128 | goal.param_env, |
| 127 | opaque_ty, | |
| 128 | ty::Invariant, | |
| 129 | opaque_ty.to_term(cx, ty::IsRigid::Yes), | |
| 129 | 130 | goal.predicate.term, |
| 130 | 131 | )?; |
| 131 | 132 | return self |
| ... | ... | @@ -133,23 +134,25 @@ where |
| 133 | 134 | .map_err(Into::into); |
| 134 | 135 | }; |
| 135 | 136 | |
| 136 | let actual = | |
| 137 | cx.type_of(def_id.into()).instantiate(cx, opaque_ty.args).skip_norm_wip(); | |
| 137 | let actual = cx.type_of(def_id.into()).instantiate(cx, opaque_ty.args); | |
| 138 | 138 | // FIXME: Actually use a proper binder here instead of relying on `ReErased`. |
| 139 | 139 | // |
| 140 | 140 | // This is also probably unsound or sth :shrug: |
| 141 | let actual = fold_regions(cx, actual, |re, _dbi| match re.kind() { | |
| 142 | ty::ReErased => self.next_region_var(), | |
| 143 | _ => re, | |
| 141 | let actual = actual.map(|v| { | |
| 142 | fold_regions(cx, v, |re, _dbi| match re.kind() { | |
| 143 | ty::ReErased => self.next_region_var(), | |
| 144 | _ => re, | |
| 145 | }) | |
| 144 | 146 | }); |
| 147 | let actual = self.normalize(GoalSource::Misc, goal.param_env, actual)?; | |
| 145 | 148 | self.eq(goal.param_env, expected, actual)?; |
| 146 | 149 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 147 | 150 | .map_err(Into::into) |
| 148 | 151 | } |
| 149 | 152 | TypingMode::PostAnalysis | TypingMode::Codegen => { |
| 150 | 153 | // FIXME: Add an assertion that opaque type storage is empty. |
| 151 | let actual = | |
| 152 | cx.type_of(def_id.into()).instantiate(cx, opaque_ty.args).skip_norm_wip(); | |
| 154 | let actual = cx.type_of(def_id.into()).instantiate(cx, opaque_ty.args); | |
| 155 | let actual = self.normalize(GoalSource::Misc, goal.param_env, actual)?; | |
| 153 | 156 | self.eq(goal.param_env, expected, actual)?; |
| 154 | 157 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 155 | 158 | .map_err(Into::into) |
| ... | ... | @@ -172,10 +175,9 @@ where |
| 172 | 175 | } |
| 173 | 176 | |
| 174 | 177 | // Always treat the opaque type as rigid. |
| 175 | self.relate_rigid_alias_non_alias( | |
| 178 | self.eq( | |
| 176 | 179 | goal.param_env, |
| 177 | opaque_ty, | |
| 178 | ty::Invariant, | |
| 180 | opaque_ty.to_term(cx, ty::IsRigid::Yes), | |
| 179 | 181 | goal.predicate.term, |
| 180 | 182 | )?; |
| 181 | 183 | self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
compiler/rustc_next_trait_solver/src/solve/trait_goals.rs+28-23| ... | ... | @@ -106,7 +106,7 @@ where |
| 106 | 106 | .iter_instantiated(cx, impl_args) |
| 107 | 107 | .map(Unnormalized::skip_norm_wip) |
| 108 | 108 | .map(|pred| goal.with(cx, pred)); |
| 109 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); | |
| 109 | ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; | |
| 110 | 110 | |
| 111 | 111 | // We currently elaborate all supertrait outlives obligations from impls. |
| 112 | 112 | // This can be removed when we actually do coinduction correctly, and prove |
| ... | ... | @@ -117,7 +117,7 @@ where |
| 117 | 117 | .iter_instantiated(cx, impl_args) |
| 118 | 118 | .map(Unnormalized::skip_norm_wip) |
| 119 | 119 | .map(|pred| goal.with(cx, pred)), |
| 120 | ); | |
| 120 | )?; | |
| 121 | 121 | |
| 122 | 122 | then(ecx, maximal_certainty).map_err(Into::into) |
| 123 | 123 | }) |
| ... | ... | @@ -235,15 +235,15 @@ where |
| 235 | 235 | // when merging candidates anyways. |
| 236 | 236 | // |
| 237 | 237 | // See tests/ui/impl-trait/auto-trait-leakage/avoid-query-cycle-via-item-bound.rs. |
| 238 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = | |
| 238 | if let ty::Alias(is_rigid, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = | |
| 239 | 239 | goal.predicate.self_ty().kind() |
| 240 | 240 | { |
| 241 | debug_assert!(is_rigid == ty::IsRigid::Yes); | |
| 241 | 242 | if ecx.opaque_accesses.might_rerun() { |
| 242 | 243 | ecx.opaque_accesses.rerun_always(RerunReason::AutoTraitLeakage)?; |
| 243 | 244 | return Err(NoSolution.into()); |
| 244 | 245 | } |
| 245 | 246 | |
| 246 | debug_assert!(ecx.opaque_type_is_rigid(def_id)); | |
| 247 | 247 | for item_bound in cx.item_self_bounds(def_id.into()).skip_binder() { |
| 248 | 248 | if item_bound |
| 249 | 249 | .as_trait_clause() |
| ... | ... | @@ -287,7 +287,7 @@ where |
| 287 | 287 | // `GoalSource::ImplWhereClause` here would be incorrect, as we also |
| 288 | 288 | // impl them, which means we're "stepping out of the impl constructor" |
| 289 | 289 | // again. To handle this, we treat these cycles as ambiguous for now. |
| 290 | ecx.add_goals(GoalSource::Misc, nested_obligations); | |
| 290 | ecx.add_goals(GoalSource::Misc, nested_obligations)?; | |
| 291 | 291 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 292 | 292 | }) |
| 293 | 293 | } |
| ... | ... | @@ -737,13 +737,13 @@ where |
| 737 | 737 | tys.iter().map(|elem_ty| { |
| 738 | 738 | goal.with(cx, ty::TraitRef::new(cx, goal.predicate.def_id(), [elem_ty])) |
| 739 | 739 | }), |
| 740 | ); | |
| 740 | )?; | |
| 741 | 741 | } |
| 742 | 742 | ty::Array(elem_ty, _) => { |
| 743 | 743 | ecx.add_goal( |
| 744 | 744 | GoalSource::ImplWhereBound, |
| 745 | 745 | goal.with(cx, ty::TraitRef::new(cx, goal.predicate.def_id(), [elem_ty])), |
| 746 | ); | |
| 746 | )?; | |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | // All other types implement `BikeshedGuaranteedNoDrop` only if |
| ... | ... | @@ -784,7 +784,7 @@ where |
| 784 | 784 | [ty], |
| 785 | 785 | ), |
| 786 | 786 | ), |
| 787 | ); | |
| 787 | )?; | |
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | ty::Bound(..) |
| ... | ... | @@ -891,14 +891,14 @@ where |
| 891 | 891 | param_env: goal.param_env, |
| 892 | 892 | predicate: TraitRef::new(ecx.cx(), sized_trait, [base]).upcast(ecx.cx()), |
| 893 | 893 | }, |
| 894 | ); | |
| 894 | )?; | |
| 895 | 895 | ecx.add_goal( |
| 896 | 896 | GoalSource::ImplWhereBound, |
| 897 | 897 | Goal { |
| 898 | 898 | param_env: goal.param_env, |
| 899 | 899 | predicate: TraitRef::new(ecx.cx(), sized_trait, [ty]).upcast(ecx.cx()), |
| 900 | 900 | }, |
| 901 | ); | |
| 901 | )?; | |
| 902 | 902 | // FIXME(field_projections): This function does some questionable incomplete stuff by |
| 903 | 903 | // returning `Err(NoSolution)` on ambiguity. |
| 904 | 904 | ecx.try_evaluate_added_goals()? == Certainty::Yes |
| ... | ... | @@ -1018,7 +1018,7 @@ where |
| 1018 | 1018 | ecx.add_goals( |
| 1019 | 1019 | GoalSource::ImplWhereBound, |
| 1020 | 1020 | b_data.iter().map(|pred| goal.with(cx, pred.with_self_ty(cx, a_ty))), |
| 1021 | ); | |
| 1021 | )?; | |
| 1022 | 1022 | |
| 1023 | 1023 | // The type must be `Sized` to be unsized. |
| 1024 | 1024 | ecx.add_goal( |
| ... | ... | @@ -1031,10 +1031,10 @@ where |
| 1031 | 1031 | [a_ty], |
| 1032 | 1032 | ), |
| 1033 | 1033 | ), |
| 1034 | ); | |
| 1034 | )?; | |
| 1035 | 1035 | |
| 1036 | 1036 | // The type must outlive the lifetime of the `dyn` we're unsizing into. |
| 1037 | ecx.add_goal(GoalSource::Misc, goal.with(cx, ty::OutlivesPredicate(a_ty, b_region))); | |
| 1037 | ecx.add_goal(GoalSource::Misc, goal.with(cx, ty::OutlivesPredicate(a_ty, b_region)))?; | |
| 1038 | 1038 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 1039 | 1039 | }) |
| 1040 | 1040 | } |
| ... | ... | @@ -1154,7 +1154,7 @@ where |
| 1154 | 1154 | ecx.add_goal( |
| 1155 | 1155 | GoalSource::ImplWhereBound, |
| 1156 | 1156 | Goal::new(ecx.cx(), param_env, ty::OutlivesPredicate(a_region, b_region)), |
| 1157 | ); | |
| 1157 | )?; | |
| 1158 | 1158 | |
| 1159 | 1159 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into) |
| 1160 | 1160 | }) |
| ... | ... | @@ -1235,7 +1235,7 @@ where |
| 1235 | 1235 | [a_tail_ty, b_tail_ty], |
| 1236 | 1236 | ), |
| 1237 | 1237 | ), |
| 1238 | ); | |
| 1238 | )?; | |
| 1239 | 1239 | self.probe_builtin_trait_candidate(BuiltinImplSource::Misc) |
| 1240 | 1240 | .enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)) |
| 1241 | 1241 | } |
| ... | ... | @@ -1287,14 +1287,15 @@ where |
| 1287 | 1287 | ty::Dynamic(..) |
| 1288 | 1288 | | ty::Param(..) |
| 1289 | 1289 | | ty::Foreign(..) |
| 1290 | | ty::Alias(ty::AliasTy { | |
| 1291 | kind: ty::Projection { .. } | ty::Free { .. } | ty::Inherent { .. }, | |
| 1292 | .. | |
| 1293 | }) | |
| 1290 | | ty::Alias( | |
| 1291 | ty::IsRigid::Yes, | |
| 1292 | ty::AliasTy { | |
| 1293 | kind: ty::Projection { .. } | ty::Free { .. } | ty::Inherent { .. }, | |
| 1294 | .. | |
| 1295 | }, | |
| 1296 | ) | |
| 1294 | 1297 | | ty::Placeholder(..) => Some(Err(NoSolution.into())), |
| 1295 | 1298 | |
| 1296 | ty::Infer(_) | ty::Bound(_, _) => panic!("unexpected type `{self_ty:?}`"), | |
| 1297 | ||
| 1298 | 1299 | // Coroutines have one special built-in candidate, `Unpin`, which |
| 1299 | 1300 | // takes precedence over the structural auto trait candidate being |
| 1300 | 1301 | // assembled. |
| ... | ... | @@ -1317,7 +1318,7 @@ where |
| 1317 | 1318 | // okay to consider auto traits because that'll reveal its hidden type. For |
| 1318 | 1319 | // non-opaque aliases, we will not assemble any candidates since there's no way |
| 1319 | 1320 | // to further look into its type. |
| 1320 | ty::Alias(..) => None, | |
| 1321 | ty::Alias(ty::IsRigid::Yes, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => None, | |
| 1321 | 1322 | |
| 1322 | 1323 | // For rigid types, any possible implementation that could apply to |
| 1323 | 1324 | // the type (even if after unification and processing nested goals |
| ... | ... | @@ -1347,6 +1348,10 @@ where |
| 1347 | 1348 | | ty::Adt(_, _) |
| 1348 | 1349 | | ty::UnsafeBinder(_) => check_impls(), |
| 1349 | 1350 | ty::Error(_) => None, |
| 1351 | ||
| 1352 | ty::Infer(_) | ty::Alias(ty::IsRigid::No, _) | ty::Bound(_, _) => { | |
| 1353 | panic!("unexpected type `{self_ty:?}`") | |
| 1354 | } | |
| 1350 | 1355 | } |
| 1351 | 1356 | } |
| 1352 | 1357 | |
| ... | ... | @@ -1375,7 +1380,7 @@ where |
| 1375 | 1380 | .collect::<Vec<_>>() |
| 1376 | 1381 | }, |
| 1377 | 1382 | ); |
| 1378 | ecx.add_goals(GoalSource::ImplWhereBound, goals); | |
| 1383 | ecx.add_goals(GoalSource::ImplWhereBound, goals)?; | |
| 1379 | 1384 | ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) |
| 1380 | 1385 | }) |
| 1381 | 1386 | } |
compiler/rustc_passes/src/check_export.rs+1-1| ... | ... | @@ -314,7 +314,7 @@ impl<'tcx, 'a> TypeVisitor<TyCtxt<'tcx>> for ExportableItemsChecker<'tcx, 'a> { |
| 314 | 314 | | ty::CoroutineWitness(_, _) |
| 315 | 315 | | ty::Never |
| 316 | 316 | | ty::UnsafeBinder(_) |
| 317 | | ty::Alias(ty::AliasTy { kind: ty::AliasTyKind::Opaque { .. }, .. }) => { | |
| 317 | | ty::Alias(_, ty::AliasTy { kind: ty::AliasTyKind::Opaque { .. }, .. }) => { | |
| 318 | 318 | return ControlFlow::Break(ty); |
| 319 | 319 | } |
| 320 | 320 |
compiler/rustc_pattern_analysis/src/rustc.rs+4-3| ... | ... | @@ -126,7 +126,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 126 | 126 | #[inline] |
| 127 | 127 | pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> { |
| 128 | 128 | fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> { |
| 129 | let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind() | |
| 129 | debug_assert!(!cx.tcx.next_trait_solver_globally()); | |
| 130 | let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) = *ty.kind() | |
| 130 | 131 | else { |
| 131 | 132 | bug!() |
| 132 | 133 | }; |
| ... | ... | @@ -138,7 +139,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 138 | 139 | } |
| 139 | 140 | RevealedTy(ty) |
| 140 | 141 | } |
| 141 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { | |
| 142 | if let ty::Alias(ty::IsRigid::No, ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() { | |
| 142 | 143 | reveal_inner(self, ty) |
| 143 | 144 | } else { |
| 144 | 145 | RevealedTy(ty) |
| ... | ... | @@ -426,7 +427,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { |
| 426 | 427 | | ty::CoroutineClosure(..) |
| 427 | 428 | | ty::Coroutine(_, _) |
| 428 | 429 | | ty::UnsafeBinder(_) |
| 429 | | ty::Alias(_) | |
| 430 | | ty::Alias(_, _) | |
| 430 | 431 | | ty::Param(_) |
| 431 | 432 | | ty::Error(_) => ConstructorSet::Unlistable, |
| 432 | 433 | ty::CoroutineWitness(_, _) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) => { |
compiler/rustc_privacy/src/lib.rs+2-1| ... | ... | @@ -215,6 +215,7 @@ where |
| 215 | 215 | } |
| 216 | 216 | } |
| 217 | 217 | ty::Alias( |
| 218 | _, | |
| 218 | 219 | data @ ty::AliasTy { |
| 219 | 220 | kind: |
| 220 | 221 | kind @ (ty::Inherent { def_id } |
| ... | ... | @@ -274,7 +275,7 @@ where |
| 274 | 275 | try_visit!(self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)); |
| 275 | 276 | } |
| 276 | 277 | } |
| 277 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 278 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 278 | 279 | // Skip repeated `Opaque`s to avoid infinite recursion. |
| 279 | 280 | if self.visited_tys.insert(ty) { |
| 280 | 281 | // The intent is to treat `impl Trait1 + Trait2` identically to |
compiler/rustc_public/src/unstable/convert/stable/ty.rs+2-2| ... | ... | @@ -487,7 +487,7 @@ impl<'tcx> Stable<'tcx> for ty::TyKind<'tcx> { |
| 487 | 487 | ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple( |
| 488 | 488 | fields.iter().map(|ty| ty.stable(tables, cx)).collect(), |
| 489 | 489 | )), |
| 490 | ty::Alias(alias_ty) => { | |
| 490 | ty::Alias(_, alias_ty) => { | |
| 491 | 491 | TyKind::Alias(alias_ty.kind.stable(tables, cx), alias_ty.stable(tables, cx)) |
| 492 | 492 | } |
| 493 | 493 | ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)), |
| ... | ... | @@ -552,7 +552,7 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> { |
| 552 | 552 | } |
| 553 | 553 | } |
| 554 | 554 | ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)), |
| 555 | ty::ConstKind::Unevaluated(uv) => { | |
| 555 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 556 | 556 | let Some(def_id) = uv.kind.opt_def_id() else { |
| 557 | 557 | // FIXME: implement (both AliasTy and UnevaluatedConst will be needing this soon) |
| 558 | 558 | panic!( |
compiler/rustc_public_bridge/src/builder.rs+1-1| ... | ... | @@ -38,7 +38,7 @@ impl<'tcx> BodyBuilder<'tcx> { |
| 38 | 38 | let mut mono_body = self.instance.instantiate_mir_and_normalize_erasing_regions( |
| 39 | 39 | self.tcx, |
| 40 | 40 | ty::TypingEnv::fully_monomorphized(), |
| 41 | ty::EarlyBinder::bind(body), | |
| 41 | ty::EarlyBinder::bind(self.tcx, body), | |
| 42 | 42 | ); |
| 43 | 43 | self.visit_body(&mut mono_body); |
| 44 | 44 | mono_body |
compiler/rustc_query_impl/src/handle_cycle_error.rs+4-3| ... | ... | @@ -43,9 +43,10 @@ pub(crate) fn fn_sig<'tcx>( |
| 43 | 43 | unreachable!() |
| 44 | 44 | }; |
| 45 | 45 | |
| 46 | ty::EarlyBinder::bind(ty::Binder::dummy( | |
| 47 | tcx.mk_fn_sig_safe_rust_abi(std::iter::repeat_n(err, arity), err), | |
| 48 | )) | |
| 46 | ty::EarlyBinder::bind( | |
| 47 | tcx, | |
| 48 | ty::Binder::dummy(tcx.mk_fn_sig_safe_rust_abi(std::iter::repeat_n(err, arity), err)), | |
| 49 | ) | |
| 49 | 50 | } |
| 50 | 51 | |
| 51 | 52 | pub(crate) fn check_representability<'tcx>( |
compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs+6-3| ... | ... | @@ -252,9 +252,12 @@ fn trait_object_ty<'tcx>(tcx: TyCtxt<'tcx>, poly_trait_ref: ty::PolyTraitRef<'tc |
| 252 | 252 | ); |
| 253 | 253 | let term = tcx.normalize_erasing_regions( |
| 254 | 254 | ty::TypingEnv::fully_monomorphized(), |
| 255 | Unnormalized::new_wip(projection_term.to_term(tcx)), | |
| 255 | Unnormalized::new_wip(projection_term.to_term(tcx, ty::IsRigid::No)), | |
| 256 | ); | |
| 257 | debug!( | |
| 258 | "Projection {:?} -> {term}", | |
| 259 | projection_term.to_term(tcx, ty::IsRigid::No) | |
| 256 | 260 | ); |
| 257 | debug!("Projection {:?} -> {term}", projection_term.to_term(tcx),); | |
| 258 | 261 | ty::ExistentialPredicate::Projection( |
| 259 | 262 | ty::ExistentialProjection::erase_self_ty( |
| 260 | 263 | tcx, |
| ... | ... | @@ -506,7 +509,7 @@ fn implemented_method<'tcx>( |
| 506 | 509 | trait_method = assoc; |
| 507 | 510 | method_id = trait_method_def_id; |
| 508 | 511 | trait_id = tcx.parent(method_id); |
| 509 | trait_ref = ty::EarlyBinder::bind(TraitRef::from_assoc(tcx, trait_id, instance.args)); | |
| 512 | trait_ref = ty::EarlyBinder::bind(tcx, TraitRef::from_assoc(tcx, trait_id, instance.args)); | |
| 510 | 513 | trait_id |
| 511 | 514 | } else { |
| 512 | 515 | return None; |
compiler/rustc_session/src/options.rs+2| ... | ... | @@ -2654,6 +2654,8 @@ options! { |
| 2654 | 2654 | remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED], |
| 2655 | 2655 | "directory into which to write optimization remarks (if not specified, they will be \ |
| 2656 | 2656 | written to standard error output)"), |
| 2657 | renormalize_rigid_aliases: bool = (false, parse_bool, [TRACKED], | |
| 2658 | "do not skip rigid aliases in normalization for internal debugging"), | |
| 2657 | 2659 | retpoline: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: Retpoline }, |
| 2658 | 2660 | "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"), |
| 2659 | 2661 | retpoline_external_thunk: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: RetpolineExternalThunk }, |
compiler/rustc_symbol_mangling/src/export.rs+1-1| ... | ... | @@ -118,7 +118,7 @@ impl<'tcx> AbiStableHash<'tcx> for Ty<'tcx> { |
| 118 | 118 | | ty::CoroutineWitness(_, _) |
| 119 | 119 | | ty::Never |
| 120 | 120 | | ty::Tuple(_) |
| 121 | | ty::Alias(_) | |
| 121 | | ty::Alias(_, _) | |
| 122 | 122 | | ty::Param(_) |
| 123 | 123 | | ty::Bound(_, _) |
| 124 | 124 | | ty::Placeholder(_) |
compiler/rustc_symbol_mangling/src/legacy.rs+7-6| ... | ... | @@ -246,11 +246,12 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { |
| 246 | 246 | match *ty.kind() { |
| 247 | 247 | // Print all nominal types as paths (unlike `pretty_print_type`). |
| 248 | 248 | ty::FnDef(def_id, args) |
| 249 | | ty::Alias(ty::AliasTy { | |
| 250 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, | |
| 251 | args, | |
| 252 | .. | |
| 253 | }) | |
| 249 | | ty::Alias( | |
| 250 | _, | |
| 251 | ty::AliasTy { | |
| 252 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, args, .. | |
| 253 | }, | |
| 254 | ) | |
| 254 | 255 | | ty::Closure(def_id, args) |
| 255 | 256 | | ty::CoroutineClosure(def_id, args) |
| 256 | 257 | | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args), |
| ... | ... | @@ -272,7 +273,7 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> { |
| 272 | 273 | Ok(()) |
| 273 | 274 | } |
| 274 | 275 | |
| 275 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 276 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 276 | 277 | panic!("unexpected inherent projection") |
| 277 | 278 | } |
| 278 | 279 |
compiler/rustc_symbol_mangling/src/v0.rs+2-2| ... | ... | @@ -554,7 +554,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { |
| 554 | 554 | |
| 555 | 555 | // We may still encounter projections here due to the printing |
| 556 | 556 | // logic sometimes passing identity-substituted impl headers. |
| 557 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 557 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 558 | 558 | self.print_def_path(def_id, args)?; |
| 559 | 559 | } |
| 560 | 560 | |
| ... | ... | @@ -698,7 +698,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> { |
| 698 | 698 | |
| 699 | 699 | // We may still encounter unevaluated consts due to the printing |
| 700 | 700 | // logic sometimes passing identity-substituted impl headers. |
| 701 | ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, args, .. }) => match kind { | |
| 701 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => match kind { | |
| 702 | 702 | ty::UnevaluatedConstKind::Projection { def_id } |
| 703 | 703 | | ty::UnevaluatedConstKind::Inherent { def_id } |
| 704 | 704 | | ty::UnevaluatedConstKind::Free { def_id } |
compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs+9-8| ... | ... | @@ -246,10 +246,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 246 | 246 | param_env: ty::ParamEnv<'tcx>, |
| 247 | 247 | ) { |
| 248 | 248 | let (alias, &def_id, concrete) = match (expected.kind(), found.kind()) { |
| 249 | (ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), _) => { | |
| 249 | (ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), _) => { | |
| 250 | 250 | (proj, def_id, found) |
| 251 | 251 | } |
| 252 | (_, ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })) => { | |
| 252 | (_, ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })) => { | |
| 253 | 253 | (proj, def_id, expected) |
| 254 | 254 | } |
| 255 | 255 | _ => return, |
| ... | ... | @@ -314,7 +314,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 314 | 314 | "the associated type `{}` is defined as `{}` in the implementation, \ |
| 315 | 315 | but the where-bound `{}` shadows this definition\n\ |
| 316 | 316 | see issue #152409 <https://github.com/rust-lang/rust/issues/152409> for more information", |
| 317 | self.ty_to_string(tcx.mk_ty_from_kind(ty::Alias(*alias))), | |
| 317 | self.ty_to_string(alias.to_ty(tcx, ty::IsRigid::No)), | |
| 318 | 318 | self.ty_to_string(concrete), |
| 319 | 319 | self.ty_to_string(alias.self_ty()) |
| 320 | 320 | )); |
| ... | ... | @@ -1671,7 +1671,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1671 | 1671 | && values.expected.sort_string(self.tcx) |
| 1672 | 1672 | != values.found.sort_string(self.tcx); |
| 1673 | 1673 | let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) { |
| 1674 | (true, ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) => { | |
| 1674 | (true, ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })) => { | |
| 1675 | 1675 | let sm = self.tcx.sess.source_map(); |
| 1676 | 1676 | let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); |
| 1677 | 1677 | DiagStyledString::normal(format!( |
| ... | ... | @@ -1681,9 +1681,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1681 | 1681 | pos.col.to_usize() + 1, |
| 1682 | 1682 | )) |
| 1683 | 1683 | } |
| 1684 | (true, &ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. })) | |
| 1685 | if self.tcx.is_impl_trait_in_trait(def_id) => | |
| 1686 | { | |
| 1684 | ( | |
| 1685 | true, | |
| 1686 | &ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, .. }), | |
| 1687 | ) if self.tcx.is_impl_trait_in_trait(def_id) => { | |
| 1687 | 1688 | let sm = self.tcx.sess.source_map(); |
| 1688 | 1689 | let pos = sm.lookup_char_pos(self.tcx.def_span(def_id).lo()); |
| 1689 | 1690 | DiagStyledString::normal(format!( |
| ... | ... | @@ -2519,7 +2520,7 @@ impl TyCategory { |
| 2519 | 2520 | pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { |
| 2520 | 2521 | match *ty.kind() { |
| 2521 | 2522 | ty::Closure(def_id, _) => Some((Self::Closure, def_id)), |
| 2522 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 2523 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 2523 | 2524 | let kind = |
| 2524 | 2525 | if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque }; |
| 2525 | 2526 | Some((kind, def_id)) |
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+1-1| ... | ... | @@ -1060,7 +1060,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { |
| 1060 | 1060 | GenericArgKind::Type(ty) => { |
| 1061 | 1061 | if matches!( |
| 1062 | 1062 | ty.kind(), |
| 1063 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 1063 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) | |
| 1064 | 1064 | | ty::Closure(..) |
| 1065 | 1065 | | ty::CoroutineClosure(..) |
| 1066 | 1066 | | ty::Coroutine(..) |
compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs+6-1| ... | ... | @@ -162,7 +162,12 @@ pub fn suggest_new_region_bound( |
| 162 | 162 | TyKind::OpaqueDef(opaque) => { |
| 163 | 163 | // Get the identity type for this RPIT |
| 164 | 164 | let did = opaque.def_id.to_def_id(); |
| 165 | let ty = Ty::new_opaque(tcx, did, ty::GenericArgs::identity_for_item(tcx, did)); | |
| 165 | let ty = Ty::new_opaque( | |
| 166 | tcx, | |
| 167 | ty::IsRigid::No, | |
| 168 | did, | |
| 169 | ty::GenericArgs::identity_for_item(tcx, did), | |
| 170 | ); | |
| 166 | 171 | |
| 167 | 172 | if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg { |
| 168 | 173 | GenericBound::Outlives(Lifetime { |
compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs+31-23| ... | ... | @@ -46,8 +46,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 46 | 46 | ); |
| 47 | 47 | } |
| 48 | 48 | ( |
| 49 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 50 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 49 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 50 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 51 | 51 | ) => { |
| 52 | 52 | // Issue #63167 |
| 53 | 53 | diag.note("distinct uses of `impl Trait` result in different opaque types"); |
| ... | ... | @@ -89,24 +89,28 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 89 | 89 | ); |
| 90 | 90 | } |
| 91 | 91 | ( |
| 92 | ty::Alias(ty::AliasTy { | |
| 93 | kind: ty::Projection { .. } | ty::Inherent { .. }, | |
| 94 | .. | |
| 95 | }), | |
| 96 | ty::Alias(ty::AliasTy { | |
| 97 | kind: ty::Projection { .. } | ty::Inherent { .. }, | |
| 98 | .. | |
| 99 | }), | |
| 92 | ty::Alias( | |
| 93 | _, | |
| 94 | ty::AliasTy { | |
| 95 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 96 | }, | |
| 97 | ), | |
| 98 | ty::Alias( | |
| 99 | _, | |
| 100 | ty::AliasTy { | |
| 101 | kind: ty::Projection { .. } | ty::Inherent { .. }, .. | |
| 102 | }, | |
| 103 | ), | |
| 100 | 104 | ) => { |
| 101 | 105 | diag.note("an associated type was expected, but a different one was found"); |
| 102 | 106 | } |
| 103 | 107 | // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too. |
| 104 | 108 | ( |
| 105 | 109 | ty::Param(p), |
| 106 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), | |
| 110 | ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), | |
| 107 | 111 | ) |
| 108 | 112 | | ( |
| 109 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), | |
| 113 | ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }), | |
| 110 | 114 | ty::Param(p), |
| 111 | 115 | ) if !tcx.is_impl_trait_in_trait(def_id) |
| 112 | 116 | && let Some(generics) = body_generics => |
| ... | ... | @@ -229,10 +233,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 229 | 233 | } |
| 230 | 234 | ( |
| 231 | 235 | ty::Param(p), |
| 232 | ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 236 | ty::Dynamic(..) | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 233 | 237 | ) |
| 234 | 238 | | ( |
| 235 | ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 239 | ty::Dynamic(..) | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), | |
| 236 | 240 | ty::Param(p), |
| 237 | 241 | ) => { |
| 238 | 242 | if let Some(generics) = body_generics { |
| ... | ... | @@ -308,6 +312,7 @@ impl<T> Trait<T> for X { |
| 308 | 312 | } |
| 309 | 313 | ( |
| 310 | 314 | ty::Alias( |
| 315 | _, | |
| 311 | 316 | proj_ty @ ty::AliasTy { |
| 312 | 317 | kind: ty::Projection { def_id } | ty::Inherent { def_id }, |
| 313 | 318 | .. |
| ... | ... | @@ -328,6 +333,7 @@ impl<T> Trait<T> for X { |
| 328 | 333 | ( |
| 329 | 334 | _, |
| 330 | 335 | ty::Alias( |
| 336 | _, | |
| 331 | 337 | proj_ty @ ty::AliasTy { |
| 332 | 338 | kind: ty::Projection { def_id } | ty::Inherent { def_id }, |
| 333 | 339 | .. |
| ... | ... | @@ -368,9 +374,10 @@ impl<T> Trait<T> for X { |
| 368 | 374 | } |
| 369 | 375 | ( |
| 370 | 376 | ty::Dynamic(t, _), |
| 371 | ty::Alias(ty::AliasTy { | |
| 372 | kind: ty::Opaque { def_id: opaque_def_id }, .. | |
| 373 | }), | |
| 377 | ty::Alias( | |
| 378 | _, | |
| 379 | ty::AliasTy { kind: ty::Opaque { def_id: opaque_def_id }, .. }, | |
| 380 | ), | |
| 374 | 381 | ) if let Some(def_id) = t.principal_def_id() |
| 375 | 382 | && tcx |
| 376 | 383 | .explicit_item_self_bounds(opaque_def_id) |
| ... | ... | @@ -429,8 +436,8 @@ impl<T> Trait<T> for X { |
| 429 | 436 | )); |
| 430 | 437 | } |
| 431 | 438 | } |
| 432 | (_, ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 433 | | (ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) => { | |
| 439 | (_, ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })) | |
| 440 | | (ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }), _) => { | |
| 434 | 441 | if let Some(body_owner_def_id) = body_owner_def_id |
| 435 | 442 | && def_id.is_local() |
| 436 | 443 | && matches!( |
| ... | ... | @@ -830,7 +837,7 @@ fn foo(&self) -> Self::T { String::new() } |
| 830 | 837 | }; |
| 831 | 838 | |
| 832 | 839 | let assoc = tcx.associated_item(def_id); |
| 833 | if let ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = | |
| 840 | if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) = | |
| 834 | 841 | *proj_ty.self_ty().kind() |
| 835 | 842 | { |
| 836 | 843 | let opaque_local_def_id = def_id.as_local(); |
| ... | ... | @@ -881,9 +888,10 @@ fn foo(&self) -> Self::T { String::new() } |
| 881 | 888 | .filter_map(|item| { |
| 882 | 889 | let method = tcx.fn_sig(item.def_id).instantiate_identity().skip_norm_wip(); |
| 883 | 890 | match *method.output().skip_binder().kind() { |
| 884 | ty::Alias(ty::AliasTy { | |
| 885 | kind: ty::Projection { def_id: item_def_id }, .. | |
| 886 | }) if item_def_id == proj_ty_item_def_id => Some(( | |
| 891 | ty::Alias( | |
| 892 | _, | |
| 893 | ty::AliasTy { kind: ty::Projection { def_id: item_def_id }, .. }, | |
| 894 | ) if item_def_id == proj_ty_item_def_id => Some(( | |
| 887 | 895 | tcx.def_span(item.def_id), |
| 888 | 896 | format!("consider calling `{}`", tcx.def_path_str(item.def_id)), |
| 889 | 897 | )), |
compiler/rustc_trait_selection/src/error_reporting/infer/region.rs+6-1| ... | ... | @@ -1278,7 +1278,12 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>( |
| 1278 | 1278 | let tcx = infcx.tcx; |
| 1279 | 1279 | let mut err = infcx.dcx().create_err(diagnostics::OpaqueCapturesLifetime { |
| 1280 | 1280 | span, |
| 1281 | opaque_ty: Ty::new_opaque(tcx, opaque_ty_key.def_id.to_def_id(), opaque_ty_key.args), | |
| 1281 | opaque_ty: Ty::new_opaque( | |
| 1282 | tcx, | |
| 1283 | ty::IsRigid::No, | |
| 1284 | opaque_ty_key.def_id.to_def_id(), | |
| 1285 | opaque_ty_key.args, | |
| 1286 | ), | |
| 1282 | 1287 | opaque_ty_span: tcx.def_span(opaque_ty_key.def_id), |
| 1283 | 1288 | }); |
| 1284 | 1289 |
compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs+14-12| ... | ... | @@ -769,20 +769,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { |
| 769 | 769 | StatementAsExpression::CorrectType |
| 770 | 770 | } |
| 771 | 771 | ( |
| 772 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: last_def_id }, .. }), | |
| 773 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id: exp_def_id }, .. }), | |
| 772 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: last_def_id }, .. }), | |
| 773 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id: exp_def_id }, .. }), | |
| 774 | 774 | ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, |
| 775 | 775 | ( |
| 776 | ty::Alias(ty::AliasTy { | |
| 777 | kind: ty::Opaque { def_id: last_def_id }, | |
| 778 | args: last_bounds, | |
| 779 | .. | |
| 780 | }), | |
| 781 | ty::Alias(ty::AliasTy { | |
| 782 | kind: ty::Opaque { def_id: exp_def_id }, | |
| 783 | args: exp_bounds, | |
| 784 | .. | |
| 785 | }), | |
| 776 | ty::Alias( | |
| 777 | _, | |
| 778 | ty::AliasTy { | |
| 779 | kind: ty::Opaque { def_id: last_def_id }, args: last_bounds, .. | |
| 780 | }, | |
| 781 | ), | |
| 782 | ty::Alias( | |
| 783 | _, | |
| 784 | ty::AliasTy { | |
| 785 | kind: ty::Opaque { def_id: exp_def_id }, args: exp_bounds, .. | |
| 786 | }, | |
| 787 | ), | |
| 786 | 788 | ) => { |
| 787 | 789 | debug!( |
| 788 | 790 | "both opaque, likely future {:?} {:?} {:?} {:?}", |
compiler/rustc_trait_selection/src/error_reporting/traits/call_kind.rs+7-2| ... | ... | @@ -6,7 +6,7 @@ use rustc_hir::def::DefKind; |
| 6 | 6 | use rustc_hir::def_id::DefId; |
| 7 | 7 | use rustc_hir::{LangItem, lang_items}; |
| 8 | 8 | use rustc_middle::ty::{ |
| 9 | AssocContainer, GenericArgsRef, Instance, Ty, TyCtxt, TypingEnv, Unnormalized, | |
| 9 | self, AssocContainer, GenericArgsRef, Instance, Ty, TyCtxt, TypingEnv, Unnormalized, | |
| 10 | 10 | }; |
| 11 | 11 | use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, sym}; |
| 12 | 12 | use tracing::debug; |
| ... | ... | @@ -104,7 +104,12 @@ pub fn call_kind<'tcx>( |
| 104 | 104 | tcx.get_diagnostic_item(sym::deref_target).expect("deref method but no deref target"); |
| 105 | 105 | let deref_target_ty = tcx.normalize_erasing_regions( |
| 106 | 106 | typing_env, |
| 107 | Unnormalized::new(Ty::new_projection(tcx, deref_target_def_id, method_args)), | |
| 107 | Unnormalized::new(Ty::new_projection( | |
| 108 | tcx, | |
| 109 | ty::IsRigid::No, | |
| 110 | deref_target_def_id, | |
| 111 | method_args, | |
| 112 | )), | |
| 108 | 113 | ); |
| 109 | 114 | let deref_target_span = if let Ok(Some(instance)) = |
| 110 | 115 | Instance::try_resolve(tcx, typing_env, method_did, method_args) |
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+30-13| ... | ... | @@ -1612,7 +1612,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1612 | 1612 | infer::BoundRegionConversionTime::HigherRankedType, |
| 1613 | 1613 | bound_predicate.rebind(data), |
| 1614 | 1614 | ); |
| 1615 | let unnormalized_term = data.projection_term.to_term(self.tcx); | |
| 1615 | let unnormalized_term = data.projection_term.to_term(self.tcx, ty::IsRigid::No); | |
| 1616 | 1616 | // FIXME(-Znext-solver): For diagnostic purposes, it would be nice |
| 1617 | 1617 | // to deeply normalize this type. |
| 1618 | 1618 | let normalized_term = ocx.normalize( |
| ... | ... | @@ -1651,7 +1651,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1651 | 1651 | let normalized_term = ocx.normalize( |
| 1652 | 1652 | &ObligationCause::dummy(), |
| 1653 | 1653 | obligation.param_env, |
| 1654 | Unnormalized::new_wip(alias_term.to_term(self.tcx)), | |
| 1654 | Unnormalized::new_wip( | |
| 1655 | alias_term.to_term(self.tcx, ty::IsRigid::No), | |
| 1656 | ), | |
| 1655 | 1657 | ); |
| 1656 | 1658 | |
| 1657 | 1659 | if let Err(terr) = ocx.eq( |
| ... | ... | @@ -1919,10 +1921,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1919 | 1921 | ty::Closure(..) => Some(9), |
| 1920 | 1922 | ty::Tuple(..) => Some(10), |
| 1921 | 1923 | ty::Param(..) => Some(11), |
| 1922 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }) => Some(12), | |
| 1923 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => Some(13), | |
| 1924 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => Some(14), | |
| 1925 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => Some(15), | |
| 1924 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => Some(12), | |
| 1925 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => Some(13), | |
| 1926 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => Some(14), | |
| 1927 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => Some(15), | |
| 1926 | 1928 | ty::Never => Some(16), |
| 1927 | 1929 | ty::Adt(..) => Some(17), |
| 1928 | 1930 | ty::Coroutine(..) => Some(18), |
| ... | ... | @@ -2147,7 +2149,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2147 | 2149 | let impl_trait_ref = ocx.normalize( |
| 2148 | 2150 | &ObligationCause::dummy(), |
| 2149 | 2151 | param_env, |
| 2150 | ty::EarlyBinder::bind(single.trait_ref).instantiate(self.tcx, impl_args), | |
| 2152 | ty::EarlyBinder::bind(self.tcx, single.trait_ref) | |
| 2153 | .instantiate(self.tcx, impl_args), | |
| 2151 | 2154 | ); |
| 2152 | 2155 | |
| 2153 | 2156 | ocx.register_obligations( |
| ... | ... | @@ -2805,12 +2808,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 2805 | 2808 | self.infcx.tcx |
| 2806 | 2809 | } |
| 2807 | 2810 | |
| 2811 | // FIXME: why don't we also instantiate const and region params with infer vars | |
| 2812 | // here? Because diagnostics isn't soundness critical and no one bothers to be | |
| 2813 | // pedantic yet. | |
| 2808 | 2814 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 2809 | if let ty::Param(_) = *ty.kind() { | |
| 2810 | let infcx = self.infcx; | |
| 2811 | *self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var(DUMMY_SP)) | |
| 2812 | } else { | |
| 2813 | ty.super_fold_with(self) | |
| 2815 | match ty.kind() { | |
| 2816 | ty::Param(_) => { | |
| 2817 | let infcx = self.infcx; | |
| 2818 | *self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var(DUMMY_SP)) | |
| 2819 | } | |
| 2820 | // FIXME(#155345): This should automatically | |
| 2821 | // handled by type folders instead of needing to do it | |
| 2822 | // manually here. | |
| 2823 | &ty::Alias(is_rigid, alias) | |
| 2824 | if is_rigid == ty::IsRigid::Yes | |
| 2825 | && ty.has_type_flags(ty::TypeFlags::HAS_TY_PARAM) => | |
| 2826 | { | |
| 2827 | let alias = alias.fold_with(self); | |
| 2828 | Ty::new_alias(self.cx(), ty::IsRigid::No, alias) | |
| 2829 | } | |
| 2830 | _ => ty.super_fold_with(self), | |
| 2814 | 2831 | } |
| 2815 | 2832 | } |
| 2816 | 2833 | } |
| ... | ... | @@ -3752,7 +3769,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 3752 | 3769 | |
| 3753 | 3770 | match obligation.predicate.kind().skip_binder() { |
| 3754 | 3771 | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => match ct.kind() { |
| 3755 | ty::ConstKind::Unevaluated(uv) => { | |
| 3772 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 3756 | 3773 | let mut err = |
| 3757 | 3774 | self.dcx().struct_span_err(span, "unconstrained generic constant"); |
| 3758 | 3775 | let const_span = uv.kind.def_span(self.tcx); |
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs+8-7| ... | ... | @@ -476,7 +476,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 476 | 476 | let self_ty = trait_pred.skip_binder().self_ty(); |
| 477 | 477 | let (param_ty, projection) = match *self_ty.kind() { |
| 478 | 478 | ty::Param(_) => (true, None), |
| 479 | ty::Alias(alias) => { | |
| 479 | ty::Alias(_, alias) => { | |
| 480 | 480 | if let Some(projection) = alias.try_to_projection() { |
| 481 | 481 | (false, Some(projection)) |
| 482 | 482 | } else { |
| ... | ... | @@ -1484,7 +1484,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 1484 | 1484 | sig_parts.map_bound(|sig| sig.tupled_inputs_ty.tuple_fields().as_slice()), |
| 1485 | 1485 | )) |
| 1486 | 1486 | } |
| 1487 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 1487 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 1488 | 1488 | self.tcx |
| 1489 | 1489 | .item_self_bounds(def_id) |
| 1490 | 1490 | .instantiate(self.tcx, args) |
| ... | ... | @@ -4051,7 +4051,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4051 | 4051 | } |
| 4052 | 4052 | } |
| 4053 | 4053 | } |
| 4054 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 4054 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 4055 | 4055 | // If the previous type is async fn, this is the future generated by the body of an async function. |
| 4056 | 4056 | // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below). |
| 4057 | 4057 | let is_future = tcx.ty_is_opaque_future(ty); |
| ... | ... | @@ -4534,6 +4534,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4534 | 4534 | let projection_ty = trait_pred.map_bound(|trait_pred| { |
| 4535 | 4535 | Ty::new_projection( |
| 4536 | 4536 | self.tcx, |
| 4537 | ty::IsRigid::No, | |
| 4537 | 4538 | item_def_id, |
| 4538 | 4539 | // Future::Output has no args |
| 4539 | 4540 | [trait_pred.self_ty()], |
| ... | ... | @@ -4878,7 +4879,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4878 | 4879 | .skip_binder() |
| 4879 | 4880 | .projection_term |
| 4880 | 4881 | .expect_ty() |
| 4881 | .to_ty(self.tcx), | |
| 4882 | .to_ty(self.tcx, ty::IsRigid::No), | |
| 4882 | 4883 | found, |
| 4883 | 4884 | })]; |
| 4884 | 4885 | } |
| ... | ... | @@ -4976,7 +4977,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 4976 | 4977 | |
| 4977 | 4978 | // Extract `<U as Deref>::Target` assoc type and check that it is `T` |
| 4978 | 4979 | && let Some(deref_target_did) = tcx.lang_items().deref_target() |
| 4979 | && let projection = Ty::new_projection_from_args(tcx,deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)])) | |
| 4980 | && let projection = Ty::new_projection_from_args(tcx,ty::IsRigid::No, deref_target_did, tcx.mk_args(&[ty::GenericArg::from(found_ty)])) | |
| 4980 | 4981 | && let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(Unnormalized::new_wip(projection)) |
| 4981 | 4982 | && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation)) |
| 4982 | 4983 | && infcx.can_eq(param_env, deref_target, target_ty) |
| ... | ... | @@ -5338,7 +5339,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5338 | 5339 | let TypeError::Sorts(expected_found) = diff else { |
| 5339 | 5340 | continue; |
| 5340 | 5341 | }; |
| 5341 | let &ty::Alias(ty::AliasTy { kind: kind @ ty::Projection { def_id }, .. }) = | |
| 5342 | let &ty::Alias(_, ty::AliasTy { kind: kind @ ty::Projection { def_id }, .. }) = | |
| 5342 | 5343 | expected_found.expected.kind() |
| 5343 | 5344 | else { |
| 5344 | 5345 | continue; |
| ... | ... | @@ -5666,7 +5667,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 5666 | 5667 | } |
| 5667 | 5668 | |
| 5668 | 5669 | // Look for an RPITIT |
| 5669 | let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = | |
| 5670 | let ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = | |
| 5670 | 5671 | trait_pred.self_ty().skip_binder().kind() |
| 5671 | 5672 | else { |
| 5672 | 5673 | return; |
compiler/rustc_trait_selection/src/opaque_types.rs+1-1| ... | ... | @@ -225,7 +225,7 @@ pub fn report_item_does_not_constrain_error<'tcx>( |
| 225 | 225 | err.note("consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`"); |
| 226 | 226 | err.span_note(opaque_type_span, "this opaque type is supposed to be constrained"); |
| 227 | 227 | if let Some((key, span)) = non_defining_use { |
| 228 | let opaque_ty = Ty::new_opaque(tcx, key.def_id.into(), key.args); | |
| 228 | let opaque_ty = Ty::new_opaque(tcx, ty::IsRigid::No, key.def_id.into(), key.args); | |
| 229 | 229 | err.span_note( |
| 230 | 230 | span, |
| 231 | 231 | format!("this use of `{opaque_ty}` does not have unique universal generic arguments"), |
compiler/rustc_trait_selection/src/solve/delegate.rs+1-1| ... | ... | @@ -220,7 +220,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate< |
| 220 | 220 | param_env: ty::ParamEnv<'tcx>, |
| 221 | 221 | uv: ty::UnevaluatedConst<'tcx>, |
| 222 | 222 | ) -> Option<ty::Const<'tcx>> { |
| 223 | let ct = ty::Const::new_unevaluated(self.tcx, uv); | |
| 223 | let ct = ty::Const::new_unevaluated(self.tcx, ty::IsRigid::No, uv); | |
| 224 | 224 | |
| 225 | 225 | match crate::traits::try_evaluate_const(&self.0, ct, param_env) { |
| 226 | 226 | Ok(ct) => Some(ct), |
compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs+2-2| ... | ... | @@ -34,7 +34,7 @@ pub(super) fn fulfillment_error_for_no_solution<'tcx>( |
| 34 | 34 | } |
| 35 | 35 | ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => { |
| 36 | 36 | let ct_ty = match ct.kind() { |
| 37 | ty::ConstKind::Unevaluated(uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 37 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 38 | 38 | ty::ConstKind::Param(param_ct) => { |
| 39 | 39 | param_ct.find_const_ty_from_env(obligation.param_env) |
| 40 | 40 | } |
| ... | ... | @@ -300,7 +300,7 @@ impl<'tcx> BestObligation<'tcx> { |
| 300 | 300 | ) -> ControlFlow<PredicateObligation<'tcx>> { |
| 301 | 301 | assert!(!self.consider_ambiguities); |
| 302 | 302 | let tcx = goal.infcx().tcx; |
| 303 | if let ty::Alias(alias) = *self_ty.kind() { | |
| 303 | if let ty::Alias(_, alias) = *self_ty.kind() { | |
| 304 | 304 | let infer_term = goal.infcx().next_ty_var(self.obligation.cause.span); |
| 305 | 305 | let pred = |
| 306 | 306 | ty::ProjectionPredicate { projection_term: alias.into(), term: infer_term.into() }; |
compiler/rustc_trait_selection/src/solve/inspect/analyse.rs+2-2| ... | ... | @@ -151,7 +151,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> { |
| 151 | 151 | self.final_state, |
| 152 | 152 | ); |
| 153 | 153 | |
| 154 | return eager_resolve_vars(infcx, impl_args); | |
| 154 | return eager_resolve_vars(&**infcx, impl_args); | |
| 155 | 155 | } |
| 156 | 156 | inspect::ProbeStep::AddGoal(..) => {} |
| 157 | 157 | inspect::ProbeStep::MakeCanonicalResponse { .. } |
| ... | ... | @@ -331,7 +331,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> { |
| 331 | 331 | infcx, |
| 332 | 332 | depth, |
| 333 | 333 | orig_values, |
| 334 | goal: eager_resolve_vars(infcx, uncanonicalized_goal), | |
| 334 | goal: eager_resolve_vars(&**infcx, uncanonicalized_goal), | |
| 335 | 335 | result, |
| 336 | 336 | final_revision, |
| 337 | 337 | source, |
compiler/rustc_trait_selection/src/solve/normalize.rs+38-25| ... | ... | @@ -9,7 +9,7 @@ use rustc_middle::ty::{ |
| 9 | 9 | self, Binder, Flags, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, |
| 10 | 10 | UniverseIndex, Unnormalized, |
| 11 | 11 | }; |
| 12 | use rustc_next_trait_solver::normalize::NormalizationFolder; | |
| 12 | use rustc_next_trait_solver::normalize::{NormalizationFolder, NormalizationWasAmbiguous}; | |
| 13 | 13 | use rustc_next_trait_solver::solve::SolverDelegateEvalExt; |
| 14 | 14 | |
| 15 | 15 | use super::{FulfillmentCtxt, NextSolverError}; |
| ... | ... | @@ -42,26 +42,34 @@ where |
| 42 | 42 | let infcx = at.infcx; |
| 43 | 43 | let value = value.skip_normalization(); |
| 44 | 44 | let value = infcx.resolve_vars_if_possible(value); |
| 45 | ||
| 46 | if !infcx.tcx.renormalize_rigid_aliases() && !value.has_non_rigid_aliases() { | |
| 47 | return Normalized { value, obligations: Default::default() }; | |
| 48 | } | |
| 49 | ||
| 45 | 50 | let original_value = value.clone(); |
| 46 | let mut folder = | |
| 47 | NormalizationFolder::new(infcx, universes.clone(), Default::default(), |alias_term| { | |
| 48 | let delegate = <&SolverDelegate<'tcx>>::from(infcx); | |
| 49 | let infer_term = | |
| 50 | delegate.next_term_var_of_kind(alias_term.to_term(infcx.tcx), at.cause.span); | |
| 51 | let predicate = | |
| 52 | ty::ProjectionPredicate { projection_term: alias_term, term: infer_term }; | |
| 53 | let goal = Goal::new(infcx.tcx, at.param_env, predicate); | |
| 54 | let result = delegate.evaluate_root_goal(goal, at.cause.span, None)?; | |
| 55 | let normalized = infcx.resolve_vars_if_possible(infer_term); | |
| 56 | let stalled_goal = match result.certainty { | |
| 57 | Certainty::Yes => None, | |
| 58 | Certainty::Maybe { .. } => Some(infcx.resolve_vars_if_possible(result.goal)), | |
| 59 | }; | |
| 60 | Ok((normalized, stalled_goal)) | |
| 61 | }); | |
| 51 | let mut stalled_goals = vec![]; | |
| 52 | let mut folder = NormalizationFolder::new(infcx, universes.clone(), |alias_term| { | |
| 53 | let delegate = <&SolverDelegate<'tcx>>::from(infcx); | |
| 54 | let infer_term = delegate.next_term_var_of_alias_kind(alias_term, at.cause.span); | |
| 55 | let predicate = ty::ProjectionPredicate { projection_term: alias_term, term: infer_term }; | |
| 56 | let goal = Goal::new(infcx.tcx, at.param_env, predicate); | |
| 57 | let result = match delegate.evaluate_root_goal(goal, at.cause.span, None) { | |
| 58 | Ok(result) => result, | |
| 59 | Err(err) => return Err(err), | |
| 60 | }; | |
| 61 | let normalized = infcx.resolve_vars_if_possible(infer_term); | |
| 62 | let normalization_was_ambiguous = match result.certainty { | |
| 63 | Certainty::Yes => NormalizationWasAmbiguous::No, | |
| 64 | Certainty::Maybe { .. } => { | |
| 65 | stalled_goals.push(result.goal); | |
| 66 | NormalizationWasAmbiguous::Yes | |
| 67 | } | |
| 68 | }; | |
| 69 | Ok((normalized, normalization_was_ambiguous)) | |
| 70 | }); | |
| 62 | 71 | if let Ok(value) = value.try_fold_with(&mut folder) { |
| 63 | let obligations = folder | |
| 64 | .stalled_goals() | |
| 72 | let obligations = stalled_goals | |
| 65 | 73 | .into_iter() |
| 66 | 74 | .map(|goal| { |
| 67 | 75 | Obligation::new(infcx.tcx, at.cause.clone(), goal.param_env, goal.predicate) |
| ... | ... | @@ -84,8 +92,7 @@ struct ReplaceAliasWithInfer<'me, 'tcx> { |
| 84 | 92 | impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> { |
| 85 | 93 | fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>) -> ty::Term<'tcx> { |
| 86 | 94 | let infcx = self.at.infcx; |
| 87 | let infer_term = | |
| 88 | infcx.next_term_var_of_kind(alias_term.to_term(infcx.tcx), self.at.cause.span); | |
| 95 | let infer_term = infcx.next_term_var_of_alias_kind(alias_term, self.at.cause.span); | |
| 89 | 96 | let obligation = Obligation::new( |
| 90 | 97 | infcx.tcx, |
| 91 | 98 | self.at.cause.clone(), |
| ... | ... | @@ -113,12 +120,15 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> { |
| 113 | 120 | } |
| 114 | 121 | |
| 115 | 122 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 116 | if !ty.has_aliases() { | |
| 123 | if !self.cx().renormalize_rigid_aliases() && !ty.has_non_rigid_aliases() { | |
| 117 | 124 | return ty; |
| 118 | 125 | } |
| 119 | 126 | |
| 120 | 127 | let ty = ty.super_fold_with(self); |
| 121 | let ty::Alias(alias) = *ty.kind() else { return ty }; | |
| 128 | let ty::Alias(orig_is_rigid, alias) = *ty.kind() else { return ty }; | |
| 129 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 130 | return ty; | |
| 131 | } | |
| 122 | 132 | |
| 123 | 133 | if ty.has_escaping_bound_vars() { |
| 124 | 134 | let (replaced, ..) = |
| ... | ... | @@ -131,12 +141,15 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> { |
| 131 | 141 | } |
| 132 | 142 | |
| 133 | 143 | fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { |
| 134 | if !ct.has_aliases() { | |
| 144 | if !self.cx().renormalize_rigid_aliases() && !ct.has_non_rigid_aliases() { | |
| 135 | 145 | return ct; |
| 136 | 146 | } |
| 137 | 147 | |
| 138 | 148 | let ct = ct.super_fold_with(self); |
| 139 | let ty::ConstKind::Unevaluated(uv) = ct.kind() else { return ct }; | |
| 149 | let ty::ConstKind::Unevaluated(orig_is_rigid, uv) = ct.kind() else { return ct }; | |
| 150 | if !self.cx().renormalize_rigid_aliases() && orig_is_rigid == ty::IsRigid::Yes { | |
| 151 | return ct; | |
| 152 | } | |
| 140 | 153 | |
| 141 | 154 | if ct.has_escaping_bound_vars() { |
| 142 | 155 | let (replaced, ..) = |
compiler/rustc_trait_selection/src/traits/auto_trait.rs+3-3| ... | ... | @@ -552,7 +552,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { |
| 552 | 552 | pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool { |
| 553 | 553 | match ty.kind() { |
| 554 | 554 | ty::Param(_) => true, |
| 555 | ty::Alias(p @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 555 | ty::Alias(_, p @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 556 | 556 | self.is_of_param(p.self_ty()) |
| 557 | 557 | } |
| 558 | 558 | _ => false, |
| ... | ... | @@ -561,7 +561,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { |
| 561 | 561 | |
| 562 | 562 | fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool { |
| 563 | 563 | if let Some(ty) = p.term().skip_binder().as_type() { |
| 564 | matches!(ty.kind(), ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) if proj == &p.skip_binder().projection_term.expect_ty()) | |
| 564 | matches!(ty.kind(), ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) if proj == &p.skip_binder().projection_term.expect_ty()) | |
| 565 | 565 | } else { |
| 566 | 566 | false |
| 567 | 567 | } |
| ... | ... | @@ -768,7 +768,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { |
| 768 | 768 | } |
| 769 | 769 | ty::PredicateKind::ConstEquate(c1, c2) => { |
| 770 | 770 | let evaluate = |c: ty::Const<'tcx>| { |
| 771 | if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { | |
| 771 | if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { | |
| 772 | 772 | let ct = |
| 773 | 773 | super::try_evaluate_const(selcx.infcx, c, obligation.param_env); |
| 774 | 774 |
compiler/rustc_trait_selection/src/traits/coherence.rs+1-1| ... | ... | @@ -542,7 +542,7 @@ fn impl_intersection_has_negative_obligation( |
| 542 | 542 | // So there are no infer variables left now, except regions which aren't resolved by `resolve_vars_if_possible`. |
| 543 | 543 | assert!(!impl1_header_args.has_non_region_infer()); |
| 544 | 544 | |
| 545 | let param_env = ty::EarlyBinder::bind(tcx.param_env(impl1_def_id)) | |
| 545 | let param_env = ty::EarlyBinder::bind(tcx, tcx.param_env(impl1_def_id)) | |
| 546 | 546 | .instantiate(tcx, impl1_header_args) |
| 547 | 547 | .skip_norm_wip(); |
| 548 | 548 |
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs+7-7| ... | ... | @@ -30,7 +30,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 30 | 30 | ) -> Result<(), NotConstEvaluatable> { |
| 31 | 31 | let tcx = infcx.tcx; |
| 32 | 32 | match tcx.expand_abstract_consts(unexpanded_ct).kind() { |
| 33 | ty::ConstKind::Unevaluated(_) | ty::ConstKind::Expr(_) => (), | |
| 33 | ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Expr(_) => (), | |
| 34 | 34 | ty::ConstKind::Param(_) |
| 35 | 35 | | ty::ConstKind::Bound(_, _) |
| 36 | 36 | | ty::ConstKind::Placeholder(_) |
| ... | ... | @@ -44,10 +44,10 @@ pub fn is_const_evaluatable<'tcx>( |
| 44 | 44 | |
| 45 | 45 | let is_anon_ct = matches!( |
| 46 | 46 | ct.kind(), |
| 47 | ty::ConstKind::Unevaluated(ty::UnevaluatedConst { | |
| 48 | kind: ty::UnevaluatedConstKind::Anon { .. }, | |
| 49 | .. | |
| 50 | }) | |
| 47 | ty::ConstKind::Unevaluated( | |
| 48 | _, | |
| 49 | ty::UnevaluatedConst { kind: ty::UnevaluatedConstKind::Anon { .. }, .. } | |
| 50 | ) | |
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | 53 | if !is_anon_ct { |
| ... | ... | @@ -69,7 +69,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 69 | 69 | // here. |
| 70 | 70 | tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported"); |
| 71 | 71 | } |
| 72 | ty::ConstKind::Unevaluated(_) => { | |
| 72 | ty::ConstKind::Unevaluated(_, _) => { | |
| 73 | 73 | match crate::traits::try_evaluate_const(infcx, unexpanded_ct, param_env) { |
| 74 | 74 | Err(EvaluateConstErr::HasGenericsOrInfers) => { |
| 75 | 75 | Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug( |
| ... | ... | @@ -94,7 +94,7 @@ pub fn is_const_evaluatable<'tcx>( |
| 94 | 94 | Ok(()) |
| 95 | 95 | } else { |
| 96 | 96 | let uv = match unexpanded_ct.kind() { |
| 97 | ty::ConstKind::Unevaluated(uv) => uv, | |
| 97 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 98 | 98 | ty::ConstKind::Expr(_) => { |
| 99 | 99 | bug!("`ConstKind::Expr` without `feature(generic_const_exprs)` enabled") |
| 100 | 100 | } |
compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs+12-9| ... | ... | @@ -604,7 +604,7 @@ fn receiver_for_self_ty<'tcx>( |
| 604 | 604 | if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) } |
| 605 | 605 | }); |
| 606 | 606 | |
| 607 | let result = EarlyBinder::bind(receiver_ty).instantiate(tcx, args).skip_norm_wip(); | |
| 607 | let result = EarlyBinder::bind(tcx, receiver_ty).instantiate(tcx, args).skip_norm_wip(); | |
| 608 | 608 | debug!( |
| 609 | 609 | "receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}", |
| 610 | 610 | receiver_ty, self_ty, method_def_id, result |
| ... | ... | @@ -859,13 +859,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> { |
| 859 | 859 | ControlFlow::Continue(()) |
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) | |
| 862 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, .. }) | |
| 863 | 863 | if self.tcx.is_impl_trait_in_trait(*def_id) => |
| 864 | 864 | { |
| 865 | 865 | // We'll deny these later in their own pass |
| 866 | 866 | ControlFlow::Continue(()) |
| 867 | 867 | } |
| 868 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 868 | ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 869 | 869 | match self.allow_self_projections { |
| 870 | 870 | AllowSelfProjections::Yes => { |
| 871 | 871 | // Only walk contained types if the parent trait is not a supertrait. |
| ... | ... | @@ -886,11 +886,14 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> { |
| 886 | 886 | let ct = self.tcx.expand_abstract_consts(ct); |
| 887 | 887 | |
| 888 | 888 | match ct.kind() { |
| 889 | ty::ConstKind::Unevaluated(ty::UnevaluatedConst { | |
| 890 | kind: ty::UnevaluatedConstKind::Projection { def_id }, | |
| 891 | args, | |
| 892 | .. | |
| 893 | }) if self.tcx.features().min_generic_const_args() => { | |
| 889 | ty::ConstKind::Unevaluated( | |
| 890 | _, | |
| 891 | ty::UnevaluatedConst { | |
| 892 | kind: ty::UnevaluatedConstKind::Projection { def_id }, | |
| 893 | args, | |
| 894 | .. | |
| 895 | }, | |
| 896 | ) if self.tcx.features().min_generic_const_args() => { | |
| 894 | 897 | match self.allow_self_projections { |
| 895 | 898 | AllowSelfProjections::Yes => { |
| 896 | 899 | let trait_def_id = self.tcx.parent(def_id); |
| ... | ... | @@ -966,7 +969,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalRpititVisitor<'tcx> { |
| 966 | 969 | type Result = ControlFlow<MethodViolation>; |
| 967 | 970 | |
| 968 | 971 | fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { |
| 969 | if let ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = *ty.kind() | |
| 972 | if let ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }) = *ty.kind() | |
| 970 | 973 | && Some(proj) != self.allowed |
| 971 | 974 | && self.tcx.is_impl_trait_in_trait(def_id) |
| 972 | 975 | { |
compiler/rustc_trait_selection/src/traits/effects.rs+3-1| ... | ... | @@ -179,6 +179,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>( |
| 179 | 179 | |
| 180 | 180 | let mut consider_ty = obligation.predicate.self_ty(); |
| 181 | 181 | while let ty::Alias( |
| 182 | _, | |
| 182 | 183 | alias_ty @ ty::AliasTy { |
| 183 | 184 | kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }), |
| 184 | 185 | .. |
| ... | ... | @@ -274,6 +275,7 @@ fn evaluate_host_effect_from_item_bounds<'tcx>( |
| 274 | 275 | |
| 275 | 276 | let mut consider_ty = obligation.predicate.self_ty(); |
| 276 | 277 | while let ty::Alias( |
| 278 | _, | |
| 277 | 279 | alias_ty @ ty::AliasTy { |
| 278 | 280 | kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }), |
| 279 | 281 | .. |
| ... | ... | @@ -376,7 +378,7 @@ fn evaluate_host_effect_for_copy_clone_goal<'tcx>( |
| 376 | 378 | | ty::Foreign(..) |
| 377 | 379 | | ty::Ref(_, _, ty::Mutability::Mut) |
| 378 | 380 | | ty::Adt(_, _) |
| 379 | | ty::Alias(_) | |
| 381 | | ty::Alias(_, _) | |
| 380 | 382 | | ty::Param(_) |
| 381 | 383 | | ty::Placeholder(..) => Err(EvaluationFailure::NoSolution), |
| 382 | 384 |
compiler/rustc_trait_selection/src/traits/fulfill.rs+13-11| ... | ... | @@ -559,7 +559,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 559 | 559 | return ProcessResult::Changed(PendingPredicateObligations::new()); |
| 560 | 560 | } |
| 561 | 561 | ty::ConstKind::Value(cv) => cv.ty, |
| 562 | ty::ConstKind::Unevaluated(uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 562 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(infcx.tcx).skip_norm_wip(), | |
| 563 | 563 | // FIXME(generic_const_exprs): we should construct an alias like |
| 564 | 564 | // `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing |
| 565 | 565 | // `lhs + rhs`. |
| ... | ... | @@ -717,13 +717,15 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 717 | 717 | debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2); |
| 718 | 718 | |
| 719 | 719 | match (c1.kind(), c2.kind()) { |
| 720 | (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) | |
| 721 | if a.kind == b.kind | |
| 722 | && matches!( | |
| 723 | a.kind, | |
| 724 | ty::UnevaluatedConstKind::Projection { .. } | |
| 725 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 726 | ) => | |
| 720 | ( | |
| 721 | ty::ConstKind::Unevaluated(_, a), | |
| 722 | ty::ConstKind::Unevaluated(_, b), | |
| 723 | ) if a.kind == b.kind | |
| 724 | && matches!( | |
| 725 | a.kind, | |
| 726 | ty::UnevaluatedConstKind::Projection { .. } | |
| 727 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 728 | ) => | |
| 727 | 729 | { |
| 728 | 730 | if let Ok(new_obligations) = infcx |
| 729 | 731 | .at(&obligation.cause, obligation.param_env) |
| ... | ... | @@ -741,8 +743,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 741 | 743 | )); |
| 742 | 744 | } |
| 743 | 745 | } |
| 744 | (_, ty::ConstKind::Unevaluated(_)) | |
| 745 | | (ty::ConstKind::Unevaluated(_), _) => (), | |
| 746 | (_, ty::ConstKind::Unevaluated(_, _)) | |
| 747 | | (ty::ConstKind::Unevaluated(_, _), _) => (), | |
| 746 | 748 | (_, _) => { |
| 747 | 749 | if let Ok(new_obligations) = infcx |
| 748 | 750 | .at(&obligation.cause, obligation.param_env) |
| ... | ... | @@ -762,7 +764,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { |
| 762 | 764 | let stalled_on = &mut pending_obligation.stalled_on; |
| 763 | 765 | |
| 764 | 766 | let mut evaluate = |c: Const<'tcx>| { |
| 765 | if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { | |
| 767 | if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() { | |
| 766 | 768 | match super::try_evaluate_const( |
| 767 | 769 | self.selcx.infcx, |
| 768 | 770 | c, |
compiler/rustc_trait_selection/src/traits/mod.rs+8-3| ... | ... | @@ -280,6 +280,9 @@ fn do_normalize_predicates<'tcx>( |
| 280 | 280 | let infcx = tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis()); |
| 281 | 281 | let ocx = ObligationCtxt::new_with_diagnostics(&infcx); |
| 282 | 282 | let predicates = ocx.normalize(&cause, elaborated_env, Unnormalized::new_wip(predicates)); |
| 283 | // FIXME: opaque types in param env might be in defining scope but we're | |
| 284 | // using non body analysis for here. So the rigidness marker is wrong. | |
| 285 | let predicates = ty::set_aliases_to_non_rigid(tcx, predicates).skip_norm_wip(); | |
| 283 | 286 | |
| 284 | 287 | let errors = ocx.evaluate_obligations_error_on_ambiguity(); |
| 285 | 288 | if !errors.is_empty() { |
| ... | ... | @@ -366,7 +369,7 @@ pub fn normalize_param_env_or_error<'tcx>( |
| 366 | 369 | // should actually be okay since without `feature(generic_const_exprs)` the only |
| 367 | 370 | // const arguments that have a non-empty param env are array repeat counts. These |
| 368 | 371 | // do not appear in the type system though. |
| 369 | if let ty::ConstKind::Unevaluated(uv) = c.kind() | |
| 372 | if let ty::ConstKind::Unevaluated(_, uv) = c.kind() | |
| 370 | 373 | && matches!(uv.kind, ty::UnevaluatedConstKind::Anon { .. }) |
| 371 | 374 | { |
| 372 | 375 | let infcx = self.0.infer_ctxt().build(TypingMode::non_body_analysis()); |
| ... | ... | @@ -605,7 +608,7 @@ pub fn try_evaluate_const<'tcx>( |
| 605 | 608 | | ty::ConstKind::Bound(_, _) |
| 606 | 609 | | ty::ConstKind::Placeholder(_) |
| 607 | 610 | | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers), |
| 608 | ty::ConstKind::Unevaluated(uv) => { | |
| 611 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 609 | 612 | let opt_anon_const_kind = match uv.kind { |
| 610 | 613 | ty::UnevaluatedConstKind::Anon { def_id } => { |
| 611 | 614 | Some((def_id, tcx.anon_const_kind(def_id))) |
| ... | ... | @@ -923,7 +926,9 @@ fn is_impossible_associated_item( |
| 923 | 926 | tcx, |
| 924 | 927 | ObligationCause::dummy_with_span(*span), |
| 925 | 928 | param_env, |
| 926 | ty::EarlyBinder::bind(*pred).instantiate(tcx, impl_trait_ref.args).skip_norm_wip(), | |
| 929 | ty::EarlyBinder::bind(tcx, *pred) | |
| 930 | .instantiate(tcx, impl_trait_ref.args) | |
| 931 | .skip_norm_wip(), | |
| 927 | 932 | ) |
| 928 | 933 | }) |
| 929 | 934 | }); |
compiler/rustc_trait_selection/src/traits/normalize.rs+10-4| ... | ... | @@ -229,7 +229,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { |
| 229 | 229 | ) |
| 230 | 230 | .ok() |
| 231 | 231 | .flatten() |
| 232 | .unwrap_or_else(|| proj.to_term(infcx.tcx)); | |
| 232 | .unwrap_or_else(|| proj.to_term(infcx.tcx, ty::IsRigid::No)); | |
| 233 | 233 | |
| 234 | 234 | PlaceholderReplacer::replace_placeholders( |
| 235 | 235 | infcx, |
| ... | ... | @@ -391,11 +391,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 394 | // We don't use the rigid marker in old solver. | |
| 395 | debug_assert!(!ty.has_rigid_aliases()); | |
| 396 | ||
| 394 | 397 | if !needs_normalization(self.selcx.infcx, &ty) { |
| 395 | 398 | return ty; |
| 396 | 399 | } |
| 397 | 400 | |
| 398 | let ty::Alias(data) = *ty.kind() else { return ty.super_fold_with(self) }; | |
| 401 | let ty::Alias(_, data) = *ty.kind() else { return ty.super_fold_with(self) }; | |
| 399 | 402 | |
| 400 | 403 | // We try to be a little clever here as a performance optimization in |
| 401 | 404 | // cases where there are nested projections under binders. |
| ... | ... | @@ -459,18 +462,21 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx |
| 459 | 462 | |
| 460 | 463 | #[instrument(skip(self), level = "debug")] |
| 461 | 464 | fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { |
| 465 | // We don't use the rigid marker in old solver. | |
| 466 | debug_assert!(!ct.has_rigid_aliases()); | |
| 467 | ||
| 462 | 468 | let tcx = self.selcx.tcx(); |
| 463 | 469 | |
| 464 | 470 | if tcx.features().generic_const_exprs() |
| 465 | 471 | // Normalize type_const items even with feature `generic_const_exprs`. |
| 466 | && !matches!(ct.kind(), ty::ConstKind::Unevaluated(uv) if uv.kind.is_type_const(tcx)) | |
| 472 | && !matches!(ct.kind(), ty::ConstKind::Unevaluated(_, uv) if uv.kind.is_type_const(tcx)) | |
| 467 | 473 | || !needs_normalization(self.selcx.infcx, &ct) |
| 468 | 474 | { |
| 469 | 475 | return ct; |
| 470 | 476 | } |
| 471 | 477 | |
| 472 | 478 | let uv = match ct.kind() { |
| 473 | ty::ConstKind::Unevaluated(uv) => uv, | |
| 479 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 474 | 480 | _ => return ct.super_fold_with(self), |
| 475 | 481 | }; |
| 476 | 482 |
compiler/rustc_trait_selection/src/traits/project.rs+7-5| ... | ... | @@ -738,7 +738,7 @@ fn project<'cx, 'tcx>( |
| 738 | 738 | } |
| 739 | 739 | ProjectionCandidateSet::None => { |
| 740 | 740 | let tcx = selcx.tcx(); |
| 741 | let term = obligation.predicate.to_term(tcx); | |
| 741 | let term = obligation.predicate.to_term(tcx, ty::IsRigid::No); | |
| 742 | 742 | Ok(Projected::NoProgress(term)) |
| 743 | 743 | } |
| 744 | 744 | // Error occurred while trying to processing impls. |
| ... | ... | @@ -1583,7 +1583,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( |
| 1583 | 1583 | } else { |
| 1584 | 1584 | // We know that `self_ty` has the same metadata as `tail`. This allows us |
| 1585 | 1585 | // to prove predicates like `Wrapper<Tail>::Metadata == Tail::Metadata`. |
| 1586 | Ty::new_projection(tcx, metadata_def_id, [tail]) | |
| 1586 | Ty::new_projection(tcx, ty::IsRigid::No, metadata_def_id, [tail]) | |
| 1587 | 1587 | } |
| 1588 | 1588 | }); |
| 1589 | 1589 | (metadata_ty.into(), obligations) |
| ... | ... | @@ -1678,6 +1678,7 @@ fn confirm_closure_candidate<'cx, 'tcx>( |
| 1678 | 1678 | tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span); |
| 1679 | 1679 | let tupled_upvars_ty = Ty::new_projection( |
| 1680 | 1680 | tcx, |
| 1681 | ty::IsRigid::No, | |
| 1681 | 1682 | upvars_projection_def_id, |
| 1682 | 1683 | [ |
| 1683 | 1684 | ty::GenericArg::from(kind_ty), |
| ... | ... | @@ -1807,6 +1808,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( |
| 1807 | 1808 | // N.B. No need to register a `AsyncFnKindHelper` goal here, it's already in `nested`. |
| 1808 | 1809 | let tupled_upvars_ty = Ty::new_projection( |
| 1809 | 1810 | tcx, |
| 1811 | ty::IsRigid::No, | |
| 1810 | 1812 | upvars_projection_def_id, |
| 1811 | 1813 | [ |
| 1812 | 1814 | ty::GenericArg::from(kind_ty), |
| ... | ... | @@ -1855,7 +1857,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( |
| 1855 | 1857 | sym::Output => { |
| 1856 | 1858 | let future_output_def_id = |
| 1857 | 1859 | tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span); |
| 1858 | Ty::new_projection(tcx, future_output_def_id, [sig.output()]) | |
| 1860 | Ty::new_projection(tcx, ty::IsRigid::No, future_output_def_id, [sig.output()]) | |
| 1859 | 1861 | } |
| 1860 | 1862 | name => bug!("no such associated type: {name}"), |
| 1861 | 1863 | }; |
| ... | ... | @@ -1889,7 +1891,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( |
| 1889 | 1891 | sym::Output => { |
| 1890 | 1892 | let future_output_def_id = |
| 1891 | 1893 | tcx.require_lang_item(LangItem::FutureOutput, obligation.cause.span); |
| 1892 | Ty::new_projection(tcx, future_output_def_id, [sig.output()]) | |
| 1894 | Ty::new_projection(tcx, ty::IsRigid::No, future_output_def_id, [sig.output()]) | |
| 1893 | 1895 | } |
| 1894 | 1896 | name => bug!("no such associated type: {name}"), |
| 1895 | 1897 | }; |
| ... | ... | @@ -2058,7 +2060,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( |
| 2058 | 2060 | // `Projected::NoProgress`. This will ensure that the projection is |
| 2059 | 2061 | // checked for well-formedness, and it's either satisfied by a trivial |
| 2060 | 2062 | // where clause in its env or it results in an error. |
| 2061 | return Ok(Projected::NoProgress(obligation.predicate.to_term(tcx))); | |
| 2063 | return Ok(Projected::NoProgress(obligation.predicate.to_term(tcx, ty::IsRigid::No))); | |
| 2062 | 2064 | } else { |
| 2063 | 2065 | return Ok(Projected::Progress(Progress { |
| 2064 | 2066 | term: if obligation.predicate.kind.is_type() { |
compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs+3-3| ... | ... | @@ -391,17 +391,17 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( |
| 391 | 391 | constraints.dtorck_types.extend( |
| 392 | 392 | dtorck_types |
| 393 | 393 | .iter() |
| 394 | .map(|t| EarlyBinder::bind(*t).instantiate(tcx, args).skip_norm_wip()), | |
| 394 | .map(|t| EarlyBinder::bind(tcx, *t).instantiate(tcx, args).skip_norm_wip()), | |
| 395 | 395 | ); |
| 396 | 396 | constraints.outlives.extend( |
| 397 | 397 | outlives |
| 398 | 398 | .iter() |
| 399 | .map(|t| EarlyBinder::bind(*t).instantiate(tcx, args).skip_norm_wip()), | |
| 399 | .map(|t| EarlyBinder::bind(tcx, *t).instantiate(tcx, args).skip_norm_wip()), | |
| 400 | 400 | ); |
| 401 | 401 | constraints.overflows.extend( |
| 402 | 402 | overflows |
| 403 | 403 | .iter() |
| 404 | .map(|t| EarlyBinder::bind(*t).instantiate(tcx, args).skip_norm_wip()), | |
| 404 | .map(|t| EarlyBinder::bind(tcx, *t).instantiate(tcx, args).skip_norm_wip()), | |
| 405 | 405 | ); |
| 406 | 406 | } |
| 407 | 407 |
compiler/rustc_trait_selection/src/traits/query/normalize.rs+3-3| ... | ... | @@ -203,7 +203,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 203 | 203 | return Ok(*ty); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | let &ty::Alias(data) = ty.kind() else { | |
| 206 | let &ty::Alias(_, data) = ty.kind() else { | |
| 207 | 207 | let res = ty.try_super_fold_with(self)?; |
| 208 | 208 | self.cache.insert(ty, res); |
| 209 | 209 | return Ok(res); |
| ... | ... | @@ -273,7 +273,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> { |
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | let uv = match constant.kind() { |
| 276 | ty::ConstKind::Unevaluated(uv) => uv, | |
| 276 | ty::ConstKind::Unevaluated(_, uv) => uv, | |
| 277 | 277 | _ => return constant.try_super_fold_with(self), |
| 278 | 278 | }; |
| 279 | 279 | |
| ... | ... | @@ -377,7 +377,7 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> { |
| 377 | 377 | // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer |
| 378 | 378 | // of type/const and we need to continue folding it to reveal the TAIT behind it |
| 379 | 379 | // or further normalize nested unevaluated consts. |
| 380 | if res != term.to_term(tcx) | |
| 380 | if res != term.to_term(tcx, ty::IsRigid::No) | |
| 381 | 381 | && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) |
| 382 | 382 | || matches!( |
| 383 | 383 | term.kind, |
compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs+10-7| ... | ... | @@ -194,7 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 194 | 194 | // quickly check if the self-type is a projection at all. |
| 195 | 195 | match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { |
| 196 | 196 | // Excluding IATs and type aliases here as they don't have meaningful item bounds. |
| 197 | ty::Alias(ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {} | |
| 197 | ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. } | ty::Opaque { .. }, .. }) => {} | |
| 198 | 198 | ty::Infer(ty::TyVar(_)) => { |
| 199 | 199 | span_bug!( |
| 200 | 200 | obligation.cause.span, |
| ... | ... | @@ -681,7 +681,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 681 | 681 | // These may potentially implement `FnPtr` |
| 682 | 682 | ty::Placeholder(..) |
| 683 | 683 | | ty::Dynamic(_, _) |
| 684 | | ty::Alias(_) | |
| 684 | | ty::Alias(_, _) | |
| 685 | 685 | | ty::Infer(_) |
| 686 | 686 | | ty::Param(..) |
| 687 | 687 | | ty::Bound(_, _) => {} |
| ... | ... | @@ -784,10 +784,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 784 | 784 | } |
| 785 | 785 | } |
| 786 | 786 | ty::Param(..) |
| 787 | | ty::Alias(ty::AliasTy { | |
| 788 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 789 | .. | |
| 790 | }) | |
| 787 | | ty::Alias( | |
| 788 | _, | |
| 789 | ty::AliasTy { | |
| 790 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 791 | .. | |
| 792 | }, | |
| 793 | ) | |
| 791 | 794 | | ty::Placeholder(..) |
| 792 | 795 | | ty::Bound(..) => { |
| 793 | 796 | // In these cases, we don't know what the actual |
| ... | ... | @@ -838,7 +841,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 838 | 841 | ); |
| 839 | 842 | } |
| 840 | 843 | |
| 841 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 844 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => { | |
| 842 | 845 | if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate { .. })) { |
| 843 | 846 | // We do not generate an auto impl candidate for `impl Trait`s which already |
| 844 | 847 | // reference our auto trait. |
compiler/rustc_trait_selection/src/traits/select/mod.rs+22-16| ... | ... | @@ -882,13 +882,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 882 | 882 | ); |
| 883 | 883 | |
| 884 | 884 | match (c1.kind(), c2.kind()) { |
| 885 | (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) | |
| 886 | if a.kind == b.kind | |
| 887 | && matches!( | |
| 888 | a.kind, | |
| 889 | ty::UnevaluatedConstKind::Projection { .. } | |
| 890 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 891 | ) => | |
| 885 | ( | |
| 886 | ty::ConstKind::Unevaluated(_, a), | |
| 887 | ty::ConstKind::Unevaluated(_, b), | |
| 888 | ) if a.kind == b.kind | |
| 889 | && matches!( | |
| 890 | a.kind, | |
| 891 | ty::UnevaluatedConstKind::Projection { .. } | |
| 892 | | ty::UnevaluatedConstKind::Inherent { .. } | |
| 893 | ) => | |
| 892 | 894 | { |
| 893 | 895 | if let Ok(InferOk { obligations, value: () }) = self |
| 894 | 896 | .infcx |
| ... | ... | @@ -907,8 +909,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 907 | 909 | ); |
| 908 | 910 | } |
| 909 | 911 | } |
| 910 | (_, ty::ConstKind::Unevaluated(_)) | |
| 911 | | (ty::ConstKind::Unevaluated(_), _) => (), | |
| 912 | (_, ty::ConstKind::Unevaluated(_, _)) | |
| 913 | | (ty::ConstKind::Unevaluated(_, _), _) => (), | |
| 912 | 914 | (_, _) => { |
| 913 | 915 | if let Ok(InferOk { obligations, value: () }) = self |
| 914 | 916 | .infcx |
| ... | ... | @@ -927,7 +929,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 927 | 929 | } |
| 928 | 930 | |
| 929 | 931 | let evaluate = |c: ty::Const<'tcx>| { |
| 930 | if let ty::ConstKind::Unevaluated(_) = c.kind() { | |
| 932 | if let ty::ConstKind::Unevaluated(_, _) = c.kind() { | |
| 931 | 933 | match crate::traits::try_evaluate_const( |
| 932 | 934 | self.infcx, |
| 933 | 935 | c, |
| ... | ... | @@ -987,7 +989,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 987 | 989 | } |
| 988 | 990 | ty::ConstKind::Error(_) => return Ok(EvaluatedToOk), |
| 989 | 991 | ty::ConstKind::Value(cv) => cv.ty, |
| 990 | ty::ConstKind::Unevaluated(uv) => uv.type_of(self.tcx()).skip_norm_wip(), | |
| 992 | ty::ConstKind::Unevaluated(_, uv) => uv.type_of(self.tcx()).skip_norm_wip(), | |
| 991 | 993 | // FIXME(generic_const_exprs): See comment in `fulfill.rs` |
| 992 | 994 | ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk), |
| 993 | 995 | ty::ConstKind::Placeholder(_) => { |
| ... | ... | @@ -1658,6 +1660,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { |
| 1658 | 1660 | loop { |
| 1659 | 1661 | let (alias_ty, def_id) = match *self_ty.kind() { |
| 1660 | 1662 | ty::Alias( |
| 1663 | _, | |
| 1661 | 1664 | alias_ty @ ty::AliasTy { |
| 1662 | 1665 | kind: ty::Projection { def_id } | ty::Opaque { def_id }, |
| 1663 | 1666 | .. |
| ... | ... | @@ -2348,10 +2351,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> { |
| 2348 | 2351 | ty::Placeholder(..) |
| 2349 | 2352 | | ty::Dynamic(..) |
| 2350 | 2353 | | ty::Param(..) |
| 2351 | | ty::Alias(ty::AliasTy { | |
| 2352 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 2353 | .. | |
| 2354 | }) | |
| 2354 | | ty::Alias( | |
| 2355 | _, | |
| 2356 | ty::AliasTy { | |
| 2357 | kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. }, | |
| 2358 | .. | |
| 2359 | }, | |
| 2360 | ) | |
| 2355 | 2361 | | ty::Bound(..) |
| 2356 | 2362 | | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { |
| 2357 | 2363 | bug!("asked to assemble constituent types of unexpected type: {:?}", t); |
| ... | ... | @@ -2420,7 +2426,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { |
| 2420 | 2426 | assumptions: vec![], |
| 2421 | 2427 | }), |
| 2422 | 2428 | |
| 2423 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 2429 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 2424 | 2430 | if self.infcx.can_define_opaque_ty(def_id) { |
| 2425 | 2431 | unreachable!() |
| 2426 | 2432 | } else { |
compiler/rustc_trait_selection/src/traits/structural_normalize.rs+6-1| ... | ... | @@ -41,11 +41,16 @@ impl<'tcx> At<'_, 'tcx> { |
| 41 | 41 | |
| 42 | 42 | if self.infcx.next_trait_solver() { |
| 43 | 43 | let term = term.skip_normalization(); |
| 44 | ||
| 45 | if !self.infcx.tcx.renormalize_rigid_aliases() && !term.is_non_rigid_alias() { | |
| 46 | return Ok(term); | |
| 47 | }; | |
| 48 | ||
| 44 | 49 | let Some(alias) = term.to_alias_term() else { |
| 45 | 50 | return Ok(term); |
| 46 | 51 | }; |
| 47 | 52 | |
| 48 | let new_infer = self.infcx.next_term_var_of_kind(term, self.cause.span); | |
| 53 | let new_infer = self.infcx.next_term_var_of_alias_kind(alias, self.cause.span); | |
| 49 | 54 | |
| 50 | 55 | // We simply emit an `Projection` goal here, since that will take care of |
| 51 | 56 | // normalizing the LHS of the projection until it is a rigid projection |
compiler/rustc_trait_selection/src/traits/wf.rs+11-8| ... | ... | @@ -284,7 +284,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( |
| 284 | 284 | }; |
| 285 | 285 | |
| 286 | 286 | let ty_to_impl_span = |ty: Ty<'_>| { |
| 287 | if let ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind() | |
| 287 | if let ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, .. }) = ty.kind() | |
| 288 | 288 | && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(def_id) |
| 289 | 289 | && let Some(impl_item) = |
| 290 | 290 | items.iter().find(|item| item.owner_id.to_def_id() == impl_item_id) |
| ... | ... | @@ -801,15 +801,18 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 801 | 801 | // Simple cases that are WF if their type args are WF. |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | ty::Alias(ty::AliasTy { | |
| 805 | kind: ty::Projection { def_id } | ty::Opaque { def_id } | ty::Free { def_id }, | |
| 806 | args, | |
| 807 | .. | |
| 808 | }) => { | |
| 804 | ty::Alias( | |
| 805 | _, | |
| 806 | ty::AliasTy { | |
| 807 | kind: ty::Projection { def_id } | ty::Opaque { def_id } | ty::Free { def_id }, | |
| 808 | args, | |
| 809 | .. | |
| 810 | }, | |
| 811 | ) => { | |
| 809 | 812 | let obligations = self.nominal_obligations(def_id, args); |
| 810 | 813 | self.out.extend(obligations); |
| 811 | 814 | } |
| 812 | ty::Alias(data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 815 | ty::Alias(_, data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => { | |
| 813 | 816 | self.add_wf_preds_for_inherent_projection(data.into()); |
| 814 | 817 | return; // Subtree handled by compute_inherent_projection. |
| 815 | 818 | } |
| ... | ... | @@ -1061,7 +1064,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { |
| 1061 | 1064 | let tcx = self.tcx(); |
| 1062 | 1065 | |
| 1063 | 1066 | match c.kind() { |
| 1064 | ty::ConstKind::Unevaluated(uv) => { | |
| 1067 | ty::ConstKind::Unevaluated(_, uv) => { | |
| 1065 | 1068 | if !c.has_escaping_bound_vars() { |
| 1066 | 1069 | // Skip type consts as mGCA doesn't support evaluatable clauses |
| 1067 | 1070 | if !uv.kind.is_type_const(tcx) && !tcx.features().generic_const_args() { |
compiler/rustc_traits/src/coroutine_witnesses.rs+7-4| ... | ... | @@ -38,10 +38,13 @@ pub(crate) fn coroutine_hidden_types<'tcx>( |
| 38 | 38 | |
| 39 | 39 | let assumptions = compute_assumptions(tcx, def_id, bound_tys); |
| 40 | 40 | |
| 41 | ty::EarlyBinder::bind(ty::Binder::bind_with_vars( | |
| 42 | ty::CoroutineWitnessTypes { types: bound_tys, assumptions }, | |
| 43 | tcx.mk_bound_variable_kinds(&vars), | |
| 44 | )) | |
| 41 | ty::EarlyBinder::bind( | |
| 42 | tcx, | |
| 43 | ty::Binder::bind_with_vars( | |
| 44 | ty::CoroutineWitnessTypes { types: bound_tys, assumptions }, | |
| 45 | tcx.mk_bound_variable_kinds(&vars), | |
| 46 | ), | |
| 47 | ) | |
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | fn compute_assumptions<'tcx>( |
compiler/rustc_ty_utils/src/consts.rs+2-2| ... | ... | @@ -75,7 +75,7 @@ fn recurse_build<'tcx>( |
| 75 | 75 | ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id), |
| 76 | 76 | args, |
| 77 | 77 | ); |
| 78 | ty::Const::new_unevaluated(tcx, uneval) | |
| 78 | ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval) | |
| 79 | 79 | } |
| 80 | 80 | ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param), |
| 81 | 81 | |
| ... | ... | @@ -385,7 +385,7 @@ fn thir_abstract_const<'tcx>( |
| 385 | 385 | |
| 386 | 386 | let root_span = body.exprs[body_id].span; |
| 387 | 387 | |
| 388 | Ok(Some(ty::EarlyBinder::bind(recurse_build(tcx, body, body_id, root_span)?))) | |
| 388 | Ok(Some(ty::EarlyBinder::bind(tcx, recurse_build(tcx, body, body_id, root_span)?))) | |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | pub(crate) fn provide(providers: &mut Providers) { |
compiler/rustc_ty_utils/src/implied_bounds.rs+1-1| ... | ... | @@ -116,7 +116,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' |
| 116 | 116 | tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args, |
| 117 | 117 | ); |
| 118 | 118 | tcx.arena.alloc_from_iter( |
| 119 | ty::EarlyBinder::bind(tcx.assumed_wf_types_for_rpitit(rpitit_def_id)) | |
| 119 | ty::EarlyBinder::bind_iter(tcx.assumed_wf_types_for_rpitit(rpitit_def_id)) | |
| 120 | 120 | .iter_instantiated_copied(tcx, args) |
| 121 | 121 | .map(Unnormalized::skip_norm_wip) |
| 122 | 122 | .chain(tcx.assumed_wf_types(impl_def_id).into_iter().copied()), |
compiler/rustc_ty_utils/src/layout.rs+24-16| ... | ... | @@ -39,38 +39,45 @@ fn layout_of<'tcx>( |
| 39 | 39 | tcx: TyCtxt<'tcx>, |
| 40 | 40 | query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>, |
| 41 | 41 | ) -> Result<TyAndLayout<'tcx>, &'tcx LayoutError<'tcx>> { |
| 42 | let PseudoCanonicalInput { typing_env, value: ty } = query; | |
| 43 | debug!(?ty); | |
| 42 | let PseudoCanonicalInput { typing_env: original_typing_env, value: original_ty } = query; | |
| 43 | debug!(?original_ty); | |
| 44 | 44 | |
| 45 | 45 | // Optimization: We convert to TypingMode::PostAnalysis and convert opaque types in |
| 46 | 46 | // the where bounds to their hidden types. This reduces overall uncached invocations |
| 47 | 47 | // of `layout_of` and is thus a small performance improvement. |
| 48 | let typing_env = typing_env.with_post_analysis_normalized(tcx); | |
| 49 | let unnormalized_ty = ty; | |
| 48 | let typing_env = original_typing_env.with_post_analysis_normalized(tcx); | |
| 49 | // Switching to `PostAnalysis` typing mode will reveal opaque types that's marked | |
| 50 | // as rigid in the original typing env. | |
| 51 | let unnormalized_ty = if typing_env != original_typing_env { | |
| 52 | ty::set_aliases_to_non_rigid(tcx, original_ty) | |
| 53 | } else { | |
| 54 | ty::Unnormalized::new_wip(original_ty) | |
| 55 | }; | |
| 50 | 56 | |
| 51 | 57 | // FIXME: We might want to have two different versions of `layout_of`: |
| 52 | 58 | // One that can be called after typecheck has completed and can use |
| 53 | 59 | // `normalize_erasing_regions` here and another one that can be called |
| 54 | 60 | // before typecheck has completed and uses `try_normalize_erasing_regions`. |
| 55 | let ty = match tcx.try_normalize_erasing_regions(typing_env, Unnormalized::new_wip(ty)) { | |
| 61 | let normalized_ty = match tcx.try_normalize_erasing_regions(typing_env, unnormalized_ty) { | |
| 56 | 62 | Ok(t) => t, |
| 57 | 63 | Err(normalization_error) => { |
| 58 | return Err(tcx | |
| 59 | .arena | |
| 60 | .alloc(LayoutError::NormalizationFailure(ty, normalization_error))); | |
| 64 | return Err(tcx.arena.alloc(LayoutError::NormalizationFailure( | |
| 65 | unnormalized_ty.skip_normalization(), | |
| 66 | normalization_error, | |
| 67 | ))); | |
| 61 | 68 | } |
| 62 | 69 | }; |
| 63 | 70 | |
| 64 | if ty != unnormalized_ty { | |
| 71 | if normalized_ty != original_ty { | |
| 65 | 72 | // Ensure this layout is also cached for the normalized type. |
| 66 | return tcx.layout_of(typing_env.as_query_input(ty)); | |
| 73 | return tcx.layout_of(typing_env.as_query_input(normalized_ty)); | |
| 67 | 74 | } |
| 68 | 75 | |
| 69 | 76 | match typing_env.typing_mode() { |
| 70 | 77 | ty::TypingMode::Codegen => { |
| 71 | 78 | let with_postanalysis = |
| 72 | 79 | ty::TypingEnv::new(typing_env.param_env, ty::TypingMode::PostAnalysis); |
| 73 | let res = tcx.layout_of(with_postanalysis.as_query_input(ty)); | |
| 80 | let res = tcx.layout_of(with_postanalysis.as_query_input(normalized_ty)); | |
| 74 | 81 | match res { |
| 75 | 82 | Err(LayoutError::TooGeneric(_)) => {} |
| 76 | 83 | _ => return res, |
| ... | ... | @@ -86,8 +93,8 @@ fn layout_of<'tcx>( |
| 86 | 93 | |
| 87 | 94 | let cx = LayoutCx::new(tcx, typing_env); |
| 88 | 95 | |
| 89 | let layout = layout_of_uncached(&cx, ty)?; | |
| 90 | let layout = TyAndLayout { ty, layout }; | |
| 96 | let layout = layout_of_uncached(&cx, normalized_ty)?; | |
| 97 | let layout = TyAndLayout { ty: normalized_ty, layout }; | |
| 91 | 98 | |
| 92 | 99 | // If we are running with `-Zprint-type-sizes`, maybe record layouts |
| 93 | 100 | // for dumping later. |
| ... | ... | @@ -170,7 +177,7 @@ fn extract_const_value<'tcx>( |
| 170 | 177 | } |
| 171 | 178 | Err(error(cx, LayoutError::TooGeneric(ty))) |
| 172 | 179 | } |
| 173 | ty::ConstKind::Unevaluated(_) => { | |
| 180 | ty::ConstKind::Unevaluated(_, _) => { | |
| 174 | 181 | let err = if ct.has_param() { |
| 175 | 182 | LayoutError::TooGeneric(ty) |
| 176 | 183 | } else { |
| ... | ... | @@ -437,7 +444,8 @@ fn layout_of_uncached<'tcx>( |
| 437 | 444 | } |
| 438 | 445 | |
| 439 | 446 | let metadata = if let Some(metadata_def_id) = tcx.lang_items().metadata_type() { |
| 440 | let pointee_metadata = Ty::new_projection(tcx, metadata_def_id, [pointee]); | |
| 447 | let pointee_metadata = | |
| 448 | Ty::new_projection(tcx, ty::IsRigid::No, metadata_def_id, [pointee]); | |
| 441 | 449 | let metadata_ty = match tcx.try_normalize_erasing_regions( |
| 442 | 450 | cx.typing_env, |
| 443 | 451 | Unnormalized::new_wip(pointee_metadata), |
| ... | ... | @@ -557,7 +565,7 @@ fn layout_of_uncached<'tcx>( |
| 557 | 565 | .field_tys |
| 558 | 566 | .iter() |
| 559 | 567 | .map(|local| { |
| 560 | let field_ty = EarlyBinder::bind(local.ty); | |
| 568 | let field_ty = EarlyBinder::bind(tcx, local.ty); | |
| 561 | 569 | let uninit_ty = |
| 562 | 570 | Ty::new_maybe_uninit(tcx, field_ty.instantiate(tcx, args).skip_norm_wip()); |
| 563 | 571 | cx.spanned_layout_of(uninit_ty, local.source_info.span) |
compiler/rustc_ty_utils/src/needs_drop.rs+4-2| ... | ... | @@ -222,7 +222,7 @@ where |
| 222 | 222 | for field_ty in &witness.field_tys { |
| 223 | 223 | queue_type( |
| 224 | 224 | self, |
| 225 | EarlyBinder::bind(field_ty.ty) | |
| 225 | EarlyBinder::bind(tcx, field_ty.ty) | |
| 226 | 226 | .instantiate(tcx, args) |
| 227 | 227 | .skip_norm_wip(), |
| 228 | 228 | ); |
| ... | ... | @@ -374,7 +374,9 @@ fn drop_tys_helper<'tcx>( |
| 374 | 374 | match subty.kind() { |
| 375 | 375 | ty::Adt(adt_id, args) => { |
| 376 | 376 | for subty in tcx.adt_drop_tys(adt_id.did())? { |
| 377 | vec.push(EarlyBinder::bind(subty).instantiate(tcx, args).skip_norm_wip()); | |
| 377 | vec.push( | |
| 378 | EarlyBinder::bind(tcx, subty).instantiate(tcx, args).skip_norm_wip(), | |
| 379 | ); | |
| 378 | 380 | } |
| 379 | 381 | } |
| 380 | 382 | _ => vec.push(subty), |
compiler/rustc_ty_utils/src/opaque_types.rs+4-3| ... | ... | @@ -210,14 +210,14 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 210 | 210 | fn visit_ty(&mut self, t: Ty<'tcx>) { |
| 211 | 211 | t.super_visit_with(self); |
| 212 | 212 | match *t.kind() { |
| 213 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 213 | ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Opaque { def_id }, .. }) | |
| 214 | 214 | if def_id.is_local() => |
| 215 | 215 | { |
| 216 | 216 | self.visit_opaque_ty(alias_ty); |
| 217 | 217 | } |
| 218 | 218 | // Skips type aliases, as they are meant to be transparent. |
| 219 | 219 | // FIXME(type_alias_impl_trait): can we require mentioning nested type aliases explicitly? |
| 220 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) | |
| 220 | ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) | |
| 221 | 221 | if let Some(def_id) = def_id.as_local() => |
| 222 | 222 | { |
| 223 | 223 | if !self.seen.insert(def_id) { |
| ... | ... | @@ -230,6 +230,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 230 | 230 | .visit_with(self); |
| 231 | 231 | } |
| 232 | 232 | ty::Alias( |
| 233 | _, | |
| 233 | 234 | alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_def_id }, .. }, |
| 234 | 235 | ) => { |
| 235 | 236 | // This avoids having to do normalization of `Self::AssocTy` by only |
| ... | ... | @@ -299,7 +300,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> { |
| 299 | 300 | .type_of(alias_def_id) |
| 300 | 301 | .instantiate(self.tcx, alias_ty.args) |
| 301 | 302 | .skip_norm_wip(); |
| 302 | let ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Opaque { .. }, .. }) = | |
| 303 | let ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Opaque { .. }, .. }) = | |
| 303 | 304 | *ty.kind() |
| 304 | 305 | else { |
| 305 | 306 | bug!("{ty:?}") |
compiler/rustc_ty_utils/src/ty.rs+3-3| ... | ... | @@ -144,7 +144,7 @@ fn adt_sizedness_constraint<'tcx>( |
| 144 | 144 | return None; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | Some(ty::EarlyBinder::bind(constraint_ty)) | |
| 147 | Some(ty::EarlyBinder::bind(tcx, constraint_ty)) | |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /// See `ParamEnv` struct definition for details. |
| ... | ... | @@ -223,7 +223,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> { |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | fn visit_ty(&mut self, ty: Ty<'tcx>) { |
| 226 | if let ty::Alias(unshifted_alias_ty) = *ty.kind() | |
| 226 | if let ty::Alias(_, unshifted_alias_ty) = *ty.kind() | |
| 227 | 227 | && let Some(unshifted_alias_ty) = unshifted_alias_ty.try_to_projection() |
| 228 | 228 | && let Some( |
| 229 | 229 | ty::ImplTraitInTraitData::Trait { fn_def_id, .. } |
| ... | ... | @@ -387,7 +387,7 @@ fn impl_self_is_guaranteed_unsized<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId) |
| 387 | 387 | | ty::CoroutineWitness(_, _) |
| 388 | 388 | | ty::Never |
| 389 | 389 | | ty::Tuple(_) |
| 390 | | ty::Alias(_) | |
| 390 | | ty::Alias(_, _) | |
| 391 | 391 | | ty::Param(_) |
| 392 | 392 | | ty::Bound(_, _) |
| 393 | 393 | | ty::Placeholder(_) |
compiler/rustc_type_ir/src/binder.rs+38-2| ... | ... | @@ -369,11 +369,33 @@ generate!( |
| 369 | 369 | impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {} |
| 370 | 370 | ); |
| 371 | 371 | |
| 372 | impl<I: Interner, T> EarlyBinder<I, T> { | |
| 373 | pub fn bind(value: T) -> EarlyBinder<I, T> { | |
| 372 | impl<I: Interner, T: TypeFoldable<I>> EarlyBinder<I, T> { | |
| 373 | pub fn bind(cx: I, value: T) -> EarlyBinder<I, T> { | |
| 374 | // Instantiation will require normalization. | |
| 375 | let value = ty::set_aliases_to_non_rigid(cx, value).skip_normalization(); | |
| 374 | 376 | EarlyBinder { value, _tcx: PhantomData } |
| 375 | 377 | } |
| 378 | } | |
| 379 | ||
| 380 | impl<I: Interner, T: IntoIterator<Item: TypeVisitable<I>> + Clone> EarlyBinder<I, T> { | |
| 381 | pub fn bind_iter(value: T) -> EarlyBinder<I, T> { | |
| 382 | #[cfg(debug_assertions)] | |
| 383 | { | |
| 384 | value.clone().into_iter().for_each(|v| assert!(!v.has_rigid_aliases())); | |
| 385 | } | |
| 376 | 386 | |
| 387 | EarlyBinder { value, _tcx: PhantomData } | |
| 388 | } | |
| 389 | } | |
| 390 | ||
| 391 | impl<I: Interner, T: TypeVisitable<I>> EarlyBinder<I, T> { | |
| 392 | pub fn bind_no_rigid_aliases(value: T) -> EarlyBinder<I, T> { | |
| 393 | debug_assert!(!value.has_rigid_aliases()); | |
| 394 | EarlyBinder { value, _tcx: PhantomData } | |
| 395 | } | |
| 396 | } | |
| 397 | ||
| 398 | impl<I: Interner, T> EarlyBinder<I, T> { | |
| 377 | 399 | pub fn as_ref(&self) -> EarlyBinder<I, &T> { |
| 378 | 400 | EarlyBinder { value: &self.value, _tcx: PhantomData } |
| 379 | 401 | } |
| ... | ... | @@ -523,6 +545,14 @@ pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> { |
| 523 | 545 | args: &'a [I::GenericArg], |
| 524 | 546 | } |
| 525 | 547 | |
| 548 | impl<'a, I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone | |
| 549 | for IterInstantiatedCopied<'a, I, Iter> | |
| 550 | { | |
| 551 | fn clone(&self) -> IterInstantiatedCopied<'a, I, Iter> { | |
| 552 | IterInstantiatedCopied { it: self.it.clone(), cx: self.cx, args: self.args } | |
| 553 | } | |
| 554 | } | |
| 555 | ||
| 526 | 556 | impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter> |
| 527 | 557 | where |
| 528 | 558 | Iter::Item: Deref, |
| ... | ... | @@ -567,6 +597,12 @@ pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> { |
| 567 | 597 | _tcx: PhantomData<fn() -> I>, |
| 568 | 598 | } |
| 569 | 599 | |
| 600 | impl<I: Interner, Iter: IntoIterator<IntoIter: Clone>> Clone for IterIdentityCopied<I, Iter> { | |
| 601 | fn clone(&self) -> IterIdentityCopied<I, Iter> { | |
| 602 | IterIdentityCopied { it: self.it.clone(), _tcx: self._tcx } | |
| 603 | } | |
| 604 | } | |
| 605 | ||
| 570 | 606 | impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter> |
| 571 | 607 | where |
| 572 | 608 | Iter::Item: Deref, |
compiler/rustc_type_ir/src/const_kind.rs+2-2| ... | ... | @@ -34,7 +34,7 @@ pub enum ConstKind<I: Interner> { |
| 34 | 34 | /// An unnormalized const item such as an anon const or assoc const or free const item. |
| 35 | 35 | /// Right now anything other than anon consts does not actually work properly but this |
| 36 | 36 | /// should |
| 37 | Unevaluated(ty::UnevaluatedConst<I>), | |
| 37 | Unevaluated(ty::IsRigid, ty::UnevaluatedConst<I>), | |
| 38 | 38 | |
| 39 | 39 | /// Used to hold computed value. |
| 40 | 40 | Value(I::ValueConst), |
| ... | ... | @@ -59,7 +59,7 @@ impl<I: Interner> fmt::Debug for ConstKind<I> { |
| 59 | 59 | Infer(var) => write!(f, "{var:?}"), |
| 60 | 60 | Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var), |
| 61 | 61 | Placeholder(placeholder) => write!(f, "{placeholder:?}"), |
| 62 | Unevaluated(uv) => write!(f, "{uv:?}"), | |
| 62 | Unevaluated(is_rigid, uv) => write!(f, "Unevaluated({is_rigid:?}, {uv:?})"), | |
| 63 | 63 | Value(val) => write!(f, "{val:?}"), |
| 64 | 64 | Error(_) => write!(f, "{{const error}}"), |
| 65 | 65 | Expr(expr) => write!(f, "{expr:?}"), |
compiler/rustc_type_ir/src/elaborate.rs+5-2| ... | ... | @@ -276,7 +276,7 @@ fn elaborate_component_to_clause<I: Interner>( |
| 276 | 276 | // We might end up here if we have `Foo<<Bar as Baz>::Assoc>: 'a`. |
| 277 | 277 | // With this, we can deduce that `<Bar as Baz>::Assoc: 'a`. |
| 278 | 278 | Some(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate( |
| 279 | alias_ty.to_ty(cx), | |
| 279 | alias_ty.to_ty(cx, ty::IsRigid::No), | |
| 280 | 280 | outlives_region, |
| 281 | 281 | ))) |
| 282 | 282 | } |
| ... | ... | @@ -414,7 +414,10 @@ pub fn elaborate_outlives_assumptions<I: Interner>( |
| 414 | 414 | } |
| 415 | 415 | |
| 416 | 416 | Component::Alias(alias_ty) => { |
| 417 | collected.insert(ty::OutlivesPredicate(alias_ty.to_ty(cx).into(), r2)); | |
| 417 | collected.insert(ty::OutlivesPredicate( | |
| 418 | alias_ty.to_ty(cx, ty::IsRigid::No).into(), | |
| 419 | r2, | |
| 420 | )); | |
| 418 | 421 | } |
| 419 | 422 | |
| 420 | 423 | Component::UnresolvedInferenceVariable(_) | Component::EscapingAlias(_) => { |
compiler/rustc_type_ir/src/error.rs+7-1| ... | ... | @@ -2,7 +2,7 @@ use derive_where::derive_where; |
| 2 | 2 | use rustc_abi::ExternAbi; |
| 3 | 3 | use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; |
| 4 | 4 | |
| 5 | use crate::solve::NoSolution; | |
| 5 | use crate::solve::{NoSolution, NoSolutionOrRerunNonErased}; | |
| 6 | 6 | use crate::{self as ty, Interner}; |
| 7 | 7 | |
| 8 | 8 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| ... | ... | @@ -100,3 +100,9 @@ impl<I: Interner> From<TypeError<I>> for NoSolution { |
| 100 | 100 | NoSolution |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | ||
| 104 | impl<I: Interner> From<TypeError<I>> for NoSolutionOrRerunNonErased { | |
| 105 | fn from(_: TypeError<I>) -> NoSolutionOrRerunNonErased { | |
| 106 | NoSolutionOrRerunNonErased::NoSolution(NoSolution) | |
| 107 | } | |
| 108 | } |
compiler/rustc_type_ir/src/fast_reject.rs+3-2| ... | ... | @@ -261,6 +261,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_ |
| 261 | 261 | return true; |
| 262 | 262 | } |
| 263 | 263 | } |
| 264 | // FIXME(#155345): we should fast-path for rigid aliases here. | |
| 264 | 265 | ty::Error(_) | ty::Alias(..) | ty::Bound(..) => return true, |
| 265 | 266 | ty::Infer(var) => return self.var_and_ty_may_unify(var, lhs), |
| 266 | 267 | |
| ... | ... | @@ -468,7 +469,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_ |
| 468 | 469 | } |
| 469 | 470 | |
| 470 | 471 | ty::ConstKind::Expr(_) |
| 471 | | ty::ConstKind::Unevaluated(_) | |
| 472 | | ty::ConstKind::Unevaluated(_, _) | |
| 472 | 473 | | ty::ConstKind::Error(_) |
| 473 | 474 | | ty::ConstKind::Infer(_) |
| 474 | 475 | | ty::ConstKind::Bound(..) => { |
| ... | ... | @@ -499,7 +500,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_ |
| 499 | 500 | |
| 500 | 501 | // As we don't necessarily eagerly evaluate constants, |
| 501 | 502 | // they might unify with any value. |
| 502 | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => { | |
| 503 | ty::ConstKind::Expr(_) | ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Error(_) => { | |
| 503 | 504 | true |
| 504 | 505 | } |
| 505 | 506 |
compiler/rustc_type_ir/src/flags.rs+23-3| ... | ... | @@ -146,6 +146,18 @@ bitflags::bitflags! { |
| 146 | 146 | |
| 147 | 147 | /// Does this have a `Bound(BoundVarIndexKind::Canonical, _)`? |
| 148 | 148 | const HAS_CANONICAL_BOUND = 1 << 26; |
| 149 | ||
| 150 | /// Does this have any aliases with `IsRigid::Yes`? | |
| 151 | /// | |
| 152 | /// We have both rigid and non-rigid flags because both can be true for a single | |
| 153 | /// subject. E.g. one arg is rigid while another is non-rigid for some ADTs. | |
| 154 | const HAS_RIGID_ALIAS = 1 << 27; | |
| 155 | ||
| 156 | /// Does this have any aliases with `IsRigid::No`? | |
| 157 | /// | |
| 158 | /// We have a separate flag from `HAS_ALIAS` because `HAS_ALIAS` doesn't care | |
| 159 | /// about rigidness while we rely on rigidness to skip renormalization. | |
| 160 | const HAS_NON_RIGID_ALIAS = 1 << 28; | |
| 149 | 161 | } |
| 150 | 162 | } |
| 151 | 163 | |
| ... | ... | @@ -295,14 +307,14 @@ impl<I: Interner> FlagComputation<I> { |
| 295 | 307 | self.add_args(args.as_slice()); |
| 296 | 308 | } |
| 297 | 309 | |
| 298 | ty::Alias(alias) => { | |
| 310 | ty::Alias(is_rigid, alias) => { | |
| 311 | self.add_is_rigid(is_rigid); | |
| 299 | 312 | self.add_flags(match alias.kind { |
| 300 | 313 | ty::Projection { .. } => TypeFlags::HAS_TY_PROJECTION, |
| 301 | 314 | ty::Free { .. } => TypeFlags::HAS_TY_FREE_ALIAS, |
| 302 | 315 | ty::Opaque { .. } => TypeFlags::HAS_TY_OPAQUE, |
| 303 | 316 | ty::Inherent { .. } => TypeFlags::HAS_TY_INHERENT, |
| 304 | 317 | }); |
| 305 | ||
| 306 | 318 | self.add_alias_ty(alias); |
| 307 | 319 | } |
| 308 | 320 | |
| ... | ... | @@ -465,7 +477,8 @@ impl<I: Interner> FlagComputation<I> { |
| 465 | 477 | |
| 466 | 478 | fn add_const_kind(&mut self, c: &ty::ConstKind<I>) { |
| 467 | 479 | match *c { |
| 468 | ty::ConstKind::Unevaluated(uv) => { | |
| 480 | ty::ConstKind::Unevaluated(is_rigid, uv) => { | |
| 481 | self.add_is_rigid(is_rigid); | |
| 469 | 482 | self.add_args(uv.args.as_slice()); |
| 470 | 483 | self.add_flags(TypeFlags::HAS_CT_PROJECTION); |
| 471 | 484 | } |
| ... | ... | @@ -529,6 +542,13 @@ impl<I: Interner> FlagComputation<I> { |
| 529 | 542 | } |
| 530 | 543 | } |
| 531 | 544 | |
| 545 | fn add_is_rigid(&mut self, is_rigid: ty::IsRigid) { | |
| 546 | match is_rigid { | |
| 547 | ty::IsRigid::Yes => self.add_flags(TypeFlags::HAS_RIGID_ALIAS), | |
| 548 | ty::IsRigid::No => self.add_flags(TypeFlags::HAS_NON_RIGID_ALIAS), | |
| 549 | } | |
| 550 | } | |
| 551 | ||
| 532 | 552 | fn add_term(&mut self, term: I::Term) { |
| 533 | 553 | match term.kind() { |
| 534 | 554 | ty::TermKind::Ty(ty) => self.add_ty(ty), |
compiler/rustc_type_ir/src/fold.rs+63| ... | ... | @@ -554,3 +554,66 @@ where |
| 554 | 554 | if c.has_regions() { c.super_fold_with(self) } else { c } |
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | ||
| 558 | pub fn set_aliases_to_non_rigid<I: Interner, T>(cx: I, value: T) -> ty::Unnormalized<I, T> | |
| 559 | where | |
| 560 | T: TypeFoldable<I>, | |
| 561 | { | |
| 562 | if !value.has_rigid_aliases() { | |
| 563 | return ty::Unnormalized::new(value); | |
| 564 | } | |
| 565 | ||
| 566 | let mut folder = RigidnessFolder { cx }; | |
| 567 | ty::Unnormalized::new(value.fold_with(&mut folder)) | |
| 568 | } | |
| 569 | ||
| 570 | struct RigidnessFolder<I: Interner> { | |
| 571 | cx: I, | |
| 572 | } | |
| 573 | ||
| 574 | impl<I: Interner> TypeFolder<I> for RigidnessFolder<I> { | |
| 575 | #[inline] | |
| 576 | fn cx(&self) -> I { | |
| 577 | self.cx | |
| 578 | } | |
| 579 | ||
| 580 | fn fold_binder<T: TypeFoldable<I>>(&mut self, t: ty::Binder<I, T>) -> ty::Binder<I, T> { | |
| 581 | if t.has_rigid_aliases() { t.super_fold_with(self) } else { t } | |
| 582 | } | |
| 583 | ||
| 584 | fn fold_ty(&mut self, t: I::Ty) -> I::Ty { | |
| 585 | if !t.has_rigid_aliases() { | |
| 586 | return t; | |
| 587 | } | |
| 588 | ||
| 589 | match t.kind() { | |
| 590 | ty::Alias(ty::IsRigid::Yes, alias_ty) => { | |
| 591 | let alias_ty = alias_ty.fold_with(self); | |
| 592 | I::Ty::new_alias(self.cx(), ty::IsRigid::No, alias_ty) | |
| 593 | } | |
| 594 | _ => t.super_fold_with(self), | |
| 595 | } | |
| 596 | } | |
| 597 | ||
| 598 | fn fold_const(&mut self, c: I::Const) -> I::Const { | |
| 599 | if !c.has_rigid_aliases() { | |
| 600 | return c; | |
| 601 | } | |
| 602 | ||
| 603 | match c.kind() { | |
| 604 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, uv) => { | |
| 605 | let uv = uv.fold_with(self); | |
| 606 | I::Const::new_unevaluated(self.cx, ty::IsRigid::No, uv) | |
| 607 | } | |
| 608 | _ => c.super_fold_with(self), | |
| 609 | } | |
| 610 | } | |
| 611 | ||
| 612 | fn fold_predicate(&mut self, p: I::Predicate) -> I::Predicate { | |
| 613 | if p.has_rigid_aliases() { p.super_fold_with(self) } else { p } | |
| 614 | } | |
| 615 | ||
| 616 | fn fold_clauses(&mut self, c: I::Clauses) -> I::Clauses { | |
| 617 | if c.has_rigid_aliases() { c.super_fold_with(self) } else { c } | |
| 618 | } | |
| 619 | } |
compiler/rustc_type_ir/src/inherent.rs+22-5| ... | ... | @@ -53,26 +53,30 @@ pub trait Ty<I: Interner<Ty = Self>>: |
| 53 | 53 | |
| 54 | 54 | fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self; |
| 55 | 55 | |
| 56 | fn new_alias(interner: I, alias_ty: ty::AliasTy<I>) -> Self; | |
| 56 | fn new_alias(interner: I, is_rigid: ty::IsRigid, alias_ty: ty::AliasTy<I>) -> Self; | |
| 57 | 57 | |
| 58 | 58 | fn new_projection_from_args( |
| 59 | 59 | interner: I, |
| 60 | is_rigid: ty::IsRigid, | |
| 60 | 61 | def_id: I::TraitAssocTyId, |
| 61 | 62 | args: I::GenericArgs, |
| 62 | 63 | ) -> Self { |
| 63 | 64 | Self::new_alias( |
| 64 | 65 | interner, |
| 66 | is_rigid, | |
| 65 | 67 | ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args), |
| 66 | 68 | ) |
| 67 | 69 | } |
| 68 | 70 | |
| 69 | 71 | fn new_projection( |
| 70 | 72 | interner: I, |
| 73 | is_rigid: ty::IsRigid, | |
| 71 | 74 | def_id: I::TraitAssocTyId, |
| 72 | 75 | args: impl IntoIterator<Item: Into<I::GenericArg>>, |
| 73 | 76 | ) -> Self { |
| 74 | 77 | Self::new_alias( |
| 75 | 78 | interner, |
| 79 | is_rigid, | |
| 76 | 80 | ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args), |
| 77 | 81 | ) |
| 78 | 82 | } |
| ... | ... | @@ -190,7 +194,7 @@ pub trait Ty<I: Interner<Ty = Self>>: |
| 190 | 194 | | ty::CoroutineWitness(_, _) |
| 191 | 195 | | ty::Never |
| 192 | 196 | | ty::Tuple(_) |
| 193 | | ty::Alias(_) | |
| 197 | | ty::Alias(_, _) | |
| 194 | 198 | | ty::Param(_) |
| 195 | 199 | | ty::Bound(_, _) |
| 196 | 200 | | ty::Placeholder(_) |
| ... | ... | @@ -276,7 +280,7 @@ pub trait Const<I: Interner<Const = Self>>: |
| 276 | 280 | |
| 277 | 281 | fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self; |
| 278 | 282 | |
| 279 | fn new_unevaluated(interner: I, uv: ty::UnevaluatedConst<I>) -> Self; | |
| 283 | fn new_unevaluated(interner: I, is_rigid: ty::IsRigid, uv: ty::UnevaluatedConst<I>) -> Self; | |
| 280 | 284 | |
| 281 | 285 | fn new_expr(interner: I, expr: I::ExprConst) -> Self; |
| 282 | 286 | |
| ... | ... | @@ -403,15 +407,28 @@ pub trait Term<I: Interner<Term = Self>>: |
| 403 | 407 | fn to_alias_term(self) -> Option<ty::AliasTerm<I>> { |
| 404 | 408 | match self.kind() { |
| 405 | 409 | ty::TermKind::Ty(ty) => match ty.kind() { |
| 406 | ty::Alias(alias_ty) => Some(alias_ty.into()), | |
| 410 | ty::Alias(_, alias_ty) => Some(alias_ty.into()), | |
| 407 | 411 | _ => None, |
| 408 | 412 | }, |
| 409 | 413 | ty::TermKind::Const(ct) => match ct.kind() { |
| 410 | ty::ConstKind::Unevaluated(uv) => Some(uv.into()), | |
| 414 | ty::ConstKind::Unevaluated(_, uv) => Some(uv.into()), | |
| 411 | 415 | _ => None, |
| 412 | 416 | }, |
| 413 | 417 | } |
| 414 | 418 | } |
| 419 | ||
| 420 | fn is_non_rigid_alias(self) -> bool { | |
| 421 | match self.kind() { | |
| 422 | ty::TermKind::Ty(ty) => match ty.kind() { | |
| 423 | ty::Alias(is_rigid, _) => is_rigid == ty::IsRigid::No, | |
| 424 | _ => false, | |
| 425 | }, | |
| 426 | ty::TermKind::Const(ct) => match ct.kind() { | |
| 427 | ty::ConstKind::Unevaluated(is_rigid, _) => is_rigid == ty::IsRigid::No, | |
| 428 | _ => false, | |
| 429 | }, | |
| 430 | } | |
| 431 | } | |
| 415 | 432 | } |
| 416 | 433 | |
| 417 | 434 | #[rust_analyzer::prefer_underscore_import] |
compiler/rustc_type_ir/src/interner.rs+2| ... | ... | @@ -292,6 +292,8 @@ pub trait Interner: |
| 292 | 292 | |
| 293 | 293 | fn assumptions_on_binders(self) -> bool; |
| 294 | 294 | |
| 295 | fn renormalize_rigid_aliases(self) -> bool; | |
| 296 | ||
| 295 | 297 | fn coroutine_hidden_types( |
| 296 | 298 | self, |
| 297 | 299 | def_id: Self::CoroutineId, |
compiler/rustc_type_ir/src/outlives.rs+1-1| ... | ... | @@ -148,7 +148,7 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> { |
| 148 | 148 | // trait-ref. Therefore, if we see any higher-ranked regions, |
| 149 | 149 | // we simply fallback to the most restrictive rule, which |
| 150 | 150 | // requires that `Pi: 'a` for all `i`. |
| 151 | ty::Alias(alias_ty) => { | |
| 151 | ty::Alias(_, alias_ty) => { | |
| 152 | 152 | if !alias_ty.has_escaping_bound_vars() { |
| 153 | 153 | // best case: no escaping regions, so push the |
| 154 | 154 | // projection and skip the subtree (thus generating no |
compiler/rustc_type_ir/src/region_constraint.rs+9-4| ... | ... | @@ -52,9 +52,9 @@ use crate::relate::{Relate, RelateResult, TypeRelation, VarianceDiagInfo}; |
| 52 | 52 | use crate::visit::TypeSuperVisitable; |
| 53 | 53 | use crate::{ |
| 54 | 54 | AliasTy, Binder, BoundRegion, BoundVar, BoundVariableKind, ConstKind, DebruijnIndex, |
| 55 | FallibleTypeFolder, InferCtxtLike, InferTy, Interner, OutlivesPredicate, RegionKind, TyKind, | |
| 56 | TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, TypingMode, UniverseIndex, Variance, | |
| 57 | VisitorResult, | |
| 55 | FallibleTypeFolder, InferCtxtLike, InferTy, Interner, IsRigid, OutlivesPredicate, RegionKind, | |
| 56 | TyKind, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, TypingMode, UniverseIndex, | |
| 57 | Variance, VisitorResult, set_aliases_to_non_rigid, | |
| 58 | 58 | }; |
| 59 | 59 | |
| 60 | 60 | #[derive_where(Clone, Debug; I: Interner)] |
| ... | ... | @@ -1128,7 +1128,12 @@ fn alias_outlives_candidates_from_assumptions<Infcx: InferCtxtLike<Interner = I> |
| 1128 | 1128 | region_constraints: vec![RegionConstraint::RegionOutlives(r2, r)], |
| 1129 | 1129 | }; |
| 1130 | 1130 | |
| 1131 | if let Ok(_) = relation.relate(alias.to_ty(infcx.cx()), alias2) { | |
| 1131 | // FIXME(#155345): Both sides should be rigid in the future. | |
| 1132 | // Currently we can't guarantee that. | |
| 1133 | if let Ok(_) = relation.relate( | |
| 1134 | alias.to_ty(infcx.cx(), IsRigid::No), | |
| 1135 | set_aliases_to_non_rigid(infcx.cx(), alias2).skip_norm_wip(), | |
| 1136 | ) { | |
| 1132 | 1137 | candidates |
| 1133 | 1138 | .push(RegionConstraint::And(relation.region_constraints.into_boxed_slice())); |
| 1134 | 1139 | } |
compiler/rustc_type_ir/src/relate.rs+17-8| ... | ... | @@ -222,7 +222,7 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> { |
| 222 | 222 | } else { |
| 223 | 223 | relate_args_invariantly(relation, a.args, b.args)? |
| 224 | 224 | }; |
| 225 | Ok(ty::AliasTy::new_from_args(cx, a.kind, args)) | |
| 225 | Ok(ty::AliasTy::new_from_args(relation.cx(), a.kind, args)) | |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | } |
| ... | ... | @@ -236,8 +236,8 @@ impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> { |
| 236 | 236 | let cx = relation.cx(); |
| 237 | 237 | if a.kind != b.kind { |
| 238 | 238 | Err(TypeError::ConstMismatch(ExpectedFound::new( |
| 239 | Const::new_unevaluated(cx, a), | |
| 240 | Const::new_unevaluated(cx, b), | |
| 239 | Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), a), | |
| 240 | Const::new_unevaluated(cx, ty::IsRigid::yes_if_next_solver(cx), b), | |
| 241 | 241 | ))) |
| 242 | 242 | } else { |
| 243 | 243 | // FIXME(mgca): remove this |
| ... | ... | @@ -523,9 +523,12 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>( |
| 523 | 523 | } |
| 524 | 524 | |
| 525 | 525 | // Alias tend to mostly already be handled downstream due to normalization. |
| 526 | (ty::Alias(a), ty::Alias(b)) => { | |
| 527 | let alias_ty = relation.relate(a, b)?; | |
| 528 | Ok(Ty::new_alias(cx, alias_ty)) | |
| 526 | (ty::Alias(is_rigid_a, alias_a), ty::Alias(is_rigid_b, alias_b)) => { | |
| 527 | // Users shouldn't know about this so the mismatch should be caught | |
| 528 | // during development rather than presented as type error. | |
| 529 | debug_assert_eq!(is_rigid_a, is_rigid_b, "{a:?} != {b:?}"); | |
| 530 | let alias_ty = relation.relate(alias_a, alias_b)?; | |
| 531 | Ok(Ty::new_alias(cx, is_rigid_a, alias_ty)) | |
| 529 | 532 | } |
| 530 | 533 | |
| 531 | 534 | (ty::Pat(a_ty, a_pat), ty::Pat(b_ty, b_pat)) => { |
| ... | ... | @@ -611,8 +614,14 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>( |
| 611 | 614 | // While this is slightly incorrect, it shouldn't matter for `min_const_generics` |
| 612 | 615 | // and is the better alternative to waiting until `generic_const_exprs` can |
| 613 | 616 | // be stabilized. |
| 614 | (ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) => { | |
| 615 | return Ok(Const::new_unevaluated(cx, relation.relate(au, bu)?)); | |
| 617 | ( | |
| 618 | ty::ConstKind::Unevaluated(is_rigid_a, au), | |
| 619 | ty::ConstKind::Unevaluated(is_rigid_b, bu), | |
| 620 | ) => { | |
| 621 | // Users shouldn't know about this so the mismatch should be caught | |
| 622 | // during development rather than presented as type error. | |
| 623 | debug_assert_eq!(is_rigid_a, is_rigid_b, "{a:?} != {b:?}"); | |
| 624 | return Ok(Const::new_unevaluated(cx, is_rigid_a, relation.relate(au, bu)?)); | |
| 616 | 625 | } |
| 617 | 626 | (ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => { |
| 618 | 627 | let expr = relation.relate(ae, be)?; |
compiler/rustc_type_ir/src/relate/combine.rs+32-9| ... | ... | @@ -115,9 +115,29 @@ where |
| 115 | 115 | panic!("We do not expect to encounter `Fresh` variables in the new solver") |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | (other, ty::Alias(..)) | (ty::Alias(..), other) if infcx.next_trait_solver() => { | |
| 119 | match relation.structurally_relate_aliases() { | |
| 120 | StructurallyRelateAliases::Yes => match other { | |
| 118 | (ty::Alias(is_rigid_a, _), ty::Alias(is_rigid_b, _)) if infcx.next_trait_solver() => { | |
| 119 | match (is_rigid_a, is_rigid_b) { | |
| 120 | (ty::IsRigid::Yes, ty::IsRigid::Yes) => structurally_relate_tys(relation, a, b), | |
| 121 | _ => match relation.structurally_relate_aliases() { | |
| 122 | StructurallyRelateAliases::Yes => structurally_relate_tys(relation, a, b), | |
| 123 | StructurallyRelateAliases::No => { | |
| 124 | relation.register_alias_relate_predicate(a, b); | |
| 125 | Ok(a) | |
| 126 | } | |
| 127 | }, | |
| 128 | } | |
| 129 | } | |
| 130 | ||
| 131 | (other, ty::Alias(is_rigid, _)) | (ty::Alias(is_rigid, _), other) | |
| 132 | if infcx.next_trait_solver() => | |
| 133 | { | |
| 134 | if let StructurallyRelateAliases::No = relation.structurally_relate_aliases() | |
| 135 | && is_rigid == ty::IsRigid::No | |
| 136 | { | |
| 137 | relation.register_alias_relate_predicate(a, b); | |
| 138 | Ok(a) | |
| 139 | } else { | |
| 140 | match other { | |
| 121 | 141 | ty::Infer(infer_ty) => match infer_ty { |
| 122 | 142 | // Normally, we shouldn't be combining an infer ty with an alias here. But |
| 123 | 143 | // when we evaluate a `Projection(assoc_ty, expected)` goal, we normalize |
| ... | ... | @@ -139,10 +159,6 @@ where |
| 139 | 159 | | ty::InferTy::FreshFloatTy(_) => unreachable!(), |
| 140 | 160 | }, |
| 141 | 161 | _ => structurally_relate_tys(relation, a, b), |
| 142 | }, | |
| 143 | StructurallyRelateAliases::No => { | |
| 144 | relation.register_alias_relate_predicate(a, b); | |
| 145 | Ok(a) | |
| 146 | 162 | } |
| 147 | 163 | } |
| 148 | 164 | } |
| ... | ... | @@ -150,8 +166,8 @@ where |
| 150 | 166 | // All other cases of inference are errors |
| 151 | 167 | (ty::Infer(_), _) | (_, ty::Infer(_)) => Err(TypeError::Sorts(ExpectedFound::new(a, b))), |
| 152 | 168 | |
| 153 | (ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) | |
| 154 | | (_, ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | |
| 169 | (ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) | |
| 170 | | (_, ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => { | |
| 155 | 171 | assert!(!infcx.next_trait_solver()); |
| 156 | 172 | match infcx.typing_mode_raw().assert_not_erased() { |
| 157 | 173 | // During coherence, opaque types should be treated as *possibly* |
| ... | ... | @@ -223,6 +239,13 @@ where |
| 223 | 239 | Ok(a) |
| 224 | 240 | } |
| 225 | 241 | |
| 242 | ( | |
| 243 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), | |
| 244 | ty::ConstKind::Unevaluated(ty::IsRigid::Yes, _), | |
| 245 | ) if (infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver()) => { | |
| 246 | structurally_relate_consts(relation, a, b) | |
| 247 | } | |
| 248 | ||
| 226 | 249 | (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..)) |
| 227 | 250 | if infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver() => |
| 228 | 251 | { |
compiler/rustc_type_ir/src/term_kind.rs+4-2| ... | ... | @@ -209,13 +209,15 @@ impl<I: Interner> AliasTerm<I> { |
| 209 | 209 | ty::UnevaluatedConst { kind, args: self.args, _use_alias_new_instead: () } |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | pub fn to_term(self, interner: I) -> I::Term { | |
| 212 | pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term { | |
| 213 | 213 | let alias_ty = |kind| { |
| 214 | Ty::new_alias(interner, ty::AliasTy::new_from_args(interner, kind, self.args)).into() | |
| 214 | Ty::new_alias(interner, is_rigid, ty::AliasTy::new_from_args(interner, kind, self.args)) | |
| 215 | .into() | |
| 215 | 216 | }; |
| 216 | 217 | let unevaluated_const = |kind| { |
| 217 | 218 | I::Const::new_unevaluated( |
| 218 | 219 | interner, |
| 220 | is_rigid, | |
| 219 | 221 | ty::UnevaluatedConst::new(interner, kind, self.args), |
| 220 | 222 | ) |
| 221 | 223 | .into() |
compiler/rustc_type_ir/src/ty_kind.rs+33-5| ... | ... | @@ -107,6 +107,34 @@ impl<I: Interner> AliasTyKind<I> { |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | /// Whether an alias type is rigid or potentially normalizeable. | |
| 111 | /// | |
| 112 | /// This is not used by the old solver and is always `IsRigid::No` there. In the new solver, | |
| 113 | /// aliases which cannot be further normalized in their current scope normalize to themselves | |
| 114 | /// with `IsRigid::Yes`. At this point we no longer have to try and renormalize this alias | |
| 115 | /// later on. | |
| 116 | /// | |
| 117 | /// FIXME(#155345): Alias handling is currently still in flux for the new trait | |
| 118 | /// solver and this is currently somewhat messy. Please reach out on | |
| 119 | /// #t-types/trait-system-refactor-initiative if you encounter this and it isn't | |
| 120 | /// immediately clear what to do. | |
| 121 | #[derive(Debug, Clone, Copy, Hash, PartialEq)] | |
| 122 | #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] | |
| 123 | #[cfg_attr( | |
| 124 | feature = "nightly", | |
| 125 | derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext) | |
| 126 | )] | |
| 127 | pub enum IsRigid { | |
| 128 | Yes, | |
| 129 | No, | |
| 130 | } | |
| 131 | ||
| 132 | impl IsRigid { | |
| 133 | pub fn yes_if_next_solver<I: Interner>(interner: I) -> IsRigid { | |
| 134 | if interner.next_trait_solver_globally() { IsRigid::Yes } else { IsRigid::No } | |
| 135 | } | |
| 136 | } | |
| 137 | ||
| 110 | 138 | /// Defines the kinds of types used by the type system. |
| 111 | 139 | /// |
| 112 | 140 | /// Types written by the user start out as `hir::TyKind` and get |
| ... | ... | @@ -273,7 +301,7 @@ pub enum TyKind<I: Interner> { |
| 273 | 301 | /// |
| 274 | 302 | /// All of these types are represented as pairs of def-id and args, and can |
| 275 | 303 | /// be normalized, so they are grouped conceptually. |
| 276 | Alias(AliasTy<I>), | |
| 304 | Alias(IsRigid, AliasTy<I>), | |
| 277 | 305 | |
| 278 | 306 | /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`. |
| 279 | 307 | Param(I::ParamTy), |
| ... | ... | @@ -375,7 +403,7 @@ impl<I: Interner> TyKind<I> { |
| 375 | 403 | |
| 376 | 404 | ty::Error(_) |
| 377 | 405 | | ty::Infer(_) |
| 378 | | ty::Alias(_) | |
| 406 | | ty::Alias(ty::IsRigid::No | ty::IsRigid::Yes, _) | |
| 379 | 407 | | ty::Param(_) |
| 380 | 408 | | ty::Bound(_, _) |
| 381 | 409 | | ty::Placeholder(_) => false, |
| ... | ... | @@ -440,7 +468,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> { |
| 440 | 468 | } |
| 441 | 469 | write!(f, ")") |
| 442 | 470 | } |
| 443 | Alias(a) => f.debug_tuple("Alias").field(&a).finish(), | |
| 471 | Alias(is_rigid, a) => f.debug_tuple("Alias").field(&is_rigid).field(&a).finish(), | |
| 444 | 472 | Param(p) => write!(f, "{p:?}"), |
| 445 | 473 | Bound(d, b) => crate::debug_bound_var(f, *d, b), |
| 446 | 474 | Placeholder(p) => write!(f, "{p:?}"), |
| ... | ... | @@ -478,8 +506,8 @@ impl<I: Interner> AliasTy<I> { |
| 478 | 506 | matches!(self.kind, AliasTyKind::Opaque { .. }) |
| 479 | 507 | } |
| 480 | 508 | |
| 481 | pub fn to_ty(self, interner: I) -> I::Ty { | |
| 482 | Ty::new_alias(interner, self) | |
| 509 | pub fn to_ty(self, interner: I, is_rigid: ty::IsRigid) -> I::Ty { | |
| 510 | Ty::new_alias(interner, is_rigid, self) | |
| 483 | 511 | } |
| 484 | 512 | |
| 485 | 513 | pub fn try_to_projection(self) -> Option<ProjectionAliasTy<I>> { |
compiler/rustc_type_ir/src/visit.rs+16| ... | ... | @@ -167,6 +167,12 @@ impl<I: Interner, T: TypeVisitable<I>, E: TypeVisitable<I>> TypeVisitable<I> for |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for &T { | |
| 171 | fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result { | |
| 172 | (**self).visit_with(visitor) | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 170 | 176 | impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Arc<T> { |
| 171 | 177 | fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result { |
| 172 | 178 | (**self).visit_with(visitor) |
| ... | ... | @@ -363,6 +369,16 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> { |
| 363 | 369 | fn has_non_region_error(&self) -> bool { |
| 364 | 370 | self.has_type_flags(TypeFlags::HAS_NON_REGION_ERROR) |
| 365 | 371 | } |
| 372 | ||
| 373 | /// True if an alias has `IsRigid::Yes`. Used for skipping normalization. | |
| 374 | fn has_rigid_aliases(&self) -> bool { | |
| 375 | self.has_type_flags(TypeFlags::HAS_RIGID_ALIAS) | |
| 376 | } | |
| 377 | ||
| 378 | /// True if an alias has `IsRigid::No`. | |
| 379 | fn has_non_rigid_aliases(&self) -> bool { | |
| 380 | self.has_type_flags(TypeFlags::HAS_NON_RIGID_ALIAS) | |
| 381 | } | |
| 366 | 382 | } |
| 367 | 383 | |
| 368 | 384 | impl<I: Interner, T: TypeVisitable<I>> TypeVisitableExt<I> for T { |
compiler/rustc_type_ir/src/walk.rs+2-2| ... | ... | @@ -106,7 +106,7 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg |
| 106 | 106 | stack.push(ty.into()); |
| 107 | 107 | stack.push(lt.into()); |
| 108 | 108 | } |
| 109 | ty::Alias(alias) => { | |
| 109 | ty::Alias(_, alias) => { | |
| 110 | 110 | stack.extend(alias.args.iter().rev()); |
| 111 | 111 | } |
| 112 | 112 | ty::Dynamic(obj, lt) => { |
| ... | ... | @@ -160,7 +160,7 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg |
| 160 | 160 | ty::ConstKind::Value(cv) => stack.push(cv.ty().into()), |
| 161 | 161 | |
| 162 | 162 | ty::ConstKind::Expr(expr) => stack.extend(expr.args().iter().rev()), |
| 163 | ty::ConstKind::Unevaluated(ct) => { | |
| 163 | ty::ConstKind::Unevaluated(_, ct) => { | |
| 164 | 164 | stack.extend(ct.args.iter().rev()); |
| 165 | 165 | } |
| 166 | 166 | }, |
src/librustdoc/clean/mod.rs+6-6| ... | ... | @@ -1780,7 +1780,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type |
| 1780 | 1780 | let self_type = clean_ty(qself, cx); |
| 1781 | 1781 | |
| 1782 | 1782 | let (trait_, should_fully_qualify) = match ty.kind() { |
| 1783 | ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 1783 | ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => { | |
| 1784 | 1784 | let res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id); |
| 1785 | 1785 | let trait_ = clean_path(&hir::Path { span, res, segments: &[] }, cx); |
| 1786 | 1786 | register_res(cx, trait_.res); |
| ... | ... | @@ -1790,7 +1790,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type |
| 1790 | 1790 | |
| 1791 | 1791 | (Some(trait_), should_fully_qualify) |
| 1792 | 1792 | } |
| 1793 | ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => (None, false), | |
| 1793 | ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => (None, false), | |
| 1794 | 1794 | // Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s. |
| 1795 | 1795 | ty::Error(_) => return Type::Infer, |
| 1796 | 1796 | _ => bug!("clean: expected associated type, found `{ty:?}`"), |
| ... | ... | @@ -2282,7 +2282,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2282 | 2282 | Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect()) |
| 2283 | 2283 | } |
| 2284 | 2284 | |
| 2285 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 2285 | ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => { | |
| 2286 | 2286 | if cx.tcx.is_impl_trait_in_trait(def_id) { |
| 2287 | 2287 | clean_middle_opaque_bounds(cx, def_id, args) |
| 2288 | 2288 | } else { |
| ... | ... | @@ -2294,7 +2294,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2294 | 2294 | } |
| 2295 | 2295 | } |
| 2296 | 2296 | |
| 2297 | ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Inherent { def_id }, .. }) => { | |
| 2297 | ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Inherent { def_id }, .. }) => { | |
| 2298 | 2298 | let alias_ty = bound_ty.rebind(alias_ty); |
| 2299 | 2299 | let self_type = clean_middle_ty(alias_ty.map_bound(|ty| ty.self_ty()), cx, None, None); |
| 2300 | 2300 | |
| ... | ... | @@ -2317,7 +2317,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2317 | 2317 | })) |
| 2318 | 2318 | } |
| 2319 | 2319 | |
| 2320 | ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { | |
| 2320 | ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => { | |
| 2321 | 2321 | if cx.tcx.features().lazy_type_alias() { |
| 2322 | 2322 | // Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`, |
| 2323 | 2323 | // we need to use `type_of`. |
| ... | ... | @@ -2345,7 +2345,7 @@ pub(crate) fn clean_middle_ty<'tcx>( |
| 2345 | 2345 | ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"), |
| 2346 | 2346 | }, |
| 2347 | 2347 | |
| 2348 | ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 2348 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { | |
| 2349 | 2349 | // If it's already in the same alias, don't get an infinite loop. |
| 2350 | 2350 | if cx.current_type_aliases.contains_key(&def_id) { |
| 2351 | 2351 | let path = |
src/librustdoc/clean/types.rs+1-1| ... | ... | @@ -1770,7 +1770,7 @@ impl PrimitiveType { |
| 1770 | 1770 | ty::Tuple(elems) if elems.is_empty() => Some(Self::Unit), |
| 1771 | 1771 | ty::Tuple(_) => Some(Self::Tuple), |
| 1772 | 1772 | ty::Adt(..) |
| 1773 | | ty::Alias(..) | |
| 1773 | | ty::Alias(_, ..) | |
| 1774 | 1774 | | ty::Bound(..) |
| 1775 | 1775 | | ty::Closure(..) |
| 1776 | 1776 | | ty::Coroutine(..) |
src/librustdoc/clean/utils.rs+1-1| ... | ... | @@ -350,7 +350,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { |
| 350 | 350 | |
| 351 | 351 | pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String { |
| 352 | 352 | match n.kind() { |
| 353 | ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, .. }) => match kind { | |
| 353 | ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, .. }) => match kind { | |
| 354 | 354 | ty::UnevaluatedConstKind::Projection { def_id } => { |
| 355 | 355 | if let Some(local_def_id) = def_id.as_local() |
| 356 | 356 | && let Some(body_id) = tcx.hir_maybe_body_owned_by(local_def_id) |
src/librustdoc/passes/collect_intra_doc_links.rs+1-1| ... | ... | @@ -547,7 +547,7 @@ fn ty_to_res<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Res> { |
| 547 | 547 | ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) | ty::Foreign(did) => { |
| 548 | 548 | Res::from_def_id(tcx, did) |
| 549 | 549 | } |
| 550 | ty::Alias(..) | |
| 550 | ty::Alias(_, ..) | |
| 551 | 551 | | ty::Closure(..) |
| 552 | 552 | | ty::CoroutineClosure(..) |
| 553 | 553 | | ty::Coroutine(..) |
src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs+1-1| ... | ... | @@ -63,7 +63,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) - |
| 63 | 63 | ) |
| 64 | 64 | }) |
| 65 | 65 | .is_some_and(|assoc_item| { |
| 66 | let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); | |
| 66 | let proj = Ty::new_projection(cx.tcx, ty::IsRigid::No, assoc_item.def_id, cx.tcx.mk_args_trait(ty, [])); | |
| 67 | 67 | let nty = cx |
| 68 | 68 | .tcx |
| 69 | 69 | .normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(proj)); |
src/tools/clippy/clippy_lints/src/dereference.rs+4-4| ... | ... | @@ -925,18 +925,18 @@ impl TyCoercionStability { |
| 925 | 925 | continue; |
| 926 | 926 | }, |
| 927 | 927 | ty::Param(_) if for_return => Self::Deref, |
| 928 | ty::Alias(ty::AliasTy { | |
| 928 | ty::Alias(_, ty::AliasTy { | |
| 929 | 929 | kind: ty::Free { .. } | ty::Inherent { .. }, |
| 930 | 930 | .. |
| 931 | 931 | }) => unreachable!("should have been normalized away above"), |
| 932 | ty::Alias(ty::AliasTy { | |
| 932 | ty::Alias(_, ty::AliasTy { | |
| 933 | 933 | kind: ty::Projection { .. }, |
| 934 | 934 | .. |
| 935 | 935 | }) if !for_return && ty.has_non_region_param() => Self::Reborrow, |
| 936 | 936 | ty::Infer(_) |
| 937 | 937 | | ty::Error(_) |
| 938 | 938 | | ty::Bound(..) |
| 939 | | ty::Alias(ty::AliasTy { | |
| 939 | | ty::Alias(_, ty::AliasTy { | |
| 940 | 940 | kind: ty::Opaque { .. }, |
| 941 | 941 | .. |
| 942 | 942 | }) |
| ... | ... | @@ -970,7 +970,7 @@ impl TyCoercionStability { |
| 970 | 970 | | ty::CoroutineClosure(..) |
| 971 | 971 | | ty::Never |
| 972 | 972 | | ty::Tuple(_) |
| 973 | | ty::Alias(ty::AliasTy { | |
| 973 | | ty::Alias(_, ty::AliasTy { | |
| 974 | 974 | kind: ty::Projection { .. }, |
| 975 | 975 | .. |
| 976 | 976 | }) |
src/tools/clippy/clippy_lints/src/from_over_into.rs+1-1| ... | ... | @@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto { |
| 78 | 78 | && span_is_local(item.span) |
| 79 | 79 | && let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity().skip_norm_wip() |
| 80 | 80 | && cx.tcx.is_diagnostic_item(sym::Into, middle_trait_ref.def_id) |
| 81 | && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(ty::AliasTy { kind: ty::Opaque{..} , .. })) | |
| 81 | && !matches!(middle_trait_ref.args.type_at(1).kind(), ty::Alias(_, ty::AliasTy { kind: ty::Opaque{..} , .. })) | |
| 82 | 82 | && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE) |
| 83 | 83 | // skip if there's a blanket From impl, the suggested impl would conflict |
| 84 | 84 | && !has_blanket_from_impl(cx, middle_trait_ref.self_ty()) |
src/tools/clippy/clippy_lints/src/future_not_send.rs+2-1| ... | ... | @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { |
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | 78 | let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); |
| 79 | if let ty::Alias(AliasTy { kind: ty::Opaque{def_id}, args, .. }) = *ret_ty.kind() | |
| 79 | if let ty::Alias(_, AliasTy { kind: ty::Opaque{def_id}, args, .. }) = *ret_ty.kind() | |
| 80 | 80 | && let Some(future_trait) = cx.tcx.lang_items().future_trait() |
| 81 | 81 | && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send) |
| 82 | 82 | && let preds = cx.tcx.explicit_item_self_bounds(def_id) |
| ... | ... | @@ -149,6 +149,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TyParamAtTopLevelVisitor { |
| 149 | 149 | match ty.kind() { |
| 150 | 150 | ty::Param(_) => ControlFlow::Break(true), |
| 151 | 151 | ty::Alias( |
| 152 | _, | |
| 152 | 153 | ty @ AliasTy { |
| 153 | 154 | kind: ty::Projection { .. }, |
| 154 | 155 | .. |
src/tools/clippy/clippy_lints/src/indexing_slicing.rs+1-1| ... | ... | @@ -280,7 +280,7 @@ fn ty_has_applicable_get_function<'tcx>( |
| 280 | 280 | && let generic_ty = option_generic_param.expect_ty().peel_refs() |
| 281 | 281 | // FIXME: ideally this would handle type params and projections properly, for now just assume it's the same type |
| 282 | 282 | && (cx.typeck_results().expr_ty(index_expr).peel_refs() == generic_ty.peel_refs() |
| 283 | || matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_))) | |
| 283 | || matches!(generic_ty.peel_refs().kind(), ty::Param(_) | ty::Alias(_, _))) | |
| 284 | 284 | { |
| 285 | 285 | true |
| 286 | 286 | } else { |
src/tools/clippy/clippy_lints/src/len_without_is_empty.rs+1-1| ... | ... | @@ -149,7 +149,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { |
| 152 | if let ty::Alias(ty::AliasTy { | |
| 152 | if let ty::Alias(_, ty::AliasTy { | |
| 153 | 153 | kind: ty::Opaque { def_id }, |
| 154 | 154 | .. |
| 155 | 155 | }) = *ty.kind() |
src/tools/clippy/clippy_lints/src/len_zero.rs+1-1| ... | ... | @@ -336,7 +336,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: Msrv) -> bool { |
| 336 | 336 | .filter_by_name_unhygienic(sym::is_empty) |
| 337 | 337 | .any(|item| is_is_empty_and_stable(cx, item, msrv)) |
| 338 | 338 | }), |
| 339 | &ty::Alias(ty::AliasTy { | |
| 339 | &ty::Alias(_, ty::AliasTy { | |
| 340 | 340 | kind: ty::Projection { def_id }, |
| 341 | 341 | .. |
| 342 | 342 | }) => has_is_empty_impl(cx, def_id, msrv), |
src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs+1-1| ... | ... | @@ -139,7 +139,7 @@ fn is_ref_iterable<'tcx>( |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | let res_ty = cx.tcx.erase_and_anonymize_regions( |
| 142 | EarlyBinder::bind(req_res_ty) | |
| 142 | EarlyBinder::bind(cx.tcx, req_res_ty) | |
| 143 | 143 | .instantiate(cx.tcx, typeck.node_args(call_expr.hir_id)) |
| 144 | 144 | .skip_norm_wip(), |
| 145 | 145 | ); |
src/tools/clippy/clippy_lints/src/methods/needless_collect.rs+3-3| ... | ... | @@ -247,7 +247,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: |
| 247 | 247 | && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty]) |
| 248 | 248 | && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( |
| 249 | 249 | cx.typing_env(), |
| 250 | Unnormalized::new_wip(Ty::new_alias(cx.tcx, into_iter_item_proj)), | |
| 250 | Unnormalized::new_wip(Ty::new_alias(cx.tcx, ty::IsRigid::No, into_iter_item_proj)), | |
| 251 | 251 | ) |
| 252 | 252 | { |
| 253 | 253 | iter_item_ty == into_iter_item_ty |
| ... | ... | @@ -276,13 +276,13 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - |
| 276 | 276 | iter_trait, |
| 277 | 277 | ) |
| 278 | 278 | && let args = cx.tcx.mk_args(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) |
| 279 | && let proj_ty = Ty::new_projection_from_args(cx.tcx, iter_item.def_id, args) | |
| 279 | && let proj_ty = Ty::new_projection_from_args(cx.tcx, ty::IsRigid::No, iter_item.def_id, args) | |
| 280 | 280 | && let Ok(item_ty) = cx |
| 281 | 281 | .tcx |
| 282 | 282 | .try_normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(proj_ty)) |
| 283 | 283 | { |
| 284 | 284 | item_ty |
| 285 | == EarlyBinder::bind(search_ty) | |
| 285 | == EarlyBinder::bind(cx.tcx, search_ty) | |
| 286 | 286 | .instantiate(cx.tcx, cx.typeck_results().node_args(call_id)) |
| 287 | 287 | .skip_norm_wip() |
| 288 | 288 | } else { |
src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs+1-1| ... | ... | @@ -213,7 +213,7 @@ fn fn_inputs_has_impl_trait_ty(cx: &LateContext<'_>, def_id: LocalDefId) -> bool |
| 213 | 213 | inputs.iter().any(|input| { |
| 214 | 214 | matches!( |
| 215 | 215 | input.kind(), |
| 216 | &ty::Alias(ty::AliasTy { kind: ty::Free{def_id} , ..}) if cx.tcx.type_of(def_id).skip_binder().is_opaque() | |
| 216 | &ty::Alias(_, ty::AliasTy { kind: ty::Free{def_id} , ..}) if cx.tcx.type_of(def_id).skip_binder().is_opaque() | |
| 217 | 217 | ) |
| 218 | 218 | }) |
| 219 | 219 | } |
src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs+3-2| ... | ... | @@ -285,7 +285,7 @@ fn needless_borrow_count<'tcx>( |
| 285 | 285 | return false; |
| 286 | 286 | } |
| 287 | 287 | |
| 288 | let predicate = EarlyBinder::bind(predicate) | |
| 288 | let predicate = EarlyBinder::bind(cx.tcx, predicate) | |
| 289 | 289 | .instantiate(cx.tcx, &args_with_referent_ty[..]) |
| 290 | 290 | .skip_norm_wip(); |
| 291 | 291 | let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); |
| ... | ... | @@ -341,6 +341,7 @@ fn is_mixed_projection_predicate<'tcx>( |
| 341 | 341 | loop { |
| 342 | 342 | match *projection_term.self_ty().kind() { |
| 343 | 343 | ty::Alias( |
| 344 | _, | |
| 344 | 345 | inner_projection_ty @ ty::AliasTy { |
| 345 | 346 | kind: ty::Projection { .. }, |
| 346 | 347 | .. |
| ... | ... | @@ -434,7 +435,7 @@ fn replace_types<'tcx>( |
| 434 | 435 | .projection_term |
| 435 | 436 | .with_replaced_self_ty(cx.tcx, new_ty) |
| 436 | 437 | .expect_ty() |
| 437 | .to_ty(cx.tcx); | |
| 438 | .to_ty(cx.tcx, ty::IsRigid::No); | |
| 438 | 439 | |
| 439 | 440 | if let Ok(projected_ty) = cx |
| 440 | 441 | .tcx |
src/tools/clippy/clippy_lints/src/non_copy_const.rs+5-4| ... | ... | @@ -323,7 +323,7 @@ impl<'tcx> NonCopyConst<'tcx> { |
| 323 | 323 | IsFreeze::from_fields(tys.iter().map(|ty| self.is_ty_freeze(tcx, typing_env, ty))) |
| 324 | 324 | }, |
| 325 | 325 | // Treat type parameters as though they were `Freeze`. |
| 326 | ty::Param(_) | ty::Alias(..) => return IsFreeze::Yes, | |
| 326 | ty::Param(_) | ty::Alias(_, ..) => return IsFreeze::Yes, | |
| 327 | 327 | // TODO: check other types. |
| 328 | 328 | _ => { |
| 329 | 329 | *e = IsFreeze::No; |
| ... | ... | @@ -384,7 +384,7 @@ impl<'tcx> NonCopyConst<'tcx> { |
| 384 | 384 | e: &'tcx Expr<'tcx>, |
| 385 | 385 | ) -> bool { |
| 386 | 386 | // Make sure to instantiate all types coming from `typeck` with `gen_args`. |
| 387 | let ty = EarlyBinder::bind(typeck.expr_ty(e)).instantiate(tcx, gen_args); | |
| 387 | let ty = EarlyBinder::bind(tcx, typeck.expr_ty(e)).instantiate(tcx, gen_args); | |
| 388 | 388 | let ty = tcx |
| 389 | 389 | .try_normalize_erasing_regions(typing_env, ty) |
| 390 | 390 | .unwrap_or(ty.skip_norm_wip()); |
| ... | ... | @@ -401,7 +401,7 @@ impl<'tcx> NonCopyConst<'tcx> { |
| 401 | 401 | }, |
| 402 | 402 | ExprKind::Path(ref p) => { |
| 403 | 403 | let res = typeck.qpath_res(p, e.hir_id); |
| 404 | let gen_args = EarlyBinder::bind(typeck.node_args(e.hir_id)) | |
| 404 | let gen_args = EarlyBinder::bind(tcx, typeck.node_args(e.hir_id)) | |
| 405 | 405 | .instantiate(tcx, gen_args) |
| 406 | 406 | .skip_norm_wip(); |
| 407 | 407 | match res { |
| ... | ... | @@ -599,7 +599,7 @@ impl<'tcx> NonCopyConst<'tcx> { |
| 599 | 599 | init_expr = next_init; |
| 600 | 600 | }, |
| 601 | 601 | ExprKind::Path(ref init_path) => { |
| 602 | let next_init_args = EarlyBinder::bind(init_typeck.node_args(init_expr.hir_id)) | |
| 602 | let next_init_args = EarlyBinder::bind(tcx, init_typeck.node_args(init_expr.hir_id)) | |
| 603 | 603 | .instantiate(tcx, init_args) |
| 604 | 604 | .skip_norm_wip(); |
| 605 | 605 | match init_typeck.qpath_res(init_path, init_expr.hir_id) { |
| ... | ... | @@ -904,6 +904,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAssocFolder<'tcx> { |
| 904 | 904 | |
| 905 | 905 | fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { |
| 906 | 906 | if let ty::Alias( |
| 907 | _, | |
| 907 | 908 | ty @ ty::AliasTy { |
| 908 | 909 | kind: ty::Projection { .. }, |
| 909 | 910 | .. |
src/tools/clippy/clippy_lints/src/redundant_slicing.rs+2-1| ... | ... | @@ -8,7 +8,7 @@ use rustc_errors::Applicability; |
| 8 | 8 | use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability}; |
| 9 | 9 | use rustc_lint::{LateContext, LateLintPass, Lint}; |
| 10 | 10 | use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability}; |
| 11 | use rustc_middle::ty::{GenericArg, Ty, Unnormalized}; | |
| 11 | use rustc_middle::ty::{self, GenericArg, Ty, Unnormalized}; | |
| 12 | 12 | use rustc_session::declare_lint_pass; |
| 13 | 13 | |
| 14 | 14 | declare_clippy_lint! { |
| ... | ... | @@ -144,6 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { |
| 144 | 144 | cx.typing_env(), |
| 145 | 145 | Unnormalized::new_wip(Ty::new_projection_from_args( |
| 146 | 146 | cx.tcx, |
| 147 | ty::IsRigid::No, | |
| 147 | 148 | target_id, |
| 148 | 149 | cx.tcx.mk_args(&[GenericArg::from(indexed_ty)]), |
| 149 | 150 | )), |
src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs+1-1| ... | ... | @@ -107,7 +107,7 @@ pub(super) fn check<'tcx>( |
| 107 | 107 | fn ty_cannot_be_named(ty: Ty<'_>) -> bool { |
| 108 | 108 | matches!( |
| 109 | 109 | ty.kind(), |
| 110 | ty::Alias(ty::AliasTy { | |
| 110 | ty::Alias(_, ty::AliasTy { | |
| 111 | 111 | kind: ty::Opaque { .. } | ty::Inherent { .. }, |
| 112 | 112 | .. |
| 113 | 113 | }) |
src/tools/clippy/clippy_lints/src/unconditional_recursion.rs+1| ... | ... | @@ -101,6 +101,7 @@ fn get_hir_ty_def_id<'tcx>(tcx: TyCtxt<'tcx>, hir_ty: rustc_hir::Ty<'tcx>) -> Op |
| 101 | 101 | |
| 102 | 102 | match ty.kind() { |
| 103 | 103 | ty::Alias( |
| 104 | _, | |
| 104 | 105 | proj @ ty::AliasTy { |
| 105 | 106 | kind: ty::Projection { .. }, |
| 106 | 107 | .. |
src/tools/clippy/clippy_lints/src/useless_conversion.rs+1-1| ... | ... | @@ -112,7 +112,7 @@ fn into_iter_bound<'tcx>( |
| 112 | 112 | } |
| 113 | 113 | })); |
| 114 | 114 | |
| 115 | let predicate = EarlyBinder::bind(tr).instantiate(cx.tcx, args).skip_norm_wip(); | |
| 115 | let predicate = EarlyBinder::bind(cx.tcx, tr).instantiate(cx.tcx, args).skip_norm_wip(); | |
| 116 | 116 | let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate); |
| 117 | 117 | if !cx |
| 118 | 118 | .tcx |
src/tools/clippy/clippy_utils/src/lib.rs+1-1| ... | ... | @@ -3293,7 +3293,7 @@ fn get_path_to_ty<'tcx>(tcx: TyCtxt<'tcx>, from: LocalDefId, ty: Ty<'tcx>, args: |
| 3293 | 3293 | | rustc_ty::RawPtr(_, _) |
| 3294 | 3294 | | rustc_ty::Ref(..) |
| 3295 | 3295 | | rustc_ty::Slice(_) |
| 3296 | | rustc_ty::Tuple(_) => format!("<{}>", EarlyBinder::bind(ty).instantiate(tcx, args).skip_norm_wip()), | |
| 3296 | | rustc_ty::Tuple(_) => format!("<{}>", EarlyBinder::bind(tcx, ty).instantiate(tcx, args).skip_norm_wip()), | |
| 3297 | 3297 | _ => ty.to_string(), |
| 3298 | 3298 | } |
| 3299 | 3299 | } |
src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs+1-1| ... | ... | @@ -87,7 +87,7 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, span: Span, msrv: Msrv) |
| 87 | 87 | ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => { |
| 88 | 88 | return Err((span, "mutable references in const fn are unstable".into())); |
| 89 | 89 | }, |
| 90 | ty::Alias(ty::AliasTy { | |
| 90 | ty::Alias(_, ty::AliasTy { | |
| 91 | 91 | kind: ty::Opaque { .. }, |
| 92 | 92 | .. |
| 93 | 93 | }) => return Err((span, "`impl Trait` in const fn is unstable".into())), |
src/tools/clippy/clippy_utils/src/ty/mod.rs+7-7| ... | ... | @@ -104,7 +104,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' |
| 104 | 104 | return true; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | if let ty::Alias(AliasTy { | |
| 107 | if let ty::Alias(_, AliasTy { | |
| 108 | 108 | kind: ty::Opaque { def_id }, |
| 109 | 109 | .. |
| 110 | 110 | }) = *inner_ty.kind() |
| ... | ... | @@ -337,7 +337,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { |
| 337 | 337 | is_must_use_ty(cx, *ty) |
| 338 | 338 | }, |
| 339 | 339 | ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), |
| 340 | ty::Alias(AliasTy { | |
| 340 | ty::Alias(_, AliasTy { | |
| 341 | 341 | kind: ty::Opaque { def_id }, |
| 342 | 342 | .. |
| 343 | 343 | }) => { |
| ... | ... | @@ -639,7 +639,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t |
| 639 | 639 | cx.tcx.fn_sig(id).instantiate(cx.tcx, subs).skip_norm_wip(), |
| 640 | 640 | Some(id), |
| 641 | 641 | )), |
| 642 | ty::Alias(AliasTy { | |
| 642 | ty::Alias(_, AliasTy { | |
| 643 | 643 | kind: ty::Opaque { def_id }, |
| 644 | 644 | args, |
| 645 | 645 | .. |
| ... | ... | @@ -670,7 +670,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t |
| 670 | 670 | _ => None, |
| 671 | 671 | } |
| 672 | 672 | }, |
| 673 | ty::Alias(alias) if let Some(proj) = alias.try_to_projection() => match cx | |
| 673 | ty::Alias(_, alias) if let Some(proj) = alias.try_to_projection() => match cx | |
| 674 | 674 | .tcx |
| 675 | 675 | .try_normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(ty)) |
| 676 | 676 | { |
| ... | ... | @@ -1093,7 +1093,7 @@ pub fn make_normalized_projection<'tcx>( |
| 1093 | 1093 | ); |
| 1094 | 1094 | return None; |
| 1095 | 1095 | } |
| 1096 | match tcx.try_normalize_erasing_regions(typing_env, Unnormalized::new_wip(Ty::new_alias(tcx, ty))) { | |
| 1096 | match tcx.try_normalize_erasing_regions(typing_env, Unnormalized::new_wip(Ty::new_alias(tcx, ty::IsRigid::No, ty))) { | |
| 1097 | 1097 | Ok(ty) => Some(ty), |
| 1098 | 1098 | Err(e) => { |
| 1099 | 1099 | debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); |
| ... | ... | @@ -1195,7 +1195,7 @@ impl<'tcx> InteriorMut<'tcx> { |
| 1195 | 1195 | .find_map(|f| self.interior_mut_ty_chain_inner(cx, f.ty(cx.tcx, args).skip_norm_wip(), depth)) |
| 1196 | 1196 | } |
| 1197 | 1197 | }, |
| 1198 | ty::Alias(AliasTy { | |
| 1198 | ty::Alias(_, AliasTy { | |
| 1199 | 1199 | kind: ty::Projection { .. }, |
| 1200 | 1200 | .. |
| 1201 | 1201 | }) => match cx |
| ... | ... | @@ -1247,7 +1247,7 @@ pub fn make_normalized_projection_with_regions<'tcx>( |
| 1247 | 1247 | } |
| 1248 | 1248 | let cause = ObligationCause::dummy(); |
| 1249 | 1249 | let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env); |
| 1250 | match infcx.at(&cause, param_env).query_normalize(Ty::new_alias(tcx, ty)) { | |
| 1250 | match infcx.at(&cause, param_env).query_normalize(Ty::new_alias(tcx, ty::IsRigid::No, ty)) { | |
| 1251 | 1251 | Ok(ty) => Some(ty.value), |
| 1252 | 1252 | Err(e) => { |
| 1253 | 1253 | debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); |
tests/mir-opt/issue_99325.main.built.after.32bit.mir+1-1| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | | User Type Annotations |
| 4 | 4 | | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. }], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 6 | 6 | | |
| 7 | 7 | fn main() -> () { |
| 8 | 8 | let mut _0: (); |
tests/mir-opt/issue_99325.main.built.after.64bit.mir+1-1| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | | User Type Annotations |
| 4 | 4 | | 0: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [&*b"AAAA"], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:13:16: 13:46, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. }], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 5 | | 1: user_ty: Canonical { value: TypeOf(DefId(0:3 ~ issue_99325[d56d]::function_with_bytes), UserArgs { args: [Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:8 ~ issue_99325[d56d]::main::{constant#1}) }, args: [], .. })], user_self_ty: None }), max_universe: U0, var_kinds: [] }, span: $DIR/issue_99325.rs:14:16: 14:68, inferred_ty: fn() -> &'static [u8] {function_with_bytes::<&*b"AAAA">} | |
| 6 | 6 | | |
| 7 | 7 | fn main() -> () { |
| 8 | 8 | let mut _0: (); |
tests/ui/associated-inherent-types/next-solver-opaque-inherent-fn-ptr-issue-155204.stderr+1-1| ... | ... | @@ -56,7 +56,7 @@ LL | fn ret(&self) -> Self::AssocType { |
| 56 | 56 | | --------------- expected `Windows<for<'a> fn(&'a ())>::AssocType` because of return type |
| 57 | 57 | LL | |
| 58 | 58 | LL | () |
| 59 | | ^^ types differ | |
| 59 | | ^^ expected opaque type, found `()` | |
| 60 | 60 | | |
| 61 | 61 | = note: expected opaque type `Windows<for<'a> fn(&'a ())>::AssocType` |
| 62 | 62 | found unit type `()` |
tests/ui/associated-inherent-types/next-solver-opaque-inherent-no-ice.stderr+1-1| ... | ... | @@ -49,7 +49,7 @@ LL | type ImplTrait = impl Clone; |
| 49 | 49 | LL | fn f() -> Self::ImplTrait { |
| 50 | 50 | | --------------- expected `Foo::ImplTrait` because of return type |
| 51 | 51 | LL | () |
| 52 | | ^^ types differ | |
| 52 | | ^^ expected opaque type, found `()` | |
| 53 | 53 | | |
| 54 | 54 | = note: expected opaque type `Foo::ImplTrait` |
| 55 | 55 | found unit type `()` |
tests/ui/associated-inherent-types/normalization-overflow.next.stderr+3-3| ... | ... | @@ -1,9 +1,9 @@ |
| 1 | error[E0271]: type mismatch resolving `_ == T::This` | |
| 1 | error[E0275]: overflow evaluating the requirement `T::This == _` | |
| 2 | 2 | --> $DIR/normalization-overflow.rs:14:5 |
| 3 | 3 | | |
| 4 | 4 | LL | type This = Self::This; |
| 5 | | ^^^^^^^^^ types differ | |
| 5 | | ^^^^^^^^^ | |
| 6 | 6 | |
| 7 | 7 | error: aborting due to 1 previous error |
| 8 | 8 | |
| 9 | For more information about this error, try `rustc --explain E0271`. | |
| 9 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/associated-inherent-types/normalization-overflow.rs+1-1| ... | ... | @@ -13,7 +13,7 @@ struct T; |
| 13 | 13 | impl T { |
| 14 | 14 | type This = Self::This; |
| 15 | 15 | //[current]~^ ERROR: overflow evaluating associated type `T::This` |
| 16 | //[next]~^^ ERROR: type mismatch resolving `_ == T::This` | |
| 16 | //[next]~^^ ERROR: overflow evaluating the requirement `T::This == _` | |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | fn main() {} |
tests/ui/assumptions_on_binders/non_lifetime_binder_alias_outlives.rs deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | //@ compile-flags: -Znext-solver -Zassumptions-on-binders | |
| 2 | ||
| 3 | // Regression test for #157778. | |
| 4 | // | |
| 5 | // A non-lifetime binder (`for<T>`) introduces a placeholder *type* in universe `u`. The | |
| 6 | // resulting alias-outlives constraint `<!T as Trait>::Assoc: 'r` stays in `u` because the | |
| 7 | // region-only rewrite (`PlaceholderReplacer` only folds regions) cannot pull a type | |
| 8 | // placeholder out of `u`. This used to trip an `assert!(max_universe < u)` and ICE in | |
| 9 | // `pull_region_outlives_constraints_out_of_universe`. The assumptions-on-binders machinery | |
| 10 | // is region-outlives-only, so we now report ambiguity instead of panicking. | |
| 11 | ||
| 12 | #![feature(non_lifetime_binders)] | |
| 13 | ||
| 14 | trait Trait { | |
| 15 | type Assoc; | |
| 16 | type Ref //~ ERROR cannot satisfy `<T as Trait>::Assoc: 'static` | |
| 17 | where | |
| 18 | for<T> T: Trait<Assoc: 'static>; | |
| 19 | } | |
| 20 | ||
| 21 | fn main() {} |
tests/ui/assumptions_on_binders/non_lifetime_binder_alias_outlives.stderr deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | error[E0284]: type annotations needed: cannot satisfy `<T as Trait>::Assoc: 'static` | |
| 2 | --> $DIR/non_lifetime_binder_alias_outlives.rs:16:5 | |
| 3 | | | |
| 4 | LL | / type Ref | |
| 5 | LL | | where | |
| 6 | LL | | for<T> T: Trait<Assoc: 'static>; | |
| 7 | | |________________________________________^ cannot satisfy `<T as Trait>::Assoc: 'static` | |
| 8 | | | |
| 9 | note: required by a bound in `Trait::Ref` | |
| 10 | --> $DIR/non_lifetime_binder_alias_outlives.rs:18:32 | |
| 11 | | | |
| 12 | LL | type Ref | |
| 13 | | --- required by a bound in this associated type | |
| 14 | LL | where | |
| 15 | LL | for<T> T: Trait<Assoc: 'static>; | |
| 16 | | ^^^^^^^ required by this bound in `Trait::Ref` | |
| 17 | ||
| 18 | error: aborting due to 1 previous error | |
| 19 | ||
| 20 | For more information about this error, try `rustc --explain E0284`. |
tests/ui/attributes/dump-preds.stderr+1-1| ... | ... | @@ -33,7 +33,7 @@ error: rustc_dump_item_bounds |
| 33 | 33 | LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()> |
| 34 | 34 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 35 | 35 | | |
| 36 | = note: Binder { value: ProjectionPredicate(Alias { kind: ProjectionTy { def_id: DefId(..) }, args: [Alias(Alias { kind: Projection { def_id: DefId(..) }, args: [Self/#0, T/#1, P/#2], .. })], .. }, Term::Ty(())), bound_vars: [] } | |
| 36 | = note: Binder { value: ProjectionPredicate(Alias { kind: ProjectionTy { def_id: DefId(..) }, args: [Alias(No, Alias { kind: Projection { def_id: DefId(..) }, args: [Self/#0, T/#1, P/#2], .. })], .. }, Term::Ty(())), bound_vars: [] } | |
| 37 | 37 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] } |
| 38 | 38 | = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] } |
| 39 | 39 |
tests/ui/const-generics/gca/non-type-equality-fail.stderr+2-2| ... | ... | @@ -4,7 +4,7 @@ error[E0308]: mismatched types |
| 4 | 4 | LL | let _: Struct<{ <GenericStructImpl<N> as Trait>::PROJECTED_A }> = |
| 5 | 5 | | -------------------------------------------------------- expected due to this |
| 6 | 6 | LL | Struct::<{ <GenericStructImpl<N> as Trait>::PROJECTED_B }>; |
| 7 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ | |
| 7 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `<GenericStructImpl<N> as Trait>::PROJECTED_A`, found `<GenericStructImpl<N> as Trait>::PROJECTED_B` | |
| 8 | 8 | | |
| 9 | 9 | = note: expected struct `Struct<<GenericStructImpl<N> as Trait>::PROJECTED_A>` |
| 10 | 10 | found struct `Struct<<GenericStructImpl<N> as Trait>::PROJECTED_B>` |
| ... | ... | @@ -13,7 +13,7 @@ error[E0308]: mismatched types |
| 13 | 13 | --> $DIR/non-type-equality-fail.rs:37:41 |
| 14 | 14 | | |
| 15 | 15 | LL | let _: Struct<{ T::PROJECTED_A }> = Struct::<{ T::PROJECTED_B }>; |
| 16 | | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ | |
| 16 | | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `<T as Trait>::PROJECTED_A`, found `<T as Trait>::PROJECTED_B` | |
| 17 | 17 | | | |
| 18 | 18 | | expected due to this |
| 19 | 19 | | |
tests/ui/const-generics/mgca/free-const-recursive.rs+2-2| ... | ... | @@ -5,8 +5,8 @@ |
| 5 | 5 | #![expect(incomplete_features)] |
| 6 | 6 | |
| 7 | 7 | type const A: () = A; |
| 8 | //~^ ERROR type mismatch resolving `A == _` | |
| 9 | //~| ERROR the constant `A` is not of type `()` | |
| 8 | //~^ ERROR: overflow evaluating the requirement `A == _` | |
| 9 | //~| ERROR: overflow evaluating the requirement `the constant `A` has type `()`` | |
| 10 | 10 | |
| 11 | 11 | fn main() { |
| 12 | 12 | A; |
tests/ui/const-generics/mgca/free-const-recursive.stderr+5-5| ... | ... | @@ -1,15 +1,15 @@ |
| 1 | error[E0271]: type mismatch resolving `A == _` | |
| 1 | error[E0275]: overflow evaluating the requirement `A == _` | |
| 2 | 2 | --> $DIR/free-const-recursive.rs:7:1 |
| 3 | 3 | | |
| 4 | 4 | LL | type const A: () = A; |
| 5 | | ^^^^^^^^^^^^^^^^ types differ | |
| 5 | | ^^^^^^^^^^^^^^^^ | |
| 6 | 6 | |
| 7 | error: the constant `A` is not of type `()` | |
| 7 | error[E0275]: overflow evaluating the requirement `the constant `A` has type `()`` | |
| 8 | 8 | --> $DIR/free-const-recursive.rs:7:1 |
| 9 | 9 | | |
| 10 | 10 | LL | type const A: () = A; |
| 11 | | ^^^^^^^^^^^^^^^^ expected `()`, found a different `()` | |
| 11 | | ^^^^^^^^^^^^^^^^ | |
| 12 | 12 | |
| 13 | 13 | error: aborting due to 2 previous errors |
| 14 | 14 | |
| 15 | For more information about this error, try `rustc --explain E0271`. | |
| 15 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/const-generics/mgca/projection-const-recursive.rs+2-2| ... | ... | @@ -10,8 +10,8 @@ trait Trait { |
| 10 | 10 | |
| 11 | 11 | impl Trait for () { |
| 12 | 12 | type const A: () = <() as Trait>::A; |
| 13 | //~^ ERROR type mismatch resolving `<() as Trait>::A == _` | |
| 14 | //~| ERROR the constant `<() as Trait>::A` is not of type `()` | |
| 13 | //~^ ERROR: overflow evaluating the requirement `<() as Trait>::A == _` | |
| 14 | //~| ERROR: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` | |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | fn main() { |
tests/ui/const-generics/mgca/projection-const-recursive.stderr+5-5| ... | ... | @@ -1,15 +1,15 @@ |
| 1 | error[E0271]: type mismatch resolving `<() as Trait>::A == _` | |
| 1 | error[E0275]: overflow evaluating the requirement `<() as Trait>::A == _` | |
| 2 | 2 | --> $DIR/projection-const-recursive.rs:12:5 |
| 3 | 3 | | |
| 4 | 4 | LL | type const A: () = <() as Trait>::A; |
| 5 | | ^^^^^^^^^^^^^^^^ types differ | |
| 5 | | ^^^^^^^^^^^^^^^^ | |
| 6 | 6 | |
| 7 | error: the constant `<() as Trait>::A` is not of type `()` | |
| 7 | error[E0275]: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()`` | |
| 8 | 8 | --> $DIR/projection-const-recursive.rs:12:5 |
| 9 | 9 | | |
| 10 | 10 | LL | type const A: () = <() as Trait>::A; |
| 11 | | ^^^^^^^^^^^^^^^^ expected `()`, found a different `()` | |
| 11 | | ^^^^^^^^^^^^^^^^ | |
| 12 | 12 | |
| 13 | 13 | error: aborting due to 2 previous errors |
| 14 | 14 | |
| 15 | For more information about this error, try `rustc --explain E0271`. | |
| 15 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/coroutine/delayed-obligations-emit.next.stderr+1| ... | ... | @@ -4,6 +4,7 @@ error[E0275]: overflow evaluating the requirement `{async block@$DIR/delayed-obl |
| 4 | 4 | LL | spawn(async { build_dependencies().await }); |
| 5 | 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 6 | 6 | | |
| 7 | = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`delayed_obligations_emit`) | |
| 7 | 8 | note: required by a bound in `spawn` |
| 8 | 9 | --> $DIR/delayed-obligations-emit.rs:31:13 |
| 9 | 10 | | |
tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr+3-3| ... | ... | @@ -1,10 +1,10 @@ |
| 1 | 1 | error[E0284]: type annotations needed |
| 2 | --> $DIR/rigid-equate-projections-in-higher-ranked-fn-signature.rs:27:50 | |
| 2 | --> $DIR/rigid-equate-projections-in-higher-ranked-fn-signature.rs:27:12 | |
| 3 | 3 | | |
| 4 | 4 | LL | let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::<T>(); |
| 5 | | ^^^^^^^^^^ cannot infer type | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type | |
| 6 | 6 | | |
| 7 | = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == <T as Trait<'_>>::Assoc` | |
| 7 | = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == _` | |
| 8 | 8 | |
| 9 | 9 | error: aborting due to 1 previous error |
| 10 | 10 |
tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.rs+1| ... | ... | @@ -15,4 +15,5 @@ struct W<T>(T); |
| 15 | 15 | fn hello(_: W<A<usize>>) {} |
| 16 | 16 | //~^ ERROR: the trait bound `usize: Foo` is not satisfied |
| 17 | 17 | //~| ERROR: the trait bound `usize: Foo` is not satisfied |
| 18 | //~| ERROR: the type `W<A<usize>>` is not well-formed | |
| 18 | 19 | fn main() {} |
tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.stderr+7-1| ... | ... | @@ -15,6 +15,12 @@ note: required by a bound in `A` |
| 15 | 15 | LL | type A<T: Foo> = T; |
| 16 | 16 | | ^^^ required by this bound in `A` |
| 17 | 17 | |
| 18 | error: the type `W<A<usize>>` is not well-formed | |
| 19 | --> $DIR/alias-bounds-when-not-wf.rs:15:13 | |
| 20 | | | |
| 21 | LL | fn hello(_: W<A<usize>>) {} | |
| 22 | | ^^^^^^^^^^^ | |
| 23 | ||
| 18 | 24 | error[E0277]: the trait bound `usize: Foo` is not satisfied |
| 19 | 25 | --> $DIR/alias-bounds-when-not-wf.rs:15:13 |
| 20 | 26 | | |
| ... | ... | @@ -27,6 +33,6 @@ help: this trait has no implementations, consider adding one |
| 27 | 33 | LL | trait Foo {} |
| 28 | 34 | | ^^^^^^^^^ |
| 29 | 35 | |
| 30 | error: aborting due to 2 previous errors | |
| 36 | error: aborting due to 3 previous errors | |
| 31 | 37 | |
| 32 | 38 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/infinite/infinite-type-alias-mutual-recursion.feature_new.stderr+7-7| ... | ... | @@ -1,21 +1,21 @@ |
| 1 | error[E0271]: type mismatch resolving `_ == X1` | |
| 1 | error[E0275]: overflow evaluating the requirement `X2 == _` | |
| 2 | 2 | --> $DIR/infinite-type-alias-mutual-recursion.rs:12:1 |
| 3 | 3 | | |
| 4 | 4 | LL | type X1 = X2; |
| 5 | | ^^^^^^^ types differ | |
| 5 | | ^^^^^^^ | |
| 6 | 6 | |
| 7 | error[E0271]: type mismatch resolving `_ == X2` | |
| 7 | error[E0275]: overflow evaluating the requirement `X3 == _` | |
| 8 | 8 | --> $DIR/infinite-type-alias-mutual-recursion.rs:16:1 |
| 9 | 9 | | |
| 10 | 10 | LL | type X2 = X3; |
| 11 | | ^^^^^^^ types differ | |
| 11 | | ^^^^^^^ | |
| 12 | 12 | |
| 13 | error[E0271]: type mismatch resolving `_ == X3` | |
| 13 | error[E0275]: overflow evaluating the requirement `X1 == _` | |
| 14 | 14 | --> $DIR/infinite-type-alias-mutual-recursion.rs:19:1 |
| 15 | 15 | | |
| 16 | 16 | LL | type X3 = X1; |
| 17 | | ^^^^^^^ types differ | |
| 17 | | ^^^^^^^ | |
| 18 | 18 | |
| 19 | 19 | error: aborting due to 3 previous errors |
| 20 | 20 | |
| 21 | For more information about this error, try `rustc --explain E0271`. | |
| 21 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/infinite/infinite-type-alias-mutual-recursion.rs+3-3| ... | ... | @@ -12,12 +12,12 @@ |
| 12 | 12 | type X1 = X2; |
| 13 | 13 | //[gated_old,gated_new]~^ ERROR cycle detected when expanding type alias `X1` |
| 14 | 14 | //[feature_old]~^^ ERROR: overflow normalizing the type alias `X2` |
| 15 | //[feature_new]~^^^ ERROR: type mismatch resolving `_ == X1` | |
| 15 | //[feature_new]~^^^ ERROR: overflow evaluating the requirement `X2 == _` | |
| 16 | 16 | type X2 = X3; |
| 17 | 17 | //[feature_old]~^ ERROR: overflow normalizing the type alias `X3` |
| 18 | //[feature_new]~^^ ERROR: type mismatch resolving `_ == X2` | |
| 18 | //[feature_new]~^^ ERROR: overflow evaluating the requirement `X3 == _` | |
| 19 | 19 | type X3 = X1; |
| 20 | 20 | //[feature_old]~^ ERROR: overflow normalizing the type alias `X1` |
| 21 | //[feature_new]~^^ ERROR: type mismatch resolving `_ == X3` | |
| 21 | //[feature_new]~^^ ERROR: overflow evaluating the requirement `X1 == _` | |
| 22 | 22 | |
| 23 | 23 | fn main() {} |
tests/ui/lazy-type-alias/inherent-impls-overflow.next.stderr+7-8| ... | ... | @@ -1,20 +1,20 @@ |
| 1 | error[E0271]: type mismatch resolving `_ == Loop` | |
| 1 | error[E0275]: overflow evaluating the requirement `Loop == _` | |
| 2 | 2 | --> $DIR/inherent-impls-overflow.rs:8:1 |
| 3 | 3 | | |
| 4 | 4 | LL | type Loop = Loop; |
| 5 | | ^^^^^^^^^ types differ | |
| 5 | | ^^^^^^^^^ | |
| 6 | 6 | |
| 7 | error[E0271]: type mismatch resolving `_ == Loop` | |
| 7 | error[E0275]: overflow evaluating the requirement `Loop == _` | |
| 8 | 8 | --> $DIR/inherent-impls-overflow.rs:12:1 |
| 9 | 9 | | |
| 10 | 10 | LL | impl Loop {} |
| 11 | | ^^^^^^^^^^^^ types differ | |
| 11 | | ^^^^^^^^^^^^ | |
| 12 | 12 | |
| 13 | error[E0271]: type mismatch resolving `_ == Loop` | |
| 13 | error[E0275]: overflow evaluating the requirement `Loop == _` | |
| 14 | 14 | --> $DIR/inherent-impls-overflow.rs:12:6 |
| 15 | 15 | | |
| 16 | 16 | LL | impl Loop {} |
| 17 | | ^^^^ types differ | |
| 17 | | ^^^^ | |
| 18 | 18 | |
| 19 | 19 | error[E0275]: overflow evaluating the requirement `Poly1<(T,)> == _` |
| 20 | 20 | --> $DIR/inherent-impls-overflow.rs:17:1 |
| ... | ... | @@ -50,5 +50,4 @@ LL | impl Poly0<()> {} |
| 50 | 50 | |
| 51 | 51 | error: aborting due to 7 previous errors |
| 52 | 52 | |
| 53 | Some errors have detailed explanations: E0271, E0275. | |
| 54 | For more information about an error, try `rustc --explain E0271`. | |
| 53 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/lazy-type-alias/inherent-impls-overflow.rs+3-3| ... | ... | @@ -7,12 +7,12 @@ |
| 7 | 7 | |
| 8 | 8 | type Loop = Loop; |
| 9 | 9 | //[current]~^ ERROR overflow normalizing the type alias `Loop` |
| 10 | //[next]~^^ ERROR type mismatch resolving `_ == Loop` | |
| 10 | //[next]~^^ ERROR overflow evaluating the requirement `Loop == _` | |
| 11 | 11 | |
| 12 | 12 | impl Loop {} |
| 13 | 13 | //[current]~^ ERROR overflow normalizing the type alias `Loop` |
| 14 | //[next]~^^ ERROR type mismatch resolving `_ == Loop` | |
| 15 | //[next]~| ERROR type mismatch resolving `_ == Loop` | |
| 14 | //[next]~^^ ERROR overflow evaluating the requirement `Loop == _` | |
| 15 | //[next]~| ERROR overflow evaluating the requirement `Loop == _` | |
| 16 | 16 | |
| 17 | 17 | type Poly0<T> = Poly1<(T,)>; |
| 18 | 18 | //[current]~^ ERROR overflow normalizing the type alias `Poly0<(((((((...,),),),),),),)>` |
tests/ui/methods/rigid-alias-bound-is-not-inherent.next.stderr+1-1| ... | ... | @@ -9,7 +9,7 @@ note: candidate #1 is defined in the trait `Trait1` |
| 9 | 9 | | |
| 10 | 10 | LL | fn method(&self) { |
| 11 | 11 | | ^^^^^^^^^^^^^^^^ |
| 12 | note: candidate #2 is defined in the trait `Trait2` | |
| 12 | note: candidate #2 is defined in an impl of the trait `Trait2` for the type `T` | |
| 13 | 13 | --> $DIR/rigid-alias-bound-is-not-inherent.rs:27:5 |
| 14 | 14 | | |
| 15 | 15 | LL | fn method(&self) { |
tests/ui/offset-of/inside-array-length.stderr+1-1| ... | ... | @@ -37,7 +37,7 @@ LL | fn foo<'a, T: 'a>(_: [(); std::mem::offset_of!((T,), 0)]) {} |
| 37 | 37 | = note: ...which requires caching mir of `foo::{constant#0}` for CTFE... |
| 38 | 38 | = note: ...which requires elaborating drops for `foo::{constant#0}`... |
| 39 | 39 | = note: ...which requires borrow-checking `foo::{constant#0}`... |
| 40 | = note: ...which requires normalizing `Binder { value: ConstEvaluatable(Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. }), bound_vars: [] }`... | |
| 40 | = note: ...which requires normalizing `Binder { value: ConstEvaluatable(Unevaluated(No, Alias { kind: Anon { def_id: DefId(0:7 ~ inside_array_length[07d6]::foo::{constant#0}) }, args: ['^c_1, T/#1], .. })), bound_vars: [] }`... | |
| 41 | 41 | = note: ...which again requires evaluating type-level constant, completing the cycle |
| 42 | 42 | = note: cycle used when normalizing `inside_array_length::::foo::{constant#0}` |
| 43 | 43 | = note: for more information, see <https://rustc-dev-guide.rust-lang.org/overview.html#queries> and <https://rustc-dev-guide.rust-lang.org/query.html> |
tests/ui/specialization/specialization-default-projection.next.stderr+2-2| ... | ... | @@ -5,7 +5,7 @@ LL | fn generic<T>() -> <T as Foo>::Assoc { |
| 5 | 5 | | ----------------- expected `<T as Foo>::Assoc` because of return type |
| 6 | 6 | ... |
| 7 | 7 | LL | () |
| 8 | | ^^ types differ | |
| 8 | | ^^ expected associated type, found `()` | |
| 9 | 9 | | |
| 10 | 10 | = note: expected associated type `<T as Foo>::Assoc` |
| 11 | 11 | found unit type `()` |
| ... | ... | @@ -23,7 +23,7 @@ LL | fn monomorphic() -> () { |
| 23 | 23 | LL | generic::<()>() |
| 24 | 24 | | ^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;` |
| 25 | 25 | | | |
| 26 | | types differ | |
| 26 | | expected `()`, found associated type | |
| 27 | 27 | | |
| 28 | 28 | = note: expected unit type `()` |
| 29 | 29 | found associated type `<() as Foo>::Assoc` |
tests/ui/specialization/specialization-default-types.next.stderr+2-2| ... | ... | @@ -6,7 +6,7 @@ LL | default type Output = Box<T>; |
| 6 | 6 | LL | default fn generate(self) -> Self::Output { |
| 7 | 7 | | ------------ expected `<T as Example>::Output` because of return type |
| 8 | 8 | LL | Box::new(self) |
| 9 | | ^^^^^^^^^^^^^^ types differ | |
| 9 | | ^^^^^^^^^^^^^^ expected associated type, found `Box<T>` | |
| 10 | 10 | | |
| 11 | 11 | = note: expected associated type `<T as Example>::Output` |
| 12 | 12 | found struct `Box<T>` |
| ... | ... | @@ -19,7 +19,7 @@ error[E0308]: mismatched types |
| 19 | 19 | LL | fn trouble<T>(t: T) -> Box<T> { |
| 20 | 20 | | ------ expected `Box<T>` because of return type |
| 21 | 21 | LL | Example::generate(t) |
| 22 | | ^^^^^^^^^^^^^^^^^^^^ types differ | |
| 22 | | ^^^^^^^^^^^^^^^^^^^^ expected `Box<T>`, found associated type | |
| 23 | 23 | | |
| 24 | 24 | = note: expected struct `Box<T>` |
| 25 | 25 | found associated type `<T as Example>::Output` |
tests/ui/traits/next-solver-ice.stderr+5-12| ... | ... | @@ -2,19 +2,12 @@ error[E0277]: the trait bound `f32: From<<T as Iterator>::Item>` is not satisfie |
| 2 | 2 | --> $DIR/next-solver-ice.rs:5:6 |
| 3 | 3 | | |
| 4 | 4 | LL | <f32 as From<<T as Iterator>::Item>>::from; |
| 5 | | ^^^ the nightly-only, unstable trait `ZeroablePrimitive` is not implemented for `f32` | |
| 5 | | ^^^ the trait `From<<T as Iterator>::Item>` is not implemented for `f32` | |
| 6 | 6 | | |
| 7 | = help: the following other types implement trait `ZeroablePrimitive`: | |
| 8 | i128 | |
| 9 | i16 | |
| 10 | i32 | |
| 11 | i64 | |
| 12 | i8 | |
| 13 | isize | |
| 14 | u128 | |
| 15 | u16 | |
| 16 | and 4 others | |
| 17 | = note: required for `f32` to implement `From<<T as Iterator>::Item>` | |
| 7 | help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | |
| 8 | | | |
| 9 | LL | fn check<T: Iterator>() where f32: From<<T as Iterator>::Item> { | |
| 10 | | ++++++++++++++++++++++++++++++++++++++ | |
| 18 | 11 | |
| 19 | 12 | error: aborting due to 1 previous error |
| 20 | 13 |
tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-4.next.stderr+4-6| ... | ... | @@ -1,11 +1,9 @@ |
| 1 | error[E0284]: type annotations needed | |
| 2 | --> $DIR/ambiguity-due-to-uniquification-4.rs:17:44 | |
| 1 | error[E0282]: type annotations needed | |
| 2 | --> $DIR/ambiguity-due-to-uniquification-4.rs:17:47 | |
| 3 | 3 | | |
| 4 | 4 | LL | pub fn f<'a, 'b, T: Trait<'a> + Trait<'b>>(v: <T as Trait<'a>>::Type) {} |
| 5 | | ^ cannot infer type | |
| 6 | | | |
| 7 | = note: cannot satisfy `<T as Trait<'_>>::Type == _` | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for associated type `<T as Trait<'_>>::Type` | |
| 8 | 6 | |
| 9 | 7 | error: aborting due to 1 previous error |
| 10 | 8 | |
| 11 | For more information about this error, try `rustc --explain E0284`. | |
| 9 | For more information about this error, try `rustc --explain E0282`. |
tests/ui/traits/next-solver/coercion/non-wf-in-coerce-pointers.rs+1| ... | ... | @@ -7,6 +7,7 @@ trait Wf { |
| 7 | 7 | struct S { |
| 8 | 8 | f: &'static <() as Wf>::Assoc, |
| 9 | 9 | //~^ ERROR the trait bound `(): Wf` is not satisfied |
| 10 | //~| ERROR: the type `&'static <() as Wf>::Assoc` is not well-formed | |
| 10 | 11 | } |
| 11 | 12 | |
| 12 | 13 | fn main() { |
tests/ui/traits/next-solver/coercion/non-wf-in-coerce-pointers.stderr+8-2| ... | ... | @@ -10,8 +10,14 @@ help: this trait has no implementations, consider adding one |
| 10 | 10 | LL | trait Wf { |
| 11 | 11 | | ^^^^^^^^ |
| 12 | 12 | |
| 13 | error: the type `&'static <() as Wf>::Assoc` is not well-formed | |
| 14 | --> $DIR/non-wf-in-coerce-pointers.rs:8:8 | |
| 15 | | | |
| 16 | LL | f: &'static <() as Wf>::Assoc, | |
| 17 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 18 | ||
| 13 | 19 | error[E0277]: the trait bound `(): Wf` is not satisfied |
| 14 | --> $DIR/non-wf-in-coerce-pointers.rs:14:18 | |
| 20 | --> $DIR/non-wf-in-coerce-pointers.rs:15:18 | |
| 15 | 21 | | |
| 16 | 22 | LL | let y: &() = x.f; |
| 17 | 23 | | ^^^ the trait `Wf` is not implemented for `()` |
| ... | ... | @@ -22,6 +28,6 @@ help: this trait has no implementations, consider adding one |
| 22 | 28 | LL | trait Wf { |
| 23 | 29 | | ^^^^^^^^ |
| 24 | 30 | |
| 25 | error: aborting due to 2 previous errors | |
| 31 | error: aborting due to 3 previous errors | |
| 26 | 32 | |
| 27 | 33 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/traits/next-solver/normalization-shadowing/is-global-norm-concrete-alias-to-generic.next.stderr+1-1| ... | ... | @@ -5,7 +5,7 @@ LL | fn foo<T>(x: <(*const T,) as Id>::This) -> (*const T,) |
| 5 | 5 | | ----------- expected `(*const T,)` because of return type |
| 6 | 6 | ... |
| 7 | 7 | LL | x |
| 8 | | ^ types differ | |
| 8 | | ^ expected `(*const T,)`, found associated type | |
| 9 | 9 | | |
| 10 | 10 | = note: expected tuple `(*const T,)` |
| 11 | 11 | found associated type `<(*const T,) as Id>::This` |
tests/ui/traits/next-solver/normalization-shadowing/param-candidate-shadows-project.stderr+7-1| ... | ... | @@ -2,8 +2,10 @@ error[E0271]: type mismatch resolving `<T as Foo>::Assoc == i32` |
| 2 | 2 | --> $DIR/param-candidate-shadows-project.rs:27:19 |
| 3 | 3 | | |
| 4 | 4 | LL | require_bar::<T>(); |
| 5 | | ^ types differ | |
| 5 | | ^ expected `i32`, found associated type | |
| 6 | 6 | | |
| 7 | = note: expected type `i32` | |
| 8 | found associated type `<T as Foo>::Assoc` | |
| 7 | 9 | note: required for `T` to implement `Bar` |
| 8 | 10 | --> $DIR/param-candidate-shadows-project.rs:13:9 |
| 9 | 11 | | |
| ... | ... | @@ -14,6 +16,10 @@ note: required by a bound in `require_bar` |
| 14 | 16 | | |
| 15 | 17 | LL | fn require_bar<T: Bar>() {} |
| 16 | 18 | | ^^^ required by this bound in `require_bar` |
| 19 | help: consider constraining the associated type `<T as Foo>::Assoc` to `i32` | |
| 20 | | | |
| 21 | LL | fn foo<T: Foo<Assoc = i32>>() { | |
| 22 | | +++++++++++++ | |
| 17 | 23 | |
| 18 | 24 | error: aborting due to 1 previous error |
| 19 | 25 |
tests/ui/traits/next-solver/normalize/dont-ice-on-normalization-failure.rs+1-1| ... | ... | @@ -13,7 +13,7 @@ type TraitObject = dyn Generic<<i32 as Trait>::Associated>; |
| 13 | 13 | //~^ ERROR: the trait bound `i32: Trait` is not satisfied |
| 14 | 14 | |
| 15 | 15 | struct Wrap(TraitObject); |
| 16 | //~^ ERROR: the trait bound `i32: Trait` is not satisfied | |
| 16 | //~^ ERROR: type mismatch resolving `TraitObject == _` | |
| 17 | 17 | |
| 18 | 18 | fn cast(x: *mut Wrap) { |
| 19 | 19 | x as *mut Wrap; |
tests/ui/traits/next-solver/normalize/dont-ice-on-normalization-failure.stderr+4-9| ... | ... | @@ -10,18 +10,13 @@ help: this trait has no implementations, consider adding one |
| 10 | 10 | LL | trait Trait { |
| 11 | 11 | | ^^^^^^^^^^^ |
| 12 | 12 | |
| 13 | error[E0277]: the trait bound `i32: Trait` is not satisfied | |
| 13 | error[E0271]: type mismatch resolving `TraitObject == _` | |
| 14 | 14 | --> $DIR/dont-ice-on-normalization-failure.rs:15:13 |
| 15 | 15 | | |
| 16 | 16 | LL | struct Wrap(TraitObject); |
| 17 | | ^^^^^^^^^^^ the trait `Trait` is not implemented for `i32` | |
| 18 | | | |
| 19 | help: this trait has no implementations, consider adding one | |
| 20 | --> $DIR/dont-ice-on-normalization-failure.rs:6:1 | |
| 21 | | | |
| 22 | LL | trait Trait { | |
| 23 | | ^^^^^^^^^^^ | |
| 17 | | ^^^^^^^^^^^ types differ | |
| 24 | 18 | |
| 25 | 19 | error: aborting due to 2 previous errors |
| 26 | 20 | |
| 27 | For more information about this error, try `rustc --explain E0277`. | |
| 21 | Some errors have detailed explanations: E0271, E0277. | |
| 22 | For more information about an error, try `rustc --explain E0271`. |
tests/ui/traits/next-solver/normalize/normalize-assoc-ty-expected-int-var-no-ice-2.next.stderr+7-2| ... | ... | @@ -1,11 +1,16 @@ |
| 1 | error[E0271]: type mismatch resolving `<fn() -> impl Sized {foo} as FnOnce<()>>::Output == {integer}` | |
| 1 | error[E0271]: expected `foo` to return `{integer}`, but it returns `impl Sized` | |
| 2 | 2 | --> $DIR/normalize-assoc-ty-expected-int-var-no-ice-2.rs:13:10 |
| 3 | 3 | | |
| 4 | LL | fn foo() -> impl Sized {} | |
| 5 | | ---------- the found opaque type | |
| 6 | ... | |
| 4 | 7 | LL | proj(x, 1); |
| 5 | | ---- ^ types differ | |
| 8 | | ---- ^ expected integer, found opaque type | |
| 6 | 9 | | | |
| 7 | 10 | | required by a bound introduced by this call |
| 8 | 11 | | |
| 12 | = note: expected type `{integer}` | |
| 13 | found opaque type `impl Sized` | |
| 9 | 14 | note: required by a bound in `proj` |
| 10 | 15 | --> $DIR/normalize-assoc-ty-expected-int-var-no-ice-2.rs:9:24 |
| 11 | 16 | | |
tests/ui/traits/next-solver/normalize/normalize-assoc-ty-expected-int-var-no-ice-2.rs+1-2| ... | ... | @@ -11,7 +11,6 @@ fn proj<T: FnOnce() -> U, U>(x: Option<T>, y: U) {} |
| 11 | 11 | fn main() { |
| 12 | 12 | let mut x = None; |
| 13 | 13 | proj(x, 1); |
| 14 | //[current]~^ ERROR: expected `foo` to return `{integer}`, but it returns `impl Sized` | |
| 15 | //[next]~^^ ERROR: type mismatch resolving `<fn() -> impl Sized {foo} as FnOnce<()>>::Output == {integer}` | |
| 14 | //~^ ERROR: expected `foo` to return `{integer}`, but it returns `impl Sized` | |
| 16 | 15 | x = Some(foo); |
| 17 | 16 | } |
tests/ui/traits/next-solver/specialization-transmute.stderr+13-2| ... | ... | @@ -1,22 +1,33 @@ |
| 1 | 1 | error[E0308]: mismatched types |
| 2 | 2 | --> $DIR/specialization-transmute.rs:13:9 |
| 3 | 3 | | |
| 4 | LL | impl<T> Default for T { | |
| 5 | | - found this type parameter | |
| 6 | LL | default type Id = T; | |
| 4 | 7 | LL | fn intu(&self) -> &Self::Id { |
| 5 | 8 | | --------- expected `&<T as Default>::Id` because of return type |
| 6 | 9 | LL | self |
| 7 | | ^^^^ types differ | |
| 10 | | ^^^^ expected `&<T as Default>::Id`, found `&T` | |
| 8 | 11 | | |
| 9 | 12 | = note: expected reference `&<T as Default>::Id` |
| 10 | 13 | found reference `&T` |
| 14 | help: consider restricting type parameter `T` with `<Id = T>` | |
| 15 | | | |
| 16 | LL | impl<T: <Id = T>> Default for T { | |
| 17 | | ++++++++++ | |
| 11 | 18 | |
| 12 | 19 | error[E0271]: type mismatch resolving `<u8 as Default>::Id == Option<NonZero<u8>>` |
| 13 | 20 | --> $DIR/specialization-transmute.rs:24:50 |
| 14 | 21 | | |
| 15 | 22 | LL | let s = transmute::<u8, Option<NonZero<u8>>>(0); |
| 16 | | ------------------------------------ ^ types differ | |
| 23 | | ------------------------------------ ^ expected `Option<NonZero<u8>>`, found associated type | |
| 17 | 24 | | | |
| 18 | 25 | | required by a bound introduced by this call |
| 19 | 26 | | |
| 27 | = note: expected enum `Option<NonZero<u8>>` | |
| 28 | found associated type `<u8 as Default>::Id` | |
| 29 | = help: consider constraining the associated type `<u8 as Default>::Id` to `Option<NonZero<u8>>` | |
| 30 | = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html | |
| 20 | 31 | note: required by a bound in `transmute` |
| 21 | 32 | --> $DIR/specialization-transmute.rs:17:25 |
| 22 | 33 | | |
tests/ui/traits/next-solver/specialization-unconstrained.stderr+5-1| ... | ... | @@ -2,8 +2,12 @@ error[E0271]: type mismatch resolving `<u32 as Default>::Id == ()` |
| 2 | 2 | --> $DIR/specialization-unconstrained.rs:19:12 |
| 3 | 3 | | |
| 4 | 4 | LL | test::<u32, ()>(); |
| 5 | | ^^^ types differ | |
| 5 | | ^^^ expected `()`, found associated type | |
| 6 | 6 | | |
| 7 | = note: expected unit type `()` | |
| 8 | found associated type `<u32 as Default>::Id` | |
| 9 | = help: consider constraining the associated type `<u32 as Default>::Id` to `()` | |
| 10 | = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html | |
| 7 | 11 | note: required by a bound in `test` |
| 8 | 12 | --> $DIR/specialization-unconstrained.rs:16:20 |
| 9 | 13 | | |
tests/ui/traits/next-solver/stalled-coroutine-obligations.rs+4-4| ... | ... | @@ -16,11 +16,11 @@ |
| 16 | 16 | fn stalled_copy_clone() { |
| 17 | 17 | type T = impl Copy; |
| 18 | 18 | let foo: T = async {}; |
| 19 | //~^ ERROR: the trait bound | |
| 19 | //~^ ERROR: type mismatch resolving `T == {async block | |
| 20 | 20 | |
| 21 | 21 | type U = impl Clone; |
| 22 | 22 | let bar: U = async {}; |
| 23 | //~^ ERROR: the trait bound | |
| 23 | //~^ ERROR: type mismatch resolving `U == {async block | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | auto trait Valid {} |
| ... | ... | @@ -31,13 +31,13 @@ fn stalled_auto_traits() { |
| 31 | 31 | type T = impl Valid; |
| 32 | 32 | let a = False; |
| 33 | 33 | let foo: T = async { a }; |
| 34 | //~^ ERROR: the trait bound `False: Valid` is not satisfied | |
| 34 | //~^ ERROR: type mismatch resolving `T == {async block | |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | trait Trait { |
| 39 | 39 | fn stalled_send(&self, b: *mut ()) -> impl Future + Send { |
| 40 | //~^ ERROR: type mismatch resolving | |
| 40 | //~^ ERROR: type mismatch resolving `impl Future + Send == {async block | |
| 41 | 41 | async move { |
| 42 | 42 | b |
| 43 | 43 | } |
tests/ui/traits/next-solver/stalled-coroutine-obligations.stderr+14-22| ... | ... | @@ -1,41 +1,33 @@ |
| 1 | error[E0277]: the trait bound `{async block@$DIR/stalled-coroutine-obligations.rs:18:18: 18:23}: Copy` is not satisfied | |
| 1 | error[E0271]: type mismatch resolving `T == {async block@$DIR/stalled-coroutine-obligations.rs:18:18: 18:23}` | |
| 2 | 2 | --> $DIR/stalled-coroutine-obligations.rs:18:14 |
| 3 | 3 | | |
| 4 | 4 | LL | let foo: T = async {}; |
| 5 | | ^ the trait `Copy` is not implemented for `{async block@$DIR/stalled-coroutine-obligations.rs:18:18: 18:23}` | |
| 5 | | ^ types differ | |
| 6 | 6 | |
| 7 | error[E0277]: the trait bound `{async block@$DIR/stalled-coroutine-obligations.rs:22:18: 22:23}: Clone` is not satisfied | |
| 7 | error[E0271]: type mismatch resolving `U == {async block@$DIR/stalled-coroutine-obligations.rs:22:18: 22:23}` | |
| 8 | 8 | --> $DIR/stalled-coroutine-obligations.rs:22:14 |
| 9 | 9 | | |
| 10 | 10 | LL | let bar: U = async {}; |
| 11 | | ^ the trait `Clone` is not implemented for `{async block@$DIR/stalled-coroutine-obligations.rs:22:18: 22:23}` | |
| 11 | | ^ types differ | |
| 12 | 12 | |
| 13 | error[E0277]: the trait bound `False: Valid` is not satisfied in `{async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}` | |
| 13 | error[E0271]: type mismatch resolving `T == {async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}` | |
| 14 | 14 | --> $DIR/stalled-coroutine-obligations.rs:33:14 |
| 15 | 15 | | |
| 16 | 16 | LL | let foo: T = async { a }; |
| 17 | | ^ ----- within this `{async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}` | |
| 18 | | | | |
| 19 | | unsatisfied trait bound | |
| 20 | | | |
| 21 | help: within `{async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}`, the trait `Valid` is not implemented for `False` | |
| 22 | --> $DIR/stalled-coroutine-obligations.rs:27:1 | |
| 23 | | | |
| 24 | LL | struct False; | |
| 25 | | ^^^^^^^^^^^^ | |
| 26 | note: captured value does not implement `Valid` | |
| 27 | --> $DIR/stalled-coroutine-obligations.rs:33:26 | |
| 28 | | | |
| 29 | LL | let foo: T = async { a }; | |
| 30 | | ^ has type `False` which does not implement `Valid` | |
| 17 | | ^ types differ | |
| 31 | 18 | |
| 32 | 19 | error[E0271]: type mismatch resolving `impl Future + Send == {async block@$DIR/stalled-coroutine-obligations.rs:41:9: 41:19}` |
| 33 | 20 | --> $DIR/stalled-coroutine-obligations.rs:39:43 |
| 34 | 21 | | |
| 35 | 22 | LL | fn stalled_send(&self, b: *mut ()) -> impl Future + Send { |
| 36 | | ^^^^^^^^^^^^^^^^^^ types differ | |
| 23 | | ^^^^^^^^^^^^^^^^^^ expected `async` block, found associated type | |
| 24 | LL | | |
| 25 | LL | async move { | |
| 26 | | ---------- the expected `async` block | |
| 27 | | | |
| 28 | = note: expected `async` block `{async block@$DIR/stalled-coroutine-obligations.rs:41:9: 41:19}` | |
| 29 | found associated type `impl Future + Send` | |
| 37 | 30 | |
| 38 | 31 | error: aborting due to 4 previous errors |
| 39 | 32 | |
| 40 | Some errors have detailed explanations: E0271, E0277. | |
| 41 | For more information about an error, try `rustc --explain E0271`. | |
| 33 | For more information about this error, try `rustc --explain E0271`. |
tests/ui/traits/normalize/normalize-diverging-alias-in-struct.next.stderr+9-9| ... | ... | @@ -1,15 +1,15 @@ |
| 1 | error[E0271]: type mismatch resolving `<u8 as Trait>::Diverges<u8> == _` | |
| 1 | error[E0275]: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _` | |
| 2 | 2 | --> $DIR/normalize-diverging-alias-in-struct.rs:21:12 |
| 3 | 3 | | |
| 4 | 4 | LL | field: Box<<u8 as Trait>::Diverges<u8>>, |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<u8 as Trait>::Diverges<u8> == _` | |
| 6 | | | |
| 7 | note: types differ | |
| 8 | --> $DIR/normalize-diverging-alias-in-struct.rs:17:31 | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | ||
| 7 | error[E0275]: overflow evaluating whether `Box<<u8 as Trait>::Diverges<u8>>` is well-formed | |
| 8 | --> $DIR/normalize-diverging-alias-in-struct.rs:21:12 | |
| 9 | 9 | | |
| 10 | LL | type Diverges<D: Trait> = D::Diverges<D>; | |
| 11 | | ^^^^^^^^^^^^^^ | |
| 10 | LL | field: Box<<u8 as Trait>::Diverges<u8>>, | |
| 11 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 12 | 12 | |
| 13 | error: aborting due to 1 previous error | |
| 13 | error: aborting due to 2 previous errors | |
| 14 | 14 | |
| 15 | For more information about this error, try `rustc --explain E0271`. | |
| 15 | For more information about this error, try `rustc --explain E0275`. |
tests/ui/traits/normalize/normalize-diverging-alias-in-struct.rs+2-2| ... | ... | @@ -19,8 +19,8 @@ impl<T> Trait for T { |
| 19 | 19 | |
| 20 | 20 | struct Foo { |
| 21 | 21 | field: Box<<u8 as Trait>::Diverges<u8>>, |
| 22 | //[current]~^ ERROR: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _` | |
| 23 | //[next]~^^ ERROR: type mismatch resolving `<u8 as Trait>::Diverges<u8> == _` | |
| 22 | //~^ ERROR: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _` | |
| 23 | //[next]~^^ ERROR: overflow evaluating whether `Box<<u8 as Trait>::Diverges<u8>>` is well-formed | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | fn main() {} |
tests/ui/type-alias-impl-trait/coherence/coherence_different_hidden_ty.rs+2-1| ... | ... | @@ -9,6 +9,7 @@ |
| 9 | 9 | // @lcnr: Because of this I decided to not bother and cause this to fail instead. |
| 10 | 10 | // In the future we can definitely modify the compiler to accept this |
| 11 | 11 | // again. |
| 12 | ||
| 12 | 13 | #![feature(type_alias_impl_trait)] |
| 13 | 14 | |
| 14 | 15 | trait Trait {} |
| ... | ... | @@ -18,7 +19,7 @@ type TAIT = impl Sized; |
| 18 | 19 | impl Trait for (TAIT, TAIT) {} |
| 19 | 20 | |
| 20 | 21 | impl Trait for (u32, i32) {} |
| 21 | //~^ ERROR: conflicting implementations of trait `Trait` for type | |
| 22 | //~^ ERROR: conflicting implementations of trait `Trait` for type `(TAIT, TAIT)` | |
| 22 | 23 | |
| 23 | 24 | #[define_opaque(TAIT)] |
| 24 | 25 | fn define() -> TAIT {} |
tests/ui/type-alias-impl-trait/coherence/coherence_different_hidden_ty.stderr+1-1| ... | ... | @@ -1,5 +1,5 @@ |
| 1 | 1 | error[E0119]: conflicting implementations of trait `Trait` for type `(TAIT, TAIT)` |
| 2 | --> $DIR/coherence_different_hidden_ty.rs:20:1 | |
| 2 | --> $DIR/coherence_different_hidden_ty.rs:21:1 | |
| 3 | 3 | | |
| 4 | 4 | LL | impl Trait for (TAIT, TAIT) {} |
| 5 | 5 | | --------------------------- first implementation here |
tests/ui/type-alias-impl-trait/const_eval_reveal_opaque_in_param_env.rs created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | //@ edition: 2024 | |
| 2 | //@ compile-flags: -Znext-solver -Zdisable-fast-paths | |
| 3 | //@ check-pass | |
| 4 | ||
| 5 | // Test whether we mark the rigid alias in hir typeck non-rigid in const eval | |
| 6 | // where we reveal all hidden types with `PostAnalysis` typing mode. | |
| 7 | // | |
| 8 | // This shouldn't compile as we shouldn't do const eval in non-empty param env | |
| 9 | // in the future. | |
| 10 | ||
| 11 | #![feature(type_alias_impl_trait)] | |
| 12 | type Tait<T> = impl Sized; | |
| 13 | #[define_opaque(Tait)] | |
| 14 | fn foo<T>(x: T) -> Tait<T> { | |
| 15 | x | |
| 16 | } | |
| 17 | ||
| 18 | trait Trait { | |
| 19 | type Assoc; | |
| 20 | } | |
| 21 | ||
| 22 | fn bar<T>() -> [u8; 4] | |
| 23 | where | |
| 24 | T: Trait, | |
| 25 | Tait<T>: Trait<Assoc = u32>, | |
| 26 | { | |
| 27 | [0; std::mem::size_of::<<T as Trait>::Assoc>()] | |
| 28 | //~^ WARN: cannot use constants which depend on generic parameters in types | |
| 29 | //~| WARN: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | |
| 30 | } | |
| 31 | ||
| 32 | fn main() {} |
tests/ui/type-alias-impl-trait/const_eval_reveal_opaque_in_param_env.stderr created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | warning: cannot use constants which depend on generic parameters in types | |
| 2 | --> $DIR/const_eval_reveal_opaque_in_param_env.rs:27:9 | |
| 3 | | | |
| 4 | LL | [0; std::mem::size_of::<<T as Trait>::Assoc>()] | |
| 5 | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 6 | | | |
| 7 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | |
| 8 | = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200> | |
| 9 | = note: `#[warn(const_evaluatable_unchecked)]` (part of `#[warn(future_incompatible)]`) on by default | |
| 10 | ||
| 11 | warning: 1 warning emitted | |
| 12 |
tests/ui/type-alias-impl-trait/method_resolution.next.stderr+3-1| ... | ... | @@ -5,7 +5,9 @@ LL | struct Bar<T>(T); |
| 5 | 5 | | ------------- method `bar` not found for this struct |
| 6 | 6 | ... |
| 7 | 7 | LL | self.bar() |
| 8 | | ^^^ method cannot be called on `Bar<u32>` due to unsatisfied trait bounds | |
| 8 | | ^^^ method not found in `Bar<u32>` | |
| 9 | | | |
| 10 | = note: the method was found for `Bar<Foo>` | |
| 9 | 11 | |
| 10 | 12 | error: aborting due to 1 previous error |
| 11 | 13 |
tests/ui/wf/return-type-non-wf-no-ice.next.stderr+2-16| ... | ... | @@ -1,22 +1,8 @@ |
| 1 | error[E0277]: `T` is not an iterator | |
| 1 | error: the type `Foo<T>` is not well-formed | |
| 2 | 2 | --> $DIR/return-type-non-wf-no-ice.rs:13:16 |
| 3 | 3 | | |
| 4 | 4 | LL | fn foo<T>() -> Foo<T> { |
| 5 | | ^^^^^^ `T` is not an iterator | |
| 6 | | | |
| 7 | note: required by a bound in `Foo` | |
| 8 | --> $DIR/return-type-non-wf-no-ice.rs:10:8 | |
| 9 | | | |
| 10 | LL | pub struct Foo<T>(T) | |
| 11 | | --- required by a bound in this struct | |
| 12 | LL | where | |
| 13 | LL | T: Iterator, | |
| 14 | | ^^^^^^^^ required by this bound in `Foo` | |
| 15 | help: consider restricting type parameter `T` with trait `Iterator` | |
| 16 | | | |
| 17 | LL | fn foo<T: std::iter::Iterator>() -> Foo<T> { | |
| 18 | | +++++++++++++++++++++ | |
| 5 | | ^^^^^^ | |
| 19 | 6 | |
| 20 | 7 | error: aborting due to 1 previous error |
| 21 | 8 | |
| 22 | For more information about this error, try `rustc --explain E0277`. |
tests/ui/wf/return-type-non-wf-no-ice.rs+2-1| ... | ... | @@ -11,7 +11,8 @@ where |
| 11 | 11 | <T as Iterator>::Item: Default; |
| 12 | 12 | |
| 13 | 13 | fn foo<T>() -> Foo<T> { |
| 14 | //~^ ERROR: `T` is not an iterator | |
| 14 | //[current]~^ ERROR: `T` is not an iterator | |
| 15 | //[next]~^^ ERROR: the type `Foo<T>` is not well-formed | |
| 15 | 16 | loop {} |
| 16 | 17 | } |
| 17 | 18 |