-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
Code
fn is_even(value) -> bool {
value % 2 == 0
}
Current output
error: expected one of `:`, `@`, or `|`, found `)`
--> src/lib.rs:1:17
|
1 | fn is_even(value) -> bool {
| ^ expected one of `:`, `@`, or `|`
|
= note: anonymous parameters are removed in the 2018 edition (see RFC 1685)
help: if this is a `self` type, give it a parameter name
|
1 | fn is_even(self: value) -> bool {
| +++++
help: if this is a parameter name, give it a type
|
1 | fn is_even(value: TypeName) -> bool {
| ++++++++++
help: if this is a type, explicitly ignore the parameter name
|
1 | fn is_even(_: value) -> bool {
| ++
Desired output
error: expected one of `:`, `@`, or `|`, found `)`
--> src/lib.rs:1:17
|
1 | fn is_even(value) -> bool {
| ^ expected one of `:`, `@`, or `|`
|
help: if this is a parameter name, give it a type
|
1 | fn is_even(value: TypeName) -> bool {
| ++++++++++
help: if this is a type, explicitly ignore the parameter name
|
1 | fn is_even(_: value) -> bool {
| ++
Rationale and extra context
While teaching Rust to a 14-year-old, this was one of the first errors we encountered.
The first thing I notice is that the first help
advice is kind of inappropriate: this is not a member function so there is no self
. Additionally, if this error is expected among beginners (e.g. those coming from Python), it seems unwise to guide them to using (unstable) arbitrary self types.
I think the first help
suggestion could probably be deleted, promoting if this is a parameter name, give it a type
into the first spot.
Additionally, the note anonymous parameters are removed in the 2018 edition (see RFC 1685)
seems like a distraction. 2018 was a long time ago, and I don't think people should be nagged about this any longer. It especially should not appear in an error message that beginners are likely to encounter on their first day writing Rust code.
Rust Version
rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-unknown-linux-gnu
release: 1.88.0
LLVM version: 20.1.5