Auto merge of #10848 - charmitro:wildcard-prelude-detection, r=llogiq
[`wildcard_imports`] Modules that contain `prelude` are also allowed This commit fixes #10846 by checking if the path segment contains the word "prelude", allowing us `use module_prelude::*`. changelog: [`wildcard_imports`]: Modules that contain `prelude` are also allowed
This commit is contained in:
commit
8793c2a576
@ -65,8 +65,9 @@
|
||||
/// This can lead to confusing error messages at best and to unexpected behavior at worst.
|
||||
///
|
||||
/// ### Exceptions
|
||||
/// Wildcard imports are allowed from modules named `prelude`. Many crates (including the standard library)
|
||||
/// provide modules named "prelude" specifically designed for wildcard import.
|
||||
/// Wildcard imports are allowed from modules that their name contains `prelude`. Many crates
|
||||
/// (including the standard library) provide modules named "prelude" specifically designed
|
||||
/// for wildcard import.
|
||||
///
|
||||
/// `use super::*` is allowed in test modules. This is defined as any module with "test" in the name.
|
||||
///
|
||||
@ -212,7 +213,9 @@ fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> boo
|
||||
// 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().any(|ps| ps.ident.name == sym::prelude)
|
||||
segments
|
||||
.iter()
|
||||
.any(|ps| ps.ident.name.as_str().contains(sym::prelude.as_str()))
|
||||
}
|
||||
|
||||
// Allow "super::*" imports in tests.
|
||||
|
@ -25,3 +25,9 @@ pub mod v1 {
|
||||
pub struct PreludeModAnywhere;
|
||||
}
|
||||
}
|
||||
|
||||
pub mod extern_prelude {
|
||||
pub mod v1 {
|
||||
pub struct ExternPreludeModAnywhere;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar;
|
||||
use wildcard_imports_helper::{ExternA, extern_foo};
|
||||
|
||||
use std::io::prelude::*;
|
||||
use wildcard_imports_helper::extern_prelude::v1::*;
|
||||
use wildcard_imports_helper::prelude::v1::*;
|
||||
|
||||
struct ReadFoo;
|
||||
@ -81,6 +82,7 @@ fn main() {
|
||||
let _ = inner_struct_mod::C;
|
||||
let _ = ExternA;
|
||||
let _ = PreludeModAnywhere;
|
||||
let _ = ExternPreludeModAnywhere;
|
||||
|
||||
double_struct_import_test!();
|
||||
double_struct_import_test!();
|
||||
|
@ -24,6 +24,7 @@
|
||||
use wildcard_imports_helper::*;
|
||||
|
||||
use std::io::prelude::*;
|
||||
use wildcard_imports_helper::extern_prelude::v1::*;
|
||||
use wildcard_imports_helper::prelude::v1::*;
|
||||
|
||||
struct ReadFoo;
|
||||
@ -81,6 +82,7 @@ fn main() {
|
||||
let _ = inner_struct_mod::C;
|
||||
let _ = ExternA;
|
||||
let _ = PreludeModAnywhere;
|
||||
let _ = ExternPreludeModAnywhere;
|
||||
|
||||
double_struct_import_test!();
|
||||
double_struct_import_test!();
|
||||
|
@ -37,55 +37,55 @@ LL | use wildcard_imports_helper::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:95:13
|
||||
--> $DIR/wildcard_imports.rs:97:13
|
||||
|
|
||||
LL | use crate::fn_mod::*;
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:101:75
|
||||
--> $DIR/wildcard_imports.rs:103:75
|
||||
|
|
||||
LL | use wildcard_imports_helper::inner::inner_for_self_import::{self, *};
|
||||
| ^ help: try: `inner_extern_foo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:102:13
|
||||
--> $DIR/wildcard_imports.rs:104:13
|
||||
|
|
||||
LL | use wildcard_imports_helper::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:113:20
|
||||
--> $DIR/wildcard_imports.rs:115:20
|
||||
|
|
||||
LL | use self::{inner::*, inner2::*};
|
||||
| ^^^^^^^^ help: try: `inner::inner_foo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:113:30
|
||||
--> $DIR/wildcard_imports.rs:115:30
|
||||
|
|
||||
LL | use self::{inner::*, inner2::*};
|
||||
| ^^^^^^^^^ help: try: `inner2::inner_bar`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:120:13
|
||||
--> $DIR/wildcard_imports.rs:122:13
|
||||
|
|
||||
LL | use wildcard_imports_helper::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:149:9
|
||||
--> $DIR/wildcard_imports.rs:151:9
|
||||
|
|
||||
LL | use crate::in_fn_test::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:158:9
|
||||
--> $DIR/wildcard_imports.rs:160:9
|
||||
|
|
||||
LL | use crate:: in_fn_test:: * ;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:159:9
|
||||
--> $DIR/wildcard_imports.rs:161:9
|
||||
|
|
||||
LL | use crate:: fn_mod::
|
||||
| _________^
|
||||
@ -93,37 +93,37 @@ LL | | *;
|
||||
| |_________^ help: try: `crate:: fn_mod::foo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:170:13
|
||||
--> $DIR/wildcard_imports.rs:172:13
|
||||
|
|
||||
LL | use super::*;
|
||||
| ^^^^^^^^ help: try: `super::foofoo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:205:17
|
||||
--> $DIR/wildcard_imports.rs:207:17
|
||||
|
|
||||
LL | use super::*;
|
||||
| ^^^^^^^^ help: try: `super::insidefoo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:213:13
|
||||
--> $DIR/wildcard_imports.rs:215:13
|
||||
|
|
||||
LL | use super_imports::*;
|
||||
| ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:222:17
|
||||
--> $DIR/wildcard_imports.rs:224:17
|
||||
|
|
||||
LL | use super::super::*;
|
||||
| ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:231:13
|
||||
--> $DIR/wildcard_imports.rs:233:13
|
||||
|
|
||||
LL | use super::super::super_imports::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`
|
||||
|
||||
error: usage of wildcard import
|
||||
--> $DIR/wildcard_imports.rs:239:13
|
||||
--> $DIR/wildcard_imports.rs:241:13
|
||||
|
|
||||
LL | use super::*;
|
||||
| ^^^^^^^^ help: try: `super::foofoo`
|
||||
|
Loading…
Reference in New Issue
Block a user