Auto merge of #11081 - y21:issue11075, r=Manishearth

[`useless_vec`]: use the source span for initializer

Fixes #11075.

changelog: [`useless_vec`]: use the source span for the initializer expression when inside of a macro
This commit is contained in:
bors 2023-07-03 12:08:36 +00:00
commit a959061763
4 changed files with 32 additions and 4 deletions

View File

@ -181,7 +181,7 @@ impl UselessVec {
if args.len() as u64 * size_of(cx, last) > self.too_large_for_stack { if args.len() as u64 * size_of(cx, last) > self.too_large_for_stack {
return; return;
} }
let span = args[0].span.to(last.span); let span = args[0].span.source_callsite().to(last.span.source_callsite());
let args = snippet_with_applicability(cx, span, "..", &mut applicability); let args = snippet_with_applicability(cx, span, "..", &mut applicability);
match suggest_slice { match suggest_slice {

View File

@ -115,6 +115,17 @@ fn main() {
let _x = vec![1; 201]; let _x = vec![1; 201];
} }
fn issue11075() {
macro_rules! repro {
($e:expr) => {
stringify!($e)
};
}
for _string in [repro!(true), repro!(null)] {
unimplemented!();
}
}
#[clippy::msrv = "1.53"] #[clippy::msrv = "1.53"]
fn above() { fn above() {
for a in [1, 2, 3] { for a in [1, 2, 3] {

View File

@ -115,6 +115,17 @@ fn main() {
let _x = vec![1; 201]; let _x = vec![1; 201];
} }
fn issue11075() {
macro_rules! repro {
($e:expr) => {
stringify!($e)
};
}
for _string in vec![repro!(true), repro!(null)] {
unimplemented!();
}
}
#[clippy::msrv = "1.53"] #[clippy::msrv = "1.53"]
fn above() { fn above() {
for a in vec![1, 2, 3] { for a in vec![1, 2, 3] {

View File

@ -85,16 +85,22 @@ LL | for _ in vec![1, 2, 3] {}
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
error: useless use of `vec!` error: useless use of `vec!`
--> $DIR/vec.rs:120:14 --> $DIR/vec.rs:124:20
|
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
| |
LL | for a in vec![1, 2, 3] { LL | for a in vec![1, 2, 3] {
| ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]` | ^^^^^^^^^^^^^ help: you can use an array directly: `[1, 2, 3]`
error: useless use of `vec!` error: useless use of `vec!`
--> $DIR/vec.rs:124:14 --> $DIR/vec.rs:135:14
| |
LL | for a in vec![String::new(), String::new()] { LL | for a in vec![String::new(), String::new()] {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: you can use an array directly: `[String::new(), String::new()]`
error: aborting due to 16 previous errors error: aborting due to 17 previous errors