Skip to content

associated types have to be fully constrained #12

Open
@lcnr

Description

@lcnr

cc https://rust-lang.zulipchat.com/#narrow/channel/144729-t-types/topic/.E2.9C.94.20required.20outlives.20but.20otherwise.20unconstrained

trait Trait {
    type Assoc;
}
struct Inv<'a>(&'a mut &'a ());
impl<'a, 'b: 'a> Trait for Inv<'a> {
    // This must error as normalization has to be a function.
    //
    // Normalizing to two different types, even if they only differ
    // by regions, is unsound.
    type Assoc = &'b str;
}

fn identity<T: Trait<Assoc = &'static str>>(x: T::Assoc) -> &'static str {
    x
}

fn dangle() -> &'static str {
    let temp = String::from("temporary");
    identity::<Inv<'_>>(temp.as_str())
}

fn main() {
    println!("{:?}", dangle());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions