Skip to content

Commit 3095448

Browse files
committed
Auto merge of #141007 - fmease:lta-expand-before-inf-outlives, r=<try>
Expand free alias types when computing implied outlives-bounds
2 parents ab26b17 + 235a463 commit 3095448

6 files changed

Lines changed: 40 additions & 1 deletion

File tree

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
160160
// See trait-system-refactor-initiative#234.
161161
}
162162

163+
fn expand_free_alias_tys<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
164+
self.expand_free_alias_tys(t)
165+
}
166+
163167
fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
164168
self.expand_abstract_consts(t)
165169
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ impl<'tcx> TyCtxt<'tcx> {
879879
value.fold_with(&mut FreeAliasTypeExpander { tcx: self, depth: 0 })
880880
}
881881

882-
/// Peel off all [free alias types] in this type until there are none left.
882+
/// Peel off all [free alias types][free] in this type until there are none left.
883883
///
884884
/// This only expands free alias types in “head” / outermost positions. It can
885885
/// be used over [expand_free_alias_tys] as an optimization in situations where

compiler/rustc_type_ir/src/interner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ pub trait Interner:
217217
/// (in theory) only happen when concurrent.
218218
fn assert_evaluation_is_concurrent(&self);
219219

220+
fn expand_free_alias_tys<T: TypeFoldable<Self>>(self, t: T) -> T;
220221
fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
221222

222223
type GenericsOf: GenericsOf<Self>;

compiler/rustc_type_ir/src/outlives.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub fn push_outlives_components<I: Interner>(
5858
ty: I::Ty,
5959
out: &mut SmallVec<[Component<I>; 4]>,
6060
) {
61+
let ty = cx.expand_free_alias_tys(ty);
6162
ty.visit_with(&mut OutlivesCollector { cx, out, visited: Default::default() });
6263
}
6364

@@ -140,6 +141,11 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
140141
self.out.push(Component::Placeholder(p));
141142
}
142143

144+
// All free alias types should've been expanded beforehand.
145+
ty::Alias(ty::AliasTy { kind: ty::Free { .. }, .. }) => {
146+
panic!("unexpected free alias type")
147+
}
148+
143149
// For projections, we prefer to generate an obligation like
144150
// `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
145151
// regionck more ways to prove that it holds. However,
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: rustc_dump_inferred_outlives
2+
--> $DIR/implied-outlives-bounds-1.rs:13:1
3+
|
4+
LL | struct Type<'a, K, V>(&'a mut Alias<K, V>);
5+
| ^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: K: 'a
8+
= note: V: 'a
9+
10+
error: aborting due to 1 previous error
11+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Check that we infer the outlives-predicates `K: 'a`, `V: 'a` for `Type`
2+
// from the free alias `Alias`.
3+
// FIXME(fmease): Proper explainer.
4+
5+
//@ revisions: default print
6+
//@[default] check-pass
7+
8+
#![feature(lazy_type_alias)]
9+
#![cfg_attr(print, feature(rustc_attrs))]
10+
#![allow(incomplete_features)]
11+
12+
#[cfg_attr(print, rustc_dump_inferred_outlives)]
13+
struct Type<'a, K, V>(&'a mut Alias<K, V>); //[print]~ ERROR rustc_dump_inferred_outlives
14+
15+
type Alias<K, V> = (K, V);
16+
17+
fn main() {}

0 commit comments

Comments
 (0)