-
Couldn't load subscription status.
- Fork 13.9k
Description
This is a sub-issue of #44662 proposing the Rust 2015 stabilization of dyn Trait.
Status
The decision is made, we just need a stabilization PR!
Details
The new syntactic form dyn <relative-path> is added. It is an error to use dyn <relative-path> if path does not name a trait. The result is a so-called dynamic trait type.
For backwards compatibility, dyn can still be used as an identifier -- in other words, it is a contextual keyword. Note also that dyn :: foo parses as a path dyn::foo and not a use of the dyn keyword. You can however write dyn (::foo) to clarify your meaning.
There is a "allow by default" lint that suggests uses of Trait be rewritten to dyn Trait. Much code in rustc was converted using rustfix in conjunction with this lint. I believe the current plan is to keep this lint as "allow by default" for the time being, but make it as part of the "idiom shift" lints for Rust 2018.
Tests
Here are some tests documenting the current behavior:
- Positive uses of
dyn Trait, including a use ofdyn (::Path). dynby itself is an identifierdyn::foois a path
Other details
Once this is stable, we should adjust the output from ppaux to use it! (#49277)