Skip to content

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

Open

Description

@thomcc

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.

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 26, 2024
  2. added
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 26, 2024
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 26, 2024
  4. ChrisDenton commented on Jan 26, 2024

    @ChrisDenton
    Member

    Which version did it last work on?

  5. SNCPlay42 commented on Jan 26, 2024

    @SNCPlay42
    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.

  6. Jules-Bertholet commented on Jan 26, 2024

    @Jules-Bertholet
    Contributor

    @rustbot label A-diagnostics

  7. thomcc commented on Jan 26, 2024

    @thomcc
    MemberAuthor

    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.

  8. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jan 26, 2024
  9. fmease commented on Jan 26, 2024

    @fmease
    Member

    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

  10. added
    A-parserArea: The lexing & parsing of Rust source code to an AST
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    D-editionDiagnostics: An error or lint that should account for edition differences.
    and removed
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    on Jan 26, 2024
  11. bjorn3 commented on Jan 26, 2024

    @bjorn3
    Member

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

    fn g3(u8); // OK

  12. added
    D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
    and removed
    D-editionDiagnostics: An error or lint that should account for edition differences.
    on Jan 26, 2024
  13. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an ASTD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions