Skip to content

Regression: Not well-formed HRTB doesn't compile #55498

Description

@mashedcode

The code below doesn't compile anymore since nightly-2018-10-05:

use std::marker::PhantomData;

pub trait FooTypeHack: for<'a, 'b> FooType<'a, 'b> {}
impl<T: for<'a, 'b> FooType<'a, 'b>> FooTypeHack for T {}

pub trait FooType<'a, 'b: 'a> {
    type Foo: Foo<'a, 'b>;
}

pub trait Foo<'a, 'b: 'a> {}

pub struct FooStruct<T>
where
    T: FooTypeHack,
{
    _t: PhantomData<T>,
}

impl<T> FooStruct<T>
where
    T: FooTypeHack,
{
    fn new() -> Self {
        Self { _t: PhantomData }
    }
}

pub struct FooTypeImpl {}
impl<'a, 'b: 'a> FooType<'a, 'b> for FooTypeImpl {
    type Foo = FooImpl<'a, 'b>;
}

pub struct FooImpl<'a, 'b: 'a> {
    _a: &'a PhantomData<&'b String>,
}

impl<'a, 'b> Foo<'a, 'b> for FooImpl<'a, 'b> {}

fn main() {
    FooStruct::<FooTypeImpl>::new();
}

(Playground)

One would expect this to compile since it compiles on stable. Instead it throws:

error[E0279]: the requirement `for<'b, 'a> 'b : 'a` is not satisfied (`expected bound lifetime parameter 'a, found concrete lifetime`)
  --> src/main.rs:40:5

AFAIK for<'b, 'a> 'b: 'a can currently not be satisfied in rust therefore this should compile.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions