Skip to content

Commit

Permalink
Auto merge of #6271 - camsteffen:vec-box-import, r=flip1995
Browse files Browse the repository at this point in the history
Fix vec_box scope error

changelog: Fix vec_box suggestion with wrong type scope

Fixes #6236
  • Loading branch information
bors committed Nov 8, 2020
2 parents abfa331 + 7c74d87 commit b1faa7f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ impl Types {
hir_ty.span,
"`Vec<T>` is already on the heap, the boxing is unnecessary.",
"try",
format!("Vec<{}>", ty_ty),
format!("Vec<{}>", snippet(cx, boxed_ty.span, "..")),
Applicability::MachineApplicable,
);
return; // don't recurse into the type
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/vec_box_sized.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ mod should_not_trigger {
}
}

mod inner_mod {
mod inner {
pub struct S;
}

mod inner2 {
use super::inner::S;

pub fn f() -> Vec<S> {
vec![]
}
}
}

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/vec_box_sized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,18 @@ mod should_not_trigger {
}
}

mod inner_mod {
mod inner {
pub struct S;
}

mod inner2 {
use super::inner::S;

pub fn f() -> Vec<Box<S>> {
vec![]
}
}
}

fn main() {}
8 changes: 7 additions & 1 deletion tests/ui/vec_box_sized.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,11 @@ error: `Vec<T>` is already on the heap, the boxing is unnecessary.
LL | struct B(Vec<Vec<Box<(u32)>>>);
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`

error: aborting due to 3 previous errors
error: `Vec<T>` is already on the heap, the boxing is unnecessary.
--> $DIR/vec_box_sized.rs:46:23
|
LL | pub fn f() -> Vec<Box<S>> {
| ^^^^^^^^^^^ help: try: `Vec<S>`

error: aborting due to 4 previous errors

0 comments on commit b1faa7f

Please sign in to comment.