diff --git a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs index de42736ce2b06..e6ca880bd18c6 100644 --- a/compiler/rustc_infer/src/infer/outlives/test_type_match.rs +++ b/compiler/rustc_infer/src/infer/outlives/test_type_match.rs @@ -44,9 +44,6 @@ pub fn extract_verify_if_eq<'tcx>( assert!(!verify_if_eq_b.has_escaping_bound_vars()); let mut m = MatchAgainstHigherRankedOutlives::new(tcx); let verify_if_eq = verify_if_eq_b.skip_binder(); - debug_assert!( - !tcx.next_trait_solver_globally() || !(verify_if_eq.ty, test_ty).has_non_rigid_aliases() - ); m.relate(verify_if_eq.ty, test_ty).ok()?; if let ty::RegionKind::ReBound(index_kind, br) = verify_if_eq.bound.kind() { @@ -198,6 +195,13 @@ impl<'tcx> TypeRelation> for MatchAgainstHigherRankedOutlives<'tcx> self.no_match() } else if pattern == value { Ok(pattern) + } else if let (ty::Alias(_, pattern_alias), ty::Alias(_, value_alias)) = + (*pattern.kind(), *value.kind()) + { + // Rigidness is normalization state. This matcher only needs to know + // whether both sides are the same alias shape. + self.relate(pattern_alias, value_alias)?; + Ok(pattern) } else { relate::structurally_relate_tys(self, pattern, value) } @@ -211,6 +215,13 @@ impl<'tcx> TypeRelation> for MatchAgainstHigherRankedOutlives<'tcx> ) -> RelateResult<'tcx, ty::Const<'tcx>> { if pattern == value { Ok(pattern) + } else if let ( + ty::ConstKind::Alias(_, pattern_alias), + ty::ConstKind::Alias(_, value_alias), + ) = (pattern.kind(), value.kind()) + { + self.relate(pattern_alias, value_alias)?; + Ok(pattern) } else { relate::structurally_relate_consts(self, pattern, value) } diff --git a/compiler/rustc_trait_selection/src/traits/outlives_for_liveness.rs b/compiler/rustc_trait_selection/src/traits/outlives_for_liveness.rs index 5cba32d742f62..ad80864db924a 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_for_liveness.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_for_liveness.rs @@ -56,10 +56,6 @@ pub(crate) fn live_args_for_alias_from_outlives_bounds<'tcx>( test_type_match::extract_verify_if_eq( tcx, &outlives.map_bound(|ty::OutlivesClause(ty, bound)| VerifyIfEq { ty, bound }), - // FIXME(#155345): Region handling should generally only - // deal with rigid aliases, making sure we do so correctly - // everywhere is effort, so we're just using `No` everywhere - // for now. This should change soon. alias_ty, ) } diff --git a/tests/ui/traits/next-solver/rigid-alias-liveness-issue-160206.rs b/tests/ui/traits/next-solver/rigid-alias-liveness-issue-160206.rs new file mode 100644 index 0000000000000..4899645e10d58 --- /dev/null +++ b/tests/ui/traits/next-solver/rigid-alias-liveness-issue-160206.rs @@ -0,0 +1,27 @@ +//@ compile-flags: -Znext-solver=globally +//@ check-pass + +trait Foo<'x> { + type Out; + fn foo(self) -> Self::Out; +} + +struct Bar; + +impl<'x> Foo<'x> for Bar { + type Out = (); + + fn foo(self) -> Self::Out { + todo!() + } +} + +fn make_static_foo<'x>(_: &'x ()) -> impl Foo<'x, Out: 'static> { + Bar +} + +fn test() { + make_static_foo(&()); +} + +fn main() {}