diff options
| -rw-r--r-- | tests/ui/literal_string_with_formatting_arg.rs | 29 | ||||
| -rw-r--r-- | tests/ui/literal_string_with_formatting_arg.stderr | 65 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/ui/literal_string_with_formatting_arg.rs b/tests/ui/literal_string_with_formatting_arg.rs new file mode 100644 index 00000000000..539d24efe7c --- /dev/null +++ b/tests/ui/literal_string_with_formatting_arg.rs @@ -0,0 +1,29 @@ +#![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'); //~ literal_string_with_formatting_arg + // Ensure that it doesn't try to go in the middle of a unicode character. + x.expect("———{}"); //~ literal_string_with_formatting_arg + + // Should not lint! + format!("{y:?}"); + println!("{y:?}"); + x.expect("{{y} {x"); + x.expect("{{y:?}"); + x.expect("{y:...}"); + let _ = "fn main {\n\ + }"; + // Unicode characters escape should not lint either. + "\u{0052}".to_string(); +} diff --git a/tests/ui/literal_string_with_formatting_arg.stderr b/tests/ui/literal_string_with_formatting_arg.stderr new file mode 100644 index 00000000000..c05d4af017c --- /dev/null +++ b/tests/ui/literal_string_with_formatting_arg.stderr @@ -0,0 +1,65 @@ +error: these look like formatting arguments but are 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 looks like 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 looks like 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 look like 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 looks like 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 look like formatting arguments but are not part of a formatting macro + --> tests/ui/literal_string_with_formatting_arg.rs:12:16 + | +LL | x.expect(r"{y:?} {y:?} "); + | ^^^^^ ^^^^^ + +error: this looks like 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 look like 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 looks like 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: this looks like a formatting argument but it is not part of a formatting macro + --> tests/ui/literal_string_with_formatting_arg.rs:17:18 + | +LL | x.expect("———{}"); + | ^^ + +error: aborting due to 10 previous errors + |
