authorbors <bors@rust-lang.org> 2026-06-25 14:59:15 UTC
committerbors <bors@rust-lang.org> 2026-06-25 14:59:15 UTC
logfa36a479e492137fdf473a891206da127f132910
tree68526db09cc0407ba41d95c5d2b96945a90f47a7
parent973ad0d0ab149bde2e96422833c1265c7a5be217
parentb20305bb330cc7692d35d277404e0c2c177f30ca

Auto merge of #156742 - adwinwhite:rigid-alias, r=lcnr

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? lcnr

267 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> {
713713 ));
714714 let can_subst = |ty: Ty<'tcx>| {
715715 // 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);
718718 if let Ok(old_ty) = tcx.try_normalize_erasing_regions(
719719 self.infcx.typing_env(self.infcx.param_env),
720720 old_ty,
compiler/rustc_borrowck/src/diagnostics/opaque_types.rs+3-2
......@@ -76,6 +76,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
7676 "non-defining use of `{}` in the defining scope",
7777 Ty::new_opaque(
7878 infcx.tcx,
79 ty::IsRigid::No,
7980 opaque_type_key.def_id.to_def_id(),
8081 opaque_type_key.args
8182 )
......@@ -220,7 +221,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for FindOpaqueRegion<'_, 'tcx> {
220221 fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
221222 // If we find an opaque in a local ty, then for each of its captured regions,
222223 // 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()
224225 && let hir::OpaqueTyOrigin::FnReturn { parent, in_trait_or_impl: None } =
225226 self.tcx.opaque_ty_origin(def_id)
226227 {
......@@ -277,7 +278,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for CheckExplicitRegionMentionAndCollectGen
277278
278279 fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
279280 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, .. }) => {
281282 if self.seen_opaques.insert(def_id) {
282283 for (bound, _) in self
283284 .tcx
compiler/rustc_borrowck/src/diagnostics/region_errors.rs+1-1
......@@ -603,7 +603,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
603603 let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
604604
605605 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() {
607607 output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity().skip_norm_wip()
608608 };
609609
compiler/rustc_borrowck/src/lib.rs+2-2
......@@ -1928,7 +1928,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19281928 | ty::Never
19291929 | ty::Tuple(_)
19301930 | ty::UnsafeBinder(_)
1931 | ty::Alias(_)
1931 | ty::Alias(_, _)
19321932 | ty::Param(_)
19331933 | ty::Bound(_, _)
19341934 | ty::Infer(_)
......@@ -1970,7 +1970,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
19701970 | ty::CoroutineWitness(..)
19711971 | ty::Never
19721972 | ty::UnsafeBinder(_)
1973 | ty::Alias(_)
1973 | ty::Alias(_, _)
19741974 | ty::Param(_)
19751975 | ty::Bound(_, _)
19761976 | 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<'_, '_,
176176 | ty::CoroutineClosure(def_id, args)
177177 | ty::Coroutine(def_id, args) => self.visit_closure_args(def_id, args),
178178
179 ty::Alias(ty::AliasTy { kind, args, .. })
179 ty::Alias(_, ty::AliasTy { kind, args, .. })
180180 if let Some(variances) = self.cx().opt_alias_variances(kind) =>
181181 {
182182 // 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>(
367367 // usage of the opaque type and we can ignore it. This check is mirrored in typeck's
368368 // writeback.
369369 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, .. }) =
371371 hidden_type.ty.skip_binder().kind()
372372 && def_id == opaque_type_key.def_id.to_def_id()
373373 && args == opaque_type_key.args
......@@ -500,7 +500,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for ToArgRegionsFolder<'_, 'tcx> {
500500 Ty::new_coroutine(tcx, def_id, self.fold_closure_args(def_id, args)?)
501501 }
502502
503 ty::Alias(ty::AliasTy { kind, args, .. })
503 ty::Alias(_, ty::AliasTy { kind, args, .. })
504504 if let Some(variances) = tcx.opt_alias_variances(kind) =>
505505 {
506506 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> {
512512 }
513513 },
514514 ))?;
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)
516516 }
517517
518518 _ => ty.try_super_fold_with(self)?,
......@@ -541,7 +541,7 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
541541 for &(key, hidden_type) in opaque_types {
542542 let Some(expected) = hidden_types.get(&key.def_id) else {
543543 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, .. }) =
545545 hidden_type.ty.kind()
546546 && def_id == key.def_id.to_def_id()
547547 && args == key.args
compiler/rustc_borrowck/src/type_check/mod.rs+2-2
......@@ -469,7 +469,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
469469 // Necessary for non-trivial patterns whose user-type annotation is an opaque type,
470470 // e.g. `let (_a,): Tait = whatever`, see #105897
471471 if !self.infcx.next_trait_solver()
472 && let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
472 && let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) =
473473 curr_projected_ty.ty.kind()
474474 {
475475 // 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> {
17601760 let tcx = self.tcx();
17611761 let maybe_uneval = match constant.const_ {
17621762 Const::Ty(_, ct) => match ct.kind() {
1763 ty::ConstKind::Unevaluated(uv) => match uv.kind {
1763 ty::ConstKind::Unevaluated(_, uv) => match uv.kind {
17641764 ty::UnevaluatedConstKind::Projection { def_id }
17651765 | ty::UnevaluatedConstKind::Inherent { def_id }
17661766 | 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> {
150150 };
151151
152152 let (a, b) = match (a.kind(), b.kind()) {
153 (&ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
153 (&ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }), _) => {
154154 (a, enable_subtyping(b, true)?)
155155 }
156 (_, &ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
156 (_, &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })) => {
157157 (enable_subtyping(a, false)?, b)
158158 }
159159 _ => unreachable!(
......@@ -386,8 +386,8 @@ impl<'b, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'b, 'tcx> {
386386 }
387387
388388 (
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 }, .. }),
391391 ) if a_def_id == b_def_id || infcx.next_trait_solver() => {
392392 super_combine_tys(&infcx.infcx, self, a, b).map(|_| ()).or_else(|err| {
393393 // 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> {
401401 if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) }
402402 })?;
403403 }
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 }, .. }))
406406 if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() =>
407407 {
408408 self.relate_opaques(a, b)?;
compiler/rustc_codegen_cranelift/src/common.rs+1-1
......@@ -349,7 +349,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
349349 self.instance.instantiate_mir_and_normalize_erasing_regions(
350350 self.tcx,
351351 ty::TypingEnv::fully_monomorphized(),
352 ty::EarlyBinder::bind(value),
352 ty::EarlyBinder::bind(self.tcx, value),
353353 )
354354 }
355355
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> {
136136 self.instance.instantiate_mir_and_normalize_erasing_regions(
137137 self.cx.tcx(),
138138 self.cx.typing_env(),
139 ty::EarlyBinder::bind(value),
139 ty::EarlyBinder::bind(self.cx.tcx(), value),
140140 )
141141 }
142142}
......@@ -219,7 +219,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
219219 let monomorphized_mir = instance.instantiate_mir_and_normalize_erasing_regions(
220220 tcx,
221221 ty::TypingEnv::fully_monomorphized(),
222 ty::EarlyBinder::bind(mir.clone()),
222 ty::EarlyBinder::bind(tcx, mir.clone()),
223223 );
224224 mir = tcx.arena.alloc(optimize_use_clone::<Bx>(cx, monomorphized_mir));
225225 }
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
6767 .instantiate_mir_and_normalize_erasing_regions(
6868 cx.tcx(),
6969 cx.typing_env(),
70 ty::EarlyBinder::bind(value.const_),
70 ty::EarlyBinder::bind(cx.tcx(), value.const_),
7171 )
7272 .eval(cx.tcx(), cx.typing_env(), value.span)
7373 .expect("erroneous constant missed by mono item collection");
......@@ -75,7 +75,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL
7575 let mono_type = instance.instantiate_mir_and_normalize_erasing_regions(
7676 cx.tcx(),
7777 cx.typing_env(),
78 ty::EarlyBinder::bind(value.ty()),
78 ty::EarlyBinder::bind(cx.tcx(), value.ty()),
7979 );
8080
8181 let string = common::asm_const_to_str(
......@@ -91,7 +91,7 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL
9191 let mono_type = instance.instantiate_mir_and_normalize_erasing_regions(
9292 cx.tcx(),
9393 cx.typing_env(),
94 ty::EarlyBinder::bind(value.ty()),
94 ty::EarlyBinder::bind(cx.tcx(), value.ty()),
9595 );
9696
9797 let instance = match mono_type.kind() {
compiler/rustc_const_eval/src/check_consts/qualifs.rs+1-1
......@@ -345,7 +345,7 @@ where
345345 Const::Ty(_, ct) => match ct.kind() {
346346 ty::ConstKind::Param(_) | ty::ConstKind::Error(_) => None,
347347 // Unevaluated consts in MIR bodies don't have associated MIR (e.g. `type const`).
348 ty::ConstKind::Unevaluated(_) => None,
348 ty::ConstKind::Unevaluated(_, _) => None,
349349 // FIXME(mgca): Investigate whether using `None` for `ConstKind::Value` is overly
350350 // strict, and if instead we should be doing some kind of value-based analysis.
351351 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>>(
9797 body: &'tcx mir::Body<'tcx>,
9898) -> InterpResult<'tcx, R> {
9999 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())?;
102102 let (intern_kind, ret) = setup_for_eval(ecx, cid, layout)?;
103103
104104 trace!(
compiler/rustc_const_eval/src/interpret/eval_context.rs+1-1
......@@ -362,7 +362,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
362362 .try_instantiate_mir_and_normalize_erasing_regions(
363363 *self.tcx,
364364 self.typing_env,
365 ty::EarlyBinder::bind(value),
365 ty::EarlyBinder::bind(self.tcx.tcx, value),
366366 )
367367 .map_err(|_| ErrorHandled::TooGeneric(self.cur_span()))
368368 }
compiler/rustc_const_eval/src/util/type_name.rs+8-7
......@@ -53,20 +53,21 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
5353 // Types with identity (print the module path).
5454 ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
5555 | 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 )
6162 | ty::Closure(def_id, args)
6263 | ty::CoroutineClosure(def_id, args)
6364 | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
6465 ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
6566
66 ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => {
67 ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
6768 bug!("type_name: unexpected free alias")
6869 }
69 ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
70 ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
7071 bug!("type_name: unexpected inherent projection")
7172 }
7273 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> {
165165 return None;
166166 }
167167
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 ))?;
170171 debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
171172 self.state.obligations.extend(obligations);
172173
compiler/rustc_hir_analysis/src/check/always_applicable.rs+4-3
......@@ -192,8 +192,9 @@ fn ensure_all_fields_are_const_destruct<'tcx>(
192192 let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
193193
194194 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();
197198 let args = ty::GenericArgs::identity_for_item(tcx, impl_def_id);
198199 let destruct_trait = tcx.lang_items().destruct_trait().unwrap();
199200 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>(
281282 // reference the params from the ADT instead of from the impl which is bad UX. To resolve
282283 // this we "rename" the ADT's params to be the impl's params which should not affect behaviour.
283284 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))
285286 .instantiate(tcx, adt_to_impl_args)
286287 .skip_norm_wip();
287288
compiler/rustc_hir_analysis/src/check/check.rs+11-8
......@@ -337,7 +337,7 @@ fn check_opaque_meets_bounds<'tcx>(
337337 }),
338338 };
339339
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);
341341
342342 // `ReErased` regions appear in the "parent_args" of closures/coroutines.
343343 // We're ignoring them here and replacing them with fresh region variables.
......@@ -534,7 +534,7 @@ fn sanity_check_found_hidden_type<'tcx>(
534534 // Nothing was actually constrained.
535535 return Ok(());
536536 }
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() {
538538 if def_id == key.def_id.to_def_id() && args == key.args {
539539 // Nothing was actually constrained, this is an opaque usage that was
540540 // 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<(),
778778 if has_default {
779779 // need to store default and type of default
780780 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()
782782 && let Some(def_id) = uv.kind.opt_def_id()
783783 {
784784 tcx.ensure_ok().type_of(def_id);
......@@ -2191,7 +2191,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
21912191 impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
21922192 fn visit_ty(&mut self, t: Ty<'tcx>) {
21932193 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 }, .. }) => {
21952195 self.opaques.push(def);
21962196 }
21972197 ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
......@@ -2224,10 +2224,13 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
22242224 let mut label_match = |ty: Ty<'_>, span| {
22252225 for arg in ty.walk() {
22262226 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()
22312234 && captured_def_id == opaque_def_id.to_def_id()
22322235 {
22332236 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>(
761761 Ok(ty) => ty,
762762 Err(guar) => Ty::new_error(tcx, guar),
763763 };
764 remapped_types.insert(def_id, ty::EarlyBinder::bind(ty));
764 remapped_types.insert(def_id, ty::EarlyBinder::bind(tcx, ty));
765765 }
766766 Err(err) => {
767767 // 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>(
783783 if !remapped_types.contains_key(assoc_item) {
784784 remapped_types.insert(
785785 *assoc_item,
786 ty::EarlyBinder::bind(Ty::new_error_with_message(
786 ty::EarlyBinder::bind(
787787 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 ),
791794 );
792795 }
793796 }
......@@ -826,7 +829,7 @@ where
826829 }
827830
828831 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, .. }) =
830833 ty.kind()
831834 && self.cx().is_impl_trait_in_trait(def_id)
832835 {
......@@ -930,10 +933,10 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
930933 } else {
931934 let guar = match region.opt_param_def_id(self.tcx, self.impl_m_def_id) {
932935 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()
937940 {
938941 self.tcx.def_span(opaque_ty_def_id)
939942 } else {
......@@ -2721,7 +2724,7 @@ fn param_env_with_gat_bounds<'tcx>(
27212724 let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars);
27222725
27232726 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, .. })
27252728 if def_id == trait_ty.def_id && args == rebased_args =>
27262729 {
27272730 // Don't include this predicate if the projected type is
......@@ -2764,7 +2767,7 @@ fn try_report_async_mismatch<'tcx>(
27642767 return Ok(());
27652768 }
27662769
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 }, .. }) =
27682771 *tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind()
27692772 else {
27702773 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>(
8787 hidden_tys[&trait_projection.kind].instantiate(tcx, impl_opaque_args).skip_norm_wip();
8888
8989 // 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()
9191 && let Some(impl_opaque) = alias.try_to_opaque()
9292 {
9393 impl_opaque
......@@ -267,7 +267,7 @@ struct ImplTraitInTraitCollector<'tcx> {
267267
268268impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'tcx> {
269269 fn visit_ty(&mut self, ty: Ty<'tcx>) {
270 if let ty::Alias(alias) = *ty.kind()
270 if let ty::Alias(_, alias) = *ty.kind()
271271 && let Some(proj) = alias.try_to_projection()
272272 && self.tcx.is_impl_trait_in_trait(proj.kind)
273273 {
......@@ -318,9 +318,10 @@ fn report_mismatched_rpitit_signature<'tcx>(
318318 let mut return_ty = trait_m_sig.output().fold_with(&mut super::RemapLateParam { tcx, mapping });
319319
320320 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()
324325 else {
325326 span_bug!(
326327 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(
631631 vec![Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0))],
632632 Ty::new_projection_from_args(
633633 tcx,
634 ty::IsRigid::No,
634635 discriminant_def_id,
635636 tcx.mk_args(&[param(0).into()]),
636637 ),
compiler/rustc_hir_analysis/src/check/wfcheck.rs+3-3
......@@ -782,7 +782,7 @@ impl<'tcx> GATArgsCollector<'tcx> {
782782impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for GATArgsCollector<'tcx> {
783783 fn visit_ty(&mut self, t: Ty<'tcx>) {
784784 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, .. })
786786 if def_id == self.gat =>
787787 {
788788 for (idx, arg) in args.iter().enumerate() {
......@@ -1509,7 +1509,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
15091509 | ty::ConstKind::Bound(_, _) => unreachable!(),
15101510 ty::ConstKind::Error(_) | ty::ConstKind::Expr(_) => continue,
15111511 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(),
15131513 ty::ConstKind::Param(param_ct) => {
15141514 param_ct.find_const_ty_from_env(wfcx.param_env)
15151515 }
......@@ -1585,7 +1585,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id:
15851585 }
15861586 let mut param_count = CountParams::default();
15871587 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);
15891589 // Don't check non-defaulted params, dependent defaults (including lifetimes)
15901590 // or preds with multiple params.
15911591 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> {
203203 | ty::FnPtr(..)
204204 | ty::Tuple(..)
205205 | 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 )
210213 | ty::Param(_) => {
211214 Err(self.tcx.dcx().emit_err(diagnostics::InherentNominal { span: item_span }))
212215 }
......@@ -215,7 +218,7 @@ impl<'tcx> InherentCollect<'tcx> {
215218 | ty::CoroutineClosure(..)
216219 | ty::Coroutine(..)
217220 | ty::CoroutineWitness(..)
218 | ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. })
221 | ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. })
219222 | ty::Bound(..)
220223 | ty::Placeholder(_)
221224 | ty::Infer(_) => {
compiler/rustc_hir_analysis/src/coherence/orphan.rs+2-2
......@@ -194,7 +194,7 @@ pub(crate) fn orphan_check_impl(
194194 NonlocalImpl::DisallowOther,
195195 ),
196196
197 ty::Alias(ty::AliasTy { kind, .. }) => {
197 ty::Alias(_, ty::AliasTy { kind, .. }) => {
198198 let problematic_kind = match kind {
199199 // trait Id { type This: ?Sized; }
200200 // impl<T: ?Sized> Id for T {
......@@ -440,7 +440,7 @@ fn emit_orphan_check_error<'tcx>(
440440 });
441441 }
442442 }
443 ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
443 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
444444 diag.subdiagnostic(diagnostics::OnlyCurrentTraitsOpaque { span });
445445 }
446446 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
10851085 bug!("unexpected sort of node in fn_sig(): {:?}", x);
10861086 }
10871087 };
1088 ty::EarlyBinder::bind(output)
1088 ty::EarlyBinder::bind(tcx, output)
10891089}
10901090
10911091fn lower_fn_sig_recovering_infer_ret_ty<'tcx>(
......@@ -1363,7 +1363,12 @@ pub fn suggest_impl_trait<'tcx>(
13631363 let item_ty = ocx.normalize(
13641364 &ObligationCause::dummy(),
13651365 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 )),
13671372 );
13681373 // FIXME(compiler-errors): We may benefit from resolving regions here.
13691374 if ocx.try_evaluate_obligations().is_empty()
......@@ -1405,7 +1410,7 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader
14051410 let trait_ref = icx.lowerer().lower_impl_trait_ref(&of_trait.trait_ref, selfty);
14061411
14071412 ty::ImplTraitHeader {
1408 trait_ref: ty::EarlyBinder::bind(trait_ref),
1413 trait_ref: ty::EarlyBinder::bind(tcx, trait_ref),
14091414 safety: of_trait.safety,
14101415 polarity: polarity_of_impl(tcx, of_trait, is_rustc_reservation),
14111416 constness: impl_.constness,
......@@ -1626,7 +1631,7 @@ fn const_param_default<'tcx>(
16261631 default_ct,
16271632 tcx.type_of(def_id).instantiate(tcx, identity_args).skip_norm_wip(),
16281633 );
1629 ty::EarlyBinder::bind(ct)
1634 ty::EarlyBinder::bind(tcx, ct)
16301635}
16311636
16321637fn anon_const_kind<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ty::AnonConstKind {
......@@ -1676,7 +1681,7 @@ fn const_of_item<'tcx>(
16761681 tcx.def_span(def_id),
16771682 "cannot call const_of_item on a non-type_const",
16781683 );
1679 return ty::EarlyBinder::bind(Const::new_error(tcx, e));
1684 return ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e));
16801685 }
16811686 };
16821687 let icx = ItemCtxt::new(tcx, def_id);
......@@ -1688,8 +1693,8 @@ fn const_of_item<'tcx>(
16881693 if let Err(e) = icx.check_tainted_by_errors()
16891694 && !ct.references_error()
16901695 {
1691 ty::EarlyBinder::bind(Const::new_error(tcx, e))
1696 ty::EarlyBinder::bind(tcx, Const::new_error(tcx, e))
16921697 } else {
1693 ty::EarlyBinder::bind(ct)
1698 ty::EarlyBinder::bind(tcx, ct)
16941699 }
16951700}
compiler/rustc_hir_analysis/src/collect/item_bounds.rs+15-11
......@@ -33,6 +33,7 @@ fn associated_type_bounds<'tcx>(
3333 ty::print::with_reduced_queries!({
3434 let item_ty = Ty::new_projection_from_args(
3535 tcx,
36 ty::IsRigid::No,
3637 assoc_item_def_id.to_def_id(),
3738 GenericArgs::identity_for_item(tcx, assoc_item_def_id),
3839 );
......@@ -144,6 +145,7 @@ fn remap_gat_vars_and_recurse_into_nested_projections<'tcx>(
144145
145146 let gat_vars = loop {
146147 if let ty::Alias(
148 _,
147149 alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_ty_def_id }, .. },
148150 ) = *clause_ty.kind()
149151 {
......@@ -430,7 +432,7 @@ pub(super) fn explicit_item_bounds_with_filter(
430432 let opaque_ty = tcx.hir_node_by_def_id(opaque_def_id.expect_local()).expect_opaque_ty();
431433 let bounds =
432434 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);
434436 }
435437 Some(ty::ImplTraitInTraitData::Impl { .. }) => {
436438 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(
457459 in_trait_or_impl: Some(hir::RpitContext::Trait),
458460 } => {
459461 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);
461463 let bounds = &*tcx.arena.alloc_slice(
462464 &opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter)
463465 .to_vec()
......@@ -476,7 +478,7 @@ pub(super) fn explicit_item_bounds_with_filter(
476478 }
477479 | rustc_hir::OpaqueTyOrigin::TyAlias { parent: _, .. } => {
478480 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);
480482 let bounds = opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter);
481483 assert_only_contains_predicates_from(filter, bounds, item_ty);
482484 bounds
......@@ -486,7 +488,7 @@ pub(super) fn explicit_item_bounds_with_filter(
486488 node => bug!("item_bounds called on {def_id:?} => {node:?}"),
487489 };
488490
489 ty::EarlyBinder::bind(bounds)
491 ty::EarlyBinder::bind_iter(bounds)
490492}
491493
492494pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
......@@ -515,9 +517,12 @@ pub(super) fn item_non_self_bounds(
515517 let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect();
516518 let own_bounds: FxIndexSet<_> = tcx.item_self_bounds(def_id).skip_binder().iter().collect();
517519 if all_bounds.len() == own_bounds.len() {
518 ty::EarlyBinder::bind(ty::ListWithCachedTypeInfo::empty())
520 ty::EarlyBinder::bind(tcx, ty::ListWithCachedTypeInfo::empty())
519521 } 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 )
521526 }
522527}
523528
......@@ -549,11 +554,10 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTyToOpaque<'tcx> {
549554 }
550555
551556 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()
557561 && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
558562 self.tcx.opt_rpitit_info(projection_ty_def_id)
559563 && 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>(
433433
434434 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
435435 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() {
437437 if is_const_param_default(self.tcx, uv.kind) {
438438 // Do not look into const param defaults,
439439 // these get checked when they are actually instantiated.
......@@ -519,11 +519,10 @@ pub(super) fn explicit_predicates_of<'tcx>(
519519 // identity args of the trait.
520520 // * It must be an associated type for this trait (*not* a
521521 // 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()
527526 {
528527 args == trait_identity_args
529528 // FIXME(return_type_notation): This check should be more robust
......@@ -745,7 +744,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
745744
746745 assert_only_contains_predicates_from(filter, implied_bounds, tcx.types.self_param);
747746
748 ty::EarlyBinder::bind(implied_bounds)
747 ty::EarlyBinder::bind_iter(implied_bounds)
749748}
750749
751750// Make sure when elaborating supertraits, probing for associated types, etc.,
......@@ -919,7 +918,7 @@ pub(super) fn type_param_predicates<'tcx>(
919918 let icx = ItemCtxt::new(tcx, parent);
920919 icx.probe_ty_param_bounds(DUMMY_SP, def_id, assoc_ident)
921920 } else {
922 ty::EarlyBinder::bind(&[] as &[_])
921 ty::EarlyBinder::bind_iter(&[] as &[_])
923922 };
924923 let mut extend = None;
925924
......@@ -967,7 +966,7 @@ pub(super) fn type_param_predicates<'tcx>(
967966 self_ty,
968967 );
969968
970 ty::EarlyBinder::bind(bounds)
969 ty::EarlyBinder::bind_iter(bounds)
971970}
972971
973972impl<'tcx> ItemCtxt<'tcx> {
compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs+4-4
......@@ -2574,10 +2574,10 @@ fn is_late_bound_map(
25742574 ty::Param(param_ty) => {
25752575 self.arg_is_constrained[param_ty.index as usize] = true;
25762576 }
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,
25812581 _ => (),
25822582 }
25832583 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<'_
3333 return map[&trait_item_def_id];
3434 }
3535 Err(_) => {
36 return ty::EarlyBinder::bind(Ty::new_error_with_message(
36 return ty::EarlyBinder::bind(
3737 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 );
4144 }
4245 }
4346 }
4447 // For an RPITIT in a trait, just return the corresponding opaque.
4548 Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
46 return ty::EarlyBinder::bind(Ty::new_opaque(
49 return ty::EarlyBinder::bind(
4750 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 );
5158 }
5259 None => {}
5360 }
......@@ -240,9 +247,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
240247 if let Err(e) = icx.check_tainted_by_errors()
241248 && !output.references_error()
242249 {
243 ty::EarlyBinder::bind(Ty::new_error(tcx, e))
250 ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, e))
244251 } else {
245 ty::EarlyBinder::bind(output)
252 ty::EarlyBinder::bind(tcx, output)
246253 }
247254}
248255
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(
4949 name: tcx.item_ident(parent_def_id.to_def_id()),
5050 what: "impl",
5151 });
52 EarlyBinder::bind(Ty::new_error(tcx, guar))
52 EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
5353 }
5454}
5555
......@@ -94,7 +94,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(
9494 name: tcx.item_ident(parent_def_id.to_def_id()),
9595 what: "crate",
9696 });
97 EarlyBinder::bind(Ty::new_error(tcx, guar))
97 EarlyBinder::bind(tcx, Ty::new_error(tcx, guar))
9898 }
9999}
100100
......@@ -247,14 +247,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
247247 let guar = tcx
248248 .dcx()
249249 .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));
251251 }
252252
253253 match opaque_types_from {
254254 DefiningScopeKind::HirTypeck => {
255255 let tables = tcx.typeck(owner_def_id);
256256 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))
258258 } else if let Some(hidden_ty) = tables.hidden_types.get(&def_id) {
259259 hidden_ty.ty
260260 } else {
......@@ -265,7 +265,7 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
265265 // so we can just make the hidden type be `!`.
266266 // For backwards compatibility reasons, we fall back to
267267 // `()` until we the diverging default is changed.
268 EarlyBinder::bind(tcx.types.unit)
268 EarlyBinder::bind(tcx, tcx.types.unit)
269269 }
270270 }
271271 DefiningScopeKind::MirBorrowck => match tcx.mir_borrowck(owner_def_id) {
......@@ -275,14 +275,14 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(
275275 } else {
276276 let hir_ty = tcx.type_of_opaque_hir_typeck(def_id);
277277 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))
279279 } else {
280280 assert!(!tcx.next_trait_solver_globally());
281281 hir_ty
282282 }
283283 }
284284 }
285 Err(guar) => EarlyBinder::bind(Ty::new_error(tcx, guar)),
285 Err(guar) => EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)),
286286 },
287287 }
288288}
compiler/rustc_hir_analysis/src/constrained_generic_params.rs+8-5
......@@ -63,14 +63,17 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
6363 fn visit_ty(&mut self, t: Ty<'tcx>) {
6464 match *t.kind() {
6565 // 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 => {
7073 return;
7174 }
7275 // 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 { .. }, .. })
7477 if !self.include_nonconstraining =>
7578 {
7679 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>(
436436
437437 let new_pred = pred.0.fold_with(&mut self.folder);
438438 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(),
440442 pred.1,
441443 ));
442444 }
......@@ -539,7 +541,7 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>(
539541
540542 let (parent_args, child_args) = tcx.delegation_user_specified_args(def_id);
541543 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));
543545
544546 let sig = caller_sig.instantiate(tcx, args.as_slice()).skip_binder();
545547 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> + '_ {
589589 .map_bound(|projection_term| projection_term.expect_ty());
590590 // Calling `skip_binder` is okay, because `lower_bounds` expects the `param_ty`
591591 // 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());
593594 self.lower_bounds(
594595 param_ty,
595596 hir_bounds,
......@@ -679,7 +680,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
679680 ty::Binder::bind_with_vars(trait_ref, tcx.late_bound_vars(item_segment.hir_id));
680681
681682 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),
683684 Err(guar) => Ty::new_error(tcx, guar),
684685 }
685686 }
......@@ -727,7 +728,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
727728 }
728729
729730 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),
731732 Err(guar) => Ty::new_error(tcx, guar),
732733 }
733734 }
......@@ -791,7 +792,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
791792 // Next, we need to check that the return-type notation is being used on
792793 // an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait).
793794 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()
795796 && let ty::AliasTy { kind: ty::Projection { def_id: projection_def_id }, .. } = alias_ty
796797 && tcx.is_impl_trait_in_trait(projection_def_id)
797798 {
......@@ -810,7 +811,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
810811 // `rustc_middle::ty::predicate::Clause::instantiate_supertrait`
811812 // and it's no coincidence why.
812813 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())
814815 }
815816}
816817
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+23-12
......@@ -1216,7 +1216,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12161216 // feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
12171217 // then actually instantiate the where bounds of.
12181218 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)
12201220 } else {
12211221 tcx.at(span).type_of(def_id).instantiate(tcx, args).skip_norm_wip()
12221222 }
......@@ -1361,7 +1361,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13611361 ty::AliasTyKind::Inherent { def_id } => def_id,
13621362 kind => bug!("expected projection or inherent alias, got {kind:?}"),
13631363 };
1364 let ty = alias_ty.to_ty(tcx);
1364 let ty = alias_ty.to_ty(tcx, ty::IsRigid::No);
13651365 let ty = self.check_param_uses_if_mcg(ty, span, false);
13661366 Ok((ty, tcx.def_kind(def_id), def_id))
13671367 }
......@@ -1400,7 +1400,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14001400 if let Some(def_id) = alias_ct.kind.opt_def_id() {
14011401 self.require_type_const_attribute(def_id, span)?;
14021402 }
1403 let ct = Const::new_unevaluated(tcx, alias_ct);
1403 let ct = Const::new_unevaluated(tcx, ty::IsRigid::No, alias_ct);
14041404 let ct = self.check_param_uses_if_mcg(ct, span, false);
14051405 Ok(ct)
14061406 }
......@@ -1837,7 +1837,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18371837 ty::AssocTag::Type,
18381838 ) {
18391839 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)
18411841 }
18421842 Err(guar) => Ty::new_error(self.tcx(), guar),
18431843 }
......@@ -1868,7 +1868,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
18681868 ty::UnevaluatedConstKind::new_from_def_id(tcx, item_def_id),
18691869 item_args,
18701870 );
1871 Ok(Const::new_unevaluated(tcx, uv))
1871 Ok(Const::new_unevaluated(tcx, ty::IsRigid::No, uv))
18721872 }
18731873
18741874 /// Lower a [resolved][hir::QPath::Resolved] (type-level) associated item path.
......@@ -2122,7 +2122,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21222122 GenericsArgsErrExtend::OpaqueTy,
21232123 );
21242124 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)
21262126 }
21272127 Res::Def(
21282128 DefKind::Enum
......@@ -2321,7 +2321,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23212321 const_arg.span,
23222322 "anonymous constants with lifetimes in their type are not yet supported",
23232323 );
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 );
23252328 return ty::Const::new_error(tcx, e);
23262329 }
23272330 // We must error if the instantiated type has any inference variables as we will
......@@ -2332,7 +2335,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23322335 const_arg.span,
23332336 "anonymous constants with inferred types are not yet supported",
23342337 );
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 );
23362342 return ty::Const::new_error(tcx, e);
23372343 }
23382344 // We error when the type contains unsubstituted generics since we do not currently
......@@ -2342,11 +2348,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23422348 const_arg.span,
23432349 "anonymous constants referencing generics are not yet supported",
23442350 );
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 );
23462355 return ty::Const::new_error(tcx, e);
23472356 }
23482357
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));
23502359 }
23512360
23522361 let hir_id = const_arg.hir_id;
......@@ -2763,6 +2772,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
27632772 let args = self.lower_generic_args_of_path_segment(span, did, segment);
27642773 ty::Const::new_unevaluated(
27652774 tcx,
2775 ty::IsRigid::No,
27662776 ty::UnevaluatedConst::new(
27672777 tcx,
27682778 ty::UnevaluatedConstKind::new_from_def_id(tcx, did),
......@@ -2920,6 +2930,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
29202930 Some(v) => v,
29212931 None => ty::Const::new_unevaluated(
29222932 tcx,
2933 ty::IsRigid::No,
29232934 ty::UnevaluatedConst::new(
29242935 tcx,
29252936 ty::UnevaluatedConstKind::Anon { def_id: anon.def_id.to_def_id() },
......@@ -3543,9 +3554,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
35433554 debug!(?args);
35443555
35453556 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)
35473558 } else {
3548 Ty::new_opaque(tcx, def_id, args)
3559 Ty::new_opaque(tcx, ty::IsRigid::No, def_id, args)
35493560 }
35503561 }
35513562
compiler/rustc_hir_analysis/src/outlives/explicit.rs+1-1
......@@ -59,7 +59,7 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
5959 }
6060 }
6161
62 ty::EarlyBinder::bind(required_predicates)
62 ty::EarlyBinder::bind_iter(required_predicates)
6363 })
6464 }
6565}
compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs+7-5
......@@ -81,8 +81,10 @@ pub(super) fn infer_predicates(
8181 .map_or(0, |p| p.as_ref().skip_binder().len());
8282 if item_required_predicates.len() > item_predicates_len {
8383 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 );
8688 }
8789 }
8890
......@@ -154,7 +156,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
154156 );
155157 }
156158
157 ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
159 ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
158160 // This corresponds to a type like `Type<'a, T>`.
159161 // We check inferred and explicit predicates.
160162 debug!("Free");
......@@ -204,7 +206,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
204206 }
205207 }
206208
207 ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => {
209 ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, args, .. }) => {
208210 // This corresponds to a type like `<() as Trait<'a, T>>::Type`.
209211 // We only use the explicit predicates of the trait but
210212 // not the ones of the associated type itself.
......@@ -220,7 +222,7 @@ fn insert_required_predicates_to_be_wf<'tcx>(
220222 }
221223
222224 // 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 { .. }, .. }) => {}
224226
225227 _ => {}
226228 }
compiler/rustc_hir_analysis/src/outlives/utils.rs+1-1
......@@ -102,7 +102,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
102102 //
103103 // Here we want to add an explicit `where <T as Iterator>::Item: 'a`
104104 // 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);
106106 required_predicates
107107 .entry(ty::OutlivesPredicate(ty.into(), outlived_region))
108108 .or_insert(span);
compiler/rustc_hir_analysis/src/variance/constraints.rs+10-7
......@@ -260,15 +260,18 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
260260 self.add_constraints_from_args(current, def.did(), args, variance);
261261 }
262262
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 ) => {
268271 self.add_constraints_from_invariant_args(current, args, variance);
269272 }
270273
271 ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => {
274 ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
272275 let ty = self.tcx().expand_free_alias_tys(ty);
273276 self.add_constraints_from_ty(current, ty, variance);
274277 }
......@@ -405,7 +408,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
405408 debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance);
406409
407410 match &c.kind() {
408 ty::ConstKind::Unevaluated(uv) => {
411 ty::ConstKind::Unevaluated(_, uv) => {
409412 self.add_constraints_from_invariant_args(current, uv.args, variance);
410413 }
411414 _ => {}
compiler/rustc_hir_analysis/src/variance/mod.rs+1-1
......@@ -139,7 +139,7 @@ fn variance_of_opaque(
139139 #[instrument(level = "trace", skip(self), ret)]
140140 fn visit_ty(&mut self, t: Ty<'tcx>) {
141141 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, .. }) => {
143143 self.visit_opaque(*def_id, args);
144144 }
145145 _ => t.super_visit_with(self),
compiler/rustc_hir_typeck/src/_match.rs+2-2
......@@ -245,7 +245,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
245245 self.may_coerce(arm_ty, ret_ty)
246246 && prior_arm.is_none_or(|(_, ty, _)| self.may_coerce(ty, ret_ty))
247247 // 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 { .. }, .. }))
249249 }
250250 _ => false,
251251 };
......@@ -532,7 +532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
532532 let expected_ty = expectation.to_option(self)?;
533533 let (def_id, args) = match *expected_ty.kind() {
534534 // 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, .. }) => {
536536 (def_id.as_local()?, args)
537537 }
538538 // 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> {
123123 // Pointers to foreign types are thin, despite being unsized
124124 ty::Foreign(..) => Some(PointerKind::Thin),
125125 // We should really try to normalize here.
126 ty::Alias(pi) => Some(PointerKind::OfAlias(pi)),
126 ty::Alias(_, pi) => Some(PointerKind::OfAlias(pi)),
127127 ty::Param(p) => Some(PointerKind::OfParam(p)),
128128 // Insufficient type information.
129129 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> {
294294 closure_kind: hir::ClosureKind,
295295 ) -> (Option<ExpectedSig<'tcx>>, Option<ty::ClosureKind>) {
296296 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
298298 .deduce_closure_signature_from_predicates(
299299 expected_ty,
300300 closure_kind,
......@@ -990,14 +990,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
990990 get_future_output(obligation.predicate, obligation.cause.span)
991991 })?
992992 }
993 ty::Alias(ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
993 ty::Alias(_, ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
994994 return Some(Ty::new_error_with_message(
995995 self.tcx,
996996 closure_span,
997997 "this projection should have been projected to an opaque type",
998998 ));
999999 }
1000 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
1000 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => self
10011001 .tcx
10021002 .explicit_item_self_bounds(def_id)
10031003 .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> {
29762976 err.span_label(ident.span, "unknown field");
29772977 self.point_at_param_definition(&mut err, param_ty);
29782978 }
2979 ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
2979 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
29802980 self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs());
29812981 }
29822982 _ => {
......@@ -3578,6 +3578,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
35783578 self.param_env,
35793579 Unnormalized::new(Ty::new_projection_from_args(
35803580 self.tcx,
3581 ty::IsRigid::No,
35813582 index_trait_output_def_id,
35823583 impl_trait_ref.args,
35833584 )),
compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs+4-3
......@@ -1178,9 +1178,10 @@ fn find_param_in_ty<'tcx>(
11781178 return true;
11791179 }
11801180 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()
11841185 {
11851186 // This logic may seem a bit strange, but typically when
11861187 // 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> {
161161 ty::ConstKind::Param(_)
162162 | ty::ConstKind::Expr(_)
163163 | ty::ConstKind::Placeholder(_)
164 | ty::ConstKind::Unevaluated(_) => enforce_copy_bound(element, element_ty),
164 | ty::ConstKind::Unevaluated(_, _) => enforce_copy_bound(element, element_ty),
165165
166166 ty::ConstKind::Bound(_, _) | ty::ConstKind::Infer(_) | ty::ConstKind::Error(_) => {
167167 unreachable!()
......@@ -1396,7 +1396,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13961396 }
13971397 }
13981398 }
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 }, .. })
14001400 | ty::Closure(new_def_id, _)
14011401 | ty::FnDef(new_def_id, _) => {
14021402 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> {
294294 // HACK(eddyb) should get the original `Span`.
295295 let span = tcx.def_span(def_id);
296296
297 ty::EarlyBinder::bind(tcx.arena.alloc_from_iter(
297 ty::EarlyBinder::bind_iter(tcx.arena.alloc_from_iter(
298298 self.param_env.caller_bounds().iter().filter_map(|predicate| {
299299 match predicate.kind().skip_binder() {
300300 ty::ClauseKind::Trait(data) if data.self_ty().is_param(index) => {
......@@ -399,10 +399,13 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
399399 match ty.kind() {
400400 ty::Adt(adt_def, _) => Some(*adt_def),
401401 // 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() => {
406409 self.normalize(span, Unnormalized::new_wip(ty)).ty_adt_def()
407410 }
408411 _ => None,
......@@ -416,11 +419,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
416419 // WF obligations that are registered elsewhere, but they have a
417420 // better cause code assigned to them in `add_required_obligations_for_hir`.
418421 // 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()
424426 {
425427 self.add_required_obligations_for_hir(span, *def_id, args, hir_id);
426428 }
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs+1-1
......@@ -294,7 +294,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294294 return false;
295295 };
296296
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]);
298298 let item_type =
299299 self.normalize(expr.span, rustc_middle::ty::Unnormalized::new_wip(item_type));
300300
compiler/rustc_hir_typeck/src/method/probe.rs+1-1
......@@ -2050,7 +2050,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
20502050 // HACK: opaque types will match anything for which their bounds hold.
20512051 // Thus we need to prevent them from trying to match the `&_` autoref
20522052 // 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 }, .. })
20542054 if !self.next_trait_solver()
20552055 && self.infcx.can_define_opaque_ty(def_id)
20562056 && !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> {
178178 }
179179 ty::Slice(..)
180180 | ty::Adt(..)
181 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
181 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
182182 for unsatisfied in unsatisfied_predicates.iter() {
183183 if is_iterator_predicate(unsatisfied.0) {
184184 return true;
......@@ -3759,10 +3759,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
37593759 | ty::Float(_)
37603760 | ty::Adt(_, _)
37613761 | 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 )
37663768 | ty::Param(_) => format!("{deref_ty}"),
37673769 // we need to test something like <&[_]>::len or <(&[u32])>::len
37683770 // and Vec::function();
compiler/rustc_hir_typeck/src/pat.rs+1
......@@ -2745,6 +2745,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27452745 // The expected type for the deref pat's inner pattern is `<expected as Deref>::Target`.
27462746 let target_ty = Ty::new_projection(
27472747 tcx,
2748 ty::IsRigid::No,
27482749 tcx.require_lang_item(hir::LangItem::DerefTarget, span),
27492750 [source_ty],
27502751 );
compiler/rustc_hir_typeck/src/writeback.rs+2-2
......@@ -567,7 +567,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
567567 for (opaque_type_key, hidden_type) in opaque_types {
568568 let hidden_type = self.resolve(hidden_type, &hidden_type.span);
569569 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, .. }) =
571571 hidden_type.ty.kind()
572572 && def_id == opaque_type_key.def_id.to_def_id()
573573 && args == opaque_type_key.args
......@@ -1055,7 +1055,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for HasRecursiveOpaque<'_, 'tcx> {
10551055 type Result = ControlFlow<()>;
10561056
10571057 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()
10591059 && let Some(def_id) = def_id.as_local()
10601060 {
10611061 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> {
519519 self.at(cause, param_env)
520520 .eq(
521521 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),
523523 b,
524524 )?
525525 .obligations,
compiler/rustc_infer/src/infer/mod.rs+16-5
......@@ -960,10 +960,20 @@ impl<'tcx> InferCtxt<'tcx> {
960960 ty::Region::new_var(self.tcx, region_var)
961961 }
962962
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(),
967977 }
968978 }
969979
......@@ -1252,10 +1262,11 @@ impl<'tcx> InferCtxt<'tcx> {
12521262 .unwrap_or(ct),
12531263 InferConst::Fresh(_) => ct,
12541264 },
1265
12551266 ty::ConstKind::Param(_)
12561267 | ty::ConstKind::Bound(_, _)
12571268 | ty::ConstKind::Placeholder(_)
1258 | ty::ConstKind::Unevaluated(_)
1269 | ty::ConstKind::Unevaluated(_, _)
12591270 | ty::ConstKind::Value(_)
12601271 | ty::ConstKind::Error(_)
12611272 | ty::ConstKind::Expr(_) => ct,
compiler/rustc_infer/src/infer/opaque_types/mod.rs+8-8
......@@ -45,7 +45,7 @@ impl<'tcx> InferCtxt<'tcx> {
4545 lt_op: |lt| lt,
4646 ct_op: |ct| ct,
4747 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 }, .. })
4949 if self.can_define_opaque_ty(def_id) && !ty.has_escaping_bound_vars() =>
5050 {
5151 let def_span = self.tcx.def_span(def_id);
......@@ -85,7 +85,7 @@ impl<'tcx> InferCtxt<'tcx> {
8585 ) -> Result<Vec<Goal<'tcx, ty::Predicate<'tcx>>>, TypeError<'tcx>> {
8686 debug_assert!(!self.next_trait_solver());
8787 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, .. })
8989 if def_id.is_local() =>
9090 {
9191 let def_id = def_id.expect_local();
......@@ -136,7 +136,7 @@ impl<'tcx> InferCtxt<'tcx> {
136136 return None;
137137 }
138138
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 }, .. }) =
140140 *b.kind()
141141 {
142142 // We could accept this, but there are various ways to handle this situation,
......@@ -324,6 +324,7 @@ impl<'tcx> InferCtxt<'tcx> {
324324 // FIXME(RPITIT): Don't replace RPITITs with inference vars.
325325 // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
326326 ty::Alias(
327 _,
327328 projection_ty @ ty::AliasTy { kind: ty::Projection { def_id }, .. },
328329 ) if !projection_ty.has_escaping_bound_vars()
329330 && !tcx.is_impl_trait_in_trait(def_id)
......@@ -342,11 +343,10 @@ impl<'tcx> InferCtxt<'tcx> {
342343 }
343344 // Replace all other mentions of the same opaque type with the hidden type,
344345 // 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,
350350 _ => ty,
351351 },
352352 lt_op: |lt| lt,
compiler/rustc_infer/src/infer/outlives/for_liveness.rs+6-2
......@@ -56,7 +56,7 @@ where
5656 // either `'static` or a unique outlives region, and if one is
5757 // found, we just need to prove that that region is still live.
5858 // 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, .. }) => {
6060 let tcx = self.tcx;
6161 let param_env = self.param_env;
6262 let def_id = match kind {
......@@ -82,7 +82,11 @@ where
8282 &outlives.map_bound(|ty::OutlivesPredicate(ty, bound)| {
8383 VerifyIfEq { ty, bound }
8484 }),
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),
8690 )
8791 }
8892 })
compiler/rustc_infer/src/infer/outlives/test_type_match.rs+12-1
......@@ -44,7 +44,13 @@ pub fn extract_verify_if_eq<'tcx>(
4444 assert!(!verify_if_eq_b.has_escaping_bound_vars());
4545 let mut m = MatchAgainstHigherRankedOutlives::new(tcx);
4646 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()?;
4854
4955 if let ty::RegionKind::ReBound(index_kind, br) = verify_if_eq.bound.kind() {
5056 assert!(matches!(index_kind, ty::BoundVarIndexKind::Bound(ty::INNERMOST)));
......@@ -80,6 +86,11 @@ pub(super) fn can_match_erased_ty<'tcx>(
8086 assert!(!outlives_predicate.has_escaping_bound_vars());
8187 let erased_outlives_predicate = tcx.erase_and_anonymize_regions(outlives_predicate);
8288 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();
8394 if outlives_ty == erased_ty {
8495 // pointless micro-optimization
8596 true
compiler/rustc_infer/src/infer/outlives/verify.rs+20-4
......@@ -96,7 +96,15 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
9696 &self,
9797 alias_ty: ty::AliasTy<'tcx>,
9898 ) -> 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 );
100108 self.declared_generic_bounds_from_env_for_erased_ty(erased_alias_ty)
101109 }
102110
......@@ -104,8 +112,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
104112 pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> {
105113 // Search the env for where clauses like `P: 'a`.
106114 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.
107116 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()
109118 && alias_ty_from_bound == alias_ty
110119 {
111120 // Micro-optimize if this is an exact match (this
......@@ -236,12 +245,19 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
236245 // And therefore we can safely use structural equality for alias types.
237246 (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {}
238247 (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 => {}
240250 _ => return None,
241251 }
242252
243253 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 );
245261 (erased_p_ty == erased_ty).then_some(ty::Binder::dummy(ty::OutlivesPredicate(p_ty, r)))
246262 }));
247263
compiler/rustc_infer/src/infer/region_constraints/mod.rs+5-1
......@@ -805,7 +805,11 @@ impl<'tcx> GenericKind<'tcx> {
805805 match *self {
806806 GenericKind::Param(ref p) => p.to_ty(tcx),
807807 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),
809813 }
810814 }
811815}
compiler/rustc_infer/src/infer/relate/generalize.rs+36-22
......@@ -433,13 +433,16 @@ impl<'tcx> Generalizer<'_, 'tcx> {
433433 }
434434 }
435435
436 /// We only handle potentially normalizable aliases via this method. For rigid alias,
437 /// we always generalize structurally.
438 ///
436439 /// An occurs check failure inside of an alias does not mean
437440 /// that the types definitely don't unify. We may be able
438441 /// to normalize the alias after all.
439442 ///
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
443446 /// bound variables.
444447 ///
445448 /// Correctly handling aliases with escaping bound variables is
......@@ -467,7 +470,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
467470
468471 let is_nested_alias = mem::replace(&mut self.in_alias, true);
469472 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)),
471474 Err(e) => {
472475 if is_nested_alias {
473476 return Err(e);
......@@ -636,7 +639,9 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
636639 }
637640 }
638641
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 {
640645 StructurallyRelateAliases::No => {
641646 self.generalize_alias_term(data.into()).map(|v| v.expect_type())
642647 }
......@@ -752,24 +757,33 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
752757 //
753758 // FIXME: replace the StructurallyRelateAliases::Yes branch with
754759 // `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 }
771785 }
772 },
786 }
773787 ty::ConstKind::Placeholder(placeholder) => {
774788 if self.for_universe.can_name(placeholder.universe) {
775789 Ok(c)
compiler/rustc_infer/src/infer/relate/lattice.rs+4-4
......@@ -161,12 +161,12 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for LatticeOp<'_, 'tcx> {
161161 }
162162
163163 (
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 }, .. }),
166166 ) if a_def_id == b_def_id => super_combine_tys(infcx, self, a, b),
167167
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 }, .. }))
170170 if def_id.is_local() && !infcx.next_trait_solver() =>
171171 {
172172 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;
22use rustc_middle::traits::solve::Goal;
33use rustc_middle::ty::relate::combine::{combine_ty_args, super_combine_consts, super_combine_tys};
44use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation, relate_args_invariantly};
5use rustc_middle::ty::{self, DelayedSet, Ty, TyCtxt, TyVar};
5use rustc_middle::ty::{self, DelayedSet, Ty, TyCtxt, TyVar, TypeVisitableExt};
66use rustc_span::Span;
77use tracing::{debug, instrument};
88
......@@ -118,6 +118,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> {
118118
119119 #[instrument(skip(self), level = "trace")]
120120 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
121125 if a == b {
122126 return Ok(a);
123127 }
......@@ -184,14 +188,14 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> {
184188 }
185189
186190 (
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 }, .. }),
189193 ) if a_def_id == b_def_id => {
190194 super_combine_tys(infcx, self, a, b)?;
191195 }
192196
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 }, .. }))
195199 if self.define_opaque_types == DefineOpaqueTypes::Yes && def_id.is_local() =>
196200 {
197201 self.register_goals(infcx.handle_opaque_type(
......@@ -261,6 +265,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for TypeRelating<'_, 'tcx> {
261265 a: ty::Const<'tcx>,
262266 b: ty::Const<'tcx>,
263267 ) -> 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
264272 super_combine_consts(self.infcx, self, a, b)
265273 }
266274
compiler/rustc_lint/src/context.rs+1-1
......@@ -831,7 +831,7 @@ impl<'tcx> LateContext<'tcx> {
831831 tcx.associated_items(trait_id)
832832 .find_by_ident_and_kind(tcx, Ident::with_dummy_span(name), ty::AssocTag::Type, trait_id)
833833 .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]);
835835 tcx.try_normalize_erasing_regions(self.typing_env(), Unnormalized::new_wip(proj))
836836 .ok()
837837 })
compiler/rustc_lint/src/foreign_modules.rs+6-6
......@@ -355,16 +355,16 @@ fn structurally_same_type_impl<'tcx>(
355355 | (ty::Coroutine(..), ty::Coroutine(..))
356356 | (ty::CoroutineWitness(..), ty::CoroutineWitness(..))
357357 | (
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 { .. }, .. }),
360360 )
361361 | (
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 { .. }, .. }),
364364 )
365365 | (
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 { .. }, .. }),
368368 ) => false,
369369
370370 // 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> {
115115 }
116116
117117 ty::Adt(_, _)
118 | ty::Alias(_)
118 | ty::Alias(_, _)
119119 | ty::Array(_, _)
120120 | ty::Bound(_, _)
121121 | ty::Closure(_, _)
compiler/rustc_lint/src/impl_trait_overcaptures.rs+2-2
......@@ -243,12 +243,12 @@ where
243243 return;
244244 }
245245
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()
247247 && self.tcx.is_impl_trait_in_trait(def_id)
248248 {
249249 // visit the opaque of the RPITIT
250250 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()
252252 && let Some(opaque_def_id) = def_id.as_local()
253253 // Don't recurse infinitely on an opaque
254254 && 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 {
103103 let Some(proj_term) = proj.term.as_type() else { return };
104104
105105 // 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 }, .. }) =
107107 *proj_term.kind()
108108 && cx.tcx.parent(opaque_def_id) == def_id
109109 && matches!(
......@@ -130,7 +130,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
130130 return;
131131 }
132132
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);
134134 // For every instance of the projection type in the bounds,
135135 // replace them with the term we're assigning to the associated
136136 // type in our opaque type.
......@@ -177,7 +177,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
177177 // then we can emit a suggestion to add the bound.
178178 let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) {
179179 (
180 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }),
180 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }),
181181 ty::ClauseKind::Trait(trait_pred),
182182 ) => Some(AddBound {
183183 suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(),
......@@ -192,6 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
192192 OpaqueHiddenInferredBoundLint {
193193 ty: Ty::new_opaque(
194194 cx.tcx,
195 ty::IsRigid::No,
195196 def_id,
196197 ty::GenericArgs::identity_for_item(cx.tcx, def_id),
197198 ),
compiler/rustc_lint/src/types/improper_ctypes.rs+14-9
......@@ -889,16 +889,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
889889
890890 // While opaque types are checked for earlier, if a projection in a struct field
891891 // 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 { .. }, .. }) => {
893893 FfiUnsafe { ty, reason: msg!("opaque types have no C equivalent"), help: None }
894894 }
895895
896896 // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe,
897897 // so they are currently ignored for the purposes of this lint.
898898 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 }
902904
903905 ty::UnsafeBinder(_) => FfiUnsafe {
904906 ty,
......@@ -920,10 +922,13 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
920922 },
921923
922924 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 )
927932 | ty::Infer(..)
928933 | ty::Bound(..)
929934 | ty::Error(_)
......@@ -942,7 +947,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
942947 return ControlFlow::Continue(());
943948 }
944949
945 if let ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() {
950 if let ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) = ty.kind() {
946951 ControlFlow::Break(ty)
947952 } else {
948953 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>(
176176 ty::Adt(def, _) => {
177177 is_def_must_use(cx, def.did(), expr.span).map_or(IsTyMustUse::No, IsTyMustUse::Yes)
178178 }
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 ) => {
183185 elaborate(
184186 cx.tcx,
185187 cx.tcx
......@@ -296,7 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
296298
297299 if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
298300 && 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()
300302 && cx.tcx.ty_is_opaque_future(ty)
301303 && let async_fn_def_id = cx.tcx.parent(*future_def_id)
302304 && 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;
1414use rustc_middle::queries::ExternProviders;
1515use rustc_middle::query::LocalCrate;
1616use rustc_middle::ty::fast_reject::SimplifiedType;
17use rustc_middle::ty::{self, TyCtxt};
17use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
1818use rustc_middle::util::Providers;
1919use rustc_serialize::Decoder;
2020use rustc_session::StableCrateId;
......@@ -39,10 +39,11 @@ impl<T> ProcessQueryValue<'_, T> for T {
3939 }
4040}
4141
42impl<'tcx, T> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T {
42// The `TypeVisitable` bound here is merely for `EarlyBinder`'s rigidness check.
43impl<'tcx, T: TypeVisitable<TyCtxt<'tcx>>> ProcessQueryValue<'tcx, ty::EarlyBinder<'tcx, T>> for T {
4344 #[inline(always)]
4445 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)
4647 }
4748}
4849
compiler/rustc_middle/src/mir/consts.rs+14-9
......@@ -239,14 +239,17 @@ impl<'tcx> Const<'tcx> {
239239 tcx: TyCtxt<'tcx>,
240240 def_id: DefId,
241241 ) -> 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 )
250253 }
251254
252255 #[inline(always)]
......@@ -317,7 +320,9 @@ impl<'tcx> Const<'tcx> {
317320 ) -> Result<ConstValue, ErrorHandled> {
318321 match self {
319322 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() {
321326 return Err(ErrorHandled::TooGeneric(span));
322327 }
323328
compiler/rustc_middle/src/mir/mod.rs+3-3
......@@ -530,8 +530,8 @@ impl<'tcx> Body<'tcx> {
530530
531531 /// Returns the return type; it always return first element from `local_decls` array.
532532 #[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)
535535 }
536536
537537 /// Gets the location of the terminator for the given block.
......@@ -624,7 +624,7 @@ impl<'tcx> Body<'tcx> {
624624 let mono_literal = instance.instantiate_mir_and_normalize_erasing_regions(
625625 tcx,
626626 typing_env,
627 crate::ty::EarlyBinder::bind(constant.const_),
627 crate::ty::EarlyBinder::bind(tcx, constant.const_),
628628 );
629629 mono_literal.try_eval_bits(tcx, typing_env)
630630 };
compiler/rustc_middle/src/mir/pretty.rs+1-1
......@@ -1491,7 +1491,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
14911491 let val = match const_ {
14921492 Const::Ty(_, ct) => match ct.kind() {
14931493 ty::ConstKind::Param(p) => format!("ty::Param({p})"),
1494 ty::ConstKind::Unevaluated(uv) => {
1494 ty::ConstKind::Unevaluated(_, uv) => {
14951495 let kind = match uv.kind {
14961496 ty::UnevaluatedConstKind::Projection { def_id }
14971497 | 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
391391 | ty::CoroutineWitness(def_id, _)
392392 | ty::Foreign(def_id) => Some(def_id),
393393
394 ty::Alias(alias) => match alias.kind {
394 ty::Alias(_, alias) => match alias.kind {
395395 ty::AliasTyKind::Projection { def_id }
396396 | ty::AliasTyKind::Inherent { def_id }
397397 | ty::AliasTyKind::Opaque { def_id }
compiler/rustc_middle/src/ty/abstract_const.rs+3-1
......@@ -52,7 +52,9 @@ impl<'tcx> TyCtxt<'tcx> {
5252 }
5353 fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
5454 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 {
5658 match self.tcx.thir_abstract_const(def_id) {
5759 Err(e) => ty::Const::new_error(self.tcx, e),
5860 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> {
292292 self,
293293 tcx: TyCtxt<'tcx>,
294294 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = Ty<'tcx>>> {
295 ty::EarlyBinder::bind(
295 ty::EarlyBinder::bind_iter(
296296 self.all_fields().map(move |field| tcx.type_of(field.did).skip_binder()),
297297 )
298298 }
compiler/rustc_middle/src/ty/consts.rs+12-4
......@@ -107,8 +107,12 @@ impl<'tcx> Const<'tcx> {
107107 }
108108
109109 #[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))
112116 }
113117
114118 #[inline]
......@@ -190,8 +194,12 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
190194 Const::new_placeholder(tcx, placeholder)
191195 }
192196
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)
195203 }
196204
197205 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> {
20582058
20592059 /// Given a `ty`, return whether it's an `impl Future<...>`.
20602060 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 {
20622062 return false;
20632063 };
20642064 let future_trait = self.require_lang_item(LangItem::Future, DUMMY_SP);
......@@ -2690,6 +2690,10 @@ impl<'tcx> TyCtxt<'tcx> {
26902690 self.sess.opts.unstable_opts.disable_fast_paths
26912691 }
26922692
2693 pub fn renormalize_rigid_aliases(self) -> bool {
2694 self.sess.opts.unstable_opts.renormalize_rigid_aliases
2695 }
2696
26932697 #[allow(rustc::bad_opt_access)]
26942698 pub fn use_typing_mode_post_typeck_until_borrowck(self) -> bool {
26952699 self.next_trait_solver_globally()
......@@ -2706,8 +2710,8 @@ impl<'tcx> TyCtxt<'tcx> {
27062710
27072711 pub fn get_impl_future_output_ty(self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
27082712 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, .. })
27112715 if self.is_impl_trait_in_trait(def_id) =>
27122716 {
27132717 (def_id, args)
compiler/rustc_middle/src/ty/context/impl_interner.rs+12-5
......@@ -340,6 +340,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
340340 self.assumptions_on_binders()
341341 }
342342
343 fn renormalize_rigid_aliases(self) -> bool {
344 self.renormalize_rigid_aliases()
345 }
346
343347 fn coroutine_hidden_types(
344348 self,
345349 def_id: DefId,
......@@ -388,7 +392,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
388392 self,
389393 def_id: DefId,
390394 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
391 ty::EarlyBinder::bind(
395 ty::EarlyBinder::bind_iter(
392396 self.predicates_of(def_id)
393397 .instantiate_identity(self)
394398 .predicates
......@@ -401,7 +405,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
401405 self,
402406 def_id: DefId,
403407 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
404 ty::EarlyBinder::bind(
408 ty::EarlyBinder::bind_iter(
405409 self.predicates_of(def_id)
406410 .instantiate_own_identity()
407411 .map(|(clause, _)| clause.skip_normalization()),
......@@ -456,7 +460,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
456460 self,
457461 def_id: DefId,
458462 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
459 ty::EarlyBinder::bind(
463 ty::EarlyBinder::bind_iter(
460464 self.const_conditions(def_id)
461465 .instantiate_identity(self)
462466 .into_iter()
......@@ -468,7 +472,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
468472 self,
469473 def_id: DefId,
470474 ) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Binder<'tcx, ty::TraitRef<'tcx>>>> {
471 ty::EarlyBinder::bind(
475 ty::EarlyBinder::bind_iter(
472476 self.explicit_implied_const_bounds(def_id)
473477 .iter_identity_copied()
474478 .map(Unnormalized::skip_normalization)
......@@ -645,7 +649,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
645649 //
646650 // Impls which apply to an alias after normalization are handled by
647651 // `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, _) => (),
649656
650657 // FIXME: These should ideally not exist as a self type. It would be nice for
651658 // 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> {
627627 return ControlFlow::Break(());
628628 }
629629
630 Alias(AliasTy { kind: Opaque { def_id }, .. }) => {
630 Alias(_, AliasTy { kind: Opaque { def_id }, .. }) => {
631631 let parent = self.tcx.parent(def_id);
632632 let parent_ty = self.tcx.type_of(parent).instantiate_identity().skip_norm_wip();
633633 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 }, .. }) =
635635 *parent_ty.kind()
636636 && parent_opaque_def_id == def_id
637637 {
......@@ -641,7 +641,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
641641 }
642642 }
643643
644 Alias(AliasTy { kind: Projection { def_id }, .. })
644 Alias(_, AliasTy { kind: Projection { def_id }, .. })
645645 if self.tcx.def_kind(def_id) != DefKind::AssocTy =>
646646 {
647647 return ControlFlow::Break(());
......@@ -715,12 +715,12 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for MakeSuggestableFolder<'tcx> {
715715 placeholder
716716 }
717717
718 Alias(AliasTy { kind: Opaque { def_id }, .. }) => {
718 Alias(_, AliasTy { kind: Opaque { def_id }, .. }) => {
719719 let parent = self.tcx.parent(def_id);
720720 let parent_ty = self.tcx.type_of(parent).instantiate_identity().skip_norm_wip();
721721 if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy =
722722 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 }, .. }) =
724724 *parent_ty.kind()
725725 && parent_opaque_def_id == def_id
726726 {
compiler/rustc_middle/src/ty/error.rs+9-9
......@@ -148,11 +148,11 @@ impl<'tcx> Ty<'tcx> {
148148 ty::Infer(ty::FreshTy(_)) => "fresh type".into(),
149149 ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
150150 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 }
154154 ty::Param(p) => format!("type parameter `{p}`").into(),
155 ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
155 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => {
156156 if tcx.ty_is_opaque_future(self) { "future".into() } else { "opaque type".into() }
157157 }
158158 ty::Error(_) => "type error".into(),
......@@ -207,12 +207,12 @@ impl<'tcx> Ty<'tcx> {
207207 ty::Tuple(..) => "tuple".into(),
208208 ty::Placeholder(..) => "higher-ranked type".into(),
209209 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(),
214214 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(),
216216 }
217217 }
218218}
compiler/rustc_middle/src/ty/generics.rs+16-10
......@@ -402,8 +402,9 @@ impl<'tcx> GenericPredicates<'tcx> {
402402 args: GenericArgsRef<'tcx>,
403403 ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
404404 + 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| {
407408 let (clause, span) = u.unzip();
408409 (clause, span.skip_normalization())
409410 })
......@@ -413,8 +414,9 @@ impl<'tcx> GenericPredicates<'tcx> {
413414 self,
414415 ) -> impl Iterator<Item = (Unnormalized<'tcx, Clause<'tcx>>, Span)>
415416 + 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| {
418420 let (clause, span) = u.unzip();
419421 (clause, span.skip_normalization())
420422 })
......@@ -431,7 +433,7 @@ impl<'tcx> GenericPredicates<'tcx> {
431433 tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, args);
432434 }
433435 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)),
435437 );
436438 instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp));
437439 }
......@@ -482,8 +484,9 @@ impl<'tcx> ConstConditions<'tcx> {
482484 args: GenericArgsRef<'tcx>,
483485 ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
484486 + 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| {
487490 let (trait_ref, span) = u.unzip();
488491 (trait_ref, span.skip_normalization())
489492 })
......@@ -493,8 +496,9 @@ impl<'tcx> ConstConditions<'tcx> {
493496 self,
494497 ) -> impl Iterator<Item = (Unnormalized<'tcx, ty::PolyTraitRef<'tcx>>, Span)>
495498 + 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| {
498502 let (trait_ref, span) = u.unzip();
499503 (trait_ref, span.skip_normalization())
500504 })
......@@ -511,7 +515,9 @@ impl<'tcx> ConstConditions<'tcx> {
511515 tcx.const_conditions(def_id).instantiate_into(tcx, instantiated, args);
512516 }
513517 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)),
515521 );
516522 }
517523
compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs+2-2
......@@ -243,7 +243,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
243243 fn instantiate_opt(self, tcx: TyCtxt<'tcx>, args: ty::GenericArgsRef<'tcx>) -> Option<Self> {
244244 match self {
245245 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();
247247 let pred = match c.try_to_target_usize(tcx) {
248248 Some(0) => Self::True,
249249 Some(1..) => Self::False,
......@@ -252,7 +252,7 @@ impl<'tcx> InhabitedPredicate<'tcx> {
252252 Some(pred)
253253 }
254254 Self::GenericType(t) => Some(
255 ty::EarlyBinder::bind(t)
255 ty::EarlyBinder::bind(tcx, t)
256256 .instantiate(tcx, args)
257257 .skip_norm_wip()
258258 .inhabited_predicate(tcx),
compiler/rustc_middle/src/ty/inhabitedness/mod.rs+9-5
......@@ -113,12 +113,16 @@ impl<'tcx> Ty<'tcx> {
113113 InhabitedPredicate::True
114114 }
115115 Never => InhabitedPredicate::False,
116 // FIXME(#155345): This should only encounter rigid aliases with the new solver.
116117 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, .. }) => {
122126 match def_id.as_local() {
123127 // Foreign opaque is considered inhabited.
124128 None => InhabitedPredicate::True,
compiler/rustc_middle/src/ty/instance.rs+1-2
......@@ -916,11 +916,10 @@ impl<'tcx> Instance<'tcx> {
916916 self.def.has_polymorphic_mir_body().then_some(self.args)
917917 }
918918
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
920920 where
921921 T: TypeFoldable<TyCtxt<'tcx>> + Copy,
922922 {
923 let v = v.map_bound(|v| *v);
924923 if let Some(args) = self.args_for_mir_body() {
925924 v.instantiate(tcx, args).skip_norm_wip()
926925 } else {
compiler/rustc_middle/src/ty/layout.rs+12-5
......@@ -408,11 +408,13 @@ impl<'tcx> SizeSkeleton<'tcx> {
408408 );
409409
410410 match tail.kind() {
411 // FIXME(#155345): This should only handle rigid aliases if we're using
412 // the new solver.
411413 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 ) => {
416418 debug_assert!(tail.has_non_region_param());
417419 Ok(SizeSkeleton::Pointer {
418420 non_zero,
......@@ -915,7 +917,12 @@ where
915917 {
916918 let metadata = tcx.normalize_erasing_regions(
917919 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 )),
919926 );
920927
921928 // 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> {
688688 pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
689689 match self.kind() {
690690 TermKind::Ty(ty) => match *ty.kind() {
691 ty::Alias(alias_ty) => Some(alias_ty.into()),
691 ty::Alias(_, alias_ty) => Some(alias_ty.into()),
692692 _ => None,
693693 },
694694 TermKind::Const(ct) => match ct.kind() {
695 ConstKind::Unevaluated(uv) => Some(uv.into()),
695 ConstKind::Unevaluated(_, uv) => Some(uv.into()),
696696 _ => None,
697697 },
698698 }
699699 }
700700
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
701714 pub fn is_infer(&self) -> bool {
702715 match self.kind() {
703716 TermKind::Ty(ty) => ty.is_ty_var(),
......@@ -926,7 +939,7 @@ impl<'tcx> ProvisionalHiddenType<'tcx> {
926939 if cfg!(debug_assertions) && matches!(defining_scope_kind, DefiningScopeKind::HirTypeck) {
927940 assert_eq!(result_ty, fold_regions(tcx, result_ty, |_, _| tcx.lifetimes.re_erased));
928941 }
929 DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(result_ty) }
942 DefinitionSiteHiddenType { span: self.span, ty: ty::EarlyBinder::bind(tcx, result_ty) }
930943 }
931944}
932945
......@@ -954,7 +967,7 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> {
954967 pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> DefinitionSiteHiddenType<'tcx> {
955968 DefinitionSiteHiddenType {
956969 span: DUMMY_SP,
957 ty: ty::EarlyBinder::bind(Ty::new_error(tcx, guar)),
970 ty: ty::EarlyBinder::bind(tcx, Ty::new_error(tcx, guar)),
958971 }
959972 }
960973
compiler/rustc_middle/src/ty/offload_meta.rs+2-1
......@@ -119,7 +119,8 @@ impl MappingFlags {
119119 MappingFlags::LITERAL | MappingFlags::IMPLICIT
120120 }
121121
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(_) => {
123124 MappingFlags::TO
124125 }
125126
compiler/rustc_middle/src/ty/predicate.rs+1-1
......@@ -419,7 +419,7 @@ impl<'tcx> Clause<'tcx> {
419419 let shifted_pred =
420420 tcx.shift_bound_var_indices(trait_bound_vars.len(), bound_pred.skip_binder());
421421 // 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)
423423 .instantiate(tcx, trait_ref.skip_binder().args)
424424 .skip_norm_wip();
425425 // 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 {
820820 }
821821 ty::Foreign(def_id) => self.print_def_path(def_id, &[])?,
822822 ty::Alias(
823 _,
823824 ref data @ ty::AliasTy {
824825 kind: ty::Projection { .. } | ty::Inherent { .. } | ty::Free { .. },
825826 ..
826827 },
827828 ) => data.print(self)?,
828829 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, .. }) => {
830831 // We use verbose printing in 'NO_QUERIES' mode, to
831832 // avoid needing to call `predicates_of`. This should
832833 // only affect certain debug messages (e.g. messages printed
......@@ -846,12 +847,13 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
846847 DefKind::TyAlias | DefKind::AssocTy => {
847848 // NOTE: I know we should check for NO_QUERIES here, but it's alright.
848849 // `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()
855857 {
856858 if d == def_id {
857859 // If the type alias directly starts with the `impl` of the
......@@ -1367,7 +1369,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
13671369 let fn_args = if self.tcx().features().return_type_notation()
13681370 && let Some(ty::ImplTraitInTraitData::Trait { fn_def_id, .. }) =
13691371 self.tcx().opt_rpitit_info(def_id)
1370 && let ty::Alias(alias_ty) =
1372 && let ty::Alias(_, alias_ty) =
13711373 self.tcx().fn_sig(fn_def_id).skip_binder().output().skip_binder().kind()
13721374 && let Some(projection_ty) = alias_ty.try_to_projection()
13731375 && projection_ty.kind == def_id
......@@ -1566,7 +1568,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15661568 }
15671569
15681570 match ct.kind() {
1569 ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, args, .. }) => {
1571 ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, args, .. }) => {
15701572 match kind {
15711573 ty::UnevaluatedConstKind::Projection { def_id }
15721574 | 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> {
133133 | ty::FnPtr(_, _)
134134 | ty::Tuple(_)
135135 | ty::Dynamic(_, _)
136 | ty::Alias(_)
136 | ty::Alias(_, _)
137137 | ty::Bound(_, _)
138138 | ty::Pat(_, _)
139139 | ty::Placeholder(_)
compiler/rustc_middle/src/ty/structural_impls.rs+10-6
......@@ -372,7 +372,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
372372 ty::CoroutineClosure(did, args) => {
373373 ty::CoroutineClosure(did, args.try_fold_with(folder)?)
374374 }
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)?),
376376 ty::Pat(ty, pat) => ty::Pat(ty.try_fold_with(folder)?, pat.try_fold_with(folder)?),
377377
378378 ty::Bool
......@@ -411,7 +411,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for Ty<'tcx> {
411411 ty::CoroutineWitness(did, args) => ty::CoroutineWitness(did, args.fold_with(folder)),
412412 ty::Closure(did, args) => ty::Closure(did, args.fold_with(folder)),
413413 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)),
415415 ty::Pat(ty, pat) => ty::Pat(ty.fold_with(folder), pat.fold_with(folder)),
416416
417417 ty::Bool
......@@ -459,7 +459,7 @@ impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for Ty<'tcx> {
459459 ty::CoroutineWitness(_did, args) => args.visit_with(visitor),
460460 ty::Closure(_did, args) => args.visit_with(visitor),
461461 ty::CoroutineClosure(_did, args) => args.visit_with(visitor),
462 ty::Alias(data) => data.visit_with(visitor),
462 ty::Alias(_, data) => data.visit_with(visitor),
463463
464464 ty::Pat(ty, pat) => {
465465 try_visit!(ty.visit_with(visitor));
......@@ -634,7 +634,9 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
634634 folder: &mut F,
635635 ) -> Result<Self, F::Error> {
636636 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 }
638640 ConstKind::Value(v) => ConstKind::Value(v.try_fold_with(folder)?),
639641 ConstKind::Expr(e) => ConstKind::Expr(e.try_fold_with(folder)?),
640642
......@@ -649,7 +651,9 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
649651
650652 fn super_fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
651653 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 }
653657 ConstKind::Value(v) => ConstKind::Value(v.fold_with(folder)),
654658 ConstKind::Expr(e) => ConstKind::Expr(e.fold_with(folder)),
655659
......@@ -666,7 +670,7 @@ impl<'tcx> TypeSuperFoldable<TyCtxt<'tcx>> for ty::Const<'tcx> {
666670impl<'tcx> TypeSuperVisitable<TyCtxt<'tcx>> for ty::Const<'tcx> {
667671 fn super_visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
668672 match self.kind() {
669 ConstKind::Unevaluated(uv) => uv.visit_with(visitor),
673 ConstKind::Unevaluated(_, uv) => uv.visit_with(visitor),
670674 ConstKind::Value(v) => v.visit_with(visitor),
671675 ConstKind::Expr(e) => e.visit_with(visitor),
672676 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>> {
166166 if tcx.is_async_drop_in_place_coroutine(def_id) {
167167 layout.field_tys[*field].ty
168168 } else {
169 ty::EarlyBinder::bind(layout.field_tys[*field].ty)
169 ty::EarlyBinder::bind(tcx, layout.field_tys[*field].ty)
170170 .instantiate(tcx, self.args)
171171 .skip_norm_wip()
172172 }
......@@ -481,7 +481,11 @@ impl<'tcx> Ty<'tcx> {
481481 }
482482
483483 #[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> {
485489 if cfg!(debug_assertions) {
486490 match alias_ty.kind {
487491 ty::AliasTyKind::Projection { def_id } => {
......@@ -498,7 +502,7 @@ impl<'tcx> Ty<'tcx> {
498502 }
499503 }
500504 }
501 Ty::new(tcx, Alias(alias_ty))
505 Ty::new(tcx, Alias(is_rigid, alias_ty))
502506 }
503507
504508 #[inline]
......@@ -537,8 +541,13 @@ impl<'tcx> Ty<'tcx> {
537541
538542 #[inline]
539543 #[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))
542551 }
543552
544553 /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
......@@ -791,11 +800,13 @@ impl<'tcx> Ty<'tcx> {
791800 #[inline]
792801 pub fn new_projection_from_args(
793802 tcx: TyCtxt<'tcx>,
803 is_rigid: ty::IsRigid,
794804 item_def_id: DefId,
795805 args: ty::GenericArgsRef<'tcx>,
796806 ) -> Ty<'tcx> {
797807 Ty::new_alias(
798808 tcx,
809 is_rigid,
799810 AliasTy::new_from_args(tcx, ty::Projection { def_id: item_def_id }, args),
800811 )
801812 }
......@@ -803,10 +814,15 @@ impl<'tcx> Ty<'tcx> {
803814 #[inline]
804815 pub fn new_projection(
805816 tcx: TyCtxt<'tcx>,
817 is_rigid: ty::IsRigid,
806818 item_def_id: DefId,
807819 args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
808820 ) -> 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 )
810826 }
811827
812828 #[inline]
......@@ -982,8 +998,12 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
982998 Ty::new_canonical_bound(tcx, var)
983999 }
9841000
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)
9871007 }
9881008
9891009 fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
......@@ -1622,7 +1642,7 @@ impl<'tcx> Ty<'tcx> {
16221642
16231643 #[inline]
16241644 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 { .. }, .. }))
16261646 }
16271647
16281648 #[inline]
......@@ -1704,7 +1724,12 @@ impl<'tcx> Ty<'tcx> {
17041724 let assoc_items = tcx.associated_item_def_ids(
17051725 tcx.require_lang_item(hir::LangItem::DiscriminantKind, DUMMY_SP),
17061726 );
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 )
17081733 }
17091734
17101735 ty::Pat(ty, _) => ty.discriminant_ty(tcx),
......@@ -1837,7 +1862,7 @@ impl<'tcx> Ty<'tcx> {
18371862 Ok(metadata_ty) => metadata_ty,
18381863 Err(tail_ty) => {
18391864 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])
18411866 }
18421867 }
18431868 }
compiler/rustc_middle/src/ty/util.rs+6-4
......@@ -894,12 +894,14 @@ impl<'tcx> TyCtxt<'tcx> {
894894 /// [free]: ty::Free
895895 /// [expand_free_alias_tys]: Self::expand_free_alias_tys
896896 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 };
898900
899901 let limit = self.recursion_limit();
900902 let mut depth = 0;
901903
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() {
903905 if !limit.value_within_limit(depth) {
904906 let guar = self.dcx().delayed_bug("overflow expanding free alias type");
905907 return Ty::new_error(self, guar);
......@@ -993,7 +995,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for OpaqueTypeExpander<'tcx> {
993995 }
994996
995997 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() {
997999 self.expand_opaque_ty(def_id, args).unwrap_or(t)
9981000 } else if t.has_opaque_types() {
9991001 t.super_fold_with(self)
......@@ -1037,7 +1039,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for FreeAliasTypeExpander<'tcx> {
10371039 if !ty.has_type_flags(ty::TypeFlags::HAS_TY_FREE_ALIAS) {
10381040 return ty;
10391041 }
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 {
10411043 return ty.super_fold_with(self);
10421044 };
10431045 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> {
181181 match t.kind() {
182182 // If we are only looking for "constrained" regions, we have to ignore the
183183 // 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 }
193193 }
194194 _ => {}
195195 }
compiler/rustc_mir_build/src/builder/block.rs+1-1
......@@ -335,7 +335,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
335335 if destination_ty.is_unit()
336336 || matches!(
337337 destination_ty.kind(),
338 ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })
338 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })
339339 )
340340 {
341341 // 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>(
7777 ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id),
7878 args,
7979 );
80 let ct = ty::Const::new_unevaluated(tcx, uneval);
80 let ct = ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval);
8181
8282 let const_ = Const::Ty(ty, ct);
8383 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> {
4949 let mut convert = ConstToPat::new(self, id, span, c);
5050
5151 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),
5353 ty::ConstKind::Value(value) => convert.valtree_to_pat(value),
5454 _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c),
5555 }
......@@ -77,7 +77,7 @@ impl<'tcx> ConstToPat<'tcx> {
7777
7878 /// We errored. Signal that in the pattern, so that follow up errors can be silenced.
7979 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() {
8181 if let ty::UnevaluatedConstKind::Projection { def_id }
8282 | ty::UnevaluatedConstKind::Inherent { def_id } = uv.kind
8383 && let Some(def_id) = def_id.as_local()
......@@ -140,7 +140,7 @@ impl<'tcx> ConstToPat<'tcx> {
140140 self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
141141 // We've emitted an error on the original const, it would be redundant to complain
142142 // 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()
144144 && let ty::UnevaluatedConstKind::Projection { .. }
145145 | ty::UnevaluatedConstKind::Inherent { .. }
146146 | 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> {
659659 // generic args, instead of how we represent them in body expressions.
660660 let c = ty::Const::new_unevaluated(
661661 self.tcx,
662 ty::IsRigid::No,
662663 ty::UnevaluatedConst::new(
663664 self.tcx,
664665 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> {
165165 | ty::Never
166166 | ty::Tuple(_)
167167 | ty::UnsafeBinder(_)
168 | ty::Alias(_)
168 | ty::Alias(_, _)
169169 | ty::Param(_)
170170 | ty::Bound(_, _)
171171 | ty::Infer(_)
......@@ -205,7 +205,7 @@ impl<'a, 'tcx, F: Fn(Ty<'tcx>) -> bool> MoveDataBuilder<'a, 'tcx, F> {
205205 | ty::CoroutineWitness(..)
206206 | ty::Never
207207 | ty::UnsafeBinder(_)
208 | ty::Alias(_)
208 | ty::Alias(_, _)
209209 | ty::Param(_)
210210 | ty::Bound(_, _)
211211 | 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>(
247247 body_def.explicit_predicates_of(tcx.explicit_predicates_of(coroutine_def_id));
248248
249249 // 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));
251251
252252 body_def.mir_built(tcx.arena.alloc(Steal::new(by_move_body)));
253253
compiler/rustc_mir_transform/src/coroutine/layout.rs+1-1
......@@ -612,7 +612,7 @@ fn check_must_not_suspend_ty<'tcx>(
612612 }
613613 ty::Adt(def, _) => check_must_not_suspend_def(tcx, def.did(), hir_id, data),
614614 // 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 }, .. }) => {
616616 let mut has_emitted = false;
617617 for &(predicate, _) in tcx.explicit_item_bounds(def).skip_binder() {
618618 // 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> {
5252
5353 fn instantiate_ty(&self, v: Ty<'tcx>) -> Ty<'tcx> {
5454 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))
5656 } else {
5757 v
5858 }
compiler/rustc_mir_transform/src/function_item_references.rs+1-1
......@@ -83,7 +83,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
8383 // If the inner type matches the type bound by `Pointer`
8484 if inner_ty == bound_ty {
8585 // 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)
8787 .instantiate(self.tcx, args_ref)
8888 .skip_norm_wip();
8989 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> {
420420 work_list.push(target);
421421
422422 // 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 );
426427 if ty.needs_drop(tcx, self.typing_env())
427428 && let UnwindAction::Cleanup(unwind) = unwind
428429 {
......@@ -638,7 +639,7 @@ fn try_inlining<'tcx, I: Inliner<'tcx>>(
638639 let Ok(callee_body) = callsite.callee.try_instantiate_mir_and_normalize_erasing_regions(
639640 tcx,
640641 inliner.typing_env(),
641 ty::EarlyBinder::bind(callee_body.clone()),
642 ty::EarlyBinder::bind(tcx, callee_body.clone()),
642643 ) else {
643644 debug!("failed to normalize callee body");
644645 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>(
7676 let Ok(args) = caller.try_instantiate_mir_and_normalize_erasing_regions(
7777 tcx,
7878 typing_env,
79 ty::EarlyBinder::bind(args),
79 ty::EarlyBinder::bind(tcx, args),
8080 ) else {
8181 trace!(?caller, ?typing_env, ?args, "cannot normalize, skipping");
8282 continue;
compiler/rustc_mir_transform/src/liveness.rs+6-1
......@@ -235,6 +235,11 @@ fn maybe_drop_guard<'tcx>(
235235) -> bool {
236236 if ever_dropped.contains(index) {
237237 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();
238243 matches!(
239244 ty.kind(),
240245 ty::Closure(..)
......@@ -244,7 +249,7 @@ fn maybe_drop_guard<'tcx>(
244249 | ty::Dynamic(..)
245250 | ty::Array(..)
246251 | ty::Slice(..)
247 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })
252 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })
248253 ) && ty.needs_drop(tcx, typing_env)
249254 } else {
250255 false
compiler/rustc_mir_transform/src/post_analysis_normalize.rs+19-8
......@@ -4,7 +4,7 @@
44
55use rustc_middle::mir::visit::*;
66use rustc_middle::mir::*;
7use rustc_middle::ty::{self, Ty, TyCtxt, Unnormalized};
7use rustc_middle::ty::{self, Ty, TyCtxt};
88
99pub(super) struct PostAnalysisNormalize;
1010
......@@ -63,10 +63,10 @@ impl<'tcx> MutVisitor<'tcx> for PostAnalysisNormalizeVisitor<'tcx> {
6363 // We have to use `try_normalize_erasing_regions` here, since it's
6464 // possible that we visit impossible-to-satisfy where clauses here,
6565 // 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 ) {
7070 constant.const_ = c;
7171 }
7272 self.super_const_operand(constant, location);
......@@ -77,10 +77,21 @@ impl<'tcx> MutVisitor<'tcx> for PostAnalysisNormalizeVisitor<'tcx> {
7777 // We have to use `try_normalize_erasing_regions` here, since it's
7878 // possible that we visit impossible-to-satisfy where clauses here,
7979 // 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 ) {
8384 *ty = t;
8485 }
8586 }
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 }
8697}
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> {
107107 };
108108
109109 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();
111111 debug!("make_shim({:?}) = {:?}", shim, body);
112112
113113 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>(
2323 debug_assert_eq!(Some(def_id), tcx.lang_items().async_drop_in_place_fn());
2424 let generic_body = tcx.optimized_mir(def_id);
2525 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();
2728
2829 // Minimal shim passes except MentionedItems,
2930 // 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>(
206207 let source_info = SourceInfo::outermost(span);
207208 let body = tcx.optimized_mir(*coroutine_def_id).future_drop_poll().unwrap();
208209 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();
210211 body.source.instance = ty::InstanceKind::Shim(shim);
211212 body.phase = MirPhase::Runtime(RuntimePhase::Initial);
212213 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> {
679679 };
680680
681681 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, .. }) => {
683683 self.tcx.type_of(def_id).instantiate(self.tcx, args).skip_norm_wip().kind()
684684 }
685685 kind => kind,
......@@ -783,7 +783,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
783783 return;
784784 };
785785
786 ty::EarlyBinder::bind(f_ty.ty)
786 ty::EarlyBinder::bind(self.tcx, f_ty.ty)
787787 .instantiate(self.tcx, args)
788788 .skip_norm_wip()
789789 } else {
......@@ -1551,7 +1551,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15511551 pty.kind(),
15521552 ty::Adt(..)
15531553 | ty::Coroutine(..)
1554 | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })
1554 | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })
15551555 ) {
15561556 self.fail(
15571557 location,
compiler/rustc_monomorphize/src/collector.rs+2-2
......@@ -633,7 +633,7 @@ fn check_normalization_error<'tcx>(
633633 match self.instance.try_instantiate_mir_and_normalize_erasing_regions(
634634 self.tcx,
635635 ty::TypingEnv::fully_monomorphized(),
636 ty::EarlyBinder::bind(t),
636 ty::EarlyBinder::bind(self.tcx, t),
637637 ) {
638638 Ok(_) => ControlFlow::Continue(()),
639639 Err(_) => ControlFlow::Break(()),
......@@ -697,7 +697,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> {
697697 self.instance.instantiate_mir_and_normalize_erasing_regions(
698698 self.tcx,
699699 ty::TypingEnv::fully_monomorphized(),
700 ty::EarlyBinder::bind(value),
700 ty::EarlyBinder::bind(self.tcx, value),
701701 )
702702 }
703703
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
242242 let callee_ty = instance.instantiate_mir_and_normalize_erasing_regions(
243243 tcx,
244244 ty::TypingEnv::fully_monomorphized(),
245 ty::EarlyBinder::bind(callee_ty),
245 ty::EarlyBinder::bind(tcx, callee_ty),
246246 );
247247 check_call_site_abi(tcx, callee_ty, body.source.instance, || {
248248 let loc = Location {
compiler/rustc_monomorphize/src/mono_checks/move_check.rs+1-1
......@@ -60,7 +60,7 @@ impl<'tcx> MoveCheckVisitor<'tcx> {
6060 self.instance.instantiate_mir_and_normalize_erasing_regions(
6161 self.tcx,
6262 ty::TypingEnv::fully_monomorphized(),
63 ty::EarlyBinder::bind(value),
63 ty::EarlyBinder::bind(self.tcx, value),
6464 )
6565 }
6666
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
3030 let before_feature_tys = tcx.instantiate_and_normalize_erasing_regions(
3131 closure_instance.args,
3232 typing_env,
33 ty::EarlyBinder::bind(before_feature_tys),
33 ty::EarlyBinder::bind(tcx, before_feature_tys),
3434 );
3535 let after_feature_tys = tcx.instantiate_and_normalize_erasing_regions(
3636 closure_instance.args,
3737 typing_env,
38 ty::EarlyBinder::bind(after_feature_tys),
38 ty::EarlyBinder::bind(tcx, after_feature_tys),
3939 );
4040
4141 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> {
391391 | ty::CoroutineWitness(..)
392392 | ty::Never
393393 | ty::Tuple(_)
394 | ty::Alias(_)
394 | ty::Alias(_, _)
395395 | ty::Bound(_, _)
396396 | ty::Error(_) => {
397397 return ensure_sufficient_stack(|| t.super_fold_with(self));
......@@ -565,7 +565,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
565565 },
566566 // FIXME: See comment above -- we could fold the region separately or something.
567567 ty::ConstKind::Bound(_, _)
568 | ty::ConstKind::Unevaluated(_)
568 | ty::ConstKind::Unevaluated(_, _)
569569 | ty::ConstKind::Value(_)
570570 | ty::ConstKind::Error(_)
571571 | 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
333333{
334334 let var_values = CanonicalVarValues { var_values: delegate.cx().mk_args(var_values) };
335335 let state = inspect::State { var_values, data };
336 let state = eager_resolve_vars(delegate, state);
336 let state = eager_resolve_vars(&**delegate, state);
337337 Canonicalizer::canonicalize_response(delegate, max_input_universe, state)
338338}
339339
compiler/rustc_next_trait_solver/src/coherence.rs+1-1
......@@ -362,7 +362,7 @@ where
362362 // normalize to that, so we have to treat it as an uncovered ty param.
363363 // * Otherwise it may normalize to any non-type-generic type
364364 // be it local or non-local.
365 ty::Alias(ty::AliasTy { kind, .. }) => {
365 ty::Alias(_, ty::AliasTy { kind, .. }) => {
366366 if ty.has_type_flags(
367367 ty::TypeFlags::HAS_TY_PLACEHOLDER
368368 | ty::TypeFlags::HAS_TY_BOUND
compiler/rustc_next_trait_solver/src/normalize.rs+74-44
......@@ -1,6 +1,7 @@
1use std::fmt::Debug;
2
13use rustc_type_ir::data_structures::ensure_sufficient_stack;
24use rustc_type_ir::inherent::*;
3use rustc_type_ir::solve::{Goal, NoSolution};
45use rustc_type_ir::{
56 self as ty, AliasTerm, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy,
67 Interner, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
......@@ -21,7 +22,6 @@ where
2122{
2223 infcx: &'a Infcx,
2324 universes: Vec<Option<UniverseIndex>>,
24 stalled_goals: Vec<Goal<I, I::Predicate>>,
2525 normalize: F,
2626}
2727
......@@ -31,6 +31,12 @@ enum HasEscapingBoundVars {
3131 No,
3232}
3333
34#[derive(PartialEq, Eq)]
35pub enum NormalizationWasAmbiguous {
36 Yes,
37 No,
38}
39
3440/// Finds the max universe present in infer vars.
3541struct MaxUniverse<'a, Infcx, I>
3642where
......@@ -97,64 +103,53 @@ where
97103 }
98104}
99105
100impl<'a, Infcx, I, F> NormalizationFolder<'a, Infcx, I, F>
106impl<'a, Infcx, I, F, E> NormalizationFolder<'a, Infcx, I, F>
101107where
102108 Infcx: InferCtxtLike<Interner = I>,
103109 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>,
105111{
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 }
117114 }
118115
119116 fn normalize_alias_term(
120117 &mut self,
121118 alias_term: AliasTerm<I>,
122119 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)?;
128122
129123 // Return ambiguous higher ranked alias as is, if
130124 // - 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.
135128 //
136129 // 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 {
138133 let mut visitor = MaxUniverse::new(self.infcx);
139134 normalized.visit_with(&mut visitor);
140135 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()) {
142137 return Ok(None);
143138 }
144139 }
145140
146 self.stalled_goals.extend(ambig_goal);
147141 Ok(Some(normalized))
148142 }
149143}
150144
151impl<'a, Infcx, I, F> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I, F>
145impl<'a, Infcx, I, F, E> FallibleTypeFolder<I> for NormalizationFolder<'a, Infcx, I, F>
152146where
153147 Infcx: InferCtxtLike<Interner = I>,
154148 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,
156151{
157 type Error = NoSolution;
152 type Error = E;
158153
159154 fn cx(&self) -> I {
160155 self.infcx.cx()
......@@ -173,16 +168,23 @@ where
173168 #[instrument(level = "trace", skip(self), ret)]
174169 fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Self::Error> {
175170 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() {
177174 return Ok(ty);
178175 }
179176
180177 // With eager normalization, we should normalize the args of alias before
181178 // normalizing the alias itself.
182179 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 }
184186
185 if ty.has_escaping_bound_vars() {
187 let normalized = if ty.has_escaping_bound_vars() {
186188 let (alias_ty, mapped_regions, mapped_types, mapped_consts) =
187189 BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, alias_ty);
188190 let Some(result) = ensure_sufficient_stack(|| {
......@@ -192,36 +194,51 @@ where
192194 return Ok(ty);
193195 };
194196
195 Ok(PlaceholderReplacer::replace_placeholders(
197 PlaceholderReplacer::replace_placeholders(
196198 infcx,
197199 mapped_regions,
198200 mapped_types,
199201 mapped_consts,
200202 &self.universes,
201203 result.expect_ty(),
202 ))
204 )
203205 } else {
204 Ok(ensure_sufficient_stack(|| {
206 ensure_sufficient_stack(|| {
205207 self.normalize_alias_term(alias_ty.into(), HasEscapingBoundVars::No)
206208 })?
207209 .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");
209218 }
219 Ok(normalized)
210220 }
211221
212222 #[instrument(level = "trace", skip(self), ret)]
213223 fn try_fold_const(&mut self, ct: I::Const) -> Result<I::Const, Self::Error> {
214224 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() {
216228 return Ok(ct);
217229 }
218230
219231 // With eager normalization, we should normalize the args of alias before
220232 // normalizing the alias itself.
221233 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 }
223240
224 if ct.has_escaping_bound_vars() {
241 let normalized = if ct.has_escaping_bound_vars() {
225242 let (uv, mapped_regions, mapped_types, mapped_consts) =
226243 BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv);
227244 let Some(result) = ensure_sufficient_stack(|| {
......@@ -230,20 +247,33 @@ where
230247 else {
231248 return Ok(ct);
232249 };
233 Ok(PlaceholderReplacer::replace_placeholders(
250 PlaceholderReplacer::replace_placeholders(
234251 infcx,
235252 mapped_regions,
236253 mapped_types,
237254 mapped_consts,
238255 &self.universes,
239256 result.expect_const(),
240 ))
257 )
241258 } else {
242 Ok(ensure_sufficient_stack(|| {
259 ensure_sufficient_stack(|| {
243260 self.normalize_alias_term(uv.into(), HasEscapingBoundVars::No)
244261 })?
245262 .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");
247271 }
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) }
248278 }
249279}
compiler/rustc_next_trait_solver/src/resolve.rs+8-10
......@@ -5,15 +5,13 @@ use rustc_type_ir::{
55 TypeVisitableExt,
66};
77
8use crate::delegate::SolverDelegate;
9
108///////////////////////////////////////////////////////////////////////////
119// EAGER RESOLUTION
1210
1311/// Resolves ty, region, and const vars to their inferred values or their root vars.
14struct EagerResolver<'a, D, I = <D as SolverDelegate>::Interner>
12struct EagerResolver<'a, D, I = <D as InferCtxtLike>::Interner>
1513where
16 D: SolverDelegate<Interner = I>,
14 D: InferCtxtLike<Interner = I>,
1715 I: Interner,
1816{
1917 delegate: &'a D,
......@@ -22,25 +20,25 @@ where
2220 cache: DelayedMap<I::Ty, I::Ty>,
2321}
2422
25pub fn eager_resolve_vars<D: SolverDelegate, T: TypeFoldable<D::Interner>>(
26 delegate: &D,
23pub fn eager_resolve_vars<Infcx: InferCtxtLike, T: TypeFoldable<Infcx::Interner>>(
24 infcx: &Infcx,
2725 value: T,
2826) -> T {
2927 if value.has_infer() {
30 let mut folder = EagerResolver::new(delegate);
28 let mut folder = EagerResolver::new(infcx);
3129 value.fold_with(&mut folder)
3230 } else {
3331 value
3432 }
3533}
3634
37impl<'a, D: SolverDelegate> EagerResolver<'a, D> {
38 fn new(delegate: &'a D) -> Self {
35impl<'a, Infcx: InferCtxtLike> EagerResolver<'a, Infcx> {
36 fn new(delegate: &'a Infcx) -> Self {
3937 EagerResolver { delegate, cache: Default::default() }
4038 }
4139}
4240
43impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, D> {
41impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I> for EagerResolver<'_, Infcx> {
4442 fn cx(&self) -> I {
4543 self.delegate.cx()
4644 }
compiler/rustc_next_trait_solver/src/solve/alias_relate.rs+6-29
......@@ -49,11 +49,11 @@ where
4949
5050 // Structurally normalize the lhs.
5151 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);
5353 self.add_goal(
5454 GoalSource::TypeRelating,
5555 goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }),
56 );
56 )?;
5757 term
5858 } else {
5959 lhs
......@@ -61,11 +61,11 @@ where
6161
6262 // Structurally normalize the rhs.
6363 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);
6565 self.add_goal(
6666 GoalSource::TypeRelating,
6767 goal.with(cx, ty::ProjectionPredicate { projection_term: alias, term }),
68 );
68 )?;
6969 term
7070 } else {
7171 rhs
......@@ -87,30 +87,7 @@ where
8787 ty::AliasRelationDirection::Equate => ty::Invariant,
8888 ty::AliasRelationDirection::Subtype => ty::Covariant,
8989 };
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)
11592 }
11693}
compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs+18-9
......@@ -68,7 +68,7 @@ where
6868 ) -> Result<Candidate<I>, NoSolutionOrRerunNonErased> {
6969 Self::probe_and_match_goal_against_assumption(ecx, parent_source, goal, assumption, |ecx| {
7070 for (nested_source, goal) in requirements {
71 ecx.add_goal(nested_source, goal);
71 ecx.add_goal(nested_source, goal)?;
7272 }
7373 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
7474 })
......@@ -113,7 +113,7 @@ where
113113 bounds,
114114 ) {
115115 Ok(requirements) => {
116 ecx.add_goals(GoalSource::ImplWhereBound, requirements);
116 ecx.add_goals(GoalSource::ImplWhereBound, requirements)?;
117117 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
118118 }
119119 Err(_) => {
......@@ -789,13 +789,21 @@ where
789789 return Ok(());
790790 }
791791
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 }, .. }) => {
796798 (alias_ty, def_id.into())
797799 }
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 ) => {
799807 self.cx().delay_bug(format!("could not normalize {self_ty:?}, it is not WF"));
800808 return Ok(());
801809 }
......@@ -971,7 +979,7 @@ where
971979 elaborate::elaborate(cx, [predicate])
972980 .skip(1)
973981 .map(|predicate| goal.with(cx, predicate)),
974 );
982 )?;
975983 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
976984 }
977985 })
......@@ -1088,9 +1096,10 @@ where
10881096 self.cx
10891097 }
10901098 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()
10921100 && let Some(opaque_ty) = alias_ty.try_to_opaque()
10931101 {
1102 debug_assert_eq!(is_rigid, ty::IsRigid::No);
10941103 if opaque_ty == self.opaque_ty {
10951104 return self.self_ty;
10961105 }
compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs+33-23
......@@ -49,11 +49,14 @@ where
4949
5050 ty::Dynamic(..)
5151 | 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 )
5658 | ty::Placeholder(..)
59 | ty::Alias(ty::IsRigid::No, _)
5760 | ty::Bound(..)
5861 | ty::Infer(_) => {
5962 panic!("unexpected type `{ty:?}`")
......@@ -102,7 +105,7 @@ where
102105 .collect(),
103106 )),
104107
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, .. }) => {
106109 // We can resolve the `impl Trait` to its concrete type,
107110 // which enforces a DAG between the functions requiring
108111 // the auto trait bounds in question.
......@@ -227,15 +230,10 @@ where
227230 | ty::Foreign(..)
228231 | ty::Ref(_, _, Mutability::Mut)
229232 | ty::Adt(_, _)
230 | ty::Alias(_)
233 | ty::Alias(ty::IsRigid::Yes, _)
231234 | ty::Param(_)
232235 | ty::Placeholder(..) => Err(NoSolution),
233236
234 ty::Bound(..)
235 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
236 panic!("unexpected type `{ty:?}`")
237 }
238
239237 // impl Copy/Clone for (T1, T2, .., Tn) where T1: Copy/Clone, T2: Copy/Clone, .. Tn: Copy/Clone
240238 ty::Tuple(tys) => Ok(ty::Binder::dummy(tys.to_vec())),
241239
......@@ -272,6 +270,12 @@ where
272270 .instantiate(ecx.cx(), args)
273271 .skip_norm_wip()
274272 .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 }
275279 }
276280}
277281
......@@ -401,14 +405,15 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
401405 | ty::Tuple(_)
402406 | ty::Pat(_, _)
403407 | ty::UnsafeBinder(_)
404 | ty::Alias(_)
408 | ty::Alias(ty::IsRigid::Yes, _)
405409 | ty::Param(_)
406410 | ty::Placeholder(..)
407411 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
408412 | ty::Error(_) => Err(NoSolution),
409413
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(..) => {
412417 panic!("unexpected type `{self_ty:?}`")
413418 }
414419 }
......@@ -545,7 +550,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
545550
546551 let future_output_def_id =
547552 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()]);
549555 Ok((
550556 bound_sig.rebind(AsyncCallableRelevantTypes {
551557 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:
575581 | ty::Never
576582 | ty::UnsafeBinder(_)
577583 | ty::Tuple(_)
578 | ty::Alias(_)
584 | ty::Alias(ty::IsRigid::Yes, _)
579585 | ty::Param(_)
580586 | ty::Placeholder(..)
581587 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
582588 | ty::Error(_) => Err(NoSolution),
583589
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(..) => {
586593 panic!("unexpected type `{self_ty:?}`")
587594 }
588595 }
......@@ -601,7 +608,8 @@ fn fn_item_to_async_callable<I: Interner>(
601608 ];
602609 let future_output_def_id =
603610 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()]);
605613 Ok((
606614 bound_sig.rebind(AsyncCallableRelevantTypes {
607615 tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()),
......@@ -650,6 +658,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
650658 cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars);
651659 let tupled_upvars_ty = Ty::new_projection(
652660 cx,
661 ty::IsRigid::No,
653662 upvars_projection_def_id,
654663 [
655664 I::GenericArg::from(args.kind_ty()),
......@@ -739,15 +748,16 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>(
739748 | ty::Never
740749 | ty::Tuple(_)
741750 | ty::Pat(_, _)
742 | ty::Alias(_)
751 | ty::Alias(ty::IsRigid::Yes, _)
743752 | ty::Param(_)
744753 | ty::Placeholder(..)
745754 | ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
746755 | ty::Error(_)
747756 | ty::UnsafeBinder(_) => return Err(NoSolution),
748757
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(..) => {
751761 panic!("unexpected type `{self_ty:?}`")
752762 }
753763 }
......@@ -1035,7 +1045,7 @@ where
10351045 }
10361046
10371047 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()
10391049 && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
10401050 {
10411051 Ok(term.expect_ty())
compiler/rustc_next_trait_solver/src/solve/effect_goals.rs+8-8
......@@ -124,7 +124,7 @@ where
124124 )
125125 },
126126 ),
127 );
127 )?;
128128 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
129129 },
130130 ));
......@@ -176,7 +176,7 @@ where
176176 .iter_instantiated(cx, impl_args)
177177 .map(Unnormalized::skip_norm_wip)
178178 .map(|pred| goal.with(cx, pred));
179 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
179 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?;
180180
181181 // For this impl to be `const`, we need to check its `[const]` bounds too.
182182 let const_conditions = cx
......@@ -190,7 +190,7 @@ where
190190 .skip_norm_wip(),
191191 )
192192 });
193 ecx.add_goals(GoalSource::ImplWhereBound, const_conditions);
193 ecx.add_goals(GoalSource::ImplWhereBound, const_conditions)?;
194194
195195 then(ecx, certainty)
196196 })
......@@ -242,8 +242,8 @@ where
242242 // `GoalSource::ImplWhereClause` here would be incorrect, as we also
243243 // impl them, which means we're "stepping out of the impl constructor"
244244 // 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)?;
247247 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
248248 })
249249 }
......@@ -278,8 +278,8 @@ where
278278 ),
279279 )
280280 }),
281 );
282 });
281 )
282 })?;
283283
284284 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
285285 })
......@@ -432,7 +432,7 @@ where
432432 .to_host_effect_clause(cx, goal.predicate.constness),
433433 )
434434 }),
435 );
435 )?;
436436 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
437437 })
438438 }
compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs+70-205
......@@ -3,7 +3,7 @@ use std::ops::ControlFlow;
33
44#[cfg(feature = "nightly")]
55use rustc_macros::StableHash;
6use rustc_type_ir::data_structures::{HashMap, HashSet};
6use rustc_type_ir::data_structures::HashSet;
77use rustc_type_ir::inherent::*;
88use rustc_type_ir::region_constraint::RegionConstraint;
99use rustc_type_ir::relate::Relate;
......@@ -16,8 +16,8 @@ use rustc_type_ir::solve::{
1616};
1717use rustc_type_ir::{
1818 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,
2121};
2222use tracing::{Level, debug, instrument, trace, warn};
2323
......@@ -28,6 +28,7 @@ use crate::canonical::{
2828};
2929use crate::coherence;
3030use crate::delegate::SolverDelegate;
31use crate::normalize::{NormalizationFolder, NormalizationWasAmbiguous};
3132use crate::placeholder::BoundVarReplacer;
3233use crate::resolve::eager_resolve_vars;
3334use crate::solve::search_graph::SearchGraph;
......@@ -604,7 +605,7 @@ where
604605 // so we only canonicalize the lookup table and ignore
605606 // duplicate entries.
606607 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));
608609 let typing_mode = self.typing_mode();
609610 let step_kind = self.step_kind_for_source(source);
610611
......@@ -1049,15 +1050,20 @@ where
10491050 self.delegate.cx()
10501051 }
10511052
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
10571053 #[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 )?;
10591064 self.inspect.add_goal(self.delegate, self.max_input_universe, source, goal);
10601065 self.nested_goals.push((source, goal, None));
1066 Ok(())
10611067 }
10621068
10631069 #[instrument(level = "trace", skip(self, goals))]
......@@ -1065,19 +1071,11 @@ where
10651071 &mut self,
10661072 source: GoalSource,
10671073 goals: impl IntoIterator<Item = Goal<I, I::Predicate>>,
1068 ) {
1074 ) -> Result<(), NoSolutionOrRerunNonErased> {
10691075 for goal in goals {
1070 self.add_goal(source, goal);
1076 self.add_goal(source, goal)?;
10711077 }
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(())
10811079 }
10821080
10831081 pub(super) fn next_region_var(&mut self) -> I::Region {
......@@ -1100,10 +1098,19 @@ where
11001098
11011099 /// Returns a ty infer or a const infer depending on whether `kind` is a `Ty` or `Const`.
11021100 /// 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(),
11071114 }
11081115 }
11091116
......@@ -1240,88 +1247,17 @@ where
12401247 param_env: I::ParamEnv,
12411248 lhs: T,
12421249 rhs: T,
1243 ) -> Result<(), NoSolution> {
1250 ) -> Result<(), NoSolutionOrRerunNonErased> {
12441251 self.relate(param_env, lhs, ty::Variance::Invariant, rhs)
12451252 }
12461253
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
13181254 #[instrument(level = "trace", skip(self, param_env), ret)]
13191255 pub(super) fn sub<T: Relate<I>>(
13201256 &mut self,
13211257 param_env: I::ParamEnv,
13221258 sub: T,
13231259 sup: T,
1324 ) -> Result<(), NoSolution> {
1260 ) -> Result<(), NoSolutionOrRerunNonErased> {
13251261 self.relate(param_env, sub, ty::Variance::Covariant, sup)
13261262 }
13271263
......@@ -1332,7 +1268,7 @@ where
13321268 lhs: T,
13331269 variance: ty::Variance,
13341270 rhs: T,
1335 ) -> Result<(), NoSolution> {
1271 ) -> Result<(), NoSolutionOrRerunNonErased> {
13361272 let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
13371273 for &goal in goals.iter() {
13381274 let source = match goal.predicate.kind().skip_binder() {
......@@ -1343,7 +1279,7 @@ where
13431279 ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
13441280 p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
13451281 };
1346 self.add_goal(source, goal);
1282 self.add_goal(source, goal)?;
13471283 }
13481284 Ok(())
13491285 }
......@@ -1484,7 +1420,7 @@ where
14841420 opaque_args: I::GenericArgs,
14851421 param_env: I::ParamEnv,
14861422 hidden_ty: I::Ty,
1487 ) {
1423 ) -> Result<(), NoSolutionOrRerunNonErased> {
14881424 let mut goals = Vec::new();
14891425 self.delegate.add_item_bounds_for_hidden_type(
14901426 opaque_def_id,
......@@ -1493,7 +1429,8 @@ where
14931429 hidden_ty,
14941430 &mut goals,
14951431 );
1496 self.add_goals(GoalSource::AliasWellFormed, goals);
1432 self.add_goals(GoalSource::AliasWellFormed, goals)?;
1433 Ok(())
14971434 }
14981435
14991436 // Try to evaluate a const, or return `None` if the const is too generic.
......@@ -1540,10 +1477,9 @@ where
15401477 // however, we want to structurally instantiate to the original, non-rebased,
15411478 // trait `Self` form of the constant (with generic arguments being the trait
15421479 // `Self` type).
1543 self.relate_rigid_alias_non_alias(
1480 self.eq(
15441481 param_env,
1545 projection_term,
1546 ty::Invariant,
1482 projection_term.to_term(self.cx(), ty::IsRigid::Yes),
15471483 expected_term,
15481484 )?;
15491485 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
......@@ -1695,7 +1631,7 @@ where
16951631 let external_constraints =
16961632 self.compute_external_query_constraints(certainty, normalization_nested_goals);
16971633 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));
16991635
17001636 // Remove any trivial or duplicated region constraints once we've resolved regions
17011637 let mut unique = HashSet::default();
......@@ -1781,110 +1717,39 @@ where
17811717
17821718 ExternalConstraintsData { region_constraints, opaque_types, normalization_nested_goals }
17831719 }
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.
1802struct ReplaceAliasWithInfer<'me, 'a, D, I>
1803where
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}
18121720
1813impl<'me, 'a, D, I> ReplaceAliasWithInfer<'me, 'a, D, I>
1814where
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,
18211724 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());
18321728
1833impl<D, I> TypeFolder<I> for ReplaceAliasWithInfer<'_, '_, D, I>
1834where
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);
18671731 }
1868 }
18691732
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 };
18851749
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)
18881753 }
18891754}
18901755
......@@ -1919,7 +1784,7 @@ pub(super) fn evaluate_root_goal_for_proof_tree<D: SolverDelegate<Interner = I>,
19191784 origin_span: I::Span,
19201785) -> (Result<NestedNormalizationGoals<I>, NoSolution>, inspect::GoalEvaluation<I>) {
19211786 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));
19231788 let typing_mode = delegate.typing_mode_raw().assert_not_erased();
19241789
19251790 let (orig_values, canonical_goal) =
compiler/rustc_next_trait_solver/src/solve/mod.rs+27-30
......@@ -24,7 +24,7 @@ mod trait_goals;
2424use derive_where::derive_where;
2525use rustc_type_ir::inherent::*;
2626pub use rustc_type_ir::solve::*;
27use rustc_type_ir::{self as ty, Interner, TyVid, TypingMode};
27use rustc_type_ir::{self as ty, Interner, TyVid};
2828use tracing::instrument;
2929
3030pub use self::eval_ctxt::{
......@@ -171,7 +171,7 @@ where
171171 ) -> QueryResultOrRerunNonErased<I> {
172172 match self.well_formed_goals(goal.param_env, goal.predicate) {
173173 Some(goals) => {
174 self.add_goals(GoalSource::Misc, goals);
174 self.add_goals(GoalSource::Misc, goals)?;
175175 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
176176 }
177177 None => self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS),
......@@ -196,7 +196,18 @@ where
196196 Goal { param_env, predicate: ct }: Goal<I, I::Const>,
197197 ) -> QueryResultOrRerunNonErased<I> {
198198 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) => {
200211 // We never return `NoSolution` here as `evaluate_const` emits an
201212 // error itself when failing to evaluate, so emitting an additional fulfillment
202213 // error in that case is unnecessary noise. This may change in the future once
......@@ -211,12 +222,7 @@ where
211222 self.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
212223 }
213224 }
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
220226 // We can freely ICE here as:
221227 // - `Param` gets replaced with a placeholder during canonicalization
222228 // - `Bound` cannot exist as we don't have a binder around the self Type
......@@ -246,7 +252,12 @@ where
246252 .evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
247253 .map_err(Into::into);
248254 }
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 ),
250261 ty::ConstKind::Expr(_) => unimplemented!(
251262 "`feature(generic_const_exprs)` is not supported in the new trait solver"
252263 ),
......@@ -366,8 +377,12 @@ where
366377 param_env: I::ParamEnv,
367378 term: I::Term,
368379 ) -> Result<I::Term, NoSolutionOrRerunNonErased> {
380 if !self.cx().renormalize_rigid_aliases() && !term.is_non_rigid_alias() {
381 return Ok(term);
382 }
383
369384 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);
371386 let projection_goal = Goal::new(
372387 self.cx(),
373388 param_env,
......@@ -375,31 +390,13 @@ where
375390 );
376391 // We normalize the self type to be able to relate it with
377392 // types from candidates.
378 self.add_goal(GoalSource::TypeRelating, projection_goal);
393 self.add_goal(GoalSource::TypeRelating, projection_goal)?;
379394 self.try_evaluate_added_goals()?;
380395 Ok(self.resolve_vars_if_possible(normalized_term))
381396 } else {
382397 Ok(term)
383398 }
384399 }
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 }
403400}
404401
405402/// The result of evaluating a goal.
compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs+66-38
......@@ -101,7 +101,7 @@ where
101101 param_env: I::ParamEnv,
102102 alias: ty::AliasTerm<I>,
103103 term: I::Term,
104 ) {
104 ) -> Result<(), NoSolutionOrRerunNonErased> {
105105 if let Some(ct) = term.as_const() {
106106 let cx = self.cx();
107107 let expected_ty = alias.expect_ct().type_of(cx).skip_norm_wip();
......@@ -111,8 +111,9 @@ where
111111 param_env,
112112 predicate: ty::ClauseKind::ConstArgHasType(ct, expected_ty).upcast(cx),
113113 },
114 );
114 )?;
115115 }
116 Ok(())
116117 }
117118
118119 /// When normalizing an associated item, constrain the expected term to `term`.
......@@ -141,10 +142,15 @@ where
141142 /// fires a `span_bug!`. Registering the obligation here ensures the type
142143 /// mismatch is reported during normalization itself, tainting the MIR
143144 /// 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)?;
146151 self.eq(goal.param_env, goal.predicate.term, term)
147152 .expect("expected goal term to be fully unconstrained");
153 Ok(())
148154 }
149155
150156 /// Unlike `instantiate_normalizes_to_term` this instantiates the expected term
......@@ -154,8 +160,13 @@ where
154160 goal: Goal<I, NormalizesTo<I>>,
155161 term: ty::AliasTerm<I>,
156162 ) {
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");
159170 }
160171}
161172
......@@ -214,7 +225,7 @@ where
214225 let assumption_projection_pred = ecx.instantiate_binder_with_infer(projection_pred);
215226 ecx.eq(goal.param_env, goal.predicate.alias, assumption_projection_pred.projection_term)?;
216227
217 ecx.instantiate_normalizes_to_term(goal, assumption_projection_pred.term);
228 ecx.instantiate_normalizes_to_term(goal, assumption_projection_pred.term)?;
218229
219230 // Add GAT where clauses from the trait's definition
220231 // FIXME: We don't need these, since these are the type's own WF obligations.
......@@ -224,7 +235,7 @@ where
224235 .iter_instantiated(cx, goal.predicate.alias.args)
225236 .map(Unnormalized::skip_norm_wip)
226237 .map(|pred| goal.with(cx, pred)),
227 );
238 )?;
228239
229240 then(ecx)
230241 }
......@@ -290,7 +301,7 @@ where
290301 .iter_instantiated(cx, impl_args)
291302 .map(Unnormalized::skip_norm_wip)
292303 .map(|pred| goal.with(cx, pred));
293 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
304 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?;
294305
295306 // Bail if the nested goals don't hold here. This is to avoid unnecessarily
296307 // computing the `type_of` query for associated types that never apply, as
......@@ -307,7 +318,7 @@ where
307318 .iter_instantiated(cx, goal.predicate.alias.args)
308319 .map(Unnormalized::skip_norm_wip)
309320 .map(|pred| goal.with(cx, pred)),
310 );
321 )?;
311322
312323 let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| {
313324 let error_term = match goal.predicate.alias.kind {
......@@ -315,7 +326,7 @@ where
315326 ty::AliasTermKind::ProjectionConst { .. } => Const::new_error(cx, guar).into(),
316327 kind => panic!("expected projection, found {kind:?}"),
317328 };
318 ecx.instantiate_normalizes_to_term(goal, error_term);
329 ecx.instantiate_normalizes_to_term(goal, error_term)?;
319330 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
320331 };
321332
......@@ -339,7 +350,7 @@ where
339350 ecx.add_goal(
340351 GoalSource::Misc,
341352 goal.with(cx, PredicateKind::Ambiguous),
342 );
353 )?;
343354 return ecx
344355 .evaluate_added_goals_and_make_canonical_response(
345356 Certainty::Yes,
......@@ -389,7 +400,7 @@ where
389400 // would be relevant if any of the nested goals refer to the `term`.
390401 // This is not the case here and we only prefer adding an ambiguous
391402 // 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))?;
393404 return then(ecx, Certainty::Yes).map_err(Into::into);
394405 } else {
395406 ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
......@@ -429,18 +440,18 @@ where
429440
430441 // Finally we construct the actual value of the associated type.
431442 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 }
437448 ty::AliasTermKind::ProjectionConst { .. }
438449 if cx.is_type_const(target_item_def_id.into()) =>
439450 {
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()
444455 }
445456 ty::AliasTermKind::ProjectionConst { .. } => {
446457 let uv = ty::UnevaluatedConst::new(
......@@ -460,7 +471,7 @@ where
460471 kind => panic!("expected projection, found {kind:?}"),
461472 };
462473
463 ecx.instantiate_normalizes_to_term(goal, term);
474 ecx.instantiate_normalizes_to_term(goal, term)?;
464475 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into)
465476 })
466477 }
......@@ -480,7 +491,7 @@ where
480491 };
481492
482493 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)?;
484495 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
485496 })
486497 }
......@@ -690,7 +701,7 @@ where
690701 );
691702
692703 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())?;
694705 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
695706 })
696707 }
......@@ -743,7 +754,7 @@ where
743754 .skip_norm_wip()
744755 }
745756
746 ty::Alias(_) | ty::Param(_) | ty::Placeholder(..) => {
757 ty::Alias(ty::IsRigid::Yes, _) | ty::Param(_) | ty::Placeholder(..) => {
747758 // This is the "fallback impl" for type parameters, unnormalizable projections
748759 // and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
749760 // FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
......@@ -755,8 +766,8 @@ where
755766 cx.require_trait_lang_item(SolverTraitLangItem::Sized),
756767 [I::GenericArg::from(goal.predicate.self_ty())],
757768 );
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())?;
760771 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
761772 });
762773
......@@ -782,6 +793,7 @@ where
782793 None => Ty::new_unit(cx),
783794 Some(tail_ty) => Ty::new_projection(
784795 cx,
796 ty::IsRigid::No,
785797 metadata_def_id,
786798 [tail_ty.instantiate(cx, args).skip_norm_wip()],
787799 ),
......@@ -790,7 +802,9 @@ where
790802
791803 ty::Tuple(elements) => match elements.last() {
792804 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 }
794808 },
795809
796810 ty::UnsafeBinder(_) => {
......@@ -799,6 +813,7 @@ where
799813 }
800814
801815 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
816 | ty::Alias(ty::IsRigid::No, _)
802817 | ty::Bound(..) => panic!(
803818 "unexpected self ty `{:?}` when normalizing `<T as Pointee>::Metadata`",
804819 goal.predicate.self_ty()
......@@ -806,7 +821,7 @@ where
806821 };
807822
808823 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())?;
810825 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
811826 })
812827 }
......@@ -833,7 +848,13 @@ where
833848 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
834849 goal,
835850 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 ),
837858 term,
838859 }
839860 .upcast(cx),
......@@ -865,7 +886,13 @@ where
865886 CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
866887 goal,
867888 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 ),
869896 term,
870897 }
871898 .upcast(cx),
......@@ -914,7 +941,7 @@ where
914941 );
915942 let yield_ty = args.as_coroutine().yield_ty();
916943 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())?;
918945 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
919946 })
920947 }
......@@ -1011,7 +1038,7 @@ where
10111038 // Given an alias, parameter, or placeholder we add an impl candidate normalizing to a rigid
10121039 // alias. In case there's a where-bound further constraining this alias it is preferred over
10131040 // 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(..) => {
10151042 return ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
10161043 ecx.structurally_instantiate_normalizes_to_term(goal, goal.predicate.alias);
10171044 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
......@@ -1019,6 +1046,7 @@ where
10191046 }
10201047
10211048 ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
1049 | ty::Alias(ty::IsRigid::No, _)
10221050 | ty::Bound(..) => panic!(
10231051 "unexpected self ty `{:?}` when normalizing `<T as DiscriminantKind>::Discriminant`",
10241052 goal.predicate.self_ty()
......@@ -1026,7 +1054,7 @@ where
10261054 };
10271055
10281056 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())?;
10301058 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
10311059 })
10321060 }
......@@ -1071,7 +1099,7 @@ where
10711099 _ => panic!("unexpected associated type {:?} in `Field`", goal.predicate),
10721100 };
10731101 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())?;
10751103 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
10761104 })
10771105 }
......@@ -1089,7 +1117,7 @@ where
10891117 impl_args: I::GenericArgs,
10901118 impl_trait_ref: rustc_type_ir::TraitRef<I>,
10911119 target_container_def_id: I::DefId,
1092 ) -> Result<I::GenericArgs, NoSolution> {
1120 ) -> Result<I::GenericArgs, NoSolutionOrRerunNonErased> {
10931121 let cx = self.cx();
10941122 Ok(if target_container_def_id == impl_trait_ref.def_id.into() {
10951123 // Default value from the trait definition. No need to rebase.
......@@ -1114,7 +1142,7 @@ where
11141142 .iter_instantiated(cx, target_args)
11151143 .map(Unnormalized::skip_norm_wip)
11161144 .map(|pred| goal.with(cx, pred)),
1117 );
1145 )?;
11181146 goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), target_args)
11191147 })
11201148 }
compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs+11-8
......@@ -29,17 +29,20 @@ where
2929 .iter_instantiated(cx, free_alias.args)
3030 .map(Unnormalized::skip_norm_wip)
3131 .map(|pred| goal.with(cx, pred)),
32 );
32 )?;
3333
3434 let actual = match free_alias.kind {
3535 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()
3745 }
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(),
4346 ty::AliasTermKind::FreeConst { .. } => {
4447 return self.evaluate_const_and_instantiate_projection_term(
4548 goal.param_env,
......@@ -51,7 +54,7 @@ where
5154 kind => panic!("expected free alias, found {kind:?}"),
5255 };
5356
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)?;
5558 self.eq(goal.param_env, goal.predicate.term, actual)?;
5659 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
5760 }
compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs+10-8
......@@ -51,17 +51,19 @@ where
5151 .iter_instantiated(cx, inherent_args)
5252 .map(Unnormalized::skip_norm_wip)
5353 .map(|pred| goal.with(cx, pred)),
54 );
54 )?;
5555
5656 let normalized: I::Term = match inherent.kind {
5757 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()
5966 }
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(),
6567 ty::AliasTermKind::InherentConst { .. } => {
6668 // FIXME(gca): This is dead code at the moment. It should eventually call
6769 // self.evaluate_const like projected consts do in consider_impl_candidate in
......@@ -78,7 +80,7 @@ where
7880 goal.param_env,
7981 goal.predicate.projection_term,
8082 normalized,
81 );
83 )?;
8284 self.eq(goal.param_env, goal.predicate.term, normalized)?;
8385 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
8486 }
compiler/rustc_next_trait_solver/src/solve/project_goals/mod.rs+3-26
......@@ -44,7 +44,7 @@ where
4444 goal: Goal<I, ProjectionPredicate<I>>,
4545 ) -> QueryResultOrRerunNonErased<I> {
4646 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);
4848 let normalizes_to =
4949 goal.with(self.cx(), ty::NormalizesTo { alias, term: unconstrained_term });
5050
......@@ -77,34 +77,11 @@ where
7777 // since equating the normalized terms will lead to additional constraints.
7878 self.inspect.make_canonical_response(Certainty::AMBIGUOUS);
7979
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)?;
10481
10582 // Add the nested goals from normalization to our own nested goals.
10683 for (s, g) in nested_goals {
107 self.add_goal(s, g);
84 self.add_goal(s, g)?;
10885 }
10986
11087 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
3232 opaque_ty.args,
3333 goal.param_env,
3434 expected,
35 );
35 )?;
3636 // Trying to normalize an opaque type during coherence is always ambiguous.
3737 // We add a nested ambiguous goal here instead of using `Certainty::AMBIGUOUS`.
3838 // This allows us to return the nested goals to the parent `AliasRelate` goal.
3939 // 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))?;
4141 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
4242 .map_err(Into::into)
4343 }
......@@ -48,10 +48,9 @@ where
4848 .filter(|&def_id| defining_opaque_types.contains(&def_id.into()))
4949 else {
5050 // If we're not in the defining scope, treat the alias as rigid.
51 self.relate_rigid_alias_non_alias(
51 self.eq(
5252 goal.param_env,
53 opaque_ty,
54 ty::Invariant,
53 opaque_ty.to_term(cx, ty::IsRigid::Yes),
5554 goal.predicate.term,
5655 )?;
5756 return self
......@@ -93,12 +92,15 @@ where
9392 TypingMode::PostTypeckUntilBorrowck { .. } => {
9493 let actual = cx
9594 .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 })
101101 });
102 let actual =
103 self.normalize(GoalSource::Misc, goal.param_env, actual)?;
102104 self.eq(goal.param_env, expected, actual)?;
103105 }
104106 TypingMode::Coherence
......@@ -113,7 +115,7 @@ where
113115 normalized_args,
114116 goal.param_env,
115117 expected,
116 );
118 )?;
117119 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
118120 .map_err(Into::into)
119121 }
......@@ -122,10 +124,9 @@ where
122124 .as_local()
123125 .filter(|&def_id| defined_opaque_types.contains(&def_id.into()))
124126 else {
125 self.relate_rigid_alias_non_alias(
127 self.eq(
126128 goal.param_env,
127 opaque_ty,
128 ty::Invariant,
129 opaque_ty.to_term(cx, ty::IsRigid::Yes),
129130 goal.predicate.term,
130131 )?;
131132 return self
......@@ -133,23 +134,25 @@ where
133134 .map_err(Into::into);
134135 };
135136
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);
138138 // FIXME: Actually use a proper binder here instead of relying on `ReErased`.
139139 //
140140 // 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 })
144146 });
147 let actual = self.normalize(GoalSource::Misc, goal.param_env, actual)?;
145148 self.eq(goal.param_env, expected, actual)?;
146149 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
147150 .map_err(Into::into)
148151 }
149152 TypingMode::PostAnalysis | TypingMode::Codegen => {
150153 // 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)?;
153156 self.eq(goal.param_env, expected, actual)?;
154157 self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
155158 .map_err(Into::into)
......@@ -172,10 +175,9 @@ where
172175 }
173176
174177 // Always treat the opaque type as rigid.
175 self.relate_rigid_alias_non_alias(
178 self.eq(
176179 goal.param_env,
177 opaque_ty,
178 ty::Invariant,
180 opaque_ty.to_term(cx, ty::IsRigid::Yes),
179181 goal.predicate.term,
180182 )?;
181183 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
106106 .iter_instantiated(cx, impl_args)
107107 .map(Unnormalized::skip_norm_wip)
108108 .map(|pred| goal.with(cx, pred));
109 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
109 ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?;
110110
111111 // We currently elaborate all supertrait outlives obligations from impls.
112112 // This can be removed when we actually do coinduction correctly, and prove
......@@ -117,7 +117,7 @@ where
117117 .iter_instantiated(cx, impl_args)
118118 .map(Unnormalized::skip_norm_wip)
119119 .map(|pred| goal.with(cx, pred)),
120 );
120 )?;
121121
122122 then(ecx, maximal_certainty).map_err(Into::into)
123123 })
......@@ -235,15 +235,15 @@ where
235235 // when merging candidates anyways.
236236 //
237237 // 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 }, .. }) =
239239 goal.predicate.self_ty().kind()
240240 {
241 debug_assert!(is_rigid == ty::IsRigid::Yes);
241242 if ecx.opaque_accesses.might_rerun() {
242243 ecx.opaque_accesses.rerun_always(RerunReason::AutoTraitLeakage)?;
243244 return Err(NoSolution.into());
244245 }
245246
246 debug_assert!(ecx.opaque_type_is_rigid(def_id));
247247 for item_bound in cx.item_self_bounds(def_id.into()).skip_binder() {
248248 if item_bound
249249 .as_trait_clause()
......@@ -287,7 +287,7 @@ where
287287 // `GoalSource::ImplWhereClause` here would be incorrect, as we also
288288 // impl them, which means we're "stepping out of the impl constructor"
289289 // 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)?;
291291 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
292292 })
293293 }
......@@ -737,13 +737,13 @@ where
737737 tys.iter().map(|elem_ty| {
738738 goal.with(cx, ty::TraitRef::new(cx, goal.predicate.def_id(), [elem_ty]))
739739 }),
740 );
740 )?;
741741 }
742742 ty::Array(elem_ty, _) => {
743743 ecx.add_goal(
744744 GoalSource::ImplWhereBound,
745745 goal.with(cx, ty::TraitRef::new(cx, goal.predicate.def_id(), [elem_ty])),
746 );
746 )?;
747747 }
748748
749749 // All other types implement `BikeshedGuaranteedNoDrop` only if
......@@ -784,7 +784,7 @@ where
784784 [ty],
785785 ),
786786 ),
787 );
787 )?;
788788 }
789789
790790 ty::Bound(..)
......@@ -891,14 +891,14 @@ where
891891 param_env: goal.param_env,
892892 predicate: TraitRef::new(ecx.cx(), sized_trait, [base]).upcast(ecx.cx()),
893893 },
894 );
894 )?;
895895 ecx.add_goal(
896896 GoalSource::ImplWhereBound,
897897 Goal {
898898 param_env: goal.param_env,
899899 predicate: TraitRef::new(ecx.cx(), sized_trait, [ty]).upcast(ecx.cx()),
900900 },
901 );
901 )?;
902902 // FIXME(field_projections): This function does some questionable incomplete stuff by
903903 // returning `Err(NoSolution)` on ambiguity.
904904 ecx.try_evaluate_added_goals()? == Certainty::Yes
......@@ -1018,7 +1018,7 @@ where
10181018 ecx.add_goals(
10191019 GoalSource::ImplWhereBound,
10201020 b_data.iter().map(|pred| goal.with(cx, pred.with_self_ty(cx, a_ty))),
1021 );
1021 )?;
10221022
10231023 // The type must be `Sized` to be unsized.
10241024 ecx.add_goal(
......@@ -1031,10 +1031,10 @@ where
10311031 [a_ty],
10321032 ),
10331033 ),
1034 );
1034 )?;
10351035
10361036 // 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)))?;
10381038 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
10391039 })
10401040 }
......@@ -1154,7 +1154,7 @@ where
11541154 ecx.add_goal(
11551155 GoalSource::ImplWhereBound,
11561156 Goal::new(ecx.cx(), param_env, ty::OutlivesPredicate(a_region, b_region)),
1157 );
1157 )?;
11581158
11591159 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes).map_err(Into::into)
11601160 })
......@@ -1235,7 +1235,7 @@ where
12351235 [a_tail_ty, b_tail_ty],
12361236 ),
12371237 ),
1238 );
1238 )?;
12391239 self.probe_builtin_trait_candidate(BuiltinImplSource::Misc)
12401240 .enter(|ecx| ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes))
12411241 }
......@@ -1287,14 +1287,15 @@ where
12871287 ty::Dynamic(..)
12881288 | ty::Param(..)
12891289 | 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 )
12941297 | ty::Placeholder(..) => Some(Err(NoSolution.into())),
12951298
1296 ty::Infer(_) | ty::Bound(_, _) => panic!("unexpected type `{self_ty:?}`"),
1297
12981299 // Coroutines have one special built-in candidate, `Unpin`, which
12991300 // takes precedence over the structural auto trait candidate being
13001301 // assembled.
......@@ -1317,7 +1318,7 @@ where
13171318 // okay to consider auto traits because that'll reveal its hidden type. For
13181319 // non-opaque aliases, we will not assemble any candidates since there's no way
13191320 // to further look into its type.
1320 ty::Alias(..) => None,
1321 ty::Alias(ty::IsRigid::Yes, ty::AliasTy { kind: ty::Opaque { .. }, .. }) => None,
13211322
13221323 // For rigid types, any possible implementation that could apply to
13231324 // the type (even if after unification and processing nested goals
......@@ -1347,6 +1348,10 @@ where
13471348 | ty::Adt(_, _)
13481349 | ty::UnsafeBinder(_) => check_impls(),
13491350 ty::Error(_) => None,
1351
1352 ty::Infer(_) | ty::Alias(ty::IsRigid::No, _) | ty::Bound(_, _) => {
1353 panic!("unexpected type `{self_ty:?}`")
1354 }
13501355 }
13511356 }
13521357
......@@ -1375,7 +1380,7 @@ where
13751380 .collect::<Vec<_>>()
13761381 },
13771382 );
1378 ecx.add_goals(GoalSource::ImplWhereBound, goals);
1383 ecx.add_goals(GoalSource::ImplWhereBound, goals)?;
13791384 ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
13801385 })
13811386 }
compiler/rustc_passes/src/check_export.rs+1-1
......@@ -314,7 +314,7 @@ impl<'tcx, 'a> TypeVisitor<TyCtxt<'tcx>> for ExportableItemsChecker<'tcx, 'a> {
314314 | ty::CoroutineWitness(_, _)
315315 | ty::Never
316316 | ty::UnsafeBinder(_)
317 | ty::Alias(ty::AliasTy { kind: ty::AliasTyKind::Opaque { .. }, .. }) => {
317 | ty::Alias(_, ty::AliasTy { kind: ty::AliasTyKind::Opaque { .. }, .. }) => {
318318 return ControlFlow::Break(ty);
319319 }
320320
compiler/rustc_pattern_analysis/src/rustc.rs+4-3
......@@ -126,7 +126,8 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
126126 #[inline]
127127 pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> {
128128 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()
130131 else {
131132 bug!()
132133 };
......@@ -138,7 +139,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
138139 }
139140 RevealedTy(ty)
140141 }
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() {
142143 reveal_inner(self, ty)
143144 } else {
144145 RevealedTy(ty)
......@@ -426,7 +427,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
426427 | ty::CoroutineClosure(..)
427428 | ty::Coroutine(_, _)
428429 | ty::UnsafeBinder(_)
429 | ty::Alias(_)
430 | ty::Alias(_, _)
430431 | ty::Param(_)
431432 | ty::Error(_) => ConstructorSet::Unlistable,
432433 ty::CoroutineWitness(_, _) | ty::Bound(_, _) | ty::Placeholder(_) | ty::Infer(_) => {
compiler/rustc_privacy/src/lib.rs+2-1
......@@ -215,6 +215,7 @@ where
215215 }
216216 }
217217 ty::Alias(
218 _,
218219 data @ ty::AliasTy {
219220 kind:
220221 kind @ (ty::Inherent { def_id }
......@@ -274,7 +275,7 @@ where
274275 try_visit!(self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref));
275276 }
276277 }
277 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
278 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
278279 // Skip repeated `Opaque`s to avoid infinite recursion.
279280 if self.visited_tys.insert(ty) {
280281 // 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> {
487487 ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
488488 fields.iter().map(|ty| ty.stable(tables, cx)).collect(),
489489 )),
490 ty::Alias(alias_ty) => {
490 ty::Alias(_, alias_ty) => {
491491 TyKind::Alias(alias_ty.kind.stable(tables, cx), alias_ty.stable(tables, cx))
492492 }
493493 ty::Param(param_ty) => TyKind::Param(param_ty.stable(tables, cx)),
......@@ -552,7 +552,7 @@ impl<'tcx> Stable<'tcx> for ty::Const<'tcx> {
552552 }
553553 }
554554 ty::ConstKind::Param(param) => crate::ty::TyConstKind::Param(param.stable(tables, cx)),
555 ty::ConstKind::Unevaluated(uv) => {
555 ty::ConstKind::Unevaluated(_, uv) => {
556556 let Some(def_id) = uv.kind.opt_def_id() else {
557557 // FIXME: implement (both AliasTy and UnevaluatedConst will be needing this soon)
558558 panic!(
compiler/rustc_public_bridge/src/builder.rs+1-1
......@@ -38,7 +38,7 @@ impl<'tcx> BodyBuilder<'tcx> {
3838 let mut mono_body = self.instance.instantiate_mir_and_normalize_erasing_regions(
3939 self.tcx,
4040 ty::TypingEnv::fully_monomorphized(),
41 ty::EarlyBinder::bind(body),
41 ty::EarlyBinder::bind(self.tcx, body),
4242 );
4343 self.visit_body(&mut mono_body);
4444 mono_body
compiler/rustc_query_impl/src/handle_cycle_error.rs+4-3
......@@ -43,9 +43,10 @@ pub(crate) fn fn_sig<'tcx>(
4343 unreachable!()
4444 };
4545
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 )
4950}
5051
5152pub(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
252252 );
253253 let term = tcx.normalize_erasing_regions(
254254 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)
256260 );
257 debug!("Projection {:?} -> {term}", projection_term.to_term(tcx),);
258261 ty::ExistentialPredicate::Projection(
259262 ty::ExistentialProjection::erase_self_ty(
260263 tcx,
......@@ -506,7 +509,7 @@ fn implemented_method<'tcx>(
506509 trait_method = assoc;
507510 method_id = trait_method_def_id;
508511 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));
510513 trait_id
511514 } else {
512515 return None;
compiler/rustc_session/src/options.rs+2
......@@ -2654,6 +2654,8 @@ options! {
26542654 remark_dir: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
26552655 "directory into which to write optimization remarks (if not specified, they will be \
26562656written to standard error output)"),
2657 renormalize_rigid_aliases: bool = (false, parse_bool, [TRACKED],
2658 "do not skip rigid aliases in normalization for internal debugging"),
26572659 retpoline: bool = (false, parse_bool, [TRACKED] { TARGET_MODIFIER: Retpoline },
26582660 "enables retpoline-indirect-branches and retpoline-indirect-calls target features (default: no)"),
26592661 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> {
118118 | ty::CoroutineWitness(_, _)
119119 | ty::Never
120120 | ty::Tuple(_)
121 | ty::Alias(_)
121 | ty::Alias(_, _)
122122 | ty::Param(_)
123123 | ty::Bound(_, _)
124124 | ty::Placeholder(_)
compiler/rustc_symbol_mangling/src/legacy.rs+7-6
......@@ -246,11 +246,12 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
246246 match *ty.kind() {
247247 // Print all nominal types as paths (unlike `pretty_print_type`).
248248 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 )
254255 | ty::Closure(def_id, args)
255256 | ty::CoroutineClosure(def_id, args)
256257 | ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
......@@ -272,7 +273,7 @@ impl<'tcx> Printer<'tcx> for LegacySymbolMangler<'tcx> {
272273 Ok(())
273274 }
274275
275 ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
276 ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
276277 panic!("unexpected inherent projection")
277278 }
278279
compiler/rustc_symbol_mangling/src/v0.rs+2-2
......@@ -554,7 +554,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
554554
555555 // We may still encounter projections here due to the printing
556556 // 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, .. }) => {
558558 self.print_def_path(def_id, args)?;
559559 }
560560
......@@ -698,7 +698,7 @@ impl<'tcx> Printer<'tcx> for V0SymbolMangler<'tcx> {
698698
699699 // We may still encounter unevaluated consts due to the printing
700700 // 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 {
702702 ty::UnevaluatedConstKind::Projection { def_id }
703703 | ty::UnevaluatedConstKind::Inherent { def_id }
704704 | 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> {
246246 param_env: ty::ParamEnv<'tcx>,
247247 ) {
248248 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 }, .. }), _) => {
250250 (proj, def_id, found)
251251 }
252 (_, ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })) => {
252 (_, ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. })) => {
253253 (proj, def_id, expected)
254254 }
255255 _ => return,
......@@ -314,7 +314,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
314314 "the associated type `{}` is defined as `{}` in the implementation, \
315315 but the where-bound `{}` shadows this definition\n\
316316 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)),
318318 self.ty_to_string(concrete),
319319 self.ty_to_string(alias.self_ty())
320320 ));
......@@ -1671,7 +1671,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16711671 && values.expected.sort_string(self.tcx)
16721672 != values.found.sort_string(self.tcx);
16731673 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 }, .. })) => {
16751675 let sm = self.tcx.sess.source_map();
16761676 let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo());
16771677 DiagStyledString::normal(format!(
......@@ -1681,9 +1681,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16811681 pos.col.to_usize() + 1,
16821682 ))
16831683 }
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) => {
16871688 let sm = self.tcx.sess.source_map();
16881689 let pos = sm.lookup_char_pos(self.tcx.def_span(def_id).lo());
16891690 DiagStyledString::normal(format!(
......@@ -2519,7 +2520,7 @@ impl TyCategory {
25192520 pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
25202521 match *ty.kind() {
25212522 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 }, .. }) => {
25232524 let kind =
25242525 if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque };
25252526 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> {
10601060 GenericArgKind::Type(ty) => {
10611061 if matches!(
10621062 ty.kind(),
1063 ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. })
1063 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. })
10641064 | ty::Closure(..)
10651065 | ty::CoroutineClosure(..)
10661066 | 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(
162162 TyKind::OpaqueDef(opaque) => {
163163 // Get the identity type for this RPIT
164164 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 );
166171
167172 if let Some(span) = opaque.bounds.iter().find_map(|arg| match arg {
168173 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> {
4646 );
4747 }
4848 (
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 { .. }, .. }),
5151 ) => {
5252 // Issue #63167
5353 diag.note("distinct uses of `impl Trait` result in different opaque types");
......@@ -89,24 +89,28 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
8989 );
9090 }
9191 (
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 ),
100104 ) => {
101105 diag.note("an associated type was expected, but a different one was found");
102106 }
103107 // FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
104108 (
105109 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 }, .. }),
107111 )
108112 | (
109 ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }),
113 ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { def_id }, .. }),
110114 ty::Param(p),
111115 ) if !tcx.is_impl_trait_in_trait(def_id)
112116 && let Some(generics) = body_generics =>
......@@ -229,10 +233,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
229233 }
230234 (
231235 ty::Param(p),
232 ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }),
236 ty::Dynamic(..) | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }),
233237 )
234238 | (
235 ty::Dynamic(..) | ty::Alias(ty::AliasTy { kind: ty::Opaque { .. }, .. }),
239 ty::Dynamic(..) | ty::Alias(_, ty::AliasTy { kind: ty::Opaque { .. }, .. }),
236240 ty::Param(p),
237241 ) => {
238242 if let Some(generics) = body_generics {
......@@ -308,6 +312,7 @@ impl<T> Trait<T> for X {
308312 }
309313 (
310314 ty::Alias(
315 _,
311316 proj_ty @ ty::AliasTy {
312317 kind: ty::Projection { def_id } | ty::Inherent { def_id },
313318 ..
......@@ -328,6 +333,7 @@ impl<T> Trait<T> for X {
328333 (
329334 _,
330335 ty::Alias(
336 _,
331337 proj_ty @ ty::AliasTy {
332338 kind: ty::Projection { def_id } | ty::Inherent { def_id },
333339 ..
......@@ -368,9 +374,10 @@ impl<T> Trait<T> for X {
368374 }
369375 (
370376 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 ),
374381 ) if let Some(def_id) = t.principal_def_id()
375382 && tcx
376383 .explicit_item_self_bounds(opaque_def_id)
......@@ -429,8 +436,8 @@ impl<T> Trait<T> for X {
429436 ));
430437 }
431438 }
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 }, .. }), _) => {
434441 if let Some(body_owner_def_id) = body_owner_def_id
435442 && def_id.is_local()
436443 && matches!(
......@@ -830,7 +837,7 @@ fn foo(&self) -> Self::T { String::new() }
830837 };
831838
832839 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 }, .. }) =
834841 *proj_ty.self_ty().kind()
835842 {
836843 let opaque_local_def_id = def_id.as_local();
......@@ -881,9 +888,10 @@ fn foo(&self) -> Self::T { String::new() }
881888 .filter_map(|item| {
882889 let method = tcx.fn_sig(item.def_id).instantiate_identity().skip_norm_wip();
883890 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((
887895 tcx.def_span(item.def_id),
888896 format!("consider calling `{}`", tcx.def_path_str(item.def_id)),
889897 )),
compiler/rustc_trait_selection/src/error_reporting/infer/region.rs+6-1
......@@ -1278,7 +1278,12 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
12781278 let tcx = infcx.tcx;
12791279 let mut err = infcx.dcx().create_err(diagnostics::OpaqueCapturesLifetime {
12801280 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 ),
12821287 opaque_ty_span: tcx.def_span(opaque_ty_key.def_id),
12831288 });
12841289
compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs+14-12
......@@ -769,20 +769,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
769769 StatementAsExpression::CorrectType
770770 }
771771 (
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 }, .. }),
774774 ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType,
775775 (
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 ),
786788 ) => {
787789 debug!(
788790 "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;
66use rustc_hir::def_id::DefId;
77use rustc_hir::{LangItem, lang_items};
88use rustc_middle::ty::{
9 AssocContainer, GenericArgsRef, Instance, Ty, TyCtxt, TypingEnv, Unnormalized,
9 self, AssocContainer, GenericArgsRef, Instance, Ty, TyCtxt, TypingEnv, Unnormalized,
1010};
1111use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, sym};
1212use tracing::debug;
......@@ -104,7 +104,12 @@ pub fn call_kind<'tcx>(
104104 tcx.get_diagnostic_item(sym::deref_target).expect("deref method but no deref target");
105105 let deref_target_ty = tcx.normalize_erasing_regions(
106106 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 )),
108113 );
109114 let deref_target_span = if let Ok(Some(instance)) =
110115 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> {
16121612 infer::BoundRegionConversionTime::HigherRankedType,
16131613 bound_predicate.rebind(data),
16141614 );
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);
16161616 // FIXME(-Znext-solver): For diagnostic purposes, it would be nice
16171617 // to deeply normalize this type.
16181618 let normalized_term = ocx.normalize(
......@@ -1651,7 +1651,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16511651 let normalized_term = ocx.normalize(
16521652 &ObligationCause::dummy(),
16531653 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 ),
16551657 );
16561658
16571659 if let Err(terr) = ocx.eq(
......@@ -1919,10 +1921,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19191921 ty::Closure(..) => Some(9),
19201922 ty::Tuple(..) => Some(10),
19211923 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),
19261928 ty::Never => Some(16),
19271929 ty::Adt(..) => Some(17),
19281930 ty::Coroutine(..) => Some(18),
......@@ -2147,7 +2149,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21472149 let impl_trait_ref = ocx.normalize(
21482150 &ObligationCause::dummy(),
21492151 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),
21512154 );
21522155
21532156 ocx.register_obligations(
......@@ -2805,12 +2808,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
28052808 self.infcx.tcx
28062809 }
28072810
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.
28082814 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),
28142831 }
28152832 }
28162833 }
......@@ -3752,7 +3769,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
37523769
37533770 match obligation.predicate.kind().skip_binder() {
37543771 ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => match ct.kind() {
3755 ty::ConstKind::Unevaluated(uv) => {
3772 ty::ConstKind::Unevaluated(_, uv) => {
37563773 let mut err =
37573774 self.dcx().struct_span_err(span, "unconstrained generic constant");
37583775 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> {
476476 let self_ty = trait_pred.skip_binder().self_ty();
477477 let (param_ty, projection) = match *self_ty.kind() {
478478 ty::Param(_) => (true, None),
479 ty::Alias(alias) => {
479 ty::Alias(_, alias) => {
480480 if let Some(projection) = alias.try_to_projection() {
481481 (false, Some(projection))
482482 } else {
......@@ -1484,7 +1484,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
14841484 sig_parts.map_bound(|sig| sig.tupled_inputs_ty.tuple_fields().as_slice()),
14851485 ))
14861486 }
1487 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
1487 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
14881488 self.tcx
14891489 .item_self_bounds(def_id)
14901490 .instantiate(self.tcx, args)
......@@ -4051,7 +4051,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
40514051 }
40524052 }
40534053 }
4054 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
4054 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
40554055 // If the previous type is async fn, this is the future generated by the body of an async function.
40564056 // Avoid printing it twice (it was already printed in the `ty::Coroutine` arm below).
40574057 let is_future = tcx.ty_is_opaque_future(ty);
......@@ -4534,6 +4534,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45344534 let projection_ty = trait_pred.map_bound(|trait_pred| {
45354535 Ty::new_projection(
45364536 self.tcx,
4537 ty::IsRigid::No,
45374538 item_def_id,
45384539 // Future::Output has no args
45394540 [trait_pred.self_ty()],
......@@ -4878,7 +4879,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
48784879 .skip_binder()
48794880 .projection_term
48804881 .expect_ty()
4881 .to_ty(self.tcx),
4882 .to_ty(self.tcx, ty::IsRigid::No),
48824883 found,
48834884 })];
48844885 }
......@@ -4976,7 +4977,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
49764977
49774978 // Extract `<U as Deref>::Target` assoc type and check that it is `T`
49784979 && 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)]))
49804981 && let InferOk { value: deref_target, obligations } = infcx.at(&ObligationCause::dummy(), param_env).normalize(Unnormalized::new_wip(projection))
49814982 && obligations.iter().all(|obligation| infcx.predicate_must_hold_modulo_regions(obligation))
49824983 && infcx.can_eq(param_env, deref_target, target_ty)
......@@ -5338,7 +5339,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
53385339 let TypeError::Sorts(expected_found) = diff else {
53395340 continue;
53405341 };
5341 let &ty::Alias(ty::AliasTy { kind: kind @ ty::Projection { def_id }, .. }) =
5342 let &ty::Alias(_, ty::AliasTy { kind: kind @ ty::Projection { def_id }, .. }) =
53425343 expected_found.expected.kind()
53435344 else {
53445345 continue;
......@@ -5666,7 +5667,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
56665667 }
56675668
56685669 // 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 }, .. }) =
56705671 trait_pred.self_ty().skip_binder().kind()
56715672 else {
56725673 return;
compiler/rustc_trait_selection/src/opaque_types.rs+1-1
......@@ -225,7 +225,7 @@ pub fn report_item_does_not_constrain_error<'tcx>(
225225 err.note("consider removing `#[define_opaque]` or adding an empty `#[define_opaque()]`");
226226 err.span_note(opaque_type_span, "this opaque type is supposed to be constrained");
227227 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);
229229 err.span_note(
230230 span,
231231 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<
220220 param_env: ty::ParamEnv<'tcx>,
221221 uv: ty::UnevaluatedConst<'tcx>,
222222 ) -> 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);
224224
225225 match crate::traits::try_evaluate_const(&self.0, ct, param_env) {
226226 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>(
3434 }
3535 ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, expected_ty)) => {
3636 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(),
3838 ty::ConstKind::Param(param_ct) => {
3939 param_ct.find_const_ty_from_env(obligation.param_env)
4040 }
......@@ -300,7 +300,7 @@ impl<'tcx> BestObligation<'tcx> {
300300 ) -> ControlFlow<PredicateObligation<'tcx>> {
301301 assert!(!self.consider_ambiguities);
302302 let tcx = goal.infcx().tcx;
303 if let ty::Alias(alias) = *self_ty.kind() {
303 if let ty::Alias(_, alias) = *self_ty.kind() {
304304 let infer_term = goal.infcx().next_ty_var(self.obligation.cause.span);
305305 let pred =
306306 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> {
151151 self.final_state,
152152 );
153153
154 return eager_resolve_vars(infcx, impl_args);
154 return eager_resolve_vars(&**infcx, impl_args);
155155 }
156156 inspect::ProbeStep::AddGoal(..) => {}
157157 inspect::ProbeStep::MakeCanonicalResponse { .. }
......@@ -331,7 +331,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
331331 infcx,
332332 depth,
333333 orig_values,
334 goal: eager_resolve_vars(infcx, uncanonicalized_goal),
334 goal: eager_resolve_vars(&**infcx, uncanonicalized_goal),
335335 result,
336336 final_revision,
337337 source,
compiler/rustc_trait_selection/src/solve/normalize.rs+38-25
......@@ -9,7 +9,7 @@ use rustc_middle::ty::{
99 self, Binder, Flags, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
1010 UniverseIndex, Unnormalized,
1111};
12use rustc_next_trait_solver::normalize::NormalizationFolder;
12use rustc_next_trait_solver::normalize::{NormalizationFolder, NormalizationWasAmbiguous};
1313use rustc_next_trait_solver::solve::SolverDelegateEvalExt;
1414
1515use super::{FulfillmentCtxt, NextSolverError};
......@@ -42,26 +42,34 @@ where
4242 let infcx = at.infcx;
4343 let value = value.skip_normalization();
4444 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
4550 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 });
6271 if let Ok(value) = value.try_fold_with(&mut folder) {
63 let obligations = folder
64 .stalled_goals()
72 let obligations = stalled_goals
6573 .into_iter()
6674 .map(|goal| {
6775 Obligation::new(infcx.tcx, at.cause.clone(), goal.param_env, goal.predicate)
......@@ -84,8 +92,7 @@ struct ReplaceAliasWithInfer<'me, 'tcx> {
8492impl<'me, 'tcx> ReplaceAliasWithInfer<'me, 'tcx> {
8593 fn term_to_infer(&mut self, alias_term: ty::AliasTerm<'tcx>) -> ty::Term<'tcx> {
8694 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);
8996 let obligation = Obligation::new(
9097 infcx.tcx,
9198 self.at.cause.clone(),
......@@ -113,12 +120,15 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> {
113120 }
114121
115122 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() {
117124 return ty;
118125 }
119126
120127 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 }
122132
123133 if ty.has_escaping_bound_vars() {
124134 let (replaced, ..) =
......@@ -131,12 +141,15 @@ impl<'me, 'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAliasWithInfer<'me, 'tcx> {
131141 }
132142
133143 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() {
135145 return ct;
136146 }
137147
138148 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 }
140153
141154 if ct.has_escaping_bound_vars() {
142155 let (replaced, ..) =
compiler/rustc_trait_selection/src/traits/auto_trait.rs+3-3
......@@ -552,7 +552,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
552552 pub fn is_of_param(&self, ty: Ty<'tcx>) -> bool {
553553 match ty.kind() {
554554 ty::Param(_) => true,
555 ty::Alias(p @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
555 ty::Alias(_, p @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
556556 self.is_of_param(p.self_ty())
557557 }
558558 _ => false,
......@@ -561,7 +561,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
561561
562562 fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool {
563563 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())
565565 } else {
566566 false
567567 }
......@@ -768,7 +768,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
768768 }
769769 ty::PredicateKind::ConstEquate(c1, c2) => {
770770 let evaluate = |c: ty::Const<'tcx>| {
771 if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
771 if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() {
772772 let ct =
773773 super::try_evaluate_const(selcx.infcx, c, obligation.param_env);
774774
compiler/rustc_trait_selection/src/traits/coherence.rs+1-1
......@@ -542,7 +542,7 @@ fn impl_intersection_has_negative_obligation(
542542 // So there are no infer variables left now, except regions which aren't resolved by `resolve_vars_if_possible`.
543543 assert!(!impl1_header_args.has_non_region_infer());
544544
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))
546546 .instantiate(tcx, impl1_header_args)
547547 .skip_norm_wip();
548548
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs+7-7
......@@ -30,7 +30,7 @@ pub fn is_const_evaluatable<'tcx>(
3030) -> Result<(), NotConstEvaluatable> {
3131 let tcx = infcx.tcx;
3232 match tcx.expand_abstract_consts(unexpanded_ct).kind() {
33 ty::ConstKind::Unevaluated(_) | ty::ConstKind::Expr(_) => (),
33 ty::ConstKind::Unevaluated(_, _) | ty::ConstKind::Expr(_) => (),
3434 ty::ConstKind::Param(_)
3535 | ty::ConstKind::Bound(_, _)
3636 | ty::ConstKind::Placeholder(_)
......@@ -44,10 +44,10 @@ pub fn is_const_evaluatable<'tcx>(
4444
4545 let is_anon_ct = matches!(
4646 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 )
5151 );
5252
5353 if !is_anon_ct {
......@@ -69,7 +69,7 @@ pub fn is_const_evaluatable<'tcx>(
6969 // here.
7070 tcx.dcx().span_bug(span, "evaluating `ConstKind::Expr` is not currently supported");
7171 }
72 ty::ConstKind::Unevaluated(_) => {
72 ty::ConstKind::Unevaluated(_, _) => {
7373 match crate::traits::try_evaluate_const(infcx, unexpanded_ct, param_env) {
7474 Err(EvaluateConstErr::HasGenericsOrInfers) => {
7575 Err(NotConstEvaluatable::Error(infcx.dcx().span_delayed_bug(
......@@ -94,7 +94,7 @@ pub fn is_const_evaluatable<'tcx>(
9494 Ok(())
9595 } else {
9696 let uv = match unexpanded_ct.kind() {
97 ty::ConstKind::Unevaluated(uv) => uv,
97 ty::ConstKind::Unevaluated(_, uv) => uv,
9898 ty::ConstKind::Expr(_) => {
9999 bug!("`ConstKind::Expr` without `feature(generic_const_exprs)` enabled")
100100 }
compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs+12-9
......@@ -604,7 +604,7 @@ fn receiver_for_self_ty<'tcx>(
604604 if param.index == 0 { self_ty.into() } else { tcx.mk_param_from_def(param) }
605605 });
606606
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();
608608 debug!(
609609 "receiver_for_self_ty({:?}, {:?}, {:?}) = {:?}",
610610 receiver_ty, self_ty, method_def_id, result
......@@ -859,13 +859,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
859859 ControlFlow::Continue(())
860860 }
861861 }
862 ty::Alias(ty::AliasTy { kind: ty::Projection { def_id }, .. })
862 ty::Alias(_, ty::AliasTy { kind: ty::Projection { def_id }, .. })
863863 if self.tcx.is_impl_trait_in_trait(*def_id) =>
864864 {
865865 // We'll deny these later in their own pass
866866 ControlFlow::Continue(())
867867 }
868 ty::Alias(proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
868 ty::Alias(_, proj @ ty::AliasTy { kind: ty::Projection { .. }, .. }) => {
869869 match self.allow_self_projections {
870870 AllowSelfProjections::Yes => {
871871 // Only walk contained types if the parent trait is not a supertrait.
......@@ -886,11 +886,14 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalSelfTypeVisitor<'tcx> {
886886 let ct = self.tcx.expand_abstract_consts(ct);
887887
888888 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() => {
894897 match self.allow_self_projections {
895898 AllowSelfProjections::Yes => {
896899 let trait_def_id = self.tcx.parent(def_id);
......@@ -966,7 +969,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IllegalRpititVisitor<'tcx> {
966969 type Result = ControlFlow<MethodViolation>;
967970
968971 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()
970973 && Some(proj) != self.allowed
971974 && self.tcx.is_impl_trait_in_trait(def_id)
972975 {
compiler/rustc_trait_selection/src/traits/effects.rs+3-1
......@@ -179,6 +179,7 @@ fn evaluate_host_effect_from_conditionally_const_item_bounds<'tcx>(
179179
180180 let mut consider_ty = obligation.predicate.self_ty();
181181 while let ty::Alias(
182 _,
182183 alias_ty @ ty::AliasTy {
183184 kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }),
184185 ..
......@@ -274,6 +275,7 @@ fn evaluate_host_effect_from_item_bounds<'tcx>(
274275
275276 let mut consider_ty = obligation.predicate.self_ty();
276277 while let ty::Alias(
278 _,
277279 alias_ty @ ty::AliasTy {
278280 kind: kind @ (ty::Projection { def_id } | ty::Opaque { def_id }),
279281 ..
......@@ -376,7 +378,7 @@ fn evaluate_host_effect_for_copy_clone_goal<'tcx>(
376378 | ty::Foreign(..)
377379 | ty::Ref(_, _, ty::Mutability::Mut)
378380 | ty::Adt(_, _)
379 | ty::Alias(_)
381 | ty::Alias(_, _)
380382 | ty::Param(_)
381383 | ty::Placeholder(..) => Err(EvaluationFailure::NoSolution),
382384
compiler/rustc_trait_selection/src/traits/fulfill.rs+13-11
......@@ -559,7 +559,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
559559 return ProcessResult::Changed(PendingPredicateObligations::new());
560560 }
561561 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(),
563563 // FIXME(generic_const_exprs): we should construct an alias like
564564 // `<lhs_ty as Add<rhs_ty>>::Output` when this is an `Expr` representing
565565 // `lhs + rhs`.
......@@ -717,13 +717,15 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
717717 debug!("equating consts:\nc1= {:?}\nc2= {:?}", c1, c2);
718718
719719 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 ) =>
727729 {
728730 if let Ok(new_obligations) = infcx
729731 .at(&obligation.cause, obligation.param_env)
......@@ -741,8 +743,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
741743 ));
742744 }
743745 }
744 (_, ty::ConstKind::Unevaluated(_))
745 | (ty::ConstKind::Unevaluated(_), _) => (),
746 (_, ty::ConstKind::Unevaluated(_, _))
747 | (ty::ConstKind::Unevaluated(_, _), _) => (),
746748 (_, _) => {
747749 if let Ok(new_obligations) = infcx
748750 .at(&obligation.cause, obligation.param_env)
......@@ -762,7 +764,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
762764 let stalled_on = &mut pending_obligation.stalled_on;
763765
764766 let mut evaluate = |c: Const<'tcx>| {
765 if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() {
767 if let ty::ConstKind::Unevaluated(_, unevaluated) = c.kind() {
766768 match super::try_evaluate_const(
767769 self.selcx.infcx,
768770 c,
compiler/rustc_trait_selection/src/traits/mod.rs+8-3
......@@ -280,6 +280,9 @@ fn do_normalize_predicates<'tcx>(
280280 let infcx = tcx.infer_ctxt().ignoring_regions().build(TypingMode::non_body_analysis());
281281 let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
282282 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();
283286
284287 let errors = ocx.evaluate_obligations_error_on_ambiguity();
285288 if !errors.is_empty() {
......@@ -366,7 +369,7 @@ pub fn normalize_param_env_or_error<'tcx>(
366369 // should actually be okay since without `feature(generic_const_exprs)` the only
367370 // const arguments that have a non-empty param env are array repeat counts. These
368371 // 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()
370373 && matches!(uv.kind, ty::UnevaluatedConstKind::Anon { .. })
371374 {
372375 let infcx = self.0.infer_ctxt().build(TypingMode::non_body_analysis());
......@@ -605,7 +608,7 @@ pub fn try_evaluate_const<'tcx>(
605608 | ty::ConstKind::Bound(_, _)
606609 | ty::ConstKind::Placeholder(_)
607610 | ty::ConstKind::Expr(_) => Err(EvaluateConstErr::HasGenericsOrInfers),
608 ty::ConstKind::Unevaluated(uv) => {
611 ty::ConstKind::Unevaluated(_, uv) => {
609612 let opt_anon_const_kind = match uv.kind {
610613 ty::UnevaluatedConstKind::Anon { def_id } => {
611614 Some((def_id, tcx.anon_const_kind(def_id)))
......@@ -923,7 +926,9 @@ fn is_impossible_associated_item(
923926 tcx,
924927 ObligationCause::dummy_with_span(*span),
925928 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(),
927932 )
928933 })
929934 });
compiler/rustc_trait_selection/src/traits/normalize.rs+10-4
......@@ -229,7 +229,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
229229 )
230230 .ok()
231231 .flatten()
232 .unwrap_or_else(|| proj.to_term(infcx.tcx));
232 .unwrap_or_else(|| proj.to_term(infcx.tcx, ty::IsRigid::No));
233233
234234 PlaceholderReplacer::replace_placeholders(
235235 infcx,
......@@ -391,11 +391,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
391391 }
392392
393393 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
394397 if !needs_normalization(self.selcx.infcx, &ty) {
395398 return ty;
396399 }
397400
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) };
399402
400403 // We try to be a little clever here as a performance optimization in
401404 // cases where there are nested projections under binders.
......@@ -459,18 +462,21 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
459462
460463 #[instrument(skip(self), level = "debug")]
461464 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
462468 let tcx = self.selcx.tcx();
463469
464470 if tcx.features().generic_const_exprs()
465471 // 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))
467473 || !needs_normalization(self.selcx.infcx, &ct)
468474 {
469475 return ct;
470476 }
471477
472478 let uv = match ct.kind() {
473 ty::ConstKind::Unevaluated(uv) => uv,
479 ty::ConstKind::Unevaluated(_, uv) => uv,
474480 _ => return ct.super_fold_with(self),
475481 };
476482
compiler/rustc_trait_selection/src/traits/project.rs+7-5
......@@ -738,7 +738,7 @@ fn project<'cx, 'tcx>(
738738 }
739739 ProjectionCandidateSet::None => {
740740 let tcx = selcx.tcx();
741 let term = obligation.predicate.to_term(tcx);
741 let term = obligation.predicate.to_term(tcx, ty::IsRigid::No);
742742 Ok(Projected::NoProgress(term))
743743 }
744744 // Error occurred while trying to processing impls.
......@@ -1583,7 +1583,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
15831583 } else {
15841584 // We know that `self_ty` has the same metadata as `tail`. This allows us
15851585 // 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])
15871587 }
15881588 });
15891589 (metadata_ty.into(), obligations)
......@@ -1678,6 +1678,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
16781678 tcx.require_lang_item(LangItem::AsyncFnKindUpvars, obligation.cause.span);
16791679 let tupled_upvars_ty = Ty::new_projection(
16801680 tcx,
1681 ty::IsRigid::No,
16811682 upvars_projection_def_id,
16821683 [
16831684 ty::GenericArg::from(kind_ty),
......@@ -1807,6 +1808,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18071808 // N.B. No need to register a `AsyncFnKindHelper` goal here, it's already in `nested`.
18081809 let tupled_upvars_ty = Ty::new_projection(
18091810 tcx,
1811 ty::IsRigid::No,
18101812 upvars_projection_def_id,
18111813 [
18121814 ty::GenericArg::from(kind_ty),
......@@ -1855,7 +1857,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18551857 sym::Output => {
18561858 let future_output_def_id =
18571859 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()])
18591861 }
18601862 name => bug!("no such associated type: {name}"),
18611863 };
......@@ -1889,7 +1891,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>(
18891891 sym::Output => {
18901892 let future_output_def_id =
18911893 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()])
18931895 }
18941896 name => bug!("no such associated type: {name}"),
18951897 };
......@@ -2058,7 +2060,7 @@ fn confirm_impl_candidate<'cx, 'tcx>(
20582060 // `Projected::NoProgress`. This will ensure that the projection is
20592061 // checked for well-formedness, and it's either satisfied by a trivial
20602062 // 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)));
20622064 } else {
20632065 return Ok(Projected::Progress(Progress {
20642066 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>(
391391 constraints.dtorck_types.extend(
392392 dtorck_types
393393 .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()),
395395 );
396396 constraints.outlives.extend(
397397 outlives
398398 .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()),
400400 );
401401 constraints.overflows.extend(
402402 overflows
403403 .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()),
405405 );
406406 }
407407
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> {
203203 return Ok(*ty);
204204 }
205205
206 let &ty::Alias(data) = ty.kind() else {
206 let &ty::Alias(_, data) = ty.kind() else {
207207 let res = ty.try_super_fold_with(self)?;
208208 self.cache.insert(ty, res);
209209 return Ok(res);
......@@ -273,7 +273,7 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
273273 }
274274
275275 let uv = match constant.kind() {
276 ty::ConstKind::Unevaluated(uv) => uv,
276 ty::ConstKind::Unevaluated(_, uv) => uv,
277277 _ => return constant.try_super_fold_with(self),
278278 };
279279
......@@ -377,7 +377,7 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> {
377377 // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer
378378 // of type/const and we need to continue folding it to reveal the TAIT behind it
379379 // or further normalize nested unevaluated consts.
380 if res != term.to_term(tcx)
380 if res != term.to_term(tcx, ty::IsRigid::No)
381381 && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
382382 || matches!(
383383 term.kind,
compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs+10-7
......@@ -194,7 +194,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
194194 // quickly check if the self-type is a projection at all.
195195 match obligation.predicate.skip_binder().trait_ref.self_ty().kind() {
196196 // 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 { .. }, .. }) => {}
198198 ty::Infer(ty::TyVar(_)) => {
199199 span_bug!(
200200 obligation.cause.span,
......@@ -681,7 +681,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
681681 // These may potentially implement `FnPtr`
682682 ty::Placeholder(..)
683683 | ty::Dynamic(_, _)
684 | ty::Alias(_)
684 | ty::Alias(_, _)
685685 | ty::Infer(_)
686686 | ty::Param(..)
687687 | ty::Bound(_, _) => {}
......@@ -784,10 +784,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
784784 }
785785 }
786786 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 )
791794 | ty::Placeholder(..)
792795 | ty::Bound(..) => {
793796 // In these cases, we don't know what the actual
......@@ -838,7 +841,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
838841 );
839842 }
840843
841 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
844 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. }) => {
842845 if candidates.vec.iter().any(|c| matches!(c, ProjectionCandidate { .. })) {
843846 // We do not generate an auto impl candidate for `impl Trait`s which already
844847 // 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> {
882882 );
883883
884884 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 ) =>
892894 {
893895 if let Ok(InferOk { obligations, value: () }) = self
894896 .infcx
......@@ -907,8 +909,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
907909 );
908910 }
909911 }
910 (_, ty::ConstKind::Unevaluated(_))
911 | (ty::ConstKind::Unevaluated(_), _) => (),
912 (_, ty::ConstKind::Unevaluated(_, _))
913 | (ty::ConstKind::Unevaluated(_, _), _) => (),
912914 (_, _) => {
913915 if let Ok(InferOk { obligations, value: () }) = self
914916 .infcx
......@@ -927,7 +929,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
927929 }
928930
929931 let evaluate = |c: ty::Const<'tcx>| {
930 if let ty::ConstKind::Unevaluated(_) = c.kind() {
932 if let ty::ConstKind::Unevaluated(_, _) = c.kind() {
931933 match crate::traits::try_evaluate_const(
932934 self.infcx,
933935 c,
......@@ -987,7 +989,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
987989 }
988990 ty::ConstKind::Error(_) => return Ok(EvaluatedToOk),
989991 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(),
991993 // FIXME(generic_const_exprs): See comment in `fulfill.rs`
992994 ty::ConstKind::Expr(_) => return Ok(EvaluatedToOk),
993995 ty::ConstKind::Placeholder(_) => {
......@@ -1658,6 +1660,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16581660 loop {
16591661 let (alias_ty, def_id) = match *self_ty.kind() {
16601662 ty::Alias(
1663 _,
16611664 alias_ty @ ty::AliasTy {
16621665 kind: ty::Projection { def_id } | ty::Opaque { def_id },
16631666 ..
......@@ -2348,10 +2351,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
23482351 ty::Placeholder(..)
23492352 | ty::Dynamic(..)
23502353 | 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 )
23552361 | ty::Bound(..)
23562362 | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
23572363 bug!("asked to assemble constituent types of unexpected type: {:?}", t);
......@@ -2420,7 +2426,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24202426 assumptions: vec![],
24212427 }),
24222428
2423 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
2429 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
24242430 if self.infcx.can_define_opaque_ty(def_id) {
24252431 unreachable!()
24262432 } else {
compiler/rustc_trait_selection/src/traits/structural_normalize.rs+6-1
......@@ -41,11 +41,16 @@ impl<'tcx> At<'_, 'tcx> {
4141
4242 if self.infcx.next_trait_solver() {
4343 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
4449 let Some(alias) = term.to_alias_term() else {
4550 return Ok(term);
4651 };
4752
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);
4954
5055 // We simply emit an `Projection` goal here, since that will take care of
5156 // 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>(
284284 };
285285
286286 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()
288288 && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(def_id)
289289 && let Some(impl_item) =
290290 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> {
801801 // Simple cases that are WF if their type args are WF.
802802 }
803803
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 ) => {
809812 let obligations = self.nominal_obligations(def_id, args);
810813 self.out.extend(obligations);
811814 }
812 ty::Alias(data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
815 ty::Alias(_, data @ ty::AliasTy { kind: ty::Inherent { .. }, .. }) => {
813816 self.add_wf_preds_for_inherent_projection(data.into());
814817 return; // Subtree handled by compute_inherent_projection.
815818 }
......@@ -1061,7 +1064,7 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
10611064 let tcx = self.tcx();
10621065
10631066 match c.kind() {
1064 ty::ConstKind::Unevaluated(uv) => {
1067 ty::ConstKind::Unevaluated(_, uv) => {
10651068 if !c.has_escaping_bound_vars() {
10661069 // Skip type consts as mGCA doesn't support evaluatable clauses
10671070 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>(
3838
3939 let assumptions = compute_assumptions(tcx, def_id, bound_tys);
4040
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 )
4548}
4649
4750fn compute_assumptions<'tcx>(
compiler/rustc_ty_utils/src/consts.rs+2-2
......@@ -75,7 +75,7 @@ fn recurse_build<'tcx>(
7575 ty::UnevaluatedConstKind::new_from_def_id(tcx, def_id),
7676 args,
7777 );
78 ty::Const::new_unevaluated(tcx, uneval)
78 ty::Const::new_unevaluated(tcx, ty::IsRigid::No, uneval)
7979 }
8080 ExprKind::ConstParam { param, .. } => ty::Const::new_param(tcx, *param),
8181
......@@ -385,7 +385,7 @@ fn thir_abstract_const<'tcx>(
385385
386386 let root_span = body.exprs[body_id].span;
387387
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)?)))
389389}
390390
391391pub(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<'
116116 tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip().args,
117117 );
118118 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))
120120 .iter_instantiated_copied(tcx, args)
121121 .map(Unnormalized::skip_norm_wip)
122122 .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>(
3939 tcx: TyCtxt<'tcx>,
4040 query: ty::PseudoCanonicalInput<'tcx, Ty<'tcx>>,
4141) -> 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);
4444
4545 // Optimization: We convert to TypingMode::PostAnalysis and convert opaque types in
4646 // the where bounds to their hidden types. This reduces overall uncached invocations
4747 // 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 };
5056
5157 // FIXME: We might want to have two different versions of `layout_of`:
5258 // One that can be called after typecheck has completed and can use
5359 // `normalize_erasing_regions` here and another one that can be called
5460 // 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) {
5662 Ok(t) => t,
5763 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 )));
6168 }
6269 };
6370
64 if ty != unnormalized_ty {
71 if normalized_ty != original_ty {
6572 // 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));
6774 }
6875
6976 match typing_env.typing_mode() {
7077 ty::TypingMode::Codegen => {
7178 let with_postanalysis =
7279 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));
7481 match res {
7582 Err(LayoutError::TooGeneric(_)) => {}
7683 _ => return res,
......@@ -86,8 +93,8 @@ fn layout_of<'tcx>(
8693
8794 let cx = LayoutCx::new(tcx, typing_env);
8895
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 };
9198
9299 // If we are running with `-Zprint-type-sizes`, maybe record layouts
93100 // for dumping later.
......@@ -170,7 +177,7 @@ fn extract_const_value<'tcx>(
170177 }
171178 Err(error(cx, LayoutError::TooGeneric(ty)))
172179 }
173 ty::ConstKind::Unevaluated(_) => {
180 ty::ConstKind::Unevaluated(_, _) => {
174181 let err = if ct.has_param() {
175182 LayoutError::TooGeneric(ty)
176183 } else {
......@@ -437,7 +444,8 @@ fn layout_of_uncached<'tcx>(
437444 }
438445
439446 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]);
441449 let metadata_ty = match tcx.try_normalize_erasing_regions(
442450 cx.typing_env,
443451 Unnormalized::new_wip(pointee_metadata),
......@@ -557,7 +565,7 @@ fn layout_of_uncached<'tcx>(
557565 .field_tys
558566 .iter()
559567 .map(|local| {
560 let field_ty = EarlyBinder::bind(local.ty);
568 let field_ty = EarlyBinder::bind(tcx, local.ty);
561569 let uninit_ty =
562570 Ty::new_maybe_uninit(tcx, field_ty.instantiate(tcx, args).skip_norm_wip());
563571 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
222222 for field_ty in &witness.field_tys {
223223 queue_type(
224224 self,
225 EarlyBinder::bind(field_ty.ty)
225 EarlyBinder::bind(tcx, field_ty.ty)
226226 .instantiate(tcx, args)
227227 .skip_norm_wip(),
228228 );
......@@ -374,7 +374,9 @@ fn drop_tys_helper<'tcx>(
374374 match subty.kind() {
375375 ty::Adt(adt_id, args) => {
376376 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 );
378380 }
379381 }
380382 _ => 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> {
210210 fn visit_ty(&mut self, t: Ty<'tcx>) {
211211 t.super_visit_with(self);
212212 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 }, .. })
214214 if def_id.is_local() =>
215215 {
216216 self.visit_opaque_ty(alias_ty);
217217 }
218218 // Skips type aliases, as they are meant to be transparent.
219219 // 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, .. })
221221 if let Some(def_id) = def_id.as_local() =>
222222 {
223223 if !self.seen.insert(def_id) {
......@@ -230,6 +230,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
230230 .visit_with(self);
231231 }
232232 ty::Alias(
233 _,
233234 alias_ty @ ty::AliasTy { kind: ty::Projection { def_id: alias_def_id }, .. },
234235 ) => {
235236 // This avoids having to do normalization of `Self::AssocTy` by only
......@@ -299,7 +300,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
299300 .type_of(alias_def_id)
300301 .instantiate(self.tcx, alias_ty.args)
301302 .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 { .. }, .. }) =
303304 *ty.kind()
304305 else {
305306 bug!("{ty:?}")
compiler/rustc_ty_utils/src/ty.rs+3-3
......@@ -144,7 +144,7 @@ fn adt_sizedness_constraint<'tcx>(
144144 return None;
145145 }
146146
147 Some(ty::EarlyBinder::bind(constraint_ty))
147 Some(ty::EarlyBinder::bind(tcx, constraint_ty))
148148}
149149
150150/// See `ParamEnv` struct definition for details.
......@@ -223,7 +223,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
223223 }
224224
225225 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()
227227 && let Some(unshifted_alias_ty) = unshifted_alias_ty.try_to_projection()
228228 && let Some(
229229 ty::ImplTraitInTraitData::Trait { fn_def_id, .. }
......@@ -387,7 +387,7 @@ fn impl_self_is_guaranteed_unsized<'tcx>(tcx: TyCtxt<'tcx>, impl_def_id: DefId)
387387 | ty::CoroutineWitness(_, _)
388388 | ty::Never
389389 | ty::Tuple(_)
390 | ty::Alias(_)
390 | ty::Alias(_, _)
391391 | ty::Param(_)
392392 | ty::Bound(_, _)
393393 | ty::Placeholder(_)
compiler/rustc_type_ir/src/binder.rs+38-2
......@@ -369,11 +369,33 @@ generate!(
369369 impl<I: Interner, T> !TypeVisitable<I> for ty::EarlyBinder<I, T> {}
370370);
371371
372impl<I: Interner, T> EarlyBinder<I, T> {
373 pub fn bind(value: T) -> EarlyBinder<I, T> {
372impl<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();
374376 EarlyBinder { value, _tcx: PhantomData }
375377 }
378}
379
380impl<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 }
376386
387 EarlyBinder { value, _tcx: PhantomData }
388 }
389}
390
391impl<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
398impl<I: Interner, T> EarlyBinder<I, T> {
377399 pub fn as_ref(&self) -> EarlyBinder<I, &T> {
378400 EarlyBinder { value: &self.value, _tcx: PhantomData }
379401 }
......@@ -523,6 +545,14 @@ pub struct IterInstantiatedCopied<'a, I: Interner, Iter: IntoIterator> {
523545 args: &'a [I::GenericArg],
524546}
525547
548impl<'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
526556impl<I: Interner, Iter: IntoIterator> Iterator for IterInstantiatedCopied<'_, I, Iter>
527557where
528558 Iter::Item: Deref,
......@@ -567,6 +597,12 @@ pub struct IterIdentityCopied<I: Interner, Iter: IntoIterator> {
567597 _tcx: PhantomData<fn() -> I>,
568598}
569599
600impl<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
570606impl<I: Interner, Iter: IntoIterator> Iterator for IterIdentityCopied<I, Iter>
571607where
572608 Iter::Item: Deref,
compiler/rustc_type_ir/src/const_kind.rs+2-2
......@@ -34,7 +34,7 @@ pub enum ConstKind<I: Interner> {
3434 /// An unnormalized const item such as an anon const or assoc const or free const item.
3535 /// Right now anything other than anon consts does not actually work properly but this
3636 /// should
37 Unevaluated(ty::UnevaluatedConst<I>),
37 Unevaluated(ty::IsRigid, ty::UnevaluatedConst<I>),
3838
3939 /// Used to hold computed value.
4040 Value(I::ValueConst),
......@@ -59,7 +59,7 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
5959 Infer(var) => write!(f, "{var:?}"),
6060 Bound(debruijn, var) => crate::debug_bound_var(f, *debruijn, var),
6161 Placeholder(placeholder) => write!(f, "{placeholder:?}"),
62 Unevaluated(uv) => write!(f, "{uv:?}"),
62 Unevaluated(is_rigid, uv) => write!(f, "Unevaluated({is_rigid:?}, {uv:?})"),
6363 Value(val) => write!(f, "{val:?}"),
6464 Error(_) => write!(f, "{{const error}}"),
6565 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>(
276276 // We might end up here if we have `Foo<<Bar as Baz>::Assoc>: 'a`.
277277 // With this, we can deduce that `<Bar as Baz>::Assoc: 'a`.
278278 Some(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
279 alias_ty.to_ty(cx),
279 alias_ty.to_ty(cx, ty::IsRigid::No),
280280 outlives_region,
281281 )))
282282 }
......@@ -414,7 +414,10 @@ pub fn elaborate_outlives_assumptions<I: Interner>(
414414 }
415415
416416 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 ));
418421 }
419422
420423 Component::UnresolvedInferenceVariable(_) | Component::EscapingAlias(_) => {
compiler/rustc_type_ir/src/error.rs+7-1
......@@ -2,7 +2,7 @@ use derive_where::derive_where;
22use rustc_abi::ExternAbi;
33use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic};
44
5use crate::solve::NoSolution;
5use crate::solve::{NoSolution, NoSolutionOrRerunNonErased};
66use crate::{self as ty, Interner};
77
88#[derive(Clone, Copy, Debug, PartialEq, Eq)]
......@@ -100,3 +100,9 @@ impl<I: Interner> From<TypeError<I>> for NoSolution {
100100 NoSolution
101101 }
102102}
103
104impl<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_
261261 return true;
262262 }
263263 }
264 // FIXME(#155345): we should fast-path for rigid aliases here.
264265 ty::Error(_) | ty::Alias(..) | ty::Bound(..) => return true,
265266 ty::Infer(var) => return self.var_and_ty_may_unify(var, lhs),
266267
......@@ -468,7 +469,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
468469 }
469470
470471 ty::ConstKind::Expr(_)
471 | ty::ConstKind::Unevaluated(_)
472 | ty::ConstKind::Unevaluated(_, _)
472473 | ty::ConstKind::Error(_)
473474 | ty::ConstKind::Infer(_)
474475 | ty::ConstKind::Bound(..) => {
......@@ -499,7 +500,7 @@ impl<I: Interner, const INSTANTIATE_LHS_WITH_INFER: bool, const INSTANTIATE_RHS_
499500
500501 // As we don't necessarily eagerly evaluate constants,
501502 // 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(_) => {
503504 true
504505 }
505506
compiler/rustc_type_ir/src/flags.rs+23-3
......@@ -146,6 +146,18 @@ bitflags::bitflags! {
146146
147147 /// Does this have a `Bound(BoundVarIndexKind::Canonical, _)`?
148148 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;
149161 }
150162}
151163
......@@ -295,14 +307,14 @@ impl<I: Interner> FlagComputation<I> {
295307 self.add_args(args.as_slice());
296308 }
297309
298 ty::Alias(alias) => {
310 ty::Alias(is_rigid, alias) => {
311 self.add_is_rigid(is_rigid);
299312 self.add_flags(match alias.kind {
300313 ty::Projection { .. } => TypeFlags::HAS_TY_PROJECTION,
301314 ty::Free { .. } => TypeFlags::HAS_TY_FREE_ALIAS,
302315 ty::Opaque { .. } => TypeFlags::HAS_TY_OPAQUE,
303316 ty::Inherent { .. } => TypeFlags::HAS_TY_INHERENT,
304317 });
305
306318 self.add_alias_ty(alias);
307319 }
308320
......@@ -465,7 +477,8 @@ impl<I: Interner> FlagComputation<I> {
465477
466478 fn add_const_kind(&mut self, c: &ty::ConstKind<I>) {
467479 match *c {
468 ty::ConstKind::Unevaluated(uv) => {
480 ty::ConstKind::Unevaluated(is_rigid, uv) => {
481 self.add_is_rigid(is_rigid);
469482 self.add_args(uv.args.as_slice());
470483 self.add_flags(TypeFlags::HAS_CT_PROJECTION);
471484 }
......@@ -529,6 +542,13 @@ impl<I: Interner> FlagComputation<I> {
529542 }
530543 }
531544
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
532552 fn add_term(&mut self, term: I::Term) {
533553 match term.kind() {
534554 ty::TermKind::Ty(ty) => self.add_ty(ty),
compiler/rustc_type_ir/src/fold.rs+63
......@@ -554,3 +554,66 @@ where
554554 if c.has_regions() { c.super_fold_with(self) } else { c }
555555 }
556556}
557
558pub fn set_aliases_to_non_rigid<I: Interner, T>(cx: I, value: T) -> ty::Unnormalized<I, T>
559where
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
570struct RigidnessFolder<I: Interner> {
571 cx: I,
572}
573
574impl<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>>:
5353
5454 fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self;
5555
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;
5757
5858 fn new_projection_from_args(
5959 interner: I,
60 is_rigid: ty::IsRigid,
6061 def_id: I::TraitAssocTyId,
6162 args: I::GenericArgs,
6263 ) -> Self {
6364 Self::new_alias(
6465 interner,
66 is_rigid,
6567 ty::AliasTy::new_from_args(interner, ty::AliasTyKind::Projection { def_id }, args),
6668 )
6769 }
6870
6971 fn new_projection(
7072 interner: I,
73 is_rigid: ty::IsRigid,
7174 def_id: I::TraitAssocTyId,
7275 args: impl IntoIterator<Item: Into<I::GenericArg>>,
7376 ) -> Self {
7477 Self::new_alias(
7578 interner,
79 is_rigid,
7680 ty::AliasTy::new(interner, ty::AliasTyKind::Projection { def_id }, args),
7781 )
7882 }
......@@ -190,7 +194,7 @@ pub trait Ty<I: Interner<Ty = Self>>:
190194 | ty::CoroutineWitness(_, _)
191195 | ty::Never
192196 | ty::Tuple(_)
193 | ty::Alias(_)
197 | ty::Alias(_, _)
194198 | ty::Param(_)
195199 | ty::Bound(_, _)
196200 | ty::Placeholder(_)
......@@ -276,7 +280,7 @@ pub trait Const<I: Interner<Const = Self>>:
276280
277281 fn new_placeholder(interner: I, param: ty::PlaceholderConst<I>) -> Self;
278282
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;
280284
281285 fn new_expr(interner: I, expr: I::ExprConst) -> Self;
282286
......@@ -403,15 +407,28 @@ pub trait Term<I: Interner<Term = Self>>:
403407 fn to_alias_term(self) -> Option<ty::AliasTerm<I>> {
404408 match self.kind() {
405409 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()),
407411 _ => None,
408412 },
409413 ty::TermKind::Const(ct) => match ct.kind() {
410 ty::ConstKind::Unevaluated(uv) => Some(uv.into()),
414 ty::ConstKind::Unevaluated(_, uv) => Some(uv.into()),
411415 _ => None,
412416 },
413417 }
414418 }
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 }
415432}
416433
417434#[rust_analyzer::prefer_underscore_import]
compiler/rustc_type_ir/src/interner.rs+2
......@@ -292,6 +292,8 @@ pub trait Interner:
292292
293293 fn assumptions_on_binders(self) -> bool;
294294
295 fn renormalize_rigid_aliases(self) -> bool;
296
295297 fn coroutine_hidden_types(
296298 self,
297299 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> {
148148 // trait-ref. Therefore, if we see any higher-ranked regions,
149149 // we simply fallback to the most restrictive rule, which
150150 // requires that `Pi: 'a` for all `i`.
151 ty::Alias(alias_ty) => {
151 ty::Alias(_, alias_ty) => {
152152 if !alias_ty.has_escaping_bound_vars() {
153153 // best case: no escaping regions, so push the
154154 // 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};
5252use crate::visit::TypeSuperVisitable;
5353use crate::{
5454 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,
5858};
5959
6060#[derive_where(Clone, Debug; I: Interner)]
......@@ -1128,7 +1128,12 @@ fn alias_outlives_candidates_from_assumptions<Infcx: InferCtxtLike<Interner = I>
11281128 region_constraints: vec![RegionConstraint::RegionOutlives(r2, r)],
11291129 };
11301130
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 ) {
11321137 candidates
11331138 .push(RegionConstraint::And(relation.region_constraints.into_boxed_slice()));
11341139 }
compiler/rustc_type_ir/src/relate.rs+17-8
......@@ -222,7 +222,7 @@ impl<I: Interner> Relate<I> for ty::AliasTy<I> {
222222 } else {
223223 relate_args_invariantly(relation, a.args, b.args)?
224224 };
225 Ok(ty::AliasTy::new_from_args(cx, a.kind, args))
225 Ok(ty::AliasTy::new_from_args(relation.cx(), a.kind, args))
226226 }
227227 }
228228}
......@@ -236,8 +236,8 @@ impl<I: Interner> Relate<I> for ty::UnevaluatedConst<I> {
236236 let cx = relation.cx();
237237 if a.kind != b.kind {
238238 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),
241241 )))
242242 } else {
243243 // FIXME(mgca): remove this
......@@ -523,9 +523,12 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
523523 }
524524
525525 // 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))
529532 }
530533
531534 (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>>(
611614 // While this is slightly incorrect, it shouldn't matter for `min_const_generics`
612615 // and is the better alternative to waiting until `generic_const_exprs` can
613616 // 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)?));
616625 }
617626 (ty::ConstKind::Expr(ae), ty::ConstKind::Expr(be)) => {
618627 let expr = relation.relate(ae, be)?;
compiler/rustc_type_ir/src/relate/combine.rs+32-9
......@@ -115,9 +115,29 @@ where
115115 panic!("We do not expect to encounter `Fresh` variables in the new solver")
116116 }
117117
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 {
121141 ty::Infer(infer_ty) => match infer_ty {
122142 // Normally, we shouldn't be combining an infer ty with an alias here. But
123143 // when we evaluate a `Projection(assoc_ty, expected)` goal, we normalize
......@@ -139,10 +159,6 @@ where
139159 | ty::InferTy::FreshFloatTy(_) => unreachable!(),
140160 },
141161 _ => structurally_relate_tys(relation, a, b),
142 },
143 StructurallyRelateAliases::No => {
144 relation.register_alias_relate_predicate(a, b);
145 Ok(a)
146162 }
147163 }
148164 }
......@@ -150,8 +166,8 @@ where
150166 // All other cases of inference are errors
151167 (ty::Infer(_), _) | (_, ty::Infer(_)) => Err(TypeError::Sorts(ExpectedFound::new(a, b))),
152168
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 { .. }, .. })) => {
155171 assert!(!infcx.next_trait_solver());
156172 match infcx.typing_mode_raw().assert_not_erased() {
157173 // During coherence, opaque types should be treated as *possibly*
......@@ -223,6 +239,13 @@ where
223239 Ok(a)
224240 }
225241
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
226249 (ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
227250 if infcx.cx().features().generic_const_exprs() || infcx.next_trait_solver() =>
228251 {
compiler/rustc_type_ir/src/term_kind.rs+4-2
......@@ -209,13 +209,15 @@ impl<I: Interner> AliasTerm<I> {
209209 ty::UnevaluatedConst { kind, args: self.args, _use_alias_new_instead: () }
210210 }
211211
212 pub fn to_term(self, interner: I) -> I::Term {
212 pub fn to_term(self, interner: I, is_rigid: ty::IsRigid) -> I::Term {
213213 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()
215216 };
216217 let unevaluated_const = |kind| {
217218 I::Const::new_unevaluated(
218219 interner,
220 is_rigid,
219221 ty::UnevaluatedConst::new(interner, kind, self.args),
220222 )
221223 .into()
compiler/rustc_type_ir/src/ty_kind.rs+33-5
......@@ -107,6 +107,34 @@ impl<I: Interner> AliasTyKind<I> {
107107 }
108108}
109109
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)]
127pub enum IsRigid {
128 Yes,
129 No,
130}
131
132impl 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
110138/// Defines the kinds of types used by the type system.
111139///
112140/// Types written by the user start out as `hir::TyKind` and get
......@@ -273,7 +301,7 @@ pub enum TyKind<I: Interner> {
273301 ///
274302 /// All of these types are represented as pairs of def-id and args, and can
275303 /// be normalized, so they are grouped conceptually.
276 Alias(AliasTy<I>),
304 Alias(IsRigid, AliasTy<I>),
277305
278306 /// A type parameter; for example, `T` in `fn f<T>(x: T) {}`.
279307 Param(I::ParamTy),
......@@ -375,7 +403,7 @@ impl<I: Interner> TyKind<I> {
375403
376404 ty::Error(_)
377405 | ty::Infer(_)
378 | ty::Alias(_)
406 | ty::Alias(ty::IsRigid::No | ty::IsRigid::Yes, _)
379407 | ty::Param(_)
380408 | ty::Bound(_, _)
381409 | ty::Placeholder(_) => false,
......@@ -440,7 +468,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> {
440468 }
441469 write!(f, ")")
442470 }
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(),
444472 Param(p) => write!(f, "{p:?}"),
445473 Bound(d, b) => crate::debug_bound_var(f, *d, b),
446474 Placeholder(p) => write!(f, "{p:?}"),
......@@ -478,8 +506,8 @@ impl<I: Interner> AliasTy<I> {
478506 matches!(self.kind, AliasTyKind::Opaque { .. })
479507 }
480508
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)
483511 }
484512
485513 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
167167 }
168168}
169169
170impl<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
170176impl<I: Interner, T: TypeVisitable<I>> TypeVisitable<I> for Arc<T> {
171177 fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result {
172178 (**self).visit_with(visitor)
......@@ -363,6 +369,16 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> {
363369 fn has_non_region_error(&self) -> bool {
364370 self.has_type_flags(TypeFlags::HAS_NON_REGION_ERROR)
365371 }
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 }
366382}
367383
368384impl<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
106106 stack.push(ty.into());
107107 stack.push(lt.into());
108108 }
109 ty::Alias(alias) => {
109 ty::Alias(_, alias) => {
110110 stack.extend(alias.args.iter().rev());
111111 }
112112 ty::Dynamic(obj, lt) => {
......@@ -160,7 +160,7 @@ fn push_inner<I: Interner>(stack: &mut TypeWalkerStack<I>, parent: I::GenericArg
160160 ty::ConstKind::Value(cv) => stack.push(cv.ty().into()),
161161
162162 ty::ConstKind::Expr(expr) => stack.extend(expr.args().iter().rev()),
163 ty::ConstKind::Unevaluated(ct) => {
163 ty::ConstKind::Unevaluated(_, ct) => {
164164 stack.extend(ct.args.iter().rev());
165165 }
166166 },
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
17801780 let self_type = clean_ty(qself, cx);
17811781
17821782 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 { .. }, .. }) => {
17841784 let res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id);
17851785 let trait_ = clean_path(&hir::Path { span, res, segments: &[] }, cx);
17861786 register_res(cx, trait_.res);
......@@ -1790,7 +1790,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
17901790
17911791 (Some(trait_), should_fully_qualify)
17921792 }
1793 ty::Alias(ty::AliasTy { kind: ty::Inherent { .. }, .. }) => (None, false),
1793 ty::Alias(_, ty::AliasTy { kind: ty::Inherent { .. }, .. }) => (None, false),
17941794 // Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s.
17951795 ty::Error(_) => return Type::Infer,
17961796 _ => bug!("clean: expected associated type, found `{ty:?}`"),
......@@ -2282,7 +2282,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22822282 Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None, None)).collect())
22832283 }
22842284
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, .. }) => {
22862286 if cx.tcx.is_impl_trait_in_trait(def_id) {
22872287 clean_middle_opaque_bounds(cx, def_id, args)
22882288 } else {
......@@ -2294,7 +2294,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
22942294 }
22952295 }
22962296
2297 ty::Alias(alias_ty @ ty::AliasTy { kind: ty::Inherent { def_id }, .. }) => {
2297 ty::Alias(_, alias_ty @ ty::AliasTy { kind: ty::Inherent { def_id }, .. }) => {
22982298 let alias_ty = bound_ty.rebind(alias_ty);
22992299 let self_type = clean_middle_ty(alias_ty.map_bound(|ty| ty.self_ty()), cx, None, None);
23002300
......@@ -2317,7 +2317,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
23172317 }))
23182318 }
23192319
2320 ty::Alias(ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
2320 ty::Alias(_, ty::AliasTy { kind: ty::Free { def_id }, args, .. }) => {
23212321 if cx.tcx.features().lazy_type_alias() {
23222322 // Free type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
23232323 // we need to use `type_of`.
......@@ -2345,7 +2345,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
23452345 ty::BoundTyKind::Anon => panic!("unexpected anonymous bound type variable"),
23462346 },
23472347
2348 ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
2348 ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => {
23492349 // If it's already in the same alias, don't get an infinite loop.
23502350 if cx.current_type_aliases.contains_key(&def_id) {
23512351 let path =
src/librustdoc/clean/types.rs+1-1
......@@ -1770,7 +1770,7 @@ impl PrimitiveType {
17701770 ty::Tuple(elems) if elems.is_empty() => Some(Self::Unit),
17711771 ty::Tuple(_) => Some(Self::Tuple),
17721772 ty::Adt(..)
1773 | ty::Alias(..)
1773 | ty::Alias(_, ..)
17741774 | ty::Bound(..)
17751775 | ty::Closure(..)
17761776 | ty::Coroutine(..)
src/librustdoc/clean/utils.rs+1-1
......@@ -350,7 +350,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
350350
351351pub(crate) fn print_const(tcx: TyCtxt<'_>, n: ty::Const<'_>) -> String {
352352 match n.kind() {
353 ty::ConstKind::Unevaluated(ty::UnevaluatedConst { kind, .. }) => match kind {
353 ty::ConstKind::Unevaluated(_, ty::UnevaluatedConst { kind, .. }) => match kind {
354354 ty::UnevaluatedConstKind::Projection { def_id } => {
355355 if let Some(local_def_id) = def_id.as_local()
356356 && 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> {
547547 ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) | ty::Foreign(did) => {
548548 Res::from_def_id(tcx, did)
549549 }
550 ty::Alias(..)
550 ty::Alias(_, ..)
551551 | ty::Closure(..)
552552 | ty::CoroutineClosure(..)
553553 | 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>) -
6363 )
6464 })
6565 .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, []));
6767 let nty = cx
6868 .tcx
6969 .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 {
925925 continue;
926926 },
927927 ty::Param(_) if for_return => Self::Deref,
928 ty::Alias(ty::AliasTy {
928 ty::Alias(_, ty::AliasTy {
929929 kind: ty::Free { .. } | ty::Inherent { .. },
930930 ..
931931 }) => unreachable!("should have been normalized away above"),
932 ty::Alias(ty::AliasTy {
932 ty::Alias(_, ty::AliasTy {
933933 kind: ty::Projection { .. },
934934 ..
935935 }) if !for_return && ty.has_non_region_param() => Self::Reborrow,
936936 ty::Infer(_)
937937 | ty::Error(_)
938938 | ty::Bound(..)
939 | ty::Alias(ty::AliasTy {
939 | ty::Alias(_, ty::AliasTy {
940940 kind: ty::Opaque { .. },
941941 ..
942942 })
......@@ -970,7 +970,7 @@ impl TyCoercionStability {
970970 | ty::CoroutineClosure(..)
971971 | ty::Never
972972 | ty::Tuple(_)
973 | ty::Alias(ty::AliasTy {
973 | ty::Alias(_, ty::AliasTy {
974974 kind: ty::Projection { .. },
975975 ..
976976 })
src/tools/clippy/clippy_lints/src/from_over_into.rs+1-1
......@@ -78,7 +78,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
7878 && span_is_local(item.span)
7979 && let middle_trait_ref = cx.tcx.impl_trait_ref(item.owner_id).instantiate_identity().skip_norm_wip()
8080 && 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{..} , .. }))
8282 && self.msrv.meets(cx, msrvs::RE_REBALANCING_COHERENCE)
8383 // skip if there's a blanket From impl, the suggested impl would conflict
8484 && !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 {
7676 return;
7777 }
7878 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()
8080 && let Some(future_trait) = cx.tcx.lang_items().future_trait()
8181 && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send)
8282 && let preds = cx.tcx.explicit_item_self_bounds(def_id)
......@@ -149,6 +149,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for TyParamAtTopLevelVisitor {
149149 match ty.kind() {
150150 ty::Param(_) => ControlFlow::Break(true),
151151 ty::Alias(
152 _,
152153 ty @ AliasTy {
153154 kind: ty::Projection { .. },
154155 ..
src/tools/clippy/clippy_lints/src/indexing_slicing.rs+1-1
......@@ -280,7 +280,7 @@ fn ty_has_applicable_get_function<'tcx>(
280280 && let generic_ty = option_generic_param.expect_ty().peel_refs()
281281 // FIXME: ideally this would handle type params and projections properly, for now just assume it's the same type
282282 && (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(_, _)))
284284 {
285285 true
286286 } 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
149149}
150150
151151fn 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 {
153153 kind: ty::Opaque { def_id },
154154 ..
155155 }) = *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 {
336336 .filter_by_name_unhygienic(sym::is_empty)
337337 .any(|item| is_is_empty_and_stable(cx, item, msrv))
338338 }),
339 &ty::Alias(ty::AliasTy {
339 &ty::Alias(_, ty::AliasTy {
340340 kind: ty::Projection { def_id },
341341 ..
342342 }) => 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>(
139139 }
140140
141141 let res_ty = cx.tcx.erase_and_anonymize_regions(
142 EarlyBinder::bind(req_res_ty)
142 EarlyBinder::bind(cx.tcx, req_res_ty)
143143 .instantiate(cx.tcx, typeck.node_args(call_expr.hir_id))
144144 .skip_norm_wip(),
145145 );
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:
247247 && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty])
248248 && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
249249 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)),
251251 )
252252 {
253253 iter_item_ty == into_iter_item_ty
......@@ -276,13 +276,13 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
276276 iter_trait,
277277 )
278278 && 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)
280280 && let Ok(item_ty) = cx
281281 .tcx
282282 .try_normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(proj_ty))
283283 {
284284 item_ty
285 == EarlyBinder::bind(search_ty)
285 == EarlyBinder::bind(cx.tcx, search_ty)
286286 .instantiate(cx.tcx, cx.typeck_results().node_args(call_id))
287287 .skip_norm_wip()
288288 } 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
213213 inputs.iter().any(|input| {
214214 matches!(
215215 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()
217217 )
218218 })
219219}
src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs+3-2
......@@ -285,7 +285,7 @@ fn needless_borrow_count<'tcx>(
285285 return false;
286286 }
287287
288 let predicate = EarlyBinder::bind(predicate)
288 let predicate = EarlyBinder::bind(cx.tcx, predicate)
289289 .instantiate(cx.tcx, &args_with_referent_ty[..])
290290 .skip_norm_wip();
291291 let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
......@@ -341,6 +341,7 @@ fn is_mixed_projection_predicate<'tcx>(
341341 loop {
342342 match *projection_term.self_ty().kind() {
343343 ty::Alias(
344 _,
344345 inner_projection_ty @ ty::AliasTy {
345346 kind: ty::Projection { .. },
346347 ..
......@@ -434,7 +435,7 @@ fn replace_types<'tcx>(
434435 .projection_term
435436 .with_replaced_self_ty(cx.tcx, new_ty)
436437 .expect_ty()
437 .to_ty(cx.tcx);
438 .to_ty(cx.tcx, ty::IsRigid::No);
438439
439440 if let Ok(projected_ty) = cx
440441 .tcx
src/tools/clippy/clippy_lints/src/non_copy_const.rs+5-4
......@@ -323,7 +323,7 @@ impl<'tcx> NonCopyConst<'tcx> {
323323 IsFreeze::from_fields(tys.iter().map(|ty| self.is_ty_freeze(tcx, typing_env, ty)))
324324 },
325325 // Treat type parameters as though they were `Freeze`.
326 ty::Param(_) | ty::Alias(..) => return IsFreeze::Yes,
326 ty::Param(_) | ty::Alias(_, ..) => return IsFreeze::Yes,
327327 // TODO: check other types.
328328 _ => {
329329 *e = IsFreeze::No;
......@@ -384,7 +384,7 @@ impl<'tcx> NonCopyConst<'tcx> {
384384 e: &'tcx Expr<'tcx>,
385385 ) -> bool {
386386 // 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);
388388 let ty = tcx
389389 .try_normalize_erasing_regions(typing_env, ty)
390390 .unwrap_or(ty.skip_norm_wip());
......@@ -401,7 +401,7 @@ impl<'tcx> NonCopyConst<'tcx> {
401401 },
402402 ExprKind::Path(ref p) => {
403403 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))
405405 .instantiate(tcx, gen_args)
406406 .skip_norm_wip();
407407 match res {
......@@ -599,7 +599,7 @@ impl<'tcx> NonCopyConst<'tcx> {
599599 init_expr = next_init;
600600 },
601601 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))
603603 .instantiate(tcx, init_args)
604604 .skip_norm_wip();
605605 match init_typeck.qpath_res(init_path, init_expr.hir_id) {
......@@ -904,6 +904,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceAssocFolder<'tcx> {
904904
905905 fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
906906 if let ty::Alias(
907 _,
907908 ty @ ty::AliasTy {
908909 kind: ty::Projection { .. },
909910 ..
src/tools/clippy/clippy_lints/src/redundant_slicing.rs+2-1
......@@ -8,7 +8,7 @@ use rustc_errors::Applicability;
88use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
99use rustc_lint::{LateContext, LateLintPass, Lint};
1010use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability};
11use rustc_middle::ty::{GenericArg, Ty, Unnormalized};
11use rustc_middle::ty::{self, GenericArg, Ty, Unnormalized};
1212use rustc_session::declare_lint_pass;
1313
1414declare_clippy_lint! {
......@@ -144,6 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
144144 cx.typing_env(),
145145 Unnormalized::new_wip(Ty::new_projection_from_args(
146146 cx.tcx,
147 ty::IsRigid::No,
147148 target_id,
148149 cx.tcx.mk_args(&[GenericArg::from(indexed_ty)]),
149150 )),
src/tools/clippy/clippy_lints/src/transmute/missing_transmute_annotations.rs+1-1
......@@ -107,7 +107,7 @@ pub(super) fn check<'tcx>(
107107fn ty_cannot_be_named(ty: Ty<'_>) -> bool {
108108 matches!(
109109 ty.kind(),
110 ty::Alias(ty::AliasTy {
110 ty::Alias(_, ty::AliasTy {
111111 kind: ty::Opaque { .. } | ty::Inherent { .. },
112112 ..
113113 })
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
101101
102102 match ty.kind() {
103103 ty::Alias(
104 _,
104105 proj @ ty::AliasTy {
105106 kind: ty::Projection { .. },
106107 ..
src/tools/clippy/clippy_lints/src/useless_conversion.rs+1-1
......@@ -112,7 +112,7 @@ fn into_iter_bound<'tcx>(
112112 }
113113 }));
114114
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();
116116 let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
117117 if !cx
118118 .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:
32933293 | rustc_ty::RawPtr(_, _)
32943294 | rustc_ty::Ref(..)
32953295 | 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()),
32973297 _ => ty.to_string(),
32983298 }
32993299}
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)
8787 ty::Ref(_, _, hir::Mutability::Mut) if !msrv.meets(cx, msrvs::CONST_MUT_REFS) => {
8888 return Err((span, "mutable references in const fn are unstable".into()));
8989 },
90 ty::Alias(ty::AliasTy {
90 ty::Alias(_, ty::AliasTy {
9191 kind: ty::Opaque { .. },
9292 ..
9393 }) => 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<'
104104 return true;
105105 }
106106
107 if let ty::Alias(AliasTy {
107 if let ty::Alias(_, AliasTy {
108108 kind: ty::Opaque { def_id },
109109 ..
110110 }) = *inner_ty.kind()
......@@ -337,7 +337,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
337337 is_must_use_ty(cx, *ty)
338338 },
339339 ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)),
340 ty::Alias(AliasTy {
340 ty::Alias(_, AliasTy {
341341 kind: ty::Opaque { def_id },
342342 ..
343343 }) => {
......@@ -639,7 +639,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
639639 cx.tcx.fn_sig(id).instantiate(cx.tcx, subs).skip_norm_wip(),
640640 Some(id),
641641 )),
642 ty::Alias(AliasTy {
642 ty::Alias(_, AliasTy {
643643 kind: ty::Opaque { def_id },
644644 args,
645645 ..
......@@ -670,7 +670,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
670670 _ => None,
671671 }
672672 },
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
674674 .tcx
675675 .try_normalize_erasing_regions(cx.typing_env(), Unnormalized::new_wip(ty))
676676 {
......@@ -1093,7 +1093,7 @@ pub fn make_normalized_projection<'tcx>(
10931093 );
10941094 return None;
10951095 }
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))) {
10971097 Ok(ty) => Some(ty),
10981098 Err(e) => {
10991099 debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}");
......@@ -1195,7 +1195,7 @@ impl<'tcx> InteriorMut<'tcx> {
11951195 .find_map(|f| self.interior_mut_ty_chain_inner(cx, f.ty(cx.tcx, args).skip_norm_wip(), depth))
11961196 }
11971197 },
1198 ty::Alias(AliasTy {
1198 ty::Alias(_, AliasTy {
11991199 kind: ty::Projection { .. },
12001200 ..
12011201 }) => match cx
......@@ -1247,7 +1247,7 @@ pub fn make_normalized_projection_with_regions<'tcx>(
12471247 }
12481248 let cause = ObligationCause::dummy();
12491249 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)) {
12511251 Ok(ty) => Some(ty.value),
12521252 Err(e) => {
12531253 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 @@
22
33| User Type Annotations
44| 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">}
66|
77fn main() -> () {
88 let mut _0: ();
tests/mir-opt/issue_99325.main.built.after.64bit.mir+1-1
......@@ -2,7 +2,7 @@
22
33| User Type Annotations
44| 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">}
66|
77fn main() -> () {
88 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 {
5656 | --------------- expected `Windows<for<'a> fn(&'a ())>::AssocType` because of return type
5757LL |
5858LL | ()
59 | ^^ types differ
59 | ^^ expected opaque type, found `()`
6060 |
6161 = note: expected opaque type `Windows<for<'a> fn(&'a ())>::AssocType`
6262 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;
4949LL | fn f() -> Self::ImplTrait {
5050 | --------------- expected `Foo::ImplTrait` because of return type
5151LL | ()
52 | ^^ types differ
52 | ^^ expected opaque type, found `()`
5353 |
5454 = note: expected opaque type `Foo::ImplTrait`
5555 found unit type `()`
tests/ui/associated-inherent-types/normalization-overflow.next.stderr+3-3
......@@ -1,9 +1,9 @@
1error[E0271]: type mismatch resolving `_ == T::This`
1error[E0275]: overflow evaluating the requirement `T::This == _`
22 --> $DIR/normalization-overflow.rs:14:5
33 |
44LL | type This = Self::This;
5 | ^^^^^^^^^ types differ
5 | ^^^^^^^^^
66
77error: aborting due to 1 previous error
88
9For more information about this error, try `rustc --explain E0271`.
9For 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;
1313impl T {
1414 type This = Self::This;
1515 //[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 == _`
1717}
1818
1919fn 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
14trait 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
21fn main() {}
tests/ui/assumptions_on_binders/non_lifetime_binder_alias_outlives.stderr deleted-20
......@@ -1,20 +0,0 @@
1error[E0284]: type annotations needed: cannot satisfy `<T as Trait>::Assoc: 'static`
2 --> $DIR/non_lifetime_binder_alias_outlives.rs:16:5
3 |
4LL | / type Ref
5LL | | where
6LL | | for<T> T: Trait<Assoc: 'static>;
7 | |________________________________________^ cannot satisfy `<T as Trait>::Assoc: 'static`
8 |
9note: required by a bound in `Trait::Ref`
10 --> $DIR/non_lifetime_binder_alias_outlives.rs:18:32
11 |
12LL | type Ref
13 | --- required by a bound in this associated type
14LL | where
15LL | for<T> T: Trait<Assoc: 'static>;
16 | ^^^^^^^ required by this bound in `Trait::Ref`
17
18error: aborting due to 1 previous error
19
20For 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
3333LL | type Assoc<P: Eq>: std::ops::Deref<Target = ()>
3434 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3535 |
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: [] }
3737 = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::ops::Deref>, polarity:Positive), bound_vars: [] }
3838 = note: Binder { value: TraitPredicate(<<Self as Trait<T>>::Assoc<P> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
3939
tests/ui/const-generics/gca/non-type-equality-fail.stderr+2-2
......@@ -4,7 +4,7 @@ error[E0308]: mismatched types
44LL | let _: Struct<{ <GenericStructImpl<N> as Trait>::PROJECTED_A }> =
55 | -------------------------------------------------------- expected due to this
66LL | 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`
88 |
99 = note: expected struct `Struct<<GenericStructImpl<N> as Trait>::PROJECTED_A>`
1010 found struct `Struct<<GenericStructImpl<N> as Trait>::PROJECTED_B>`
......@@ -13,7 +13,7 @@ error[E0308]: mismatched types
1313 --> $DIR/non-type-equality-fail.rs:37:41
1414 |
1515LL | 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`
1717 | |
1818 | expected due to this
1919 |
tests/ui/const-generics/mgca/free-const-recursive.rs+2-2
......@@ -5,8 +5,8 @@
55#![expect(incomplete_features)]
66
77type 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 `()``
1010
1111fn main() {
1212 A;
tests/ui/const-generics/mgca/free-const-recursive.stderr+5-5
......@@ -1,15 +1,15 @@
1error[E0271]: type mismatch resolving `A == _`
1error[E0275]: overflow evaluating the requirement `A == _`
22 --> $DIR/free-const-recursive.rs:7:1
33 |
44LL | type const A: () = A;
5 | ^^^^^^^^^^^^^^^^ types differ
5 | ^^^^^^^^^^^^^^^^
66
7error: the constant `A` is not of type `()`
7error[E0275]: overflow evaluating the requirement `the constant `A` has type `()``
88 --> $DIR/free-const-recursive.rs:7:1
99 |
1010LL | type const A: () = A;
11 | ^^^^^^^^^^^^^^^^ expected `()`, found a different `()`
11 | ^^^^^^^^^^^^^^^^
1212
1313error: aborting due to 2 previous errors
1414
15For more information about this error, try `rustc --explain E0271`.
15For 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 {
1010
1111impl Trait for () {
1212 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 `()``
1515}
1616
1717fn main() {
tests/ui/const-generics/mgca/projection-const-recursive.stderr+5-5
......@@ -1,15 +1,15 @@
1error[E0271]: type mismatch resolving `<() as Trait>::A == _`
1error[E0275]: overflow evaluating the requirement `<() as Trait>::A == _`
22 --> $DIR/projection-const-recursive.rs:12:5
33 |
44LL | type const A: () = <() as Trait>::A;
5 | ^^^^^^^^^^^^^^^^ types differ
5 | ^^^^^^^^^^^^^^^^
66
7error: the constant `<() as Trait>::A` is not of type `()`
7error[E0275]: overflow evaluating the requirement `the constant `<() as Trait>::A` has type `()``
88 --> $DIR/projection-const-recursive.rs:12:5
99 |
1010LL | type const A: () = <() as Trait>::A;
11 | ^^^^^^^^^^^^^^^^ expected `()`, found a different `()`
11 | ^^^^^^^^^^^^^^^^
1212
1313error: aborting due to 2 previous errors
1414
15For more information about this error, try `rustc --explain E0271`.
15For 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
44LL | spawn(async { build_dependencies().await });
55 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66 |
7 = help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`delayed_obligations_emit`)
78note: required by a bound in `spawn`
89 --> $DIR/delayed-obligations-emit.rs:31:13
910 |
tests/ui/higher-ranked/trait-bounds/rigid-equate-projections-in-higher-ranked-fn-signature.next.stderr+3-3
......@@ -1,10 +1,10 @@
11error[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
33 |
44LL | let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::<T>();
5 | ^^^^^^^^^^ cannot infer type
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
66 |
7 = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == <T as Trait<'_>>::Assoc`
7 = note: cannot satisfy `for<'a> <_ as Trait<'a>>::Assoc == _`
88
99error: aborting due to 1 previous error
1010
tests/ui/impl-trait/in-trait/alias-bounds-when-not-wf.rs+1
......@@ -15,4 +15,5 @@ struct W<T>(T);
1515fn hello(_: W<A<usize>>) {}
1616//~^ ERROR: the trait bound `usize: Foo` is not satisfied
1717//~| ERROR: the trait bound `usize: Foo` is not satisfied
18//~| ERROR: the type `W<A<usize>>` is not well-formed
1819fn 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`
1515LL | type A<T: Foo> = T;
1616 | ^^^ required by this bound in `A`
1717
18error: the type `W<A<usize>>` is not well-formed
19 --> $DIR/alias-bounds-when-not-wf.rs:15:13
20 |
21LL | fn hello(_: W<A<usize>>) {}
22 | ^^^^^^^^^^^
23
1824error[E0277]: the trait bound `usize: Foo` is not satisfied
1925 --> $DIR/alias-bounds-when-not-wf.rs:15:13
2026 |
......@@ -27,6 +33,6 @@ help: this trait has no implementations, consider adding one
2733LL | trait Foo {}
2834 | ^^^^^^^^^
2935
30error: aborting due to 2 previous errors
36error: aborting due to 3 previous errors
3137
3238For 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 @@
1error[E0271]: type mismatch resolving `_ == X1`
1error[E0275]: overflow evaluating the requirement `X2 == _`
22 --> $DIR/infinite-type-alias-mutual-recursion.rs:12:1
33 |
44LL | type X1 = X2;
5 | ^^^^^^^ types differ
5 | ^^^^^^^
66
7error[E0271]: type mismatch resolving `_ == X2`
7error[E0275]: overflow evaluating the requirement `X3 == _`
88 --> $DIR/infinite-type-alias-mutual-recursion.rs:16:1
99 |
1010LL | type X2 = X3;
11 | ^^^^^^^ types differ
11 | ^^^^^^^
1212
13error[E0271]: type mismatch resolving `_ == X3`
13error[E0275]: overflow evaluating the requirement `X1 == _`
1414 --> $DIR/infinite-type-alias-mutual-recursion.rs:19:1
1515 |
1616LL | type X3 = X1;
17 | ^^^^^^^ types differ
17 | ^^^^^^^
1818
1919error: aborting due to 3 previous errors
2020
21For more information about this error, try `rustc --explain E0271`.
21For more information about this error, try `rustc --explain E0275`.
tests/ui/infinite/infinite-type-alias-mutual-recursion.rs+3-3
......@@ -12,12 +12,12 @@
1212type X1 = X2;
1313//[gated_old,gated_new]~^ ERROR cycle detected when expanding type alias `X1`
1414//[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 == _`
1616type X2 = X3;
1717//[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 == _`
1919type X3 = X1;
2020//[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 == _`
2222
2323fn main() {}
tests/ui/lazy-type-alias/inherent-impls-overflow.next.stderr+7-8
......@@ -1,20 +1,20 @@
1error[E0271]: type mismatch resolving `_ == Loop`
1error[E0275]: overflow evaluating the requirement `Loop == _`
22 --> $DIR/inherent-impls-overflow.rs:8:1
33 |
44LL | type Loop = Loop;
5 | ^^^^^^^^^ types differ
5 | ^^^^^^^^^
66
7error[E0271]: type mismatch resolving `_ == Loop`
7error[E0275]: overflow evaluating the requirement `Loop == _`
88 --> $DIR/inherent-impls-overflow.rs:12:1
99 |
1010LL | impl Loop {}
11 | ^^^^^^^^^^^^ types differ
11 | ^^^^^^^^^^^^
1212
13error[E0271]: type mismatch resolving `_ == Loop`
13error[E0275]: overflow evaluating the requirement `Loop == _`
1414 --> $DIR/inherent-impls-overflow.rs:12:6
1515 |
1616LL | impl Loop {}
17 | ^^^^ types differ
17 | ^^^^
1818
1919error[E0275]: overflow evaluating the requirement `Poly1<(T,)> == _`
2020 --> $DIR/inherent-impls-overflow.rs:17:1
......@@ -50,5 +50,4 @@ LL | impl Poly0<()> {}
5050
5151error: aborting due to 7 previous errors
5252
53Some errors have detailed explanations: E0271, E0275.
54For more information about an error, try `rustc --explain E0271`.
53For more information about this error, try `rustc --explain E0275`.
tests/ui/lazy-type-alias/inherent-impls-overflow.rs+3-3
......@@ -7,12 +7,12 @@
77
88type Loop = Loop;
99//[current]~^ ERROR overflow normalizing the type alias `Loop`
10//[next]~^^ ERROR type mismatch resolving `_ == Loop`
10//[next]~^^ ERROR overflow evaluating the requirement `Loop == _`
1111
1212impl Loop {}
1313//[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 == _`
1616
1717type Poly0<T> = Poly1<(T,)>;
1818//[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`
99 |
1010LL | fn method(&self) {
1111 | ^^^^^^^^^^^^^^^^
12note: candidate #2 is defined in the trait `Trait2`
12note: candidate #2 is defined in an impl of the trait `Trait2` for the type `T`
1313 --> $DIR/rigid-alias-bound-is-not-inherent.rs:27:5
1414 |
1515LL | 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)]) {}
3737 = note: ...which requires caching mir of `foo::{constant#0}` for CTFE...
3838 = note: ...which requires elaborating drops for `foo::{constant#0}`...
3939 = 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: [] }`...
4141 = note: ...which again requires evaluating type-level constant, completing the cycle
4242 = note: cycle used when normalizing `inside_array_length::::foo::{constant#0}`
4343 = 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 {
55 | ----------------- expected `<T as Foo>::Assoc` because of return type
66...
77LL | ()
8 | ^^ types differ
8 | ^^ expected associated type, found `()`
99 |
1010 = note: expected associated type `<T as Foo>::Assoc`
1111 found unit type `()`
......@@ -23,7 +23,7 @@ LL | fn monomorphic() -> () {
2323LL | generic::<()>()
2424 | ^^^^^^^^^^^^^^^- help: consider using a semicolon here: `;`
2525 | |
26 | types differ
26 | expected `()`, found associated type
2727 |
2828 = note: expected unit type `()`
2929 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>;
66LL | default fn generate(self) -> Self::Output {
77 | ------------ expected `<T as Example>::Output` because of return type
88LL | Box::new(self)
9 | ^^^^^^^^^^^^^^ types differ
9 | ^^^^^^^^^^^^^^ expected associated type, found `Box<T>`
1010 |
1111 = note: expected associated type `<T as Example>::Output`
1212 found struct `Box<T>`
......@@ -19,7 +19,7 @@ error[E0308]: mismatched types
1919LL | fn trouble<T>(t: T) -> Box<T> {
2020 | ------ expected `Box<T>` because of return type
2121LL | Example::generate(t)
22 | ^^^^^^^^^^^^^^^^^^^^ types differ
22 | ^^^^^^^^^^^^^^^^^^^^ expected `Box<T>`, found associated type
2323 |
2424 = note: expected struct `Box<T>`
2525 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
22 --> $DIR/next-solver-ice.rs:5:6
33 |
44LL | <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`
66 |
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>`
7help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
8 |
9LL | fn check<T: Iterator>() where f32: From<<T as Iterator>::Item> {
10 | ++++++++++++++++++++++++++++++++++++++
1811
1912error: aborting due to 1 previous error
2013
tests/ui/traits/next-solver/assembly/ambiguity-due-to-uniquification-4.next.stderr+4-6
......@@ -1,11 +1,9 @@
1error[E0284]: type annotations needed
2 --> $DIR/ambiguity-due-to-uniquification-4.rs:17:44
1error[E0282]: type annotations needed
2 --> $DIR/ambiguity-due-to-uniquification-4.rs:17:47
33 |
44LL | 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`
86
97error: aborting due to 1 previous error
108
11For more information about this error, try `rustc --explain E0284`.
9For 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 {
77struct S {
88 f: &'static <() as Wf>::Assoc,
99 //~^ ERROR the trait bound `(): Wf` is not satisfied
10 //~| ERROR: the type `&'static <() as Wf>::Assoc` is not well-formed
1011}
1112
1213fn 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
1010LL | trait Wf {
1111 | ^^^^^^^^
1212
13error: the type `&'static <() as Wf>::Assoc` is not well-formed
14 --> $DIR/non-wf-in-coerce-pointers.rs:8:8
15 |
16LL | f: &'static <() as Wf>::Assoc,
17 | ^^^^^^^^^^^^^^^^^^^^^^^^^^
18
1319error[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
1521 |
1622LL | let y: &() = x.f;
1723 | ^^^ the trait `Wf` is not implemented for `()`
......@@ -22,6 +28,6 @@ help: this trait has no implementations, consider adding one
2228LL | trait Wf {
2329 | ^^^^^^^^
2430
25error: aborting due to 2 previous errors
31error: aborting due to 3 previous errors
2632
2733For 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,)
55 | ----------- expected `(*const T,)` because of return type
66...
77LL | x
8 | ^ types differ
8 | ^ expected `(*const T,)`, found associated type
99 |
1010 = note: expected tuple `(*const T,)`
1111 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`
22 --> $DIR/param-candidate-shadows-project.rs:27:19
33 |
44LL | require_bar::<T>();
5 | ^ types differ
5 | ^ expected `i32`, found associated type
66 |
7 = note: expected type `i32`
8 found associated type `<T as Foo>::Assoc`
79note: required for `T` to implement `Bar`
810 --> $DIR/param-candidate-shadows-project.rs:13:9
911 |
......@@ -14,6 +16,10 @@ note: required by a bound in `require_bar`
1416 |
1517LL | fn require_bar<T: Bar>() {}
1618 | ^^^ required by this bound in `require_bar`
19help: consider constraining the associated type `<T as Foo>::Assoc` to `i32`
20 |
21LL | fn foo<T: Foo<Assoc = i32>>() {
22 | +++++++++++++
1723
1824error: aborting due to 1 previous error
1925
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>;
1313//~^ ERROR: the trait bound `i32: Trait` is not satisfied
1414
1515struct Wrap(TraitObject);
16//~^ ERROR: the trait bound `i32: Trait` is not satisfied
16//~^ ERROR: type mismatch resolving `TraitObject == _`
1717
1818fn cast(x: *mut Wrap) {
1919 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
1010LL | trait Trait {
1111 | ^^^^^^^^^^^
1212
13error[E0277]: the trait bound `i32: Trait` is not satisfied
13error[E0271]: type mismatch resolving `TraitObject == _`
1414 --> $DIR/dont-ice-on-normalization-failure.rs:15:13
1515 |
1616LL | struct Wrap(TraitObject);
17 | ^^^^^^^^^^^ the trait `Trait` is not implemented for `i32`
18 |
19help: this trait has no implementations, consider adding one
20 --> $DIR/dont-ice-on-normalization-failure.rs:6:1
21 |
22LL | trait Trait {
23 | ^^^^^^^^^^^
17 | ^^^^^^^^^^^ types differ
2418
2519error: aborting due to 2 previous errors
2620
27For more information about this error, try `rustc --explain E0277`.
21Some errors have detailed explanations: E0271, E0277.
22For 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 @@
1error[E0271]: type mismatch resolving `<fn() -> impl Sized {foo} as FnOnce<()>>::Output == {integer}`
1error[E0271]: expected `foo` to return `{integer}`, but it returns `impl Sized`
22 --> $DIR/normalize-assoc-ty-expected-int-var-no-ice-2.rs:13:10
33 |
4LL | fn foo() -> impl Sized {}
5 | ---------- the found opaque type
6...
47LL | proj(x, 1);
5 | ---- ^ types differ
8 | ---- ^ expected integer, found opaque type
69 | |
710 | required by a bound introduced by this call
811 |
12 = note: expected type `{integer}`
13 found opaque type `impl Sized`
914note: required by a bound in `proj`
1015 --> $DIR/normalize-assoc-ty-expected-int-var-no-ice-2.rs:9:24
1116 |
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) {}
1111fn main() {
1212 let mut x = None;
1313 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`
1615 x = Some(foo);
1716}
tests/ui/traits/next-solver/specialization-transmute.stderr+13-2
......@@ -1,22 +1,33 @@
11error[E0308]: mismatched types
22 --> $DIR/specialization-transmute.rs:13:9
33 |
4LL | impl<T> Default for T {
5 | - found this type parameter
6LL | default type Id = T;
47LL | fn intu(&self) -> &Self::Id {
58 | --------- expected `&<T as Default>::Id` because of return type
69LL | self
7 | ^^^^ types differ
10 | ^^^^ expected `&<T as Default>::Id`, found `&T`
811 |
912 = note: expected reference `&<T as Default>::Id`
1013 found reference `&T`
14help: consider restricting type parameter `T` with `<Id = T>`
15 |
16LL | impl<T: <Id = T>> Default for T {
17 | ++++++++++
1118
1219error[E0271]: type mismatch resolving `<u8 as Default>::Id == Option<NonZero<u8>>`
1320 --> $DIR/specialization-transmute.rs:24:50
1421 |
1522LL | let s = transmute::<u8, Option<NonZero<u8>>>(0);
16 | ------------------------------------ ^ types differ
23 | ------------------------------------ ^ expected `Option<NonZero<u8>>`, found associated type
1724 | |
1825 | required by a bound introduced by this call
1926 |
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
2031note: required by a bound in `transmute`
2132 --> $DIR/specialization-transmute.rs:17:25
2233 |
tests/ui/traits/next-solver/specialization-unconstrained.stderr+5-1
......@@ -2,8 +2,12 @@ error[E0271]: type mismatch resolving `<u32 as Default>::Id == ()`
22 --> $DIR/specialization-unconstrained.rs:19:12
33 |
44LL | test::<u32, ()>();
5 | ^^^ types differ
5 | ^^^ expected `()`, found associated type
66 |
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
711note: required by a bound in `test`
812 --> $DIR/specialization-unconstrained.rs:16:20
913 |
tests/ui/traits/next-solver/stalled-coroutine-obligations.rs+4-4
......@@ -16,11 +16,11 @@
1616fn stalled_copy_clone() {
1717 type T = impl Copy;
1818 let foo: T = async {};
19 //~^ ERROR: the trait bound
19 //~^ ERROR: type mismatch resolving `T == {async block
2020
2121 type U = impl Clone;
2222 let bar: U = async {};
23 //~^ ERROR: the trait bound
23 //~^ ERROR: type mismatch resolving `U == {async block
2424}
2525
2626auto trait Valid {}
......@@ -31,13 +31,13 @@ fn stalled_auto_traits() {
3131 type T = impl Valid;
3232 let a = False;
3333 let foo: T = async { a };
34 //~^ ERROR: the trait bound `False: Valid` is not satisfied
34 //~^ ERROR: type mismatch resolving `T == {async block
3535}
3636
3737
3838trait Trait {
3939 fn stalled_send(&self, b: *mut ()) -> impl Future + Send {
40 //~^ ERROR: type mismatch resolving
40 //~^ ERROR: type mismatch resolving `impl Future + Send == {async block
4141 async move {
4242 b
4343 }
tests/ui/traits/next-solver/stalled-coroutine-obligations.stderr+14-22
......@@ -1,41 +1,33 @@
1error[E0277]: the trait bound `{async block@$DIR/stalled-coroutine-obligations.rs:18:18: 18:23}: Copy` is not satisfied
1error[E0271]: type mismatch resolving `T == {async block@$DIR/stalled-coroutine-obligations.rs:18:18: 18:23}`
22 --> $DIR/stalled-coroutine-obligations.rs:18:14
33 |
44LL | 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
66
7error[E0277]: the trait bound `{async block@$DIR/stalled-coroutine-obligations.rs:22:18: 22:23}: Clone` is not satisfied
7error[E0271]: type mismatch resolving `U == {async block@$DIR/stalled-coroutine-obligations.rs:22:18: 22:23}`
88 --> $DIR/stalled-coroutine-obligations.rs:22:14
99 |
1010LL | 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
1212
13error[E0277]: the trait bound `False: Valid` is not satisfied in `{async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}`
13error[E0271]: type mismatch resolving `T == {async block@$DIR/stalled-coroutine-obligations.rs:33:18: 33:23}`
1414 --> $DIR/stalled-coroutine-obligations.rs:33:14
1515 |
1616LL | 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 |
21help: 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 |
24LL | struct False;
25 | ^^^^^^^^^^^^
26note: captured value does not implement `Valid`
27 --> $DIR/stalled-coroutine-obligations.rs:33:26
28 |
29LL | let foo: T = async { a };
30 | ^ has type `False` which does not implement `Valid`
17 | ^ types differ
3118
3219error[E0271]: type mismatch resolving `impl Future + Send == {async block@$DIR/stalled-coroutine-obligations.rs:41:9: 41:19}`
3320 --> $DIR/stalled-coroutine-obligations.rs:39:43
3421 |
3522LL | fn stalled_send(&self, b: *mut ()) -> impl Future + Send {
36 | ^^^^^^^^^^^^^^^^^^ types differ
23 | ^^^^^^^^^^^^^^^^^^ expected `async` block, found associated type
24LL |
25LL | 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`
3730
3831error: aborting due to 4 previous errors
3932
40Some errors have detailed explanations: E0271, E0277.
41For more information about an error, try `rustc --explain E0271`.
33For 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 @@
1error[E0271]: type mismatch resolving `<u8 as Trait>::Diverges<u8> == _`
1error[E0275]: overflow evaluating the requirement `<u8 as Trait>::Diverges<u8> == _`
22 --> $DIR/normalize-diverging-alias-in-struct.rs:21:12
33 |
44LL | field: Box<<u8 as Trait>::Diverges<u8>>,
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<u8 as Trait>::Diverges<u8> == _`
6 |
7note: types differ
8 --> $DIR/normalize-diverging-alias-in-struct.rs:17:31
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6
7error[E0275]: overflow evaluating whether `Box<<u8 as Trait>::Diverges<u8>>` is well-formed
8 --> $DIR/normalize-diverging-alias-in-struct.rs:21:12
99 |
10LL | type Diverges<D: Trait> = D::Diverges<D>;
11 | ^^^^^^^^^^^^^^
10LL | field: Box<<u8 as Trait>::Diverges<u8>>,
11 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
13error: aborting due to 1 previous error
13error: aborting due to 2 previous errors
1414
15For more information about this error, try `rustc --explain E0271`.
15For 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 {
1919
2020struct Foo {
2121 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
2424}
2525
2626fn main() {}
tests/ui/type-alias-impl-trait/coherence/coherence_different_hidden_ty.rs+2-1
......@@ -9,6 +9,7 @@
99// @lcnr: Because of this I decided to not bother and cause this to fail instead.
1010// In the future we can definitely modify the compiler to accept this
1111// again.
12
1213#![feature(type_alias_impl_trait)]
1314
1415trait Trait {}
......@@ -18,7 +19,7 @@ type TAIT = impl Sized;
1819impl Trait for (TAIT, TAIT) {}
1920
2021impl Trait for (u32, i32) {}
21//~^ ERROR: conflicting implementations of trait `Trait` for type
22//~^ ERROR: conflicting implementations of trait `Trait` for type `(TAIT, TAIT)`
2223
2324#[define_opaque(TAIT)]
2425fn define() -> TAIT {}
tests/ui/type-alias-impl-trait/coherence/coherence_different_hidden_ty.stderr+1-1
......@@ -1,5 +1,5 @@
11error[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
33 |
44LL | impl Trait for (TAIT, TAIT) {}
55 | --------------------------- 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)]
12type Tait<T> = impl Sized;
13#[define_opaque(Tait)]
14fn foo<T>(x: T) -> Tait<T> {
15 x
16}
17
18trait Trait {
19 type Assoc;
20}
21
22fn bar<T>() -> [u8; 4]
23where
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
32fn main() {}
tests/ui/type-alias-impl-trait/const_eval_reveal_opaque_in_param_env.stderr created+12
......@@ -0,0 +1,12 @@
1warning: cannot use constants which depend on generic parameters in types
2 --> $DIR/const_eval_reveal_opaque_in_param_env.rs:27:9
3 |
4LL | [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
11warning: 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);
55 | ------------- method `bar` not found for this struct
66...
77LL | 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>`
911
1012error: aborting due to 1 previous error
1113
tests/ui/wf/return-type-non-wf-no-ice.next.stderr+2-16
......@@ -1,22 +1,8 @@
1error[E0277]: `T` is not an iterator
1error: the type `Foo<T>` is not well-formed
22 --> $DIR/return-type-non-wf-no-ice.rs:13:16
33 |
44LL | fn foo<T>() -> Foo<T> {
5 | ^^^^^^ `T` is not an iterator
6 |
7note: required by a bound in `Foo`
8 --> $DIR/return-type-non-wf-no-ice.rs:10:8
9 |
10LL | pub struct Foo<T>(T)
11 | --- required by a bound in this struct
12LL | where
13LL | T: Iterator,
14 | ^^^^^^^^ required by this bound in `Foo`
15help: consider restricting type parameter `T` with trait `Iterator`
16 |
17LL | fn foo<T: std::iter::Iterator>() -> Foo<T> {
18 | +++++++++++++++++++++
5 | ^^^^^^
196
207error: aborting due to 1 previous error
218
22For 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
1111 <T as Iterator>::Item: Default;
1212
1313fn 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
1516 loop {}
1617}
1718