]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/wildcard_imports.rs
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / clippy_lints / src / wildcard_imports.rs
index 32d9a45c37d78fea94190d3273cbf3844cab6b73..10005a7fc81ed1381abdada242234bcbbcb802de 100644 (file)
@@ -7,7 +7,8 @@
 };
 use rustc_lint::{LateContext, LateLintPass};
 use rustc_session::{declare_tool_lint, impl_lint_pass};
-use rustc_span::BytePos;
+use rustc_span::symbol::kw;
+use rustc_span::{sym, BytePos};
 
 declare_clippy_lint! {
     /// **What it does:** Checks for `use Enum::*`.
     /// still around.
     ///
     /// **Example:**
-    /// ```rust
+    /// ```rust,ignore
+    /// // Bad
     /// use std::cmp::Ordering::*;
+    /// foo(Less);
+    ///
+    /// // Good
+    /// use std::cmp::Ordering;
+    /// foo(Ordering::Less)
     /// ```
     pub ENUM_GLOB_USE,
     pedantic,
@@ -30,7 +37,7 @@
 declare_clippy_lint! {
     /// **What it does:** Checks for wildcard imports `use _::*`.
     ///
-    /// **Why is this bad?** wildcard imports can polute the namespace. This is especially bad if
+    /// **Why is this bad?** wildcard imports can pollute the namespace. This is especially bad if
     /// you try to import something through a wildcard, that already has been imported by name from
     /// a different source:
     ///
     ///
     /// **Example:**
     ///
-    /// Bad:
     /// ```rust,ignore
+    /// // Bad
     /// use crate1::*;
     ///
     /// foo();
     /// ```
     ///
-    /// Good:
     /// ```rust,ignore
+    /// // Good
     /// use crate1::foo;
     ///
     /// foo();
@@ -95,8 +102,8 @@ pub fn new(warn_on_all: bool) -> Self {
 
 impl_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]);
 
-impl LateLintPass<'_, '_> for WildcardImports {
-    fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
+impl LateLintPass<'_> for WildcardImports {
+    fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
         if is_test_module_or_function(item) {
             self.test_modules_deep = self.test_modules_deep.saturating_add(1);
         }
@@ -174,7 +181,7 @@ fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) {
         }
     }
 
-    fn check_item_post(&mut self, _: &LateContext<'_, '_>, item: &Item<'_>) {
+    fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
         if is_test_module_or_function(item) {
             self.test_modules_deep = self.test_modules_deep.saturating_sub(1);
         }
@@ -189,18 +196,15 @@ fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> boo
     }
 }
 
-// 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.name == sym::prelude)
 }
 
 // Allow "super::*" imports in tests.
 fn is_super_only_import(segments: &[PathSegment<'_>]) -> bool {
-    segments.len() == 1 && segments[0].ident.as_str() == "super"
+    segments.len() == 1 && segments[0].ident.name == kw::Super
 }
 
 fn is_test_module_or_function(item: &Item<'_>) -> bool {