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
This commit is contained in:
Christian Stefanescu 2020-08-20 22:49:39 +02:00
parent a8520b0636
commit 5b07b9ed61
3 changed files with 10 additions and 5 deletions

View File

@ -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.

View File

@ -19,3 +19,9 @@ mod extern_exports {
A,
}
}
pub mod prelude {
pub mod v1 {
pub struct PreludeModAnywhere;
}
}

View File

@ -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!();