Code
struct Foo { bar: i32 }
fn main() {
let foo = Foo { bar: 10 };
let _x = format!("Hello {foo.bar}");
}
Current output
error: invalid format string: field access isn't supported
--> src/main.rs:5:30
|
5 | let _x = format!("Hello {foo.bar}");
| ^^^^^^^ not supported in format string
|
help: consider using a positional formatting argument instead
|
5 | let _x = format!("Hello {0}", foo.bar);
| ~ +++++++++
Desired output
error: invalid format string: field access isn't supported
--> src/main.rs:5:30
|
5 | let _x = format!("Hello {foo.bar}");
| ^^^^^^^ not supported in format string
|
help: consider putting the value in a local variable instead
|
5 | let name = foo.bar;
6 | let _x = format!("Hello {name}");
| ++++
Rationale and extra context
Inspired by someone who said "oh cool! I was getting errors when trying to do the widget.name expression, didn't know I could assign it to a variable and it would work. I'll fix it".
I think that, since they appear to be trying to put the named things into the format, rather than using positional syntax, it would be good to suggest a way that lets them continue to use a name rather than positional.
Other cases
No response
Anything else?
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a2ebc266f27d96c2f20e095495cc606a
Code
Current output
Desired output
Rationale and extra context
Inspired by someone who said "oh cool! I was getting errors when trying to do the
widget.nameexpression, didn't know I could assign it to a variable and it would work. I'll fix it".I think that, since they appear to be trying to put the named things into the format, rather than using positional syntax, it would be good to suggest a way that lets them continue to use a name rather than positional.
Other cases
No response
Anything else?
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a2ebc266f27d96c2f20e095495cc606a