Add ui test for useless_concat lint

This commit is contained in:
Guillaume Gomez 2024-12-14 23:40:55 +01:00
parent a8679816dc
commit 126fb00585
3 changed files with 69 additions and 0 deletions

View file

@ -0,0 +1,20 @@
#![warn(clippy::useless_concat)]
#![allow(clippy::print_literal)]
macro_rules! my_concat {
($fmt:literal $(, $e:expr)*) => {
println!(concat!("ERROR: ", $fmt), $($e,)*);
}
}
fn main() {
let x = ""; //~ useless_concat
let x = "a"; //~ useless_concat
let x = "1"; //~ useless_concat
println!("b: {}", "a"); //~ useless_concat
// Should not lint.
let x = concat!("a", "b");
let local_i32 = 1;
my_concat!("{}", local_i32);
let x = concat!(file!(), "#L", line!());
}

View file

@ -0,0 +1,20 @@
#![warn(clippy::useless_concat)]
#![allow(clippy::print_literal)]
macro_rules! my_concat {
($fmt:literal $(, $e:expr)*) => {
println!(concat!("ERROR: ", $fmt), $($e,)*);
}
}
fn main() {
let x = concat!(); //~ useless_concat
let x = concat!("a"); //~ useless_concat
let x = concat!(1); //~ useless_concat
println!("b: {}", concat!("a")); //~ useless_concat
// Should not lint.
let x = concat!("a", "b");
let local_i32 = 1;
my_concat!("{}", local_i32);
let x = concat!(file!(), "#L", line!());
}

View file

@ -0,0 +1,29 @@
error: unneeded use of `concat!` macro
--> tests/ui/useless_concat.rs:11:13
|
LL | let x = concat!();
| ^^^^^^^^^ help: replace with: `""`
|
= note: `-D clippy::useless-concat` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::useless_concat)]`
error: unneeded use of `concat!` macro
--> tests/ui/useless_concat.rs:12:13
|
LL | let x = concat!("a");
| ^^^^^^^^^^^^ help: replace with: `"a"`
error: unneeded use of `concat!` macro
--> tests/ui/useless_concat.rs:13:13
|
LL | let x = concat!(1);
| ^^^^^^^^^^ help: replace with: `"1"`
error: unneeded use of `concat!` macro
--> tests/ui/useless_concat.rs:14:23
|
LL | println!("b: {}", concat!("a"));
| ^^^^^^^^^^^^ help: replace with: `"a"`
error: aborting due to 4 previous errors