Skip to content

Commit

Permalink
Add ui test for useless_concat lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 15, 2024
1 parent 3b76a53 commit b92d91b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/ui/useless_concat.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![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
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!());
}
19 changes: 19 additions & 0 deletions tests/ui/useless_concat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![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
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!());
}
23 changes: 23 additions & 0 deletions tests/ui/useless_concat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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:23
|
LL | println!("b: {}", concat!("a"));
| ^^^^^^^^^^^^ help: replace with: `"a"`

error: aborting due to 3 previous errors

0 comments on commit b92d91b

Please sign in to comment.