This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +64
-12
lines changed Expand file tree Collapse file tree 4 files changed +64
-12
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,14 @@ declare_clippy_lint! {
4343 ///
4444 /// This can lead to confusing error messages at best and to unexpected behavior at worst.
4545 ///
46- /// Note that this will not warn about wildcard imports from modules named `prelude`; many
47- /// crates (including the standard library) provide modules named "prelude" specifically
48- /// designed for wildcard import.
46+ /// **Exceptions:**
47+ ///
48+ /// Wildcard imports are allowed from modules named `prelude`. Many crates (including the standard library)
49+ /// provide modules named "prelude" specifically designed for wildcard import.
50+ ///
51+ /// `use super::*` is allowed in test modules. This is defined as any module with "test" in the name.
52+ ///
53+ /// These exceptions can be disabled using the `warn-on-all-wildcard-imports` configuration flag.
4954 ///
5055 /// **Known problems:** If macros are imported through the wildcard, this macro is not included
5156 /// by the suggestion and has to be added by hand.
@@ -198,5 +203,5 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
198203}
199204
200205fn is_test_module_or_function ( item : & Item < ' _ > ) -> bool {
201- matches ! ( item. kind, ItemKind :: Fn ( .. ) | ItemKind :: Mod ( ..) ) && item. ident . name . as_str ( ) . contains ( "test" )
206+ matches ! ( item. kind, ItemKind :: Mod ( ..) ) && item. ident . name . as_str ( ) . contains ( "test" )
202207}
Original file line number Diff line number Diff line change @@ -175,13 +175,34 @@ mod super_imports {
175175 }
176176 }
177177
178- mod inner {
179- fn test_should_pass () {
178+ mod test_should_pass_inside_function {
179+ fn with_super_inside_function () {
180180 use super::*;
181181 let _ = foofoo();
182182 }
183183 }
184184
185+ mod test_should_pass_further_inside {
186+ fn insidefoo() {}
187+ mod inner {
188+ use super::*;
189+ fn with_super() {
190+ let _ = insidefoo();
191+ }
192+ }
193+ }
194+
195+ mod should_be_replaced_futher_inside {
196+ fn insidefoo() {}
197+ mod inner {
198+ use super::insidefoo;
199+ fn with_super() {
200+ let _ = insidefoo();
201+ }
202+ }
203+ }
204+
205+
185206 mod use_explicit_should_be_replaced {
186207 use super_imports::foofoo;
187208
Original file line number Diff line number Diff line change @@ -176,13 +176,33 @@ mod super_imports {
176176 }
177177 }
178178
179- mod inner {
180- fn test_should_pass ( ) {
179+ mod test_should_pass_inside_function {
180+ fn with_super_inside_function ( ) {
181181 use super :: * ;
182182 let _ = foofoo ( ) ;
183183 }
184184 }
185185
186+ mod test_should_pass_further_inside {
187+ fn insidefoo ( ) { }
188+ mod inner {
189+ use super :: * ;
190+ fn with_super ( ) {
191+ let _ = insidefoo ( ) ;
192+ }
193+ }
194+ }
195+
196+ mod should_be_replaced_futher_inside {
197+ fn insidefoo ( ) { }
198+ mod inner {
199+ use super :: * ;
200+ fn with_super ( ) {
201+ let _ = insidefoo ( ) ;
202+ }
203+ }
204+ }
205+
186206 mod use_explicit_should_be_replaced {
187207 use super_imports:: * ;
188208
Original file line number Diff line number Diff line change @@ -99,22 +99,28 @@ LL | use super::*;
9999 | ^^^^^^^^ help: try: `super::foofoo`
100100
101101error: usage of wildcard import
102- --> $DIR/wildcard_imports.rs:187:13
102+ --> $DIR/wildcard_imports.rs:199:17
103+ |
104+ LL | use super::*;
105+ | ^^^^^^^^ help: try: `super::insidefoo`
106+
107+ error: usage of wildcard import
108+ --> $DIR/wildcard_imports.rs:208:13
103109 |
104110LL | use super_imports::*;
105111 | ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
106112
107113error: usage of wildcard import
108- --> $DIR/wildcard_imports.rs:196 :17
114+ --> $DIR/wildcard_imports.rs:217 :17
109115 |
110116LL | use super::super::*;
111117 | ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
112118
113119error: usage of wildcard import
114- --> $DIR/wildcard_imports.rs:205 :13
120+ --> $DIR/wildcard_imports.rs:226 :13
115121 |
116122LL | use super::super::super_imports::*;
117123 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
118124
119- error: aborting due to 19 previous errors
125+ error: aborting due to 20 previous errors
120126
You can’t perform that action at this time.
0 commit comments