rust-lang / trait-system-refactor-initiative

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

requiring item bounds for coinduction may be breaking #80

Open lcnr opened 10 months ago

lcnr commented 10 months ago

our current plan to soundly support coinductive traits is to require proving the item bounds of a trait when using an implementation. Afaict this should break the following example:

trait WithSuper<T>: Copy {}

trait WithAliasBound {
    type Assoc: Copy;
}

// With our approach to coinduction, using this impl should require
// proving `<T as WithAliasBound>::Assoc: Copy`
impl<T: WithAliasBound> WithSuper<T> for <T as WithAliasBound>::Assoc {}

fn impls_with_super<T: WithSuper<U>, U>() {}

fn item_bounds_not_checked<T: WithAliasBound<Assoc = U>, U>() {
    impls_with_super::<U, T>();
    // This uses the impl and would fail to prove `U: Copy`.
}

related issues

compiler-errors commented 10 months ago

would this be fixed if we auto-elaborated item bounds, i.e. elaborate U: Copy from T: WithAliasBound<Assoc = U>?

lcnr commented 10 months ago

yes it would, had the same convo with @BoxyUwU rn 😆 doing so is non-trivial however.

Instead of T: WithAliasBound<Assoc = U> you can have T: WithIntoIteratorAliasBound<Assoc = Vec<U>>. So if you now add Vec<u32>: IntoIterator into the environment it probably shadows the actual impl, preventing you from normalizing <Vec<u32> as IntoIterator>::Item. We probably want param env Trait-candidates to prevent normalizing via impls due to #76/https://github.com/rust-lang/trait-system-refactor-initiative/issues/12