Skip to content

Commit 79df3dd

Browse files
authored
Update to match the latest version of the epochs RFC
1 parent 0209758 commit 79df3dd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

text/0000-dyn-trait-syntax.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
# Summary
77
[summary]: #summary
88

9-
Introduce a new `dyn Trait` syntax for trait objects using a contextual `dyn` keyword, and deprecate "bare trait" syntax for trait objects. In a future checkpoint, `dyn` will become a proper keyword and bare trait syntax will be removed.
9+
Introduce a new `dyn Trait` syntax for trait objects using a contextual `dyn` keyword, and deprecate "bare trait" syntax for trait objects. In a future epoch, `dyn` will become a proper keyword and a lint against bare trait syntax will become deny-by-default.
1010

1111
# Motivation
1212
[motivation]: #motivation
1313

1414
### In a nutshell
1515

16-
The current syntax is often ambiguous and confusing, even to veterans, and favors a feature that is not more frequently used than its alternatives, is sometimes slower, and often cannot be used at all when its alternatives can. By itself, that's not enough to make a breaking change to syntax that's already been stabilized. Now that we have checkpoints, it won't have to be a breaking change, but it will still cause significant churn. However, impl Trait is going to require a significant shift in idioms and teaching materials all on its own, and "dyn Trait vs impl Trait" is much nicer for teaching and ergonomics than "bare trait vs impl Trait", so this author believes it is worthwhile to change trait object syntax too.
16+
The current syntax is often ambiguous and confusing, even to veterans, and favors a feature that is not more frequently used than its alternatives, is sometimes slower, and often cannot be used at all when its alternatives can. By itself, that's not enough to make a breaking change to syntax that's already been stabilized. Now that we have epochs, it won't have to be a breaking change, but it will still cause significant churn. However, impl Trait is going to require a significant shift in idioms and teaching materials all on its own, and "dyn Trait vs impl Trait" is much nicer for teaching and ergonomics than "bare trait vs impl Trait", so this author believes it is worthwhile to change trait object syntax too.
1717

1818
Motivation is the key issue for this RFC, so let's expand on some of those claims:
1919

@@ -72,6 +72,18 @@ The functionality of `dyn Trait` is identical to today's trait object syntax.
7272

7373
`&Trait` and `&mut Trait` become `&dyn Trait` and `&mut dyn Trait`.
7474

75+
### Migration
76+
77+
On the current epoch:
78+
- The `dyn` keyword will be added, and will be a contextual keyword
79+
- A lint against bare trait syntax will be added
80+
81+
In the next epoch:
82+
- `dyn` becomes a real keyword, uses of it as an identifier become hard errors
83+
- The bare trait syntax lint is raised to deny-by-default
84+
85+
This follows the policy laid out in the epochs RFC, where a hard error is "only available when the deprecation is expected to hit a relatively small percentage of code." Adding the `dyn` keyword is unlikely to affect much code, but removing bare trait syntax will clearly affect a lot of code, so only the latter change is implemented as a deny-by-default lint.
86+
7587
# Drawbacks
7688
[drawbacks]: #drawbacks
7789

@@ -92,7 +104,7 @@ This author believes that `dyn` is a better choice because the notion of "dynami
92104

93105
We could also use a more radical syntax for trait objects. `Object<Trait>` was suggested on the original RFC thread but didn't gain much traction, presumably because it adds more "noise" than a keyword and is arguably misleading.
94106

95-
Finally, we could repurpose bare trait syntax for something other than trait objects. It's been frequently suggested in the past that impl Trait would be a far better candidate for bare trait syntax than trait objects. Even this RFC's motivation section indirectly argues for this, e.g. impl Trait does work with all traits and does not carry a runtime cost, unlike trait objects. However, this RFC does not propose repurposing bare trait syntax yet, only deprecating and removing it. This author believes dyn Trait is worth adding even if we never repurpose bare trait, and repurposing it has some significant downsides that dyn Trait does not (such as creating the possibility of code that compiles in two different checkpoints with radically different semantics). This author believes the repurposing debate should come later, probably after impl Trait and dyn Trait have been stabilized.
107+
Finally, we could repurpose bare trait syntax for something other than trait objects. It's been frequently suggested in the past that impl Trait would be a far better candidate for bare trait syntax than trait objects. Even this RFC's motivation section indirectly argues for this, e.g. impl Trait does work with all traits and does not carry a runtime cost, unlike trait objects. However, this RFC does not propose repurposing bare trait syntax yet, only deprecating and removing it. This author believes dyn Trait is worth adding even if we never repurpose bare trait, and repurposing it has some significant downsides that dyn Trait does not (such as creating the possibility of code that compiles in two different epochs with radically different semantics). This author believes the repurposing debate should come later, probably after impl Trait and dyn Trait have been stabilized.
96108

97109
# Unresolved questions
98110
[unresolved]: #unresolved-questions

0 commit comments

Comments
 (0)