Skip to content

Commit 4f48283

Browse files
stchrisHenri Lunnikivi
authored andcommitted
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
1 parent 8cb0135 commit 4f48283

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

clippy_lints/src/wildcard_imports.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,10 @@ impl WildcardImports {
195195
}
196196
}
197197

198-
// Allow "...prelude::*" imports.
198+
// Allow "...prelude::..::*" imports.
199199
// Many crates have a prelude, and it is imported as a glob by design.
200200
fn is_prelude_import(segments: &[PathSegment<'_>]) -> bool {
201-
segments
202-
.iter()
203-
.last()
204-
.map_or(false, |ps| ps.ident.as_str() == "prelude")
201+
segments.iter().filter(|ps| ps.ident.as_str() == "prelude").count() > 0
205202
}
206203

207204
// Allow "super::*" imports in tests.

tests/ui/auxiliary/wildcard_imports_helper.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ mod extern_exports {
1919
A,
2020
}
2121
}
22+
23+
pub mod prelude {
24+
pub mod v1 {
25+
pub struct PreludeModAnywhere;
26+
}
27+
}

tests/ui/wildcard_imports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use wildcard_imports_helper::inner::inner_for_self_import::*;
2020
use wildcard_imports_helper::*;
2121

2222
use std::io::prelude::*;
23+
use wildcard_imports_helper::prelude::v1::*;
2324

2425
struct ReadFoo;
2526

@@ -75,6 +76,7 @@ fn main() {
7576
let _ = A;
7677
let _ = inner_struct_mod::C;
7778
let _ = ExternA;
79+
let _ = PreludeModAnywhere;
7880

7981
double_struct_import_test!();
8082
double_struct_import_test!();

0 commit comments

Comments
 (0)