about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-08-22 12:50:22 +0000
committerbors <bors@rust-lang.org>2020-08-22 12:50:22 +0000
commitf21d10b970c2ff7216dc1ae2e9b7c0e8610eed2a (patch)
treef34783d02fddd0d77cc53fcd1592dce18d664745
parenta8520b06365013cb5777f21cfc2672ab6f2cc21d (diff)
parente615a26ae4fe293cda83961470907e78e4b2ee75 (diff)
downloadrust-f21d10b970c2ff7216dc1ae2e9b7c0e8610eed2a.tar.gz
rust-f21d10b970c2ff7216dc1ae2e9b7c0e8610eed2a.zip
Auto merge of #5929 - stchris:issues/5917, r=ebroto
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

changelog: Allow `prelude` to appear in any segment of the import path in [`wildcard_imports`]
-rw-r--r--clippy_lints/src/wildcard_imports.rs7
-rw-r--r--tests/ui/auxiliary/wildcard_imports_helper.rs6
-rw-r--r--tests/ui/wildcard_imports.fixed2
-rw-r--r--tests/ui/wildcard_imports.rs2
-rw-r--r--tests/ui/wildcard_imports.stderr28
5 files changed, 26 insertions, 19 deletions
diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs
index e7eb7c2e980..5683a71efea 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().any(|ps| ps.ident.as_str() == "prelude")
 }
 
 // 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.fixed b/tests/ui/wildcard_imports.fixed
index 67423e6ec1d..287f8935327 100644
--- a/tests/ui/wildcard_imports.fixed
+++ b/tests/ui/wildcard_imports.fixed
@@ -20,6 +20,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::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!();
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!();
diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr
index fab43b738eb..351988f31ea 100644
--- a/tests/ui/wildcard_imports.stderr
+++ b/tests/ui/wildcard_imports.stderr
@@ -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:89:13
+  --> $DIR/wildcard_imports.rs:91:13
    |
 LL |         use crate::fn_mod::*;
    |             ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:95:75
+  --> $DIR/wildcard_imports.rs:97: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:96:13
+  --> $DIR/wildcard_imports.rs:98:13
    |
 LL |         use wildcard_imports_helper::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:107:20
+  --> $DIR/wildcard_imports.rs:109:20
    |
 LL |         use self::{inner::*, inner2::*};
    |                    ^^^^^^^^ help: try: `inner::inner_foo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:107:30
+  --> $DIR/wildcard_imports.rs:109:30
    |
 LL |         use self::{inner::*, inner2::*};
    |                              ^^^^^^^^^ help: try: `inner2::inner_bar`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:114:13
+  --> $DIR/wildcard_imports.rs:116:13
    |
 LL |         use wildcard_imports_helper::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:143:9
+  --> $DIR/wildcard_imports.rs:145: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:152:9
+  --> $DIR/wildcard_imports.rs:154:9
    |
 LL |     use crate:: in_fn_test::  * ;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:153:9
+  --> $DIR/wildcard_imports.rs:155:9
    |
 LL |       use crate:: fn_mod::
    |  _________^
@@ -93,31 +93,31 @@ LL | |         *;
    | |_________^ help: try: `crate:: fn_mod::foo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:164:13
+  --> $DIR/wildcard_imports.rs:166:13
    |
 LL |         use super::*;
    |             ^^^^^^^^ help: try: `super::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:199:17
+  --> $DIR/wildcard_imports.rs:201:17
    |
 LL |             use super::*;
    |                 ^^^^^^^^ help: try: `super::insidefoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:207:13
+  --> $DIR/wildcard_imports.rs:209:13
    |
 LL |         use super_imports::*;
    |             ^^^^^^^^^^^^^^^^ help: try: `super_imports::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:216:17
+  --> $DIR/wildcard_imports.rs:218:17
    |
 LL |             use super::super::*;
    |                 ^^^^^^^^^^^^^^^ help: try: `super::super::foofoo`
 
 error: usage of wildcard import
-  --> $DIR/wildcard_imports.rs:225:13
+  --> $DIR/wildcard_imports.rs:227:13
    |
 LL |         use super::super::super_imports::*;
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `super::super::super_imports::foofoo`