-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
1.63.0-nightly (2022-05-22)
struct A {
config: String,
}
impl A {
fn do_something(self, cofig: String) {
println!("{config}"); //~ Error cannot find value `config` in this scope
}
}
fn main() {}
The current output is:
This suggestion can cause compiler errors.
Compiling playground v0.0.1 (/playground)
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `config` in this scope
--> src/main.rs:7:20
|
7 | println!("{config}"); //~ Error cannot find value `config` in this scope
| ^^^^^^ help: you might have meant to use the available field: `self.config`
For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to previous error
Ideally the output should look like:
help
shouldn't be emitted.
or should look like println!("{}", self.config)
.
Compiling playground v0.0.1 (/playground)
error[[E0425]](https://doc.rust-lang.org/nightly/error-index.html#E0425): cannot find value `config` in this scope
--> src/main.rs:7:20
|
7 | println!("{config}"); //~ Error cannot find value `config` in this scope
| ^^^^^^
For more information about this error, try `rustc --explain E0425`.
error: could not compile `playground` due to previous error
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]Wrong suggestions for typos on variables that has the same name as struct fields[/-][+]Wrong suggestions for typos on variables that have the same name as struct fields[/+]ChayimFriedman2 commentedon May 24, 2022
Really ideally we should suggest something like
println!("{}", self.config)
, but I'm pretty sure this is infeasible. On the other hand, maybe one day we'll have field accesses in the formatting macros.estebank commentedon Jun 2, 2022
I think that if we had #96999 it'd be enough. I consider it "ok" if a suggestion gives you incorrect code that will in turn give you a suggestion for working code.
Rollup merge of rust-lang#100058 - TaKO8Ki:suggest-positional-formatt…