forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for
literal_string_with_formatting_arg
- Loading branch information
1 parent
dc8f125
commit a9193f2
Showing
2 changed files
with
84 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#![warn(clippy::literal_string_with_formatting_arg)] | ||
#![allow(clippy::unnecessary_literal_unwrap)] | ||
|
||
fn main() { | ||
let x: Option<usize> = None; | ||
let y = "hello"; | ||
x.expect("{y}"); //~ literal_string_with_formatting_arg | ||
x.expect("{:?}"); //~ literal_string_with_formatting_arg | ||
x.expect("{y:?}"); //~ literal_string_with_formatting_arg | ||
x.expect(" {y:?} {y:?} "); //~ literal_string_with_formatting_arg | ||
x.expect(" {y:..} {y:?} "); //~ literal_string_with_formatting_arg | ||
x.expect(r" {y:?} {y:?} "); //~ literal_string_with_formatting_arg | ||
x.expect(r"{y:?} y:?}"); //~ literal_string_with_formatting_arg | ||
x.expect(r##" {y:?} {y:?} "##); //~ literal_string_with_formatting_arg | ||
"\\.+*?()|[]{}^$#&-~".chars().any(|x| x == 'a'); | ||
|
||
// Should not lint! | ||
format!("{y:?}"); | ||
println!("{y:?}"); | ||
x.expect("{{y} {x"); | ||
x.expect("{{y:?}"); | ||
x.expect("{y:...}"); | ||
// Unicode characters escape should not lint either. | ||
"\u{0052}".to_string(); | ||
} |
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,59 @@ | ||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:7:15 | ||
| | ||
LL | x.expect("{y}"); | ||
| ^^^ | ||
| | ||
= note: `-D clippy::literal-string-with-formatting-arg` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_arg)]` | ||
|
||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:8:15 | ||
| | ||
LL | x.expect("{:?}"); | ||
| ^^^^ | ||
|
||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:9:15 | ||
| | ||
LL | x.expect("{y:?}"); | ||
| ^^^^^ | ||
|
||
error: these are formatting arguments but are not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:10:16 | ||
| | ||
LL | x.expect(" {y:?} {y:?} "); | ||
| ^^^^^ ^^^^^ | ||
|
||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:11:23 | ||
| | ||
LL | x.expect(" {y:..} {y:?} "); | ||
| ^^^^^ | ||
|
||
error: these are formatting arguments but are not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:12:17 | ||
| | ||
LL | x.expect(r" {y:?} {y:?} "); | ||
| ^^^^^ ^^^^^ | ||
|
||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:13:16 | ||
| | ||
LL | x.expect(r"{y:?} y:?}"); | ||
| ^^^^^ | ||
|
||
error: these are formatting arguments but are not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:14:19 | ||
| | ||
LL | x.expect(r##" {y:?} {y:?} "##); | ||
| ^^^^^ ^^^^^ | ||
|
||
error: this is a formatting argument but it is not part of a formatting macro | ||
--> tests/ui/literal_string_with_formatting_arg.rs:15:17 | ||
| | ||
LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == 'a'); | ||
| ^^ | ||
|
||
error: aborting due to 9 previous errors | ||
|