[useless_vec]: add more tests for macro combinations

This commit is contained in:
y21 2023-07-03 18:13:01 +02:00
parent 3f17c5c388
commit b4549c50b5
4 changed files with 77 additions and 3 deletions

View File

@ -154,6 +154,10 @@ fn check_vec_macro<'tcx>(
span: Span,
suggest_slice: SuggestedType,
) {
if span.from_expansion() {
return;
}
let mut applicability = Applicability::MachineApplicable;
let snippet = match *vec_args {

View File

@ -124,6 +124,35 @@ fn issue11075() {
for _string in [repro!(true), repro!(null)] {
unimplemented!();
}
macro_rules! in_macro {
($e:expr, $vec:expr, $vec2:expr) => {{
vec![1; 2].fill(3);
vec![1, 2].fill(3);
for _ in vec![1, 2] {}
for _ in vec![1; 2] {}
for _ in vec![$e, $e] {}
for _ in vec![$e; 2] {}
for _ in $vec {}
for _ in $vec2 {}
}};
}
in_macro!(1, [1, 2], [1; 2]);
macro_rules! from_macro {
() => {
vec![1, 2, 3]
};
}
macro_rules! from_macro_repeat {
() => {
vec![1; 3]
};
}
for _ in from_macro!() {}
for _ in from_macro_repeat!() {}
}
#[clippy::msrv = "1.53"]

View File

@ -124,6 +124,35 @@ macro_rules! repro {
for _string in vec![repro!(true), repro!(null)] {
unimplemented!();
}
macro_rules! in_macro {
($e:expr, $vec:expr, $vec2:expr) => {{
vec![1; 2].fill(3);
vec![1, 2].fill(3);
for _ in vec![1, 2] {}
for _ in vec![1; 2] {}
for _ in vec![$e, $e] {}
for _ in vec![$e; 2] {}
for _ in $vec {}
for _ in $vec2 {}
}};
}
in_macro!(1, vec![1, 2], vec![1; 2]);
macro_rules! from_macro {
() => {
vec![1, 2, 3]
};
}
macro_rules! from_macro_repeat {
() => {
vec![1; 3]
};
}
for _ in from_macro!() {}
for _ in from_macro_repeat!() {}
}
#[clippy::msrv = "1.53"]

View File

@ -91,16 +91,28 @@ LL | for _string in vec![repro!(true), repro!(null)] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]`
error: useless use of `vec!`
--> $DIR/vec.rs:131:14
--> $DIR/vec.rs:141:18
|
LL | in_macro!(1, vec![1, 2], vec![1; 2]);
| ^^^^^^^^^^ help: you can use an array directly: `[1, 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:141:30
|
LL | in_macro!(1, vec![1, 2], vec![1; 2]);
| ^^^^^^^^^^ help: you can use an array directly: `[1; 2]`
error: useless use of `vec!`
--> $DIR/vec.rs:160:14
|
LL | for a in vec![1, 2, 3] {
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
error: useless use of `vec!`
--> $DIR/vec.rs:135:14
--> $DIR/vec.rs:164:14
|
LL | for a in vec![String::new(), String::new()] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
error: aborting due to 17 previous errors
error: aborting due to 19 previous errors