use clippy_utils::diagnostics::span_lint_and_sugg;
+use clippy_utils::is_test_module_or_function;
use clippy_utils::source::{snippet, snippet_with_applicability};
-use clippy_utils::{in_macro, is_test_module_or_function};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{
Item, ItemKind, PathSegment, UseKind,
};
use rustc_lint::{LateContext, LateLintPass};
+use rustc_middle::ty;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::kw;
use rustc_span::{sym, BytePos};
/// still around.
///
/// ### Example
- /// ```rust,ignore
- /// // Bad
+ /// ```rust
/// use std::cmp::Ordering::*;
+ ///
+ /// # fn foo(_: std::cmp::Ordering) {}
/// foo(Less);
+ /// ```
///
- /// // Good
+ /// Use instead:
+ /// ```rust
/// use std::cmp::Ordering;
+ ///
+ /// # fn foo(_: Ordering) {}
/// foo(Ordering::Less)
/// ```
+ #[clippy::version = "pre 1.29.0"]
pub ENUM_GLOB_USE,
pedantic,
"use items that import all variants of an enum"
///
/// ### Example
/// ```rust,ignore
- /// // Bad
/// use crate1::*;
///
/// foo();
/// ```
///
+ /// Use instead:
/// ```rust,ignore
- /// // Good
/// use crate1::foo;
///
/// foo();
/// ```
+ #[clippy::version = "1.43.0"]
pub WILDCARD_IMPORTS,
pedantic,
"lint `use _::*` statements"
if is_test_module_or_function(cx.tcx, item) {
self.test_modules_deep = self.test_modules_deep.saturating_add(1);
}
- if item.vis.node.is_pub() || item.vis.node.is_pub_restricted() {
+ let module = cx.tcx.parent_module_from_def_id(item.def_id);
+ if cx.tcx.visibility(item.def_id) != ty::Visibility::Restricted(module.to_def_id()) {
return;
}
if_chain! {
impl WildcardImports {
fn check_exceptions(&self, item: &Item<'_>, segments: &[PathSegment<'_>]) -> bool {
- in_macro(item.span)
+ item.span.from_expansion()
|| is_prelude_import(segments)
|| (is_super_only_import(segments) && self.test_modules_deep > 0)
}