Skip to content

Commit 850e3b0

Browse files
committed
Address rfc feedback
* Add "learning curve" category of drawbacks. * Specify "Hard" and "Soft" deprecation strategies.
1 parent b5b107a commit 850e3b0

File tree

1 file changed

+62
-14
lines changed

1 file changed

+62
-14
lines changed

text/0000-deprecate-anonymous-parameters.md

+62-14
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ propose to remove this syntax.
2424
# Motivation
2525
[motivation]: #motivation
2626

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.
2929

3030
1. Surprising pattern syntax in traits
3131

@@ -55,6 +55,7 @@ significant problems, but lead to a number of annoyances.
5555
}
5656
}
5757
```
58+
5859
3. Inconsistency between method declarations in traits and in extern blocks
5960

6061
```Rust
@@ -79,13 +80,34 @@ significant problems, but lead to a number of annoyances.
7980

8081
None of these issues is significant, but they exist.
8182

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+
82101
[historic accident]: https://github.com/rust-lang/rust/pull/29406#issuecomment-151859611
83102
[IntelliJ Rust]: https://github.com/intellij-rust/intellij-rust/commit/1bb65c47341a04aecef5fa6817e8b2b56bfc9abb#diff-66f3ba596f0ecf74a2942b3223789ab5R41
84103

85104

86105
# Detailed design
87106
[design]: #detailed-design
88107

108+
109+
## Backward compatibility
110+
89111
Removing anonymous parameters from the language is formally a breaking change.
90112
The breakage can be trivially and automatically fixed by adding `_:` (suggested by @nagisa):
91113

@@ -109,23 +131,53 @@ trait Display {
109131
}
110132
```
111133

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:
115146

116147
* Rust 2.0 release.
117-
* A tool to automatically fix deprecation warnings.
148+
* A widely deployed tool to automatically fix deprecation warnings.
118149
* Storing crates on crates.io in "elaborated" syntax independent format.
119150

120151
Enabling deprecation early makes potential future removal easier in practice.
121152

122153

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+
123172
# Drawbacks
124173
[drawbacks]: #drawbacks
125174

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.
129181

130182
* It is not clear if it will ever be possible to remove this syntax entirely.
131183

@@ -145,8 +197,4 @@ Enabling deprecation early makes potential future removal easier in practice.
145197
# Unresolved questions
146198
[unresolved]: #unresolved-questions
147199

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

Comments
 (0)