You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Detect likely attempts to use interpolation in string literals #100584
We should additionally point at the x inside the string literal and mention that if we wanted string interpolation, it's not gonna work because it needs to be inside of a format!() invocation.
warning: unused variable: `x`
--> main.rs:1:8
|
1 | fn foo(x: &str) {
| let _ = "{x}";
| ======= x needs to be inside of a format!() invocation
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `x`
--> main.rs:1:8
|
1 | fn foo(x: &str) {
| ^ unused variable
2 | let _ = "{x}";
| - you might have meant to use string interpolation in this string literal
help: string interpolation only works in `format!` invocations
|
2 | let _ = format!("{x}");
| ++++++++ +
|
= note: `#[warn(unused_variables)]` on by default
warning: unused variable: `xyza`
--> main.rs:1:8
|
1 | fn foo(xyza: &str) {
| ^^^^ help: if this is intentional, prefix it with an underscore: `_xyza`
|
= note: `#[warn(unused_variables)]` on by default
warning: 1 warning emitted
warning: unused variable: `xyza`
--> main.rs:1:8
|
1 | fn foo(xyza: &str) {
| ^^^^
| |
| unused variable
| help: if this is intentional, prefix it with an underscore: `_xyza`
2 | let _ = "{xyza}";
| -------- you might have meant to use string interpolation in this string literal
|
= note: `#[warn(unused_variables)]` on by default
= help: string interpolation only works in `format!` invocations
warning: 1 warning emitted
There are still 2 issues for me. #1 I am not able to emit something like
|
2 | let _ = format!("{x}");
| ++++++++ +
|
please give me an example, then I can look how the compiler deal with it.
#2 I can't upload a specific test case for this issue, because the test script will opt out the unused variable. Here is the script I got:
err.multipart_suggestion(vec![(lit_expr.span.shrink_to_lo(),"format!(".to_string()),(lit_expr.span.shrink_to_hi(),")".to_string()),],"if you meant to use string interpolation in the string literal, use the `format!` marco",Applicability::MachineApplicable,);
Have you run python3 x.py test src/test/ui/type/issue-100584.rs --bless?
Activity
lyming2007 commentedon Aug 16, 2022
Do you mean, we should emit like this?
estebank commentedon Aug 16, 2022
Ideally, it would look something like this:
lyming2007 commentedon Aug 16, 2022
@rustbot claim
lyming2007 commentedon Aug 24, 2022
Current output is:
With my fix https://github.com/lyming2007/rust/pull/new/issue-100584
The output looks like:
There are still 2 issues for me.
#1 I am not able to emit something like
please give me an example, then I can look how the compiler deal with it.
#2 I can't upload a specific test case for this issue, because the test script will opt out the unused variable. Here is the script I got:
So it will always output nothing to stderr and make the test failed.
@estebank please advise
estebank commentedon Aug 24, 2022
You'd have to use:
Have you run
python3 x.py test src/test/ui/type/issue-100584.rs --bless?lyming2007 commentedon Aug 29, 2022
thanks. please see my fix:
#100941
@estebank