You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a better error on anonymous parameters in unexpected locations #120357
In edition 2015, the following is supposed to be legal (playground):
pubfnfoo(&str){}
It is essentially semantically equivalent to
pubfnfoo(_:&str){}
Unfortunately, even though edition 2015 is enabled, the following error is generated:
error: expected one of `:`, `@`, or `|`, found `)`
--> src/lib.rs:1:16
|
1 | pub fn foo(&str) {}
| ^ 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 | pub fn foo(self: &str) {}
| +++++
help: if this is a parameter name, give it a type
|
1 | pub fn foo(str: &TypeName) {}
| ~~~~~~~~~~~~~~
help: if this is a type, explicitly ignore the parameter name
|
1 | pub fn foo(_: &str) {}
| ++
which explains that it was "removed in the 2018 edition". This should be irrelevant, as neither that edition, nor any later edition, is enabled.
RFC 1685 does not appear to describe breaking this in edition 2015, so I believe this to be a bug.
It causes a good amount of (quite old) crates to be impossible to build for no reason, which is unfortunate.
I did have issues compiling some old crates due to this, but I suppose it's possible they had #[deny(warnings)] or similar -- they had failed to compile for other reasons, so I had checked them out locally, and was going through and fixing each issue.
changed the title [-]Anonymous parameters don't work, even in 2015 edition.[/-][+]Provide a better error on anonymous parameters in unexpected locations[/+]on Jan 26, 2024
Activity
ChrisDenton commentedon Jan 26, 2024
Which version did it last work on?
SNCPlay42 commentedon Jan 26, 2024
RFC 1685 says 2015 edition allows anonymous parameters in trait methods, and this still works.
Anonymous parameters in concrete methods appears to never have compiled.
Jules-Bertholet commentedon Jan 26, 2024
@rustbot label A-diagnostics
thomcc commentedon Jan 26, 2024
Ah, my bad.
I did have issues compiling some old crates due to this, but I suppose it's possible they had
#[deny(warnings)]or similar -- they had failed to compile for other reasons, so I had checked them out locally, and was going through and fixing each issue.fmease commentedon Jan 26, 2024
The Reference seems to agree: https://doc.rust-lang.org/reference/items/functions.html#fn-param-2015
bjorn3 commentedon Jan 26, 2024
It was made a warning in 1.53 (#82918) I think it has only been supported inside trait definitions though:
rust/tests/ui/no-patterns-in-args-2.rs
Line 10 in 69db514
[-]Anonymous parameters don't work, even in 2015 edition.[/-][+]Provide a better error on anonymous parameters in unexpected locations[/+]