Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions compiler/rustc_infer/src/infer/outlives/test_type_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -198,6 +195,13 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> 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)
}
Expand All @@ -211,6 +215,13 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
}
Expand Down
27 changes: 27 additions & 0 deletions tests/ui/traits/next-solver/rigid-alias-liveness-issue-160206.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Loading