rust-lang / trait-system-refactor-initiative

The Rustc Trait System Refactor Initiative
21 stars 0 forks source link

rustc doesn't check nested WFness if it's in a higher-ranked predicate #104

Open compiler-errors opened 6 months ago

compiler-errors commented 6 months ago

https://github.com/rust-lang/rust/pull/122501#issue-2186819021

This will probably end up complicating implied bounds computation in binders?

compiler-errors commented 6 months ago

Minimal I think:

trait Bound {}

struct W<'a, T: Bound>(&'a T);

fn wf<T>() where for<'a> W<'a, T>: Sized {}

We should recurse on W<'a, T> and see T: Bound must hold, but we don't even recurse on the self arg of the predicate because the trait has escaping bound vars.

jackh726 commented 6 months ago

That regression list sucks. I think this is something we should consider slowly moving towards error (or at least deny-by-default) by starting with a warn-by-default lint.

I'm also curious if there's a good MCVE for things that are so "obvious" as the example above. This modification, for example, is pretty clear what the problem is when trying to call wf:

use std::fmt::Debug;

trait Bound {}

struct W<'a, T: Bound>(&'a T);

fn wf<T>() where for<'a> W<'a, T>: Debug {}

fn main() {
    wf::<u32>();
}

But, I could imagine that we can have move subtle things we don't check in e.g. super trait bounds. These could be good candidates to also move towards erroring quicker.