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:
Other details
Once this is stable, we should adjust the output from ppaux to use it! (#49277)
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 usedyn <relative-path>ifpathdoes not name a trait. The result is a so-called dynamic trait type.For backwards compatibility,
dyncan still be used as an identifier -- in other words, it is a contextual keyword. Note also thatdyn :: fooparses as a pathdyn::fooand not a use of thedynkeyword. You can however writedyn (::foo)to clarify your meaning.There is a "allow by default" lint that suggests uses of
Traitbe rewritten todyn Trait. Much code in rustc was converted usingrustfixin 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:
dyn Trait, including a use ofdyn (::Path).dynby itself is an identifierdyn::foois a pathOther details
Once this is stable, we should adjust the output from
ppauxto use it! (#49277)