Skip to content

printing non-existent same name variable as struct field with format_args_implicits feature suggests incorrect self.field_name #123232

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

Closed
MolotovCherry opened this issue Mar 30, 2024 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-fmt Area: `core::fmt` A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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

@MolotovCherry
Copy link

MolotovCherry commented Mar 30, 2024

Code

struct Foo {
    bar: String
}

impl Foo {
    fn dest(&self) {
        println!("{bar}");
    }
}

Current output

error[E0425]: cannot find value `bar` in this scope
 --> src/main.rs:8:20
  |
8 |         println!("{bar}");
  |                    ^^^
  |
help: you might have meant to use the available field
  |
8 |         println!("{self.bar}");
  |                    +++++

For more information about this error, try `rustc --explain E0425`.

Desired output

error[E0425]: cannot find value `bar` in this scope
 --> src/main.rs:8:20
  |
8 |         println!("{bar}");
  |                    ^^^
  |
help: you might have meant to use the available field
  |
7 |         println!("{}", self.bar);
  |                      ++++++++++

For more information about this error, try `rustc --explain E0425`.

(Something like that, my formatting is probably off, but it should get the idea across)

Rationale and extra context

No response

Other cases

No response

Rust Version

1.77.1

Anything else?

No response

@MolotovCherry MolotovCherry 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 30, 2024
@fmease fmease added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-fmt Area: `core::fmt` A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Mar 30, 2024
@lukas-code
Copy link
Member

Duplicate of #105520

@fmease
Copy link
Member

fmease commented Mar 30, 2024

Ah thanks, I knew this was a duplicate but I couldn't find the original issue.

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2024
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-fmt Area: `core::fmt` A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` 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

No branches or pull requests

3 participants