Check is_macro inside check_exceptions, update references to fix test

This commit is contained in:
Glenn Hope 2020-05-09 10:14:29 -07:00
parent a339766136
commit 0ba61c612e
2 changed files with 10 additions and 9 deletions

View file

@ -101,12 +101,11 @@ impl LateLintPass<'_, '_> for WildcardImports {
return;
}
if is_test_module_or_function(item) {
self.test_modules_deep += 1;
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}
if_chain! {
if self.warn_on_all || !in_macro(item.span);
if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind;
if self.warn_on_all || !self.check_exceptions(use_path.segments);
if self.warn_on_all || !self.check_exceptions(item, use_path.segments);
let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner);
if !used_imports.is_empty(); // Already handled by `unused_imports`
then {
@ -177,14 +176,16 @@ impl LateLintPass<'_, '_> for WildcardImports {
fn check_item_post(&mut self, _: &LateContext<'_, '_>, item: &Item<'_>) {
if is_test_module_or_function(item) {
self.test_modules_deep -= 1;
self.test_modules_deep = self.test_modules_deep.saturating_sub(1);
}
}
}
impl WildcardImports {
fn check_exceptions(&self, segments: &[PathSegment<'_>]) -> bool {
is_prelude_import(segments) || (is_super_only_import(segments) && self.test_modules_deep > 0)
fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
in_macro(item.span)
|| is_prelude_import(segments)
|| (is_super_only_import(segments) && self.test_modules_deep > 0)
}
}

View file

@ -105,19 +105,19 @@ LL | use super::*;
| ^^^^^^^^ help: try: `super::insidefoo`
error: usage of wildcard import
--> $DIR/wildcard_imports.rs:208:13
--> $DIR/wildcard_imports.rs:207:13
|
LL | use super_imports::*;
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
error: usage of wildcard import
--> $DIR/wildcard_imports.rs:217:17
--> $DIR/wildcard_imports.rs:216:17
|
LL | use super::super::*;
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
error: usage of wildcard import
--> $DIR/wildcard_imports.rs:226:13
--> $DIR/wildcard_imports.rs:225:13
|
LL | use super::super::super_imports::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`