Open nikomatsakis opened 6 years ago
Good summary. Thanks for writing this up.
Have we considered blocking stabilization on lazy normalization? That is, I'm worried that these are equivalent problems:
trait Foo<X> {}
type Bar<X: ExtraBound> = dyn Foo<X>;
fn bad<X>(_: &Bar<X>) {}
trait Foo2<X: ExtraBound> = Foo<X>;
fn bad2<X>(_: &dyn Foo2<X>) {}
The alternative, to consider Foo2
its own trait, has its own issues, IMO.
@eddyb Actually, they're not, under the current implementation, which is nice. The X: ExtraBound
bound is enforced. Example.
@nikomatsakis I just realised you never got around to factoring out the part of my old PR https://github.com/rust-lang/rust/pull/55994 that banned multi-trait objects via trait aliases... did you still want to tackle that?
5 years later and it would still be great to have.
I was thinking; a number of the points of contention might be resolved if it's switched to operating purely in name resolution.
This is the tracking issue for implementing (not discussing the design) RFC https://github.com/rust-lang/rfcs/pull/1733. It is a subissue of https://github.com/rust-lang/rust/issues/41517.
Current status
Once #55101 lands, many aspects of trait aliases will be implemented. However, some known limitations remain. These are mostly pre-existing limitations of the trait checker that we intend to lift more generally (see each case below for notes).
Well-formedness requirements. We currently require the trait alias to be well-formed. So, for example,
trait Foo<T: Send> { } trait Bar<T> = Foo<T>
is an error. We intend to modify this behavior as part of implementing the implied bounds RFC (https://github.com/rust-lang/rust/issues/44491).Trait object associated types. If you have
trait Foo = Iterator<Item =u32>
, you cannot use the trait object typedyn Foo
. This is a duplicate of https://github.com/rust-lang/rust/issues/24010.Trait object equality. If you have
trait Foo { }
andtrait Bar = Foo
, we do not currently considerdyn Foo
anddyn Bar
to be the same type. Tracking issue https://github.com/rust-lang/rust/issues/55629.Pending issues to resolve
Deviations and/or clarifications from the RFC
This section is for us to collect notes on deviations from the RFC text, or clarifications to unresolved questions.
PR history
Other links