diff --git a/compiler/rustc_middle/src/ty/predicate.rs b/compiler/rustc_middle/src/ty/predicate.rs index 7c5b49512ae50..09913953127c1 100644 --- a/compiler/rustc_middle/src/ty/predicate.rs +++ b/compiler/rustc_middle/src/ty/predicate.rs @@ -814,6 +814,10 @@ impl<'tcx> NormalizesTo<'tcx> { pub fn def_id(self) -> DefId { self.alias.def_id } + + pub fn as_projection(self) -> ProjectionPredicate<'tcx> { + ProjectionPredicate { projection_ty: self.alias, term: self.term } + } } pub trait ToPolyTraitRef<'tcx> { diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs index 9f1b4a09a20ba..2eed7f057c586 100644 --- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs @@ -378,6 +378,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { let tcx = ecx.tcx(); + let metadata_def_id = tcx.require_lang_item(LangItem::Metadata, None); + assert_eq!(metadata_def_id, goal.predicate.def_id()); ecx.probe_misc_candidate("builtin pointee").enter(|ecx| { let metadata_ty = match goal.predicate.self_ty().kind() { ty::Bool @@ -422,13 +424,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ty::Adt(def, args) if def.is_struct() => match def.non_enum_variant().tail_opt() { None => tcx.types.unit, - Some(field_def) => { - let self_ty = field_def.ty(tcx, args); + Some(tail_def) => { + let tail_ty = tail_def.ty(tcx, args); + let predicate = goal.predicate.with_self_ty(tcx, tail_ty).as_projection(); // FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`? - ecx.add_goal( - GoalSource::Misc, - goal.with(tcx, goal.predicate.with_self_ty(tcx, self_ty)), - ); + ecx.add_goal(GoalSource::Misc, goal.with(tcx, predicate)); return ecx .evaluate_added_goals_and_make_canonical_response(Certainty::Yes); } @@ -437,12 +437,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> { ty::Tuple(elements) => match elements.last() { None => tcx.types.unit, - Some(&self_ty) => { + Some(&tail_ty) => { + let predicate = goal.predicate.with_self_ty(tcx, tail_ty).as_projection(); // FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`? - ecx.add_goal( - GoalSource::Misc, - goal.with(tcx, goal.predicate.with_self_ty(tcx, self_ty)), - ); + ecx.add_goal(GoalSource::Misc, goal.with(tcx, predicate)); return ecx .evaluate_added_goals_and_make_canonical_response(Certainty::Yes); } diff --git a/tests/ui/traits/pointee-normalize-equate.rs b/tests/ui/traits/pointee-normalize-equate.rs index d70ab4d881444..2e75933aca0cf 100644 --- a/tests/ui/traits/pointee-normalize-equate.rs +++ b/tests/ui/traits/pointee-normalize-equate.rs @@ -1,4 +1,6 @@ // check-pass +// revisions: old next +//[next] compile-flags: -Znext-solver #![feature(ptr_metadata)]