File tree 4 files changed +64
-12
lines changed
4 files changed +64
-12
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,14 @@ declare_clippy_lint! {
43
43
///
44
44
/// This can lead to confusing error messages at best and to unexpected behavior at worst.
45
45
///
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.
49
54
///
50
55
/// **Known problems:** If macros are imported through the wildcard, this macro is not included
51
56
/// by the suggestion and has to be added by hand.
@@ -198,5 +203,5 @@ fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
198
203
}
199
204
200
205
fn 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" )
202
207
}
Original file line number Diff line number Diff line change @@ -175,13 +175,34 @@ mod super_imports {
175
175
}
176
176
}
177
177
178
- mod inner {
179
- fn test_should_pass () {
178
+ mod test_should_pass_inside_function {
179
+ fn with_super_inside_function () {
180
180
use super::*;
181
181
let _ = foofoo();
182
182
}
183
183
}
184
184
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
+
185
206
mod use_explicit_should_be_replaced {
186
207
use super_imports::foofoo;
187
208
Original file line number Diff line number Diff line change @@ -176,13 +176,33 @@ mod super_imports {
176
176
}
177
177
}
178
178
179
- mod inner {
180
- fn test_should_pass ( ) {
179
+ mod test_should_pass_inside_function {
180
+ fn with_super_inside_function ( ) {
181
181
use super :: * ;
182
182
let _ = foofoo ( ) ;
183
183
}
184
184
}
185
185
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
+
186
206
mod use_explicit_should_be_replaced {
187
207
use super_imports:: * ;
188
208
Original file line number Diff line number Diff line change @@ -99,22 +99,28 @@ LL | use super::*;
99
99
| ^^^^^^^^ help: try: `super::foofoo`
100
100
101
101
error: 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
103
109
|
104
110
LL | use super_imports::*;
105
111
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
106
112
107
113
error: usage of wildcard import
108
- --> $DIR/wildcard_imports.rs:196 :17
114
+ --> $DIR/wildcard_imports.rs:217 :17
109
115
|
110
116
LL | use super::super::*;
111
117
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
112
118
113
119
error: usage of wildcard import
114
- --> $DIR/wildcard_imports.rs:205 :13
120
+ --> $DIR/wildcard_imports.rs:226 :13
115
121
|
116
122
LL | use super::super::super_imports::*;
117
123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
118
124
119
- error: aborting due to 19 previous errors
125
+ error: aborting due to 20 previous errors
120
126
You can’t perform that action at this time.
0 commit comments