Skip to content

Commit

Permalink
Add regression test for literal_string_with_formatting_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Sep 18, 2024
1 parent dc8f125 commit a9193f2
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/ui/literal_string_with_formatting_arg.rs
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();
}
59 changes: 59 additions & 0 deletions tests/ui/literal_string_with_formatting_arg.stderr
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

0 comments on commit a9193f2

Please sign in to comment.