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

hopefully irrelevant candidate behavior difference of Sized/trivial builtin impls #162

Open
lcnr opened this issue Feb 12, 2025 · 1 comment

Comments

@lcnr
Copy link
Contributor

lcnr commented Feb 12, 2025

struct MaybeSized<T: ?Sized>(T);

fn is_sized<T: Sized>() -> Box<T> { todo!() }

fn foo<T: ?Sized>()
where
    MaybeSized<T>: Sized,
{
    is_sized::<MaybeSized<_>>();
}

this compiles with the old solver, inferring the _ to T. It has a ParamEnv and a BuiltinCandidate { has_nested: true } candidate and prefers the ParamEnv candidate here.

The new solver encounters a trivial impl candidate and a ParamEnv one, preferring the trivial builtin.

@lcnr lcnr moved this to potentially irrelevant in -Znext-solver=globally Feb 12, 2025
@lcnr lcnr changed the title hopefully irrelevant breakage due to trivial builtin impls hopefully irrelevant candidate behavior difference of Sized/trivial builtin impls Feb 12, 2025
@lcnr
Copy link
Contributor Author

lcnr commented Feb 12, 2025

The old solver only considers Sized impls to be trivial if the sized_conditions are empty. This means that even with a trivially true condition we prefer where-bounds. This results in the following inconsistent behavior:

trait Trait<T>: Sized {}
impl<T> Trait<T> for T {}

fn is_sized<T: Sized>() {}

fn normal_ref<'a, 'b, T>()
where
    &'a u32: Trait<T>,
{
    // Uses builtin impl, OK
    is_sized::<&'b u32>();
}

struct MyRef<'a, U: ?Sized = ()>(&'a u32, U);
fn my_ref<'a, 'b, T>()
where
    MyRef<'a>: Trait<T>,
{
    // Uses where-bound, lifetime error
    is_sized::<MyRef<'b>>();
}

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

No branches or pull requests

1 participant