Skip to content

Provide a better error on anonymous parameters in unexpected locations #120357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
thomcc opened this issue Jan 26, 2024 · 6 comments
Open

Provide a better error on anonymous parameters in unexpected locations #120357

thomcc opened this issue Jan 26, 2024 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@thomcc
Copy link
Member

thomcc commented Jan 26, 2024

In edition 2015, the following is supposed to be legal (playground):

pub fn foo(&str) {}

It is essentially semantically equivalent to

pub fn foo(_: &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.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 26, 2024
@thomcc thomcc added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 26, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 26, 2024
@ChrisDenton
Copy link
Member

Which version did it last work on?

@SNCPlay42
Copy link
Contributor

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
Copy link
Contributor

@rustbot label A-diagnostics

@rustbot rustbot added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 26, 2024
@thomcc
Copy link
Member Author

thomcc commented 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 fmease removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 26, 2024
@fmease
Copy link
Member

fmease commented Jan 26, 2024

RFC 1685 says 2015 edition allows anonymous parameters in trait methods, and this still works

The Reference seems to agree: https://doc.rust-lang.org/reference/items/functions.html#fn-param-2015

@fmease fmease added A-parser Area: The lexing & parsing of Rust source code to an AST T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-edition Diagnostics: An error or lint that should account for edition differences. and removed regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jan 26, 2024
@bjorn3
Copy link
Member

bjorn3 commented Jan 26, 2024

It was made a warning in 1.53 (#82918) I think it has only been supported inside trait definitions though:

fn g3(u8); // OK

@fmease fmease added D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. and removed D-edition Diagnostics: An error or lint that should account for edition differences. labels Jan 26, 2024
@fmease fmease changed the title Anonymous parameters don't work, even in 2015 edition. Provide a better error on anonymous parameters in unexpected locations Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants