Skip to content

Commit 0ba61c6

Browse files
committed
Check is_macro inside check_exceptions, update references to fix test
1 parent a339766 commit 0ba61c6

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

clippy_lints/src/wildcard_imports.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,11 @@ impl LateLintPass<'_, '_> for WildcardImports {
101101
return;
102102
}
103103
if is_test_module_or_function(item) {
104-
self.test_modules_deep += 1;
104+
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
105105
}
106106
if_chain! {
107-
if self.warn_on_all || !in_macro(item.span);
108107
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
109-
if self.warn_on_all || !self.check_exceptions(use_path.segments);
108+
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
110109
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner);
111110
if !used_imports.is_empty(); // Already handled by `unused_imports`
112111
then {
@@ -177,14 +176,16 @@ impl LateLintPass<'_, '_> for WildcardImports {
177176

178177
fn check_item_post(&mut self, _: &LateContext<'_, '_>, item: &Item<'_>) {
179178
if is_test_module_or_function(item) {
180-
self.test_modules_deep -= 1;
179+
self.test_modules_deep = self.test_modules_deep.saturating_sub(1);
181180
}
182181
}
183182
}
184183

185184
impl WildcardImports {
186-
fn check_exceptions(&self, segments: &[PathSegment<'_>]) -> bool {
187-
is_prelude_import(segments) || (is_super_only_import(segments) && self.test_modules_deep > 0)
185+
fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
186+
in_macro(item.span)
187+
|| is_prelude_import(segments)
188+
|| (is_super_only_import(segments) && self.test_modules_deep > 0)
188189
}
189190
}
190191

tests/ui/wildcard_imports.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,19 @@ LL | use super::*;
105105
| ^^^^^^^^ help: try: `super::insidefoo`
106106

107107
error: usage of wildcard import
108-
--> $DIR/wildcard_imports.rs:208:13
108+
--> $DIR/wildcard_imports.rs:207:13
109109
|
110110
LL | use super_imports::*;
111111
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
112112

113113
error: usage of wildcard import
114-
--> $DIR/wildcard_imports.rs:217:17
114+
--> $DIR/wildcard_imports.rs:216:17
115115
|
116116
LL | use super::super::*;
117117
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
118118

119119
error: usage of wildcard import
120-
--> $DIR/wildcard_imports.rs:226:13
120+
--> $DIR/wildcard_imports.rs:225:13
121121
|
122122
LL | use super::super::super_imports::*;
123123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`

0 commit comments

Comments
 (0)