Skip to content
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

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

Closed
Veykril opened this issue Mar 6, 2024 · 0 comments · Fixed by #122161
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. 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

@Veykril
Copy link
Member

Veykril commented Mar 6, 2024

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.

@Veykril Veykril added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 6, 2024
@fmease fmease added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Mar 6, 2024
@compiler-errors compiler-errors self-assigned this Mar 7, 2024
fmease added a commit to fmease/rust that referenced this issue Dec 4, 2024
…fmease

Fix suggestion when shorthand `self` has erroneous type

Fixes rust-lang#122086

r? estebank
fmease added a commit to fmease/rust that referenced this issue Dec 4, 2024
…fmease

Fix suggestion when shorthand `self` has erroneous type

Fixes rust-lang#122086

r? estebank
@bors bors closed this as completed in bc13c82 Dec 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 5, 2024
Rollup merge of rust-lang#122161 - compiler-errors:shorthand-self, r=fmease

Fix suggestion when shorthand `self` has erroneous type

Fixes rust-lang#122086

r? estebank
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. 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

Successfully merging a pull request may close this issue.

3 participants