- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.
Description
I tried this code:
struct X(i32);
impl X {
    pub(crate) fn f() {
        self.0
    }
}
fn main() {}I expected to see this happen: Correct compile error due to lack of self receiver.
Instead, this happened: Compile error happens. But its suggestion is not correct:
error[E0424]: expected value, found module `self`
 --> bar.rs:5:9
  |
4 |     pub(crate) fn f() {
  |                   - this function doesn't have a `self` parameter
5 |         self.0
  |         ^^^^ `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
  |
4 |     pub(&selfcrate) fn f() {
  |         +++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0424`.
&self is inserted to just after first (. But in this case, the first ( is not for method parameter. So the position is not correct.
4 |     pub(&selfcrate) fn f() {
This line should be:
4 |     pub(crate) fn f(&self) {
Meta
rustc --version --verbose:
rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-apple-darwin
release: 1.57.0
LLVM version: 13.0.0
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.