@@ -24,8 +24,8 @@ propose to remove this syntax.
24
24
# Motivation
25
25
[ motivation ] : #motivation
26
26
27
- Anonymous parameters are a [ historic accident] . They do not pose any
28
- significant problems, but lead to a number of annoyances.
27
+ Anonymous parameters are a [ historic accident] . They cause a number of technical
28
+ annoyances.
29
29
30
30
1 . Surprising pattern syntax in traits
31
31
@@ -55,6 +55,7 @@ significant problems, but lead to a number of annoyances.
55
55
}
56
56
}
57
57
```
58
+
58
59
3 . Inconsistency between method declarations in traits and in extern blocks
59
60
60
61
```Rust
@@ -79,13 +80,34 @@ significant problems, but lead to a number of annoyances.
79
80
80
81
None of these issues is significant , but they exist .
81
82
83
+
84
+ Even if we exclude these technical drawbacks , it can be argued that allowing to
85
+ omit parameter names unnecessary complicates the language . It is unnecessary
86
+ because it does not make Rust more expressive and does not provide noticeable
87
+ ergonomic improvements . It is trivial to add parameter name , and only a small
88
+ fraction of method declarations actually omits it .
89
+
90
+ Another drawback of this syntax is its impact on the learning curve . One needs
91
+ to have a C background to understand that `fn foo (T );` means a function with
92
+ single parameter of type `T `. If one comes from dynamically typed language like
93
+ Python or JavaScript , this `T ` looks more like a parameter name .
94
+
95
+ Anonymous parameters also cause inconsistencies between trait definitions and
96
+ implementations . One way to write an implementation is to copy the method
97
+ prototypes from the trait into the impl block . With anonymous parameters this
98
+ leads to syntax errors .
99
+
100
+
82
101
[historic accident ]: https : // github.com/rust-lang/rust/pull/29406#issuecomment-151859611
83
102
[IntelliJ Rust ]: https : // github.com/intellij-rust/intellij-rust/commit/1bb65c47341a04aecef5fa6817e8b2b56bfc9abb#diff-66f3ba596f0ecf74a2942b3223789ab5R41
84
103
85
104
86
105
# Detailed design
87
106
[design ]: #detailed - design
88
107
108
+
109
+ ## Backward compatibility
110
+
89
111
Removing anonymous parameters from the language is formally a breaking change .
90
112
The breakage can be trivially and automatically fixed by adding `_ : ` (suggested by @ nagisa ):
91
113
@@ -109,23 +131,53 @@ trait Display {
109
131
}
110
132
```
111
133
112
- So the proposal is just to deprecate this syntax in the hope that the removal
113
- would become feasible and practical in the future. The hypothetical future may
114
- include:
134
+ Of the 5560 packages from crates.io, 416 include at least one usage of
135
+ an anonymous parameter ([ full report] ).
136
+
137
+ [ full report ] : https://github.com/rust-lang/rfcs/pull/1685#issuecomment-238954434
138
+
139
+
140
+ ## Benefits of deprecation
141
+
142
+ So the proposal is just to deprecate this syntax. Phasing the syntax out of
143
+ usage will mostly solve the learning curve problems. The technical problems
144
+ would not be solved until the actual removal becomes feasible and
145
+ practical. This hypothetical future may include:
115
146
116
147
* Rust 2.0 release.
117
- * A tool to automatically fix deprecation warnings.
148
+ * A widely deployed tool to automatically fix deprecation warnings.
118
149
* Storing crates on crates.io in "elaborated" syntax independent format.
119
150
120
151
Enabling deprecation early makes potential future removal easier in practice.
121
152
122
153
154
+ ## Deprecation strategy
155
+
156
+ There are two possible ways to deprecate this syntax:
157
+
158
+ ### Hard deprecation
159
+
160
+ One option is to produce a warning for anonymous parameters. This is backwards
161
+ compatible, but in practice will force crate authors to actively change their
162
+ code to avoid the warnings, causing code churn.
163
+
164
+ ### Soft deprecation
165
+
166
+ Another option is to clearly document this syntax as deprecated and add an
167
+ allow-by-default lint, a clippy lint, and an IntelliJ Rust inspection, but do
168
+ not produce compiler warnings by default. This will make the update process more
169
+ gradual, but will delay the benefits of deprecation.
170
+
171
+
123
172
# Drawbacks
124
173
[ drawbacks ] : #drawbacks
125
174
126
- * Deprecation will require code changes without bringing any immediate benefits.
127
- Until the deprecation is turned into a hard error the underlying issues will
128
- stay.
175
+ * Hard deprecation will cause code churn.
176
+
177
+ * Soft deprecation might not be as efficient at removing the syntax from usage.
178
+
179
+ * The technical issues can not be solved nicely until the deprecation is turned
180
+ into a hard error.
129
181
130
182
* It is not clear if it will ever be possible to remove this syntax entirely.
131
183
@@ -145,8 +197,4 @@ Enabling deprecation early makes potential future removal easier in practice.
145
197
# Unresolved questions
146
198
[ unresolved ] : #unresolved-questions
147
199
148
- * How often are anonymous parameters used in practice? There is a rough
149
- estimate: Servo and its dependencies omit parameter names 34 times.
150
-
151
- * Is there a consensus that anonymous parameters are not a useful language
152
- feature?
200
+ * What deprecation strategy should be chosen?
0 commit comments