diff options
| author | Christian Stefanescu <chris@0chris.com> | 2020-08-20 22:49:39 +0200 |
|---|---|---|
| committer | Christian Stefanescu <chris@0chris.com> | 2020-08-22 14:22:02 +0200 |
| commit | 5b07b9ed61d1979320e9e63219b5d0d6f4b350f7 (patch) | |
| tree | abf71b5c226553c678b1b38ddc24994f649b1067 | |
| parent | a8520b06365013cb5777f21cfc2672ab6f2cc21d (diff) | |
| download | rust-5b07b9ed61d1979320e9e63219b5d0d6f4b350f7.tar.gz rust-5b07b9ed61d1979320e9e63219b5d0d6f4b350f7.zip | |
Widen understanding of prelude import
Prelude imports are exempt from wildcard import warnings. Until now only imports of the form ``` use ...::prelude::*; ``` were considered. This change makes it so that the segment `prelude` can show up anywhere, for instance: ``` use ...::prelude::v1::*; ``` Fixes #5917
| -rw-r--r-- | clippy_lints/src/wildcard_imports.rs | 7 | ||||
| -rw-r--r-- | tests/ui/auxiliary/wildcard_imports_helper.rs | 6 | ||||
| -rw-r--r-- | tests/ui/wildcard_imports.rs | 2 |
3 files changed, 10 insertions, 5 deletions
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index e7eb7c2e980..717741129a8 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -195,13 +195,10 @@ impl WildcardImports { } } -// Allow "...prelude::*" imports. +// Allow "...prelude::..::*" imports. // Many crates have a prelude, and it is imported as a glob by design. fn is_prelude_import(segments: &[PathSegment<'_>]) -> bool { - segments - .iter() - .last() - .map_or(false, |ps| ps.ident.as_str() == "prelude") + segments.iter().filter(|ps| ps.ident.as_str() == "prelude").count() > 0 } // Allow "super::*" imports in tests. diff --git a/tests/ui/auxiliary/wildcard_imports_helper.rs b/tests/ui/auxiliary/wildcard_imports_helper.rs index 414477aedd7..d75cdd625f9 100644 --- a/tests/ui/auxiliary/wildcard_imports_helper.rs +++ b/tests/ui/auxiliary/wildcard_imports_helper.rs @@ -19,3 +19,9 @@ mod extern_exports { A, } } + +pub mod prelude { + pub mod v1 { + pub struct PreludeModAnywhere; + } +} diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 3ad1a29aeba..1f261159f4a 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -20,6 +20,7 @@ use wildcard_imports_helper::inner::inner_for_self_import::*; use wildcard_imports_helper::*; use std::io::prelude::*; +use wildcard_imports_helper::prelude::v1::*; struct ReadFoo; @@ -75,6 +76,7 @@ fn main() { let _ = A; let _ = inner_struct_mod::C; let _ = ExternA; + let _ = PreludeModAnywhere; double_struct_import_test!(); double_struct_import_test!(); |
