Skip to content

Commit 3bfeb44

Browse files
committed
add tests for issue rust-lang#11861
1 parent c09188f commit 3bfeb44

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

tests/ui/vec.fixed

+17
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,20 @@ fn below() {
176176
let _: String = a;
177177
}
178178
}
179+
180+
fn func_needing_vec(_bar: usize, _baz: Vec<usize>) {}
181+
fn func_not_needing_vec(_bar: usize, _baz: usize) {}
182+
183+
fn issue11861() {
184+
macro_rules! this_macro_needs_vec {
185+
($x:expr) => {{ func_needing_vec($x.iter().sum(), $x) }};
186+
}
187+
macro_rules! this_macro_doesnt_need_vec {
188+
($x:expr) => {{ func_not_needing_vec($x.iter().sum(), $x.iter().sum()) }};
189+
}
190+
191+
// Do not lint the next line
192+
this_macro_needs_vec!(vec![1]);
193+
// Lint the next line
194+
this_macro_doesnt_need_vec!([1]);
195+
}

tests/ui/vec.rs

+17
Original file line numberDiff line numberDiff line change
@@ -176,3 +176,20 @@ fn below() {
176176
let _: String = a;
177177
}
178178
}
179+
180+
fn func_needing_vec(_bar: usize, _baz: Vec<usize>) {}
181+
fn func_not_needing_vec(_bar: usize, _baz: usize) {}
182+
183+
fn issue11861() {
184+
macro_rules! this_macro_needs_vec {
185+
($x:expr) => {{ func_needing_vec($x.iter().sum(), $x) }};
186+
}
187+
macro_rules! this_macro_doesnt_need_vec {
188+
($x:expr) => {{ func_not_needing_vec($x.iter().sum(), $x.iter().sum()) }};
189+
}
190+
191+
// Do not lint the next line
192+
this_macro_needs_vec!(vec![1]);
193+
// Lint the next line
194+
this_macro_doesnt_need_vec!(vec![1]);
195+
}

tests/ui/vec.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,11 @@ error: useless use of `vec!`
115115
LL | for a in vec![String::new(), String::new()] {
116116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
117117

118-
error: aborting due to 19 previous errors
118+
error: useless use of `vec!`
119+
--> $DIR/vec.rs:194:33
120+
|
121+
LL | this_macro_doesnt_need_vec!(vec![1]);
122+
| ^^^^^^^ help: you can use an array directly: `[1]`
123+
124+
error: aborting due to 20 previous errors
119125

0 commit comments

Comments
 (0)