File tree 3 files changed +41
-1
lines changed
3 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -176,3 +176,20 @@ fn below() {
176
176
let _: String = a;
177
177
}
178
178
}
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
+ }
Original file line number Diff line number Diff line change @@ -176,3 +176,20 @@ fn below() {
176
176
let _: String = a;
177
177
}
178
178
}
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
+ }
Original file line number Diff line number Diff line change @@ -115,5 +115,11 @@ error: useless use of `vec!`
115
115
LL | for a in vec![String::new(), String::new()] {
116
116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
117
117
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
119
125
You can’t perform that action at this time.
0 commit comments