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

imcomplete projection candidate selection for trait objects #4

Closed
lcnr opened this issue Feb 17, 2023 · 1 comment
Closed

imcomplete projection candidate selection for trait objects #4

lcnr opened this issue Feb 17, 2023 · 1 comment

Comments

@lcnr
Copy link
Owner

lcnr commented Feb 17, 2023

rust-lang/rust#107887

trait Trait<T> {
    type Assoc: ?Sized;
}

impl Trait<u32> for u32 {
    type Assoc = u16;
}

// This would trigger the check for overlap between automatic and custom impl
// They actually don't overlap so an impl like this should remain possible
// forever.
//
// impl Trait<u64> for dyn Trait<u32, Assoc = u32> {
//     type Assoc =  dyn Trait<u32, Assoc = u32>;
// }
trait Indirect<T: ?Sized> {}
impl Indirect<dyn Trait<u32, Assoc = u32>> for () {}
impl<T: ?Sized> Trait<u64> for T
where
    (): Indirect<T>,
{
    type Assoc = dyn Trait<u32, Assoc = u32>;
}

fn yay<T: Trait<U> + ?Sized, U>(x: &'static T) -> &'static <T as Trait<U>>::Assoc {
    todo!();
}

fn unconstrained<T>() -> T {
    todo!()
}

fn should_be_ambig() {
    let y: &'static dyn Trait<u32, Assoc = u32> = unconstrained();
    let _ = yay::<dyn Trait<u32, Assoc = u32>, _>(y);
    // The current solver incorrectly constrains `_` to `u32` here.
}

fn main() {
    let y: &'static dyn Trait<u32, Assoc = u32> = unconstrained();
    // let mut x = yay::<_, u64>(y); // compiles
    let mut x = yay::<_, _>(y); // errors
    x = y;
}

This example works on stable but will break with the new solver.

@lcnr
Copy link
Owner Author

lcnr commented Mar 14, 2024

closing in favor of #4

@lcnr lcnr closed this as completed Mar 14, 2024
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