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

Goofy suggestion when trying to use a raw ptr receiver and also the self keyword in the body #128042

Closed
saethlin opened this issue Jul 21, 2024 · 1 comment · Fixed by #128185
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@saethlin
Copy link
Member

saethlin commented Jul 21, 2024

I tried this code:

struct Thing {
    state: u8,
}

impl Thing {
    fn oof(*mut Self) {
        self.state = 1;
    }
}

I get this diagnostic, which is all good until it tries to construct a suggestion:

error[E0424]: expected value, found module `self`
 --> src/lib.rs:7:9
  |
6 |     fn oof(*mut Self) {
  |        --- this function doesn't have a `self` parameter
7 |         self.state = 1;
  |         ^^^^ `self` value is a keyword only available in methods with a `self` parameter
  |
help: add a `self` receiver parameter to make the associated `fn` a method
  |
6 |     fn oof&self, (*mut Self) {
  |           ++++++

This suggestion has behaved like this since it was added in 1.47.

@saethlin saethlin 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. C-bug Category: This is a bug. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jul 21, 2024
@surechen
Copy link
Contributor

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 25, 2024
…errors

Fix a span error when parsing a wrong param of function.

fixes rust-lang#128042

Before this change, the span of param `*mut Self` in  `fn oof(*mut Self)` contains `(` before it, so the suggestion in E0424 will be error.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 25, 2024
…errors

Fix a span error when parsing a wrong param of function.

fixes rust-lang#128042

Before this change, the span of param `*mut Self` in  `fn oof(*mut Self)` contains `(` before it, so the suggestion in E0424 will be error.
@bors bors closed this as completed in 4ac6060 Jul 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2024
Rollup merge of rust-lang#128185 - surechen:fix_128042_2, r=compiler-errors

Fix a span error when parsing a wrong param of function.

fixes rust-lang#128042

Before this change, the span of param `*mut Self` in  `fn oof(*mut Self)` contains `(` before it, so the suggestion in E0424 will be error.
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` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

2 participants