]> git.lizzy.rs Git - rust.git/commitdiff
Remove check for Fn, reflect this in test cases, make test cases more robust/explicit
authorGlenn Hope <glenn.alexander.hope@gmail.com>
Sat, 9 May 2020 15:04:07 +0000 (08:04 -0700)
committerGlenn Hope <glenn.alexander.hope@gmail.com>
Sat, 9 May 2020 18:09:38 +0000 (11:09 -0700)
clippy_lints/src/wildcard_imports.rs
tests/ui/wildcard_imports.fixed
tests/ui/wildcard_imports.rs
tests/ui/wildcard_imports.stderr

index 48405a00d5541dae3c57ef129e9b4b6d492a268c..e12a6659ab5b01a5b7118397012f00ec357162f0 100644 (file)
     ///
     /// This can lead to confusing error messages at best and to unexpected behavior at worst.
     ///
-    /// Note that this will not warn about wildcard imports from modules named `prelude`; many
-    /// crates (including the standard library) provide modules named "prelude" specifically
-    /// designed for wildcard import.
+    /// **Exceptions:**
+    ///
+    /// Wildcard imports are allowed from modules named `prelude`. Many crates (including the standard library)
+    /// provide modules named "prelude" specifically designed for wildcard import.
+    ///
+    /// `use super::*` is allowed in test modules. This is defined as any module with "test" in the name.
+    ///
+    /// These exceptions can be disabled using the `warn-on-all-wildcard-imports` configuration flag.
     ///
     /// **Known problems:** If macros are imported through the wildcard, this macro is not included
     /// by the suggestion and has to be added by hand.
@@ -198,5 +203,5 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
 }
 
 fn is_test_module_or_function(item: &Item<'_>) -> bool {
-    matches!(item.kind, ItemKind::Fn(..) | ItemKind::Mod(..)) && item.ident.name.as_str().contains("test")
+    matches!(item.kind, ItemKind::Mod(..)) && item.ident.name.as_str().contains("test")
 }
index 98bf6acfe55f20520627be62537f47426c17c42a..b47c8f23e2403a8b63c5303b2833ebe68e07e674 100644 (file)
@@ -175,13 +175,34 @@ mod super_imports {
         }
     }
 
-    mod inner {
-        fn test_should_pass() {
+    mod test_should_pass_inside_function {
+        fn with_super_inside_function() {
             use super::*;
             let _ = foofoo();
         }
     }
 
+    mod test_should_pass_further_inside {
+        fn insidefoo() {}
+        mod inner {
+            use super::*;
+            fn with_super() {
+                let _ = insidefoo();
+            }
+        }
+    }
+
+    mod should_be_replaced_futher_inside {
+        fn insidefoo() {}
+        mod inner {
+            use super::insidefoo;
+            fn with_super() {
+                let _ = insidefoo();
+            }
+        }
+    }
+
+
     mod use_explicit_should_be_replaced {
         use super_imports::foofoo;
 
index 9275c5a0928642f5e66b6651de94a952c3ea32f5..3ad1a29aebad1f985a19e272ac55f071263f511c 100644 (file)
@@ -176,13 +176,33 @@ fn with_super() {
         }
     }
 
-    mod inner {
-        fn test_should_pass() {
+    mod test_should_pass_inside_function {
+        fn with_super_inside_function() {
             use super::*;
             let _ = foofoo();
         }
     }
 
+    mod test_should_pass_further_inside {
+        fn insidefoo() {}
+        mod inner {
+            use super::*;
+            fn with_super() {
+                let _ = insidefoo();
+            }
+        }
+    }
+
+    mod should_be_replaced_futher_inside {
+        fn insidefoo() {}
+        mod inner {
+            use super::*;
+            fn with_super() {
+                let _ = insidefoo();
+            }
+        }
+    }
+
     mod use_explicit_should_be_replaced {
         use super_imports::*;
 
index bd000ce81616b6f42c720c331bd0a2f63d51f3dd..de07bd1d69ba1ec9decc05da407336e75da83f0c 100644 (file)
@@ -99,22 +99,28 @@ LL |         use super::*;
    |             ^^^^^^^^ help: try: `super::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:187:13
+  --> $DIR/wildcard_imports.rs:199:17
+   |
+LL |             use super::*;
+   |                 ^^^^^^^^ help: try: `super::insidefoo`
+
+error: usage of wildcard import
+  --> $DIR/wildcard_imports.rs:208:13
    |
 LL |         use super_imports::*;
    |             ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:196:17
+  --> $DIR/wildcard_imports.rs:217:17
    |
 LL |             use super::super::*;
    |                 ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:205:13
+  --> $DIR/wildcard_imports.rs:226:13
    |
 LL |         use super::super::super_imports::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
 
-error: aborting due to 19 previous errors
+error: aborting due to 20 previous errors