Skip to content

Unconstrained lifetimes permitted in assoc. type as long as they are in a projection #29861

@nikomatsakis

Description

@nikomatsakis

This makes things unsound. Here is an example from @eddyb:

pub trait MakeRef<'a> {
    type Ref;
}
impl<'a, T: 'a> MakeRef<'a> for T {
    type Ref = &'a T;
}

pub trait MakeRef2 {
    type Ref2;
}
impl<'a, T> MakeRef2 for T {
    type Ref2 = <T as MakeRef<'a>>::Ref;
}

fn foo() -> <String as MakeRef2>::Ref2 { &String::from("foo") }

fn main() {
    println!("{}", foo());
}

This should be prohibited by https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md, but it seems there is some bug.

Metadata

Metadata

Assignees

Labels

A-trait-systemArea: Trait systemI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions