This is a tracking issue for the RFC 3851 rust-lang/rfcs#3851.
The feature gate for the issue is #![feature(supertrait_auto_impl)].
Motivation
We propose supertrait auto impl as one of the solutions to facilitate trait evolution in the Rust ecosystem. auto impl would reduce the effort to rewrite trait implementation by transparently resolving items from the big subtrait to supertraits and by providing a mechanism to supply default implementation of supertraits with clear syntatical notation.
Current state of the language
Rust today would require great effort to re-organise the trait hierarchy, especially concerning the downstream trait implementations. As an illustration, moving a trait associated item to a higher supertrait would require all downstream implementations to split.
Previously, we have the following.
trait BigTrait {
fn foo(..);
fn bar(..);
}
impl BigTrait for MyType {
fn foo(..) {
// implementation
}
fn bar(..) {
// implementation
}
}
By splitting the BigTrait, so would one need to split all the existing implementations.
trait BigTrait: Supertrait {
fn foo(..);
}
trait Supertrait {
fn bar(..);
}
impl BigTrait for MyType {
fn foo(..) {
// implementation
}
}
impl Supertrait for MyType {
fn bar(..) {
// implementation
}
}
Experiment proposal
We would like to carry out an experiment to introduce supertrait auto impl, so that the existing implementation will continue to "just work."
trait BigTrait: Supertrait {
auto impl Supertrait;
fn foo(..);
}
trait Supertrait {
fn bar(..);
}
impl BigTrait for MyType {
fn foo(..) {
// implementation
}
fn bar(..) {
// implementation for Supertrait::bar
}
}
There are more motivating examples in rust-lang/rfcs#3851 which are the use cases we would like to enable when trait refactoring is concerned.
Steps
Unresolved Questions
TBD
Implementation history
This is a tracking issue for the RFC 3851 rust-lang/rfcs#3851.
The feature gate for the issue is
#![feature(supertrait_auto_impl)].Motivation
We propose supertrait
auto implas one of the solutions to facilitate trait evolution in the Rust ecosystem.auto implwould reduce the effort to rewrite trait implementation by transparently resolving items from the big subtrait to supertraits and by providing a mechanism to supply default implementation of supertraits with clear syntatical notation.Current state of the language
Rust today would require great effort to re-organise the trait hierarchy, especially concerning the downstream trait implementations. As an illustration, moving a trait associated item to a higher supertrait would require all downstream implementations to split.
Previously, we have the following.
By splitting the
BigTrait, so would one need to split all the existing implementations.Experiment proposal
We would like to carry out an experiment to introduce supertrait
auto impl, so that the existing implementation will continue to "just work."There are more motivating examples in rust-lang/rfcs#3851 which are the use cases we would like to enable when trait refactoring is concerned.
Steps
rustfmtsupport, seeStyle updatesclippylintscargo-semversupportrustfmtUnresolved Questions
TBD
Implementation history