Skip to content

"lifetime parameter is not constrained..." when using lifetime param to derive assoc. type from reference type trait impl #36431

@cjsut

Description

@cjsut

This works (playpen):

use std::marker::PhantomData;
trait X {
    type Q;
}
trait Y { } 

struct Z<T> { t: PhantomData<T> }

impl<'a, T> X for Z<T> where T: 'a, &'a T: Y {
    type Q = u8;
}

If instead we add an associated type Z to Y and try to write type Q = <&'a T as Y>::Z; in the X implementation, it fails with "error[E0207]: the lifetime parameter 'a is not constrained by the impl trait, self type, or predicates" (playpen:

use std::marker::PhantomData;
trait X {
    type Q;
}
trait Y {
    type Z;
} 

struct Z<T> { t: PhantomData<T> }

impl<'a, T> X for Z<T> where T: 'a, &'a T: Y {
    type Q = <&'a T as Y>::Z;
}

Rust version: doesn't seem to matter; all of stable, beta, and nightly on play.rlo produce the same results.

Thanks to @QuietMisdreavus on IRC for helping with the reduced example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions