about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/types/mod.rs8
-rw-r--r--tests/ui/dlist.rs3
-rw-r--r--tests/ui/dlist.stderr32
-rw-r--r--tests/ui/option_option.rs3
-rw-r--r--tests/ui/option_option.stderr38
-rw-r--r--tests/ui/vec_box_sized.fixed2
-rw-r--r--tests/ui/vec_box_sized.rs2
-rw-r--r--tests/ui/vec_box_sized.stderr26
8 files changed, 86 insertions, 28 deletions
diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs
index d5f2b3d013e..1df964db38f 100644
--- a/clippy_lints/src/types/mod.rs
+++ b/clippy_lints/src/types/mod.rs
@@ -249,6 +249,14 @@ impl<'tcx> LateLintPass<'tcx> for Types {
         self.check_fn_decl(cx, decl);
     }
 
+    fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
+        match item.kind {
+            ItemKind::Static(ref ty, _, _) | ItemKind::Const(ref ty, _) => self.check_ty(cx, ty, false),
+            // functions, enums, structs, impls and traits are covered
+            _ => (),
+        }
+    }
+
     fn check_field_def(&mut self, cx: &LateContext<'_>, field: &hir::FieldDef<'_>) {
         self.check_ty(cx, &field.ty, false);
     }
diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs
index 2940d2d2901..2c3b25cd45e 100644
--- a/tests/ui/dlist.rs
+++ b/tests/ui/dlist.rs
@@ -5,6 +5,9 @@
 extern crate alloc;
 use alloc::collections::linked_list::LinkedList;
 
+const C: LinkedList<i32> = LinkedList::new();
+static S: LinkedList<i32> = LinkedList::new();
+
 trait Foo {
     type Baz = LinkedList<u8>;
     fn foo(_: LinkedList<u8>);
diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr
index 234db33ba12..425407dc334 100644
--- a/tests/ui/dlist.stderr
+++ b/tests/ui/dlist.stderr
@@ -1,14 +1,30 @@
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:9:16
+  --> $DIR/dlist.rs:8:10
+   |
+LL | const C: LinkedList<i32> = LinkedList::new();
+   |          ^^^^^^^^^^^^^^^
+   |
+   = note: `-D clippy::linkedlist` implied by `-D warnings`
+   = help: a `VecDeque` might work
+
+error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
+  --> $DIR/dlist.rs:9:11
+   |
+LL | static S: LinkedList<i32> = LinkedList::new();
+   |           ^^^^^^^^^^^^^^^
+   |
+   = help: a `VecDeque` might work
+
+error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
+  --> $DIR/dlist.rs:12:16
    |
 LL |     type Baz = LinkedList<u8>;
    |                ^^^^^^^^^^^^^^
    |
-   = note: `-D clippy::linkedlist` implied by `-D warnings`
    = help: a `VecDeque` might work
 
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:10:15
+  --> $DIR/dlist.rs:13:15
    |
 LL |     fn foo(_: LinkedList<u8>);
    |               ^^^^^^^^^^^^^^
@@ -16,7 +32,7 @@ LL |     fn foo(_: LinkedList<u8>);
    = help: a `VecDeque` might work
 
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:11:23
+  --> $DIR/dlist.rs:14:23
    |
 LL |     const BAR: Option<LinkedList<u8>>;
    |                       ^^^^^^^^^^^^^^
@@ -24,7 +40,7 @@ LL |     const BAR: Option<LinkedList<u8>>;
    = help: a `VecDeque` might work
 
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:22:15
+  --> $DIR/dlist.rs:25:15
    |
 LL |     fn foo(_: LinkedList<u8>) {}
    |               ^^^^^^^^^^^^^^
@@ -32,7 +48,7 @@ LL |     fn foo(_: LinkedList<u8>) {}
    = help: a `VecDeque` might work
 
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:25:39
+  --> $DIR/dlist.rs:28:39
    |
 LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
    |                                       ^^^^^^^^^^^^^^
@@ -40,12 +56,12 @@ LL | pub fn test(my_favourite_linked_list: LinkedList<u8>) {
    = help: a `VecDeque` might work
 
 error: you seem to be using a `LinkedList`! Perhaps you meant some other data structure?
-  --> $DIR/dlist.rs:29:29
+  --> $DIR/dlist.rs:32:29
    |
 LL | pub fn test_ret() -> Option<LinkedList<u8>> {
    |                             ^^^^^^^^^^^^^^
    |
    = help: a `VecDeque` might work
 
-error: aborting due to 6 previous errors
+error: aborting due to 8 previous errors
 
diff --git a/tests/ui/option_option.rs b/tests/ui/option_option.rs
index 6859ba8e5bb..2faab9e035d 100644
--- a/tests/ui/option_option.rs
+++ b/tests/ui/option_option.rs
@@ -1,6 +1,9 @@
 #![deny(clippy::option_option)]
 #![allow(clippy::unnecessary_wraps)]
 
+const C: Option<Option<i32>> = None;
+static S: Option<Option<i32>> = None;
+
 fn input(_: Option<Option<u8>>) {}
 
 fn output() -> Option<Option<u8>> {
diff --git a/tests/ui/option_option.stderr b/tests/ui/option_option.stderr
index ad7f081c713..a925bb35b04 100644
--- a/tests/ui/option_option.stderr
+++ b/tests/ui/option_option.stderr
@@ -1,8 +1,8 @@
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:4:13
+  --> $DIR/option_option.rs:4:10
    |
-LL | fn input(_: Option<Option<u8>>) {}
-   |             ^^^^^^^^^^^^^^^^^^
+LL | const C: Option<Option<i32>> = None;
+   |          ^^^^^^^^^^^^^^^^^^^
    |
 note: the lint level is defined here
   --> $DIR/option_option.rs:1:9
@@ -11,58 +11,70 @@ LL | #![deny(clippy::option_option)]
    |         ^^^^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:6:16
+  --> $DIR/option_option.rs:5:11
+   |
+LL | static S: Option<Option<i32>> = None;
+   |           ^^^^^^^^^^^^^^^^^^^
+
+error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
+  --> $DIR/option_option.rs:7:13
+   |
+LL | fn input(_: Option<Option<u8>>) {}
+   |             ^^^^^^^^^^^^^^^^^^
+
+error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
+  --> $DIR/option_option.rs:9:16
    |
 LL | fn output() -> Option<Option<u8>> {
    |                ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:10:27
+  --> $DIR/option_option.rs:13:27
    |
 LL | fn output_nested() -> Vec<Option<Option<u8>>> {
    |                           ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:15:30
+  --> $DIR/option_option.rs:18:30
    |
 LL | fn output_nested_nested() -> Option<Option<Option<u8>>> {
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:20:8
+  --> $DIR/option_option.rs:23:8
    |
 LL |     x: Option<Option<u8>>,
    |        ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:24:23
+  --> $DIR/option_option.rs:27:23
    |
 LL |     fn struct_fn() -> Option<Option<u8>> {
    |                       ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:30:22
+  --> $DIR/option_option.rs:33:22
    |
 LL |     fn trait_fn() -> Option<Option<u8>>;
    |                      ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:34:11
+  --> $DIR/option_option.rs:37:11
    |
 LL |     Tuple(Option<Option<u8>>),
    |           ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:35:17
+  --> $DIR/option_option.rs:38:17
    |
 LL |     Struct { x: Option<Option<u8>> },
    |                 ^^^^^^^^^^^^^^^^^^
 
 error: consider using `Option<T>` instead of `Option<Option<T>>` or a custom enum if you need to distinguish all 3 cases
-  --> $DIR/option_option.rs:76:14
+  --> $DIR/option_option.rs:79:14
    |
 LL |         foo: Option<Option<Cow<'a, str>>>,
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: aborting due to 10 previous errors
+error: aborting due to 12 previous errors
 
diff --git a/tests/ui/vec_box_sized.fixed b/tests/ui/vec_box_sized.fixed
index 4fa28b525c3..a40d91fdb18 100644
--- a/tests/ui/vec_box_sized.fixed
+++ b/tests/ui/vec_box_sized.fixed
@@ -9,6 +9,8 @@ struct BigStruct([i32; 10000]);
 /// The following should trigger the lint
 mod should_trigger {
     use super::SizedStruct;
+    const C: Vec<i32> = Vec::new();
+    static S: Vec<i32> = Vec::new();
 
     struct StructWithVecBox {
         sized_type: Vec<SizedStruct>,
diff --git a/tests/ui/vec_box_sized.rs b/tests/ui/vec_box_sized.rs
index 7dc735cd90b..843bbb64e71 100644
--- a/tests/ui/vec_box_sized.rs
+++ b/tests/ui/vec_box_sized.rs
@@ -9,6 +9,8 @@ struct BigStruct([i32; 10000]);
 /// The following should trigger the lint
 mod should_trigger {
     use super::SizedStruct;
+    const C: Vec<Box<i32>> = Vec::new();
+    static S: Vec<Box<i32>> = Vec::new();
 
     struct StructWithVecBox {
         sized_type: Vec<Box<SizedStruct>>,
diff --git a/tests/ui/vec_box_sized.stderr b/tests/ui/vec_box_sized.stderr
index 83435a40aa1..c518267f041 100644
--- a/tests/ui/vec_box_sized.stderr
+++ b/tests/ui/vec_box_sized.stderr
@@ -1,28 +1,40 @@
 error: `Vec<T>` is already on the heap, the boxing is unnecessary
-  --> $DIR/vec_box_sized.rs:14:21
+  --> $DIR/vec_box_sized.rs:12:14
    |
-LL |         sized_type: Vec<Box<SizedStruct>>,
-   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
+LL |     const C: Vec<Box<i32>> = Vec::new();
+   |              ^^^^^^^^^^^^^ help: try: `Vec<i32>`
    |
    = note: `-D clippy::vec-box` implied by `-D warnings`
 
 error: `Vec<T>` is already on the heap, the boxing is unnecessary
-  --> $DIR/vec_box_sized.rs:17:14
+  --> $DIR/vec_box_sized.rs:13:15
+   |
+LL |     static S: Vec<Box<i32>> = Vec::new();
+   |               ^^^^^^^^^^^^^ help: try: `Vec<i32>`
+
+error: `Vec<T>` is already on the heap, the boxing is unnecessary
+  --> $DIR/vec_box_sized.rs:16:21
+   |
+LL |         sized_type: Vec<Box<SizedStruct>>,
+   |                     ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
+
+error: `Vec<T>` is already on the heap, the boxing is unnecessary
+  --> $DIR/vec_box_sized.rs:19:14
    |
 LL |     struct A(Vec<Box<SizedStruct>>);
    |              ^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<SizedStruct>`
 
 error: `Vec<T>` is already on the heap, the boxing is unnecessary
-  --> $DIR/vec_box_sized.rs:18:18
+  --> $DIR/vec_box_sized.rs:20:18
    |
 LL |     struct B(Vec<Vec<Box<(u32)>>>);
    |                  ^^^^^^^^^^^^^^^ help: try: `Vec<u32>`
 
 error: `Vec<T>` is already on the heap, the boxing is unnecessary
-  --> $DIR/vec_box_sized.rs:46:23
+  --> $DIR/vec_box_sized.rs:48:23
    |
 LL |         pub fn f() -> Vec<Box<S>> {
    |                       ^^^^^^^^^^^ help: try: `Vec<S>`
 
-error: aborting due to 4 previous errors
+error: aborting due to 6 previous errors