-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #131430 - surechen:fix_130495, r=jieyouxu
Special treatment empty tuple when suggest adding a string literal in format macro. For example: ```rust let s = "123"; println!({}, "sss", s); ``` Suggest: `println!("{:?} {} {}", {}, "sss", s);` fixes #130170
- Loading branch information
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/ui/macros/format-empty-block-unit-tuple-suggestion-130170.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ run-rustfix | ||
|
||
fn main() { | ||
let s = "123"; | ||
println!("{:?} {} {}", {}, "sss", s); | ||
//~^ ERROR format argument must be a string literal | ||
println!("{:?}", {}); | ||
//~^ ERROR format argument must be a string literal | ||
println!("{} {} {} {:?}", s, "sss", s, {}); | ||
//~^ ERROR format argument must be a string literal | ||
println!("{:?} {} {:?}", (), s, {}); | ||
//~^ ERROR format argument must be a string literal | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/macros/format-empty-block-unit-tuple-suggestion-130170.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//@ run-rustfix | ||
|
||
fn main() { | ||
let s = "123"; | ||
println!({}, "sss", s); | ||
//~^ ERROR format argument must be a string literal | ||
println!({}); | ||
//~^ ERROR format argument must be a string literal | ||
println!(s, "sss", s, {}); | ||
//~^ ERROR format argument must be a string literal | ||
println!((), s, {}); | ||
//~^ ERROR format argument must be a string literal | ||
} |
46 changes: 46 additions & 0 deletions
46
tests/ui/macros/format-empty-block-unit-tuple-suggestion-130170.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
error: format argument must be a string literal | ||
--> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:5:14 | ||
| | ||
LL | println!({}, "sss", s); | ||
| ^^ | ||
| | ||
help: you might be missing a string literal to format with | ||
| | ||
LL | println!("{:?} {} {}", {}, "sss", s); | ||
| +++++++++++++ | ||
|
||
error: format argument must be a string literal | ||
--> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:7:14 | ||
| | ||
LL | println!({}); | ||
| ^^ | ||
| | ||
help: you might be missing a string literal to format with | ||
| | ||
LL | println!("{:?}", {}); | ||
| +++++++ | ||
|
||
error: format argument must be a string literal | ||
--> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:9:14 | ||
| | ||
LL | println!(s, "sss", s, {}); | ||
| ^ | ||
| | ||
help: you might be missing a string literal to format with | ||
| | ||
LL | println!("{} {} {} {:?}", s, "sss", s, {}); | ||
| ++++++++++++++++ | ||
|
||
error: format argument must be a string literal | ||
--> $DIR/format-empty-block-unit-tuple-suggestion-130170.rs:11:14 | ||
| | ||
LL | println!((), s, {}); | ||
| ^^ | ||
| | ||
help: you might be missing a string literal to format with | ||
| | ||
LL | println!("{:?} {} {:?}", (), s, {}); | ||
| +++++++++++++++ | ||
|
||
error: aborting due to 4 previous errors | ||
|