-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest use "{}", self.x instead of {self.x} when resolve x as field of self
#141213
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
Changes from 3 commits
fe0663c
9de7fff
4ec9919
84f67a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens on struct Foo { x: i32 }
impl Foo {
fn foo(&self) { _ = {x}; }
} Does it essentially suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've opened issue #141350 to track this regression. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will give this message.
For further improvement, below two suggestions may be better? The first suggestion is
and keep the origin suggestion
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the message as emitted right now (on master) is not correct. It should indeed suggest |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
struct Foo { | ||
x: i32 | ||
} | ||
|
||
impl Foo { | ||
fn foo(&self) { | ||
let _ = format!("{x}"); //~ ERROR cannot find value `x` in this scope [E0425] | ||
let _ = format!("{x }"); //~ ERROR cannot find value `x` in this scope [E0425] | ||
let _ = format!("{ x}"); //~ ERROR invalid format string: expected `}`, found `x` | ||
let _ = format!("{}", x); //~ ERROR cannot find value `x` in this scope [E0425] | ||
println!("{x}"); //~ ERROR cannot find value `x` in this scope [E0425] | ||
} | ||
} | ||
|
||
fn main(){} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
error: invalid format string: expected `}`, found `x` | ||
--> $DIR/sugg-field-in-format-string-issue-141136.rs:9:28 | ||
| | ||
LL | let _ = format!("{ x}"); | ||
| - ^ expected `}` in format string | ||
| | | ||
| because of this opening brace | ||
| | ||
= note: if you intended to print `{`, you can escape it using `{{` | ||
|
||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/sugg-field-in-format-string-issue-141136.rs:7:27 | ||
| | ||
LL | let _ = format!("{x}"); | ||
| ^ | ||
| | ||
= help: you might have meant to use the available field in a format string: `"{}", self.x` | ||
|
||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/sugg-field-in-format-string-issue-141136.rs:8:27 | ||
| | ||
LL | let _ = format!("{x }"); | ||
| ^^ | ||
| | ||
= help: you might have meant to use the available field in a format string: `"{}", self.x` | ||
|
||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/sugg-field-in-format-string-issue-141136.rs:10:31 | ||
| | ||
LL | let _ = format!("{}", x); | ||
| ^ | ||
| | ||
help: you might have meant to use the available field | ||
| | ||
LL | let _ = format!("{}", self.x); | ||
| +++++ | ||
|
||
error[E0425]: cannot find value `x` in this scope | ||
--> $DIR/sugg-field-in-format-string-issue-141136.rs:11:20 | ||
| | ||
LL | println!("{x}"); | ||
| ^ | ||
| | ||
= help: you might have meant to use the available field in a format string: `"{}", self.x` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. |
Uh oh!
There was an error while loading. Please reload this page.