Skip to content

Commit 7c74d87

Browse files
committed
Fix vec_box scope error
Fixes rust-lang#6236
1 parent 0be6544 commit 7c74d87

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

clippy_lints/src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl Types {
553553
hir_ty.span,
554554
"`Vec<T>` is already on the heap, the boxing is unnecessary.",
555555
"try",
556-
format!("Vec<{}>", ty_ty),
556+
format!("Vec<{}>", snippet(cx, boxed_ty.span, "..")),
557557
Applicability::MachineApplicable,
558558
);
559559
return; // don't recurse into the type

tests/ui/vec_box_sized.fixed

+14
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,18 @@ mod should_not_trigger {
3535
}
3636
}
3737

38+
mod inner_mod {
39+
mod inner {
40+
pub struct S;
41+
}
42+
43+
mod inner2 {
44+
use super::inner::S;
45+
46+
pub fn f() -> Vec<S> {
47+
vec![]
48+
}
49+
}
50+
}
51+
3852
fn main() {}

tests/ui/vec_box_sized.rs

+14
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,18 @@ mod should_not_trigger {
3535
}
3636
}
3737

38+
mod inner_mod {
39+
mod inner {
40+
pub struct S;
41+
}
42+
43+
mod inner2 {
44+
use super::inner::S;
45+
46+
pub fn f() -> Vec<Box<S>> {
47+
vec![]
48+
}
49+
}
50+
}
51+
3852
fn main() {}

tests/ui/vec_box_sized.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,11 @@ error: `Vec<T>` is already on the heap, the boxing is unnecessary.
1818
LL | struct B(Vec<Vec<Box<(u32)>>>);
1919
| ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
2020

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

0 commit comments

Comments
 (0)