Skip to content

self param with ampersand (&) and explicit type yields noisy parsing diagnostics which could be more helpful #122086

@Veykril

Description

@Veykril
Member

Code

struct S;

impl S {
    fn f(&self: Self) {}
}

Current output

Compiling playground v0.0.1 (/playground)
error: expected parameter name, found `:`
 --> src/lib.rs:4:15
  |
4 |     fn f(&self: Self) {}
  |               ^ expected parameter name

error: expected one of `)` or `,`, found `:`
 --> src/lib.rs:4:15
  |
4 |     fn f(&self: Self) {}
  |               ^
  |               |
  |               expected one of `)` or `,`
  |               help: missing `,`

error: could not compile `playground` (lib) due to 2 previous errors

Desired output

Compiling playground v0.0.1 (/playground)
error: explicit self parameter type cannot be declared with `&`
 --> src/lib.rs:4:15
  |
4 |     fn f(&self: Self) {}
  |          ^ use `self: &Self` instead

error: could not compile `playground` (lib) due to 1 previous errors

Rationale and extra context

No response

Other cases

No response

Rust Version

rustc 1.78.0-nightly (0ecbd0605 2024-02-25)
binary: rustc
commit-hash: 0ecbd0605770f45c9151715e66ba2b3cae367fcb
commit-date: 2024-02-25
host: x86_64-pc-windows-msvc
release: 1.78.0-nightly
LLVM version: 18.1.0

Anything else?

Desired output is rough, but something along those lines would probably be better.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Mar 6, 2024
added
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
D-confusingDiagnostics: Confusing error or lint that should be reworked.
D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.
on Mar 6, 2024
added 3 commits that reference this issue on Dec 4, 2024
be189d0
81bbc9c
bc13c82
added a commit that references this issue on Dec 5, 2024
5d565d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-confusingDiagnostics: Confusing error or lint that should be reworked.D-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

    Participants

    @compiler-errors@Veykril@fmease

    Issue actions

      self param with ampersand (&) and explicit type yields noisy parsing diagnostics which could be more helpful · Issue #122086 · rust-lang/rust