Skip to content

Commit a959061

Browse files
committed
Auto merge of rust-lang#11081 - y21:issue11075, r=Manishearth
[`useless_vec`]: use the source span for initializer Fixes rust-lang#11075. changelog: [`useless_vec`]: use the source span for the initializer expression when inside of a macro
2 parents 2b03bb0 + 1f77f8c commit a959061

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

clippy_lints/src/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl UselessVec {
181181
if args.len() as u64 * size_of(cx, last) > self.too_large_for_stack {
182182
return;
183183
}
184-
let span = args[0].span.to(last.span);
184+
let span = args[0].span.source_callsite().to(last.span.source_callsite());
185185
let args = snippet_with_applicability(cx, span, "..", &mut applicability);
186186

187187
match suggest_slice {

tests/ui/vec.fixed

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ fn main() {
115115
let _x = vec![1; 201];
116116
}
117117

118+
fn issue11075() {
119+
macro_rules! repro {
120+
($e:expr) => {
121+
stringify!($e)
122+
};
123+
}
124+
for _string in [repro!(true), repro!(null)] {
125+
unimplemented!();
126+
}
127+
}
128+
118129
#[clippy::msrv = "1.53"]
119130
fn above() {
120131
for a in [1, 2, 3] {

tests/ui/vec.rs

+11
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ fn main() {
115115
let _x = vec![1; 201];
116116
}
117117

118+
fn issue11075() {
119+
macro_rules! repro {
120+
($e:expr) => {
121+
stringify!($e)
122+
};
123+
}
124+
for _string in vec![repro!(true), repro!(null)] {
125+
unimplemented!();
126+
}
127+
}
128+
118129
#[clippy::msrv = "1.53"]
119130
fn above() {
120131
for a in vec![1, 2, 3] {

tests/ui/vec.stderr

+9-3
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,22 @@ LL | for _ in vec![1, 2, 3] {}
8585
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
8686

8787
error: useless use of `vec!`
88-
--> $DIR/vec.rs:120:14
88+
--> $DIR/vec.rs:124:20
89+
|
90+
LL | for _string in vec![repro!(true), repro!(null)] {
91+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[repro!(true), repro!(null)]`
92+
93+
error: useless use of `vec!`
94+
--> $DIR/vec.rs:131:14
8995
|
9096
LL | for a in vec![1, 2, 3] {
9197
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
9298

9399
error: useless use of `vec!`
94-
--> $DIR/vec.rs:124:14
100+
--> $DIR/vec.rs:135:14
95101
|
96102
LL | for a in vec![String::new(), String::new()] {
97103
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
98104

99-
error: aborting due to 16 previous errors
105+
error: aborting due to 17 previous errors
100106

0 commit comments

Comments
 (0)