Skip to content

Commit 4918abc

Browse files
Add ui test for useless_concat lint
1 parent 35f92f6 commit 4918abc

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/ui/useless_concat.fixed

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![warn(clippy::useless_concat)]
2+
#![allow(clippy::print_literal)]
3+
4+
macro_rules! my_concat {
5+
($fmt:literal $(, $e:expr)*) => {
6+
println!(concat!("ERROR: ", $fmt), $($e,)*);
7+
}
8+
}
9+
10+
fn main() {
11+
let x = ""; //~ useless_concat
12+
let x = "a"; //~ useless_concat
13+
println!("b: {}", "a"); //~ useless_concat
14+
// Should not lint.
15+
let x = concat!("a", "b");
16+
let local_i32 = 1;
17+
my_concat!("{}", local_i32);
18+
}

tests/ui/useless_concat.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![warn(clippy::useless_concat)]
2+
#![allow(clippy::print_literal)]
3+
4+
macro_rules! my_concat {
5+
($fmt:literal $(, $e:expr)*) => {
6+
println!(concat!("ERROR: ", $fmt), $($e,)*);
7+
}
8+
}
9+
10+
fn main() {
11+
let x = concat!(); //~ useless_concat
12+
let x = concat!("a"); //~ useless_concat
13+
println!("b: {}", concat!("a")); //~ useless_concat
14+
// Should not lint.
15+
let x = concat!("a", "b");
16+
let local_i32 = 1;
17+
my_concat!("{}", local_i32);
18+
}

tests/ui/useless_concat.stderr

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: unneeded use of `concat!` macro
2+
--> tests/ui/useless_concat.rs:11:13
3+
|
4+
LL | let x = concat!();
5+
| ^^^^^^^^^ help: replace with: `""`
6+
|
7+
= note: `-D clippy::useless-concat` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::useless_concat)]`
9+
10+
error: unneeded use of `concat!` macro
11+
--> tests/ui/useless_concat.rs:12:13
12+
|
13+
LL | let x = concat!("a");
14+
| ^^^^^^^^^^^^ help: replace with: `"a"`
15+
16+
error: unneeded use of `concat!` macro
17+
--> tests/ui/useless_concat.rs:13:23
18+
|
19+
LL | println!("b: {}", concat!("a"));
20+
| ^^^^^^^^^^^^ help: replace with: `"a"`
21+
22+
error: aborting due to 3 previous errors
23+

0 commit comments

Comments
 (0)