Skip to content
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

impls with higher ranked projections are now usable #9

Open
lcnr opened this issue Apr 17, 2023 · 1 comment
Open

impls with higher ranked projections are now usable #9

lcnr opened this issue Apr 17, 2023 · 1 comment

Comments

@lcnr
Copy link
Contributor

lcnr commented Apr 17, 2023

trait Trait {}

trait OtherTrait {
    type Assoc<'a>;
}

impl<T: OtherTrait> Trait for (T, for<'a> fn(<T as OtherTrait>::Assoc<'a>)) {}

impl OtherTrait for u32 {
    type Assoc<'a> = &'a u32;
}

fn impls<T: Trait>() {}

fn main() {
    impls::<(u32, for<'a> fn(&'a u32))>();
}

This does not work with the old solver but will compile with the new solver. In the old solver we are unable to eagerly normalize <T as OtherTrait>::Assoc<'a> and also can't replace it with an inference variable (as it contains a bound variable), so then after constraining T the projection is still treated as rigid, even though it is now concrete.

This means that rust-lang/rust#105787 will end up being exploitable with the new solver which is not great 🤷

@lcnr
Copy link
Contributor Author

lcnr commented Oct 6, 2023

This will also break the following example with -Ztrait-solver=next-coherence: https://rust.godbolt.org/z/zW16n87oq

trait Trait {}

trait OtherTrait {
    type Assoc<'a>;
}

impl<T: OtherTrait> Trait for (T, for<'a> fn(<T as OtherTrait>::Assoc<'a>)) {}

impl OtherTrait for u32 {
    type Assoc<'a> = &'a u32;
}

impl<'a> Trait for (u32, fn(&'a u32)) {}

The overlap is unsound, but currently not exploitable.

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

No branches or pull requests

1 participant