rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
22 stars 0 forks source link

normalizing opaques in outlives constraints allows more code compile #112

Open lcnr opened 6 months ago

lcnr commented 6 months ago
#![feature(type_alias_impl_trait)]
use std::marker::PhantomData;
type Tait<'a> = impl Sized;

struct Outlives<'a, T: 'a>(PhantomData<&'a ()>, PhantomData<T>);

fn foo<'a, 'b>() -> Tait<'a> {
    let _: Outlives::<'b, Tait<'a>> = Outlives(PhantomData, PhantomData);
    ()
}

this fails with the old solver with

error: lifetime may not live long enough
 --> <source>:8:12
  |
7 | fn foo<'a, 'b>() -> Tait<'a> {
  |        --  -- lifetime `'b` defined here
  |        |
  |        lifetime `'a` defined here
8 |     let _: Outlives::<'b, Tait<'a>> = Outlives(PhantomData, PhantomData);
  |            ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'b`
  |
  = help: consider adding the following bound: `'a: 'b`
compiler-errors commented 6 months ago
trait Captures<'a, 'b> {}
impl<T> Captures<'_, '_> for T {}

fn hello<'a: 'a, 'b: 'b>() -> impl Sized + Captures<'a, 'b> {
    fn outlives<'a>(_: impl Sized + 'a) {}
    outlives::<'a>(hello::<'a, 'b>());
    ()
}