Skip to content

Commit 62afec7

Browse files
Add regression test for literal_string_with_formatting_arg
1 parent 181ad75 commit 62afec7

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#![warn(clippy::literal_string_with_formatting_arg)]
2+
#![allow(clippy::unnecessary_literal_unwrap)]
3+
4+
fn main() {
5+
let x: Option<usize> = None;
6+
let y = "hello";
7+
x.expect("{y} {}"); //~ literal_string_with_formatting_arg
8+
x.expect("{:?}"); //~ literal_string_with_formatting_arg
9+
x.expect("{y:?}"); //~ literal_string_with_formatting_arg
10+
x.expect(" {y:?} {y:?} "); //~ literal_string_with_formatting_arg
11+
x.expect(" {y:..} {y:?} "); //~ literal_string_with_formatting_arg
12+
x.expect(r"{y:?} {y:?} "); //~ literal_string_with_formatting_arg
13+
x.expect(r"{y:?} y:?}"); //~ literal_string_with_formatting_arg
14+
x.expect(r##" {y:?} {y:?} "##); //~ literal_string_with_formatting_arg
15+
"\\.+*?()|[]{}^$#&-~".chars().any(|x| x == 'a'); //~ literal_string_with_formatting_arg
16+
17+
// Should not lint!
18+
format!("{y:?}");
19+
println!("{y:?}");
20+
x.expect("{{y} {x");
21+
x.expect("{{y:?}");
22+
x.expect("{y:...}");
23+
let _ = "fn main {\n\
24+
}";
25+
// Unicode characters escape should not lint either.
26+
"\u{0052}".to_string();
27+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
error: these look like formatting arguments but are not part of a formatting macro
2+
--> tests/ui/literal_string_with_formatting_arg.rs:7:15
3+
|
4+
LL | x.expect("{y} {}");
5+
| ^^^^^^
6+
|
7+
= note: `-D clippy::literal-string-with-formatting-arg` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::literal_string_with_formatting_arg)]`
9+
10+
error: this looks like a formatting argument but it is not part of a formatting macro
11+
--> tests/ui/literal_string_with_formatting_arg.rs:8:15
12+
|
13+
LL | x.expect("{:?}");
14+
| ^^^^
15+
16+
error: this looks like a formatting argument but it is not part of a formatting macro
17+
--> tests/ui/literal_string_with_formatting_arg.rs:9:15
18+
|
19+
LL | x.expect("{y:?}");
20+
| ^^^^^
21+
22+
error: these look like formatting arguments but are not part of a formatting macro
23+
--> tests/ui/literal_string_with_formatting_arg.rs:10:16
24+
|
25+
LL | x.expect(" {y:?} {y:?} ");
26+
| ^^^^^ ^^^^^
27+
28+
error: this looks like a formatting argument but it is not part of a formatting macro
29+
--> tests/ui/literal_string_with_formatting_arg.rs:11:23
30+
|
31+
LL | x.expect(" {y:..} {y:?} ");
32+
| ^^^^^
33+
34+
error: these look like formatting arguments but are not part of a formatting macro
35+
--> tests/ui/literal_string_with_formatting_arg.rs:12:16
36+
|
37+
LL | x.expect(r"{y:?} {y:?} ");
38+
| ^^^^^ ^^^^^
39+
40+
error: this looks like a formatting argument but it is not part of a formatting macro
41+
--> tests/ui/literal_string_with_formatting_arg.rs:13:16
42+
|
43+
LL | x.expect(r"{y:?} y:?}");
44+
| ^^^^^
45+
46+
error: these look like formatting arguments but are not part of a formatting macro
47+
--> tests/ui/literal_string_with_formatting_arg.rs:14:19
48+
|
49+
LL | x.expect(r##" {y:?} {y:?} "##);
50+
| ^^^^^ ^^^^^
51+
52+
error: this looks like a formatting argument but it is not part of a formatting macro
53+
--> tests/ui/literal_string_with_formatting_arg.rs:15:17
54+
|
55+
LL | "\\.+*?()|[]{}^$#&-~".chars().any(|x| x == 'a');
56+
| ^^
57+
58+
error: aborting due to 9 previous errors
59+

0 commit comments

Comments
 (0)