Skip to content

associated types have to be fully constrained #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lcnr opened this issue Dec 20, 2024 · 0 comments
Open

associated types have to be fully constrained #12

lcnr opened this issue Dec 20, 2024 · 0 comments

Comments

@lcnr
Copy link
Owner

lcnr commented Dec 20, 2024

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());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant