-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
stabilize dyn Trait in Rust 2015 #49218
Copy link
Copy link
Closed
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-langRelevant to the language teamRelevant to the language teamdisposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.This issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.The final comment period is finished for this PR / Issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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)