Skip to content
Draft
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
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn check_explicit_predicates<'tcx>(
}
}

/// Check the inferred predicates declared on the type.
/// Check the inferred predicates of the type.
///
/// ### Example
///
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.sess.threads() > 1
}

fn expand_free_alias_tys<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
self.expand_free_alias_tys(t)
}

fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, t: T) -> T {
self.expand_abstract_consts(t)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ impl<'tcx> TyCtxt<'tcx> {
value.fold_with(&mut FreeAliasTypeExpander { tcx: self, depth: 0 })
}

/// Peel off all [free alias types] in this type until there are none left.
/// Peel off all [free alias types][free] in this type until there are none left.
///
/// This only expands free alias types in “head” / outermost positions. It can
/// be used over [expand_free_alias_tys] as an optimization in situations where
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub trait Interner:

fn evaluation_is_concurrent(&self) -> bool;

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

type GenericsOf: GenericsOf<Self>;
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_type_ir/src/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub fn push_outlives_components<I: Interner>(
ty: I::Ty,
out: &mut SmallVec<[Component<I>; 4]>,
) {
let ty = cx.expand_free_alias_tys(ty);
ty.visit_with(&mut OutlivesCollector { cx, out, visited: Default::default() });
}

Expand Down Expand Up @@ -140,6 +141,9 @@ impl<I: Interner> TypeVisitor<I> for OutlivesCollector<'_, I> {
self.out.push(Component::Placeholder(p));
}

// All free alias types should've been expanded beforehand.
ty::Alias(ty::Free, _) => panic!("unexpected free alias type"),

// For projections, we prefer to generate an obligation like
// `<P0 as Trait<P1...Pn>>::Foo: 'a`, because this gives the
// regionck more ways to prove that it holds. However,
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/lazy-type-alias/implied-outlives-bounds-1.print.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: rustc_outlives
--> $DIR/implied-outlives-bounds-1.rs:16:1
|
LL | struct Type<'a, K, V>(&'a mut Alias<K, V>);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: K: 'a
= note: V: 'a

error: aborting due to 1 previous error

17 changes: 17 additions & 0 deletions tests/ui/lazy-type-alias/implied-outlives-bounds-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Check that we infer the outlives-predicates `K: 'a`, `V: 'a` for `Type`
// from the free alias `Alias`.
// FIXME(fmease): Proper explainer.

//@ revisions: default print
//@[default] check-pass

#![feature(lazy_type_alias)]
#![cfg_attr(print, feature(rustc_attrs))]
#![allow(incomplete_features)]

#[cfg_attr(print, rustc_outlives)]
struct Type<'a, K, V>(&'a mut Alias<K, V>); //[print]~ ERROR rustc_outlives

type Alias<K, V> = (K, V);

fn main() {}
Loading