diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-09-18 00:10:16 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-11-19 15:44:19 +0100 |
| commit | 922aabe348757f69b993f5d93a5bfb7fb1db38f8 (patch) | |
| tree | 71b1c3e2789ba91925be140b6b39bf5f773d134a /tests | |
| parent | cd7cec9066f35e2fd661a69830fd57864b41ea44 (diff) | |
| download | rust-922aabe348757f69b993f5d93a5bfb7fb1db38f8.tar.gz rust-922aabe348757f69b993f5d93a5bfb7fb1db38f8.zip | |
Add regression test for `literal_string_with_formatting_arg`
Diffstat (limited to 'tests')
| -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 + |
