about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-11-08 12:02:30 +0000
committerbors <bors@rust-lang.org>2020-11-08 12:02:30 +0000
commitb1faa7f0027327e133386f32476302cc2805c963 (patch)
treee610c9ff37d0808f88f9b2fa6dba7100f0100bae
parentabfa331f266c82fcd62d26ff248f92fe59e09956 (diff)
parent7c74d870b5978fb100f8947850d0da3f38dd5c1c (diff)
downloadrust-b1faa7f0027327e133386f32476302cc2805c963.tar.gz
rust-b1faa7f0027327e133386f32476302cc2805c963.zip
Auto merge of #6271 - camsteffen:vec-box-import, r=flip1995
Fix vec_box scope error

changelog: Fix vec_box suggestion with wrong type scope

Fixes #6236
-rw-r--r--clippy_lints/src/types.rs2
-rw-r--r--tests/ui/vec_box_sized.fixed14
-rw-r--r--tests/ui/vec_box_sized.rs14
-rw-r--r--tests/ui/vec_box_sized.stderr8
4 files changed, 36 insertions, 2 deletions
diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs
index c7d82da3b8b..f0e10e374e1 100644
--- a/clippy_lints/src/types.rs
+++ b/clippy_lints/src/types.rs
@@ -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
diff --git a/tests/ui/vec_box_sized.fixed b/tests/ui/vec_box_sized.fixed
index d0bee2460dd..4fa28b525c3 100644
--- a/tests/ui/vec_box_sized.fixed
+++ b/tests/ui/vec_box_sized.fixed
@@ -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() {}
diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs
index 500a0ae263e..7dc735cd90b 100644
--- a/tests/ui/vec_box_sized.rs
+++ b/tests/ui/vec_box_sized.rs
@@ -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() {}
diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr
index 29bf7069e8a..57e2f1fdf9a 100644
--- a/tests/ui/vec_box_sized.stderr
+++ b/tests/ui/vec_box_sized.stderr
@@ -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