From 8a572a540af53bee712bc50a9d882a1c1376174c Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 7 Jan 2020 17:53:33 +0100 Subject: [PATCH 01/10] Add tests for wildcard_imports lint --- tests/ui/auxiliary/wildcard_imports_helper.rs | 21 +++ tests/ui/wildcard_imports.fixed | 137 ++++++++++++++++++ tests/ui/wildcard_imports.rs | 137 ++++++++++++++++++ tests/ui/wildcard_imports.stderr | 82 +++++++++++ 4 files changed, 377 insertions(+) create mode 100644 tests/ui/auxiliary/wildcard_imports_helper.rs create mode 100644 tests/ui/wildcard_imports.fixed create mode 100644 tests/ui/wildcard_imports.rs create mode 100644 tests/ui/wildcard_imports.stderr diff --git a/tests/ui/auxiliary/wildcard_imports_helper.rs b/tests/ui/auxiliary/wildcard_imports_helper.rs new file mode 100644 index 000000000000..414477aedd78 --- /dev/null +++ b/tests/ui/auxiliary/wildcard_imports_helper.rs @@ -0,0 +1,21 @@ +pub use crate::extern_exports::*; + +pub fn extern_foo() {} +pub fn extern_bar() {} + +pub struct ExternA; + +pub mod inner { + pub mod inner_for_self_import { + pub fn inner_extern_foo() {} + pub fn inner_extern_bar() {} + } +} + +mod extern_exports { + pub fn extern_exported() {} + pub struct ExternExportedStruct; + pub enum ExternExportedEnum { + A, + } +} diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed new file mode 100644 index 000000000000..97c8c6068e55 --- /dev/null +++ b/tests/ui/wildcard_imports.fixed @@ -0,0 +1,137 @@ +// run-rustfix +// aux-build:wildcard_imports_helper.rs + +#![warn(clippy::wildcard_imports)] +#![allow(unused)] +#![warn(unused_imports)] + +extern crate wildcard_imports_helper; + +use crate::fn_mod::foo; +use crate::mod_mod::inner_mod; +use crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}; +#[macro_use] +use crate::struct_mod::{A, inner_struct_mod}; + +#[allow(unused_imports)] +use wildcard_imports_helper::inner::inner_for_self_import; +use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; +use wildcard_imports_helper::{ExternA, extern_foo}; + +mod fn_mod { + pub fn foo() {} +} + +mod mod_mod { + pub mod inner_mod { + pub fn foo() {} + } +} + +mod multi_fn_mod { + pub fn multi_foo() {} + pub fn multi_bar() {} + pub fn multi_baz() {} + pub mod multi_inner_mod { + pub fn foo() {} + } +} + +mod struct_mod { + pub struct A; + pub struct B; + pub mod inner_struct_mod { + pub struct C; + } + + #[macro_export] + macro_rules! double_struct_import_test { + () => { + let _ = A; + }; + } +} + +fn main() { + foo(); + multi_foo(); + multi_bar(); + multi_inner_mod::foo(); + inner_mod::foo(); + extern_foo(); + inner_extern_bar(); + + let _ = A; + let _ = inner_struct_mod::C; + let _ = ExternA; + + double_struct_import_test!(); + double_struct_import_test!(); +} + +mod in_fn_test { + pub use self::inner_exported::*; + #[allow(unused_imports)] + pub(crate) use self::inner_exported2::*; + + fn test_intern() { + use crate::fn_mod::foo; + + foo(); + } + + fn test_extern() { + use wildcard_imports_helper::inner::inner_for_self_import::{self, inner_extern_foo}; + use wildcard_imports_helper::{ExternA, extern_foo}; + + inner_for_self_import::inner_extern_foo(); + inner_extern_foo(); + + extern_foo(); + + let _ = ExternA; + } + + fn test_inner_nested() { + use self::{inner::inner_foo, inner2::inner_bar}; + + inner_foo(); + inner_bar(); + } + + fn test_extern_reexported() { + use wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}; + + extern_exported(); + let _ = ExternExportedStruct; + let _ = ExternExportedEnum::A; + } + + mod inner_exported { + pub fn exported() {} + pub struct ExportedStruct; + pub enum ExportedEnum { + A, + } + } + + mod inner_exported2 { + pub(crate) fn exported2() {} + } + + mod inner { + pub fn inner_foo() {} + } + + mod inner2 { + pub fn inner_bar() {} + } +} + +fn test_reexported() { + use crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}; + + exported(); + let _ = ExportedStruct; + let _ = ExportedEnum::A; +} diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs new file mode 100644 index 000000000000..045356672e3a --- /dev/null +++ b/tests/ui/wildcard_imports.rs @@ -0,0 +1,137 @@ +// run-rustfix +// aux-build:wildcard_imports_helper.rs + +#![warn(clippy::wildcard_imports)] +#![allow(unused)] +#![warn(unused_imports)] + +extern crate wildcard_imports_helper; + +use crate::fn_mod::*; +use crate::mod_mod::*; +use crate::multi_fn_mod::*; +#[macro_use] +use crate::struct_mod::*; + +#[allow(unused_imports)] +use wildcard_imports_helper::inner::inner_for_self_import; +use wildcard_imports_helper::inner::inner_for_self_import::*; +use wildcard_imports_helper::*; + +mod fn_mod { + pub fn foo() {} +} + +mod mod_mod { + pub mod inner_mod { + pub fn foo() {} + } +} + +mod multi_fn_mod { + pub fn multi_foo() {} + pub fn multi_bar() {} + pub fn multi_baz() {} + pub mod multi_inner_mod { + pub fn foo() {} + } +} + +mod struct_mod { + pub struct A; + pub struct B; + pub mod inner_struct_mod { + pub struct C; + } + + #[macro_export] + macro_rules! double_struct_import_test { + () => { + let _ = A; + }; + } +} + +fn main() { + foo(); + multi_foo(); + multi_bar(); + multi_inner_mod::foo(); + inner_mod::foo(); + extern_foo(); + inner_extern_bar(); + + let _ = A; + let _ = inner_struct_mod::C; + let _ = ExternA; + + double_struct_import_test!(); + double_struct_import_test!(); +} + +mod in_fn_test { + pub use self::inner_exported::*; + #[allow(unused_imports)] + pub(crate) use self::inner_exported2::*; + + fn test_intern() { + use crate::fn_mod::*; + + foo(); + } + + fn test_extern() { + use wildcard_imports_helper::inner::inner_for_self_import::{self, *}; + use wildcard_imports_helper::*; + + inner_for_self_import::inner_extern_foo(); + inner_extern_foo(); + + extern_foo(); + + let _ = ExternA; + } + + fn test_inner_nested() { + use self::{inner::*, inner2::*}; + + inner_foo(); + inner_bar(); + } + + fn test_extern_reexported() { + use wildcard_imports_helper::*; + + extern_exported(); + let _ = ExternExportedStruct; + let _ = ExternExportedEnum::A; + } + + mod inner_exported { + pub fn exported() {} + pub struct ExportedStruct; + pub enum ExportedEnum { + A, + } + } + + mod inner_exported2 { + pub(crate) fn exported2() {} + } + + mod inner { + pub fn inner_foo() {} + } + + mod inner2 { + pub fn inner_bar() {} + } +} + +fn test_reexported() { + use crate::in_fn_test::*; + + exported(); + let _ = ExportedStruct; + let _ = ExportedEnum::A; +} diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr new file mode 100644 index 000000000000..111481e52d03 --- /dev/null +++ b/tests/ui/wildcard_imports.stderr @@ -0,0 +1,82 @@ +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:10:5 + | +LL | use crate::fn_mod::*; + | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` + | + = note: `-D clippy::wildcard-imports` implied by `-D warnings` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:11:5 + | +LL | use crate::mod_mod::*; + | ^^^^^^^^^^^^^^^^^ help: try: `crate::mod_mod::inner_mod` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:12:5 + | +LL | use crate::multi_fn_mod::*; + | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate::multi_fn_mod::{multi_bar, multi_foo, multi_inner_mod}` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:14:5 + | +LL | use crate::struct_mod::*; + | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::struct_mod::{A, inner_struct_mod}` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:18:5 + | +LL | use wildcard_imports_helper::inner::inner_for_self_import::*; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:19:5 + | +LL | use wildcard_imports_helper::*; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:78:13 + | +LL | use crate::fn_mod::*; + | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:84: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:85:13 + | +LL | use wildcard_imports_helper::*; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:96:20 + | +LL | use self::{inner::*, inner2::*}; + | ^^^^^^^^ help: try: `inner::inner_foo` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:96:30 + | +LL | use self::{inner::*, inner2::*}; + | ^^^^^^^^^ help: try: `inner2::inner_bar` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:103:13 + | +LL | use wildcard_imports_helper::*; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:132:9 + | +LL | use crate::in_fn_test::*; + | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` + +error: aborting due to 13 previous errors + From ba1d50cec1d6dbfbd866381f0b793cbd9c617b1b Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 7 Jan 2020 17:53:56 +0100 Subject: [PATCH 02/10] Implement wildcard_imports lint --- clippy_lints/src/wildcard_imports.rs | 271 +++++++++++++++++++++++++++ 1 file changed, 271 insertions(+) create mode 100644 clippy_lints/src/wildcard_imports.rs diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs new file mode 100644 index 000000000000..70098f31aef7 --- /dev/null +++ b/clippy_lints/src/wildcard_imports.rs @@ -0,0 +1,271 @@ +use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; +use if_chain::if_chain; +use rustc::ty::DefIdTree; +use rustc_data_structures::fx::FxHashSet; +use rustc_errors::Applicability; +use rustc_hir::def_id::DefId; +use rustc_hir::intravisit::{walk_item, NestedVisitorMap, Visitor}; +use rustc_hir::*; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_session::{declare_lint_pass, declare_tool_lint}; +use rustc_span::{symbol::Symbol, BytePos}; + +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 + /// you try to import something through a wildcard, that already has been imported by name from + /// a different source: + /// + /// ```rust,ignore + /// use crate1::foo; // Imports a function named foo + /// use crate2::*; // Has a function named foo + /// + /// foo(); // Calls crate1::foo + /// ``` + /// + /// This can lead to confusing error messages at best and to unexpected behavior at worst. + /// + /// **Known problems:** If macros are imported through the wildcard, this macro is not included + /// by the suggestion and has to be added by hand. + /// + /// **Example:** + /// + /// Bad: + /// ```rust,ignore + /// use crate1::*; + /// + /// foo(); + /// ``` + /// + /// Good: + /// ```rust,ignore + /// use crate1::foo; + /// + /// foo(); + /// ``` + pub WILDCARD_IMPORTS, + pedantic, + "lint `use _::*` statements" +} + +declare_lint_pass!(WildcardImports => [WILDCARD_IMPORTS]); + +impl LateLintPass<'_, '_> for WildcardImports { + fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) { + if item.vis.node.is_pub() || item.vis.node.is_pub_restricted() { + return; + } + if_chain! { + if !in_macro(item.span); + if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; + if let Some(def_id) = use_path.res.opt_def_id(); + then { + let hir = cx.tcx.hir(); + let parent_id = hir.get_parent_item(item.hir_id); + let (items, in_module) = if parent_id == CRATE_HIR_ID { + let items = hir + .krate() + .module + .item_ids + .iter() + .map(|item_id| hir.get(item_id.id)) + .filter_map(|node| { + if let Node::Item(item) = node { + Some(item) + } else { + None + } + }) + .collect(); + (items, true) + } else if let Node::Item(item) = hir.get(parent_id) { + (vec![item], false) + } else { + (vec![], false) + }; + + let mut import_used_visitor = ImportsUsedVisitor { + cx, + wildcard_def_id: def_id, + in_module, + used_imports: FxHashSet::default(), + }; + for item in items { + import_used_visitor.visit_item(item); + } + + if !import_used_visitor.used_imports.is_empty() { + let module_name = use_path + .segments + .iter() + .last() + .expect("path has at least one segment") + .ident + .name; + + let mut applicability = Applicability::MachineApplicable; + let import_source = snippet_with_applicability(cx, use_path.span, "..", &mut applicability); + let (span, braced_glob) = if import_source.is_empty() { + // This is a `_::{_, *}` import + // Probably it's `_::{self, *}`, in that case we don't want to suggest to + // import `self`. + // If it is something else, we also don't want to include `self` in the + // suggestion, since either it was imported through another use statement: + // ``` + // use foo::bar; + // use foo::bar::{baz, *}; + // ``` + // or it couldn't be used anywhere. + ( + use_path.span.with_hi(use_path.span.hi() + BytePos(1)), + true, + ) + } else { + ( + use_path.span.with_hi(use_path.span.hi() + BytePos(3)), + false, + ) + }; + + let imports_string = if import_used_visitor.used_imports.len() == 1 { + // We don't need to check for accidental suggesting the module name instead + // of `self` here, since if `used_imports.len() == 1`, and the only usage + // is `self`, then it's not through a `*` and if there is a `*`, it gets + // already linted by `unused_imports` of rustc. + import_used_visitor.used_imports.iter().next().unwrap().to_string() + } else { + let mut imports = import_used_visitor + .used_imports + .iter() + .filter_map(|import_name| { + if braced_glob && *import_name == module_name { + None + } else if *import_name == module_name { + Some("self".to_string()) + } else { + Some(import_name.to_string()) + } + }) + .collect::>(); + imports.sort(); + if braced_glob { + imports.join(", ") + } else { + format!("{{{}}}", imports.join(", ")) + } + }; + + let sugg = if import_source.is_empty() { + imports_string + } else { + format!("{}::{}", import_source, imports_string) + }; + + span_lint_and_sugg( + cx, + WILDCARD_IMPORTS, + span, + "usage of wildcard import", + "try", + sugg, + applicability, + ); + } + } + } + } +} + +struct ImportsUsedVisitor<'a, 'tcx> { + cx: &'a LateContext<'a, 'tcx>, + wildcard_def_id: def_id::DefId, + in_module: bool, + used_imports: FxHashSet, +} + +impl<'a, 'tcx> Visitor<'tcx> for ImportsUsedVisitor<'a, 'tcx> { + type Map = Map<'tcx>; + + fn visit_item(&mut self, item: &'tcx Item<'_>) { + match item.kind { + ItemKind::Use(..) => {}, + ItemKind::Mod(..) if self.in_module => {}, + ItemKind::Mod(..) => self.in_module = true, + _ => walk_item(self, item), + } + } + + fn visit_path(&mut self, path: &Path<'_>, _: HirId) { + if let Some(def_id) = self.first_path_segment_def_id(path) { + // Check if the function/enum/... was exported + if let Some(exports) = self.cx.tcx.module_exports(self.wildcard_def_id) { + for export in exports { + if let Some(export_def_id) = export.res.opt_def_id() { + if export_def_id == def_id { + self.used_imports.insert( + path.segments + .iter() + .next() + .expect("path has at least one segment") + .ident + .name, + ); + return; + } + } + } + } + + // Check if it is directly in the module + if let Some(parent_def_id) = self.cx.tcx.parent(def_id) { + if self.wildcard_def_id == parent_def_id { + self.used_imports.insert( + path.segments + .iter() + .next() + .expect("path has at least one segment") + .ident + .name, + ); + } + } + } + } + + fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { + NestedVisitorMap::All(&self.cx.tcx.hir()) + } +} + +impl ImportsUsedVisitor<'_, '_> { + fn skip_def_id(&self, def_id: DefId) -> DefId { + let def_key = self.cx.tcx.def_key(def_id); + match def_key.disambiguated_data.data { + DefPathData::Ctor => { + if let Some(def_id) = self.cx.tcx.parent(def_id) { + self.skip_def_id(def_id) + } else { + def_id + } + }, + _ => def_id, + } + } + + fn first_path_segment_def_id(&self, path: &Path<'_>) -> Option { + path.res.opt_def_id().and_then(|mut def_id| { + def_id = self.skip_def_id(def_id); + for _ in path.segments.iter().skip(1) { + def_id = self.skip_def_id(def_id); + if let Some(parent_def_id) = self.cx.tcx.parent(def_id) { + def_id = parent_def_id; + } else { + return None; + } + } + + Some(def_id) + }) + } +} From 4229dbcf335fa7a11b5566d9e916384bf9739c34 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 7 Jan 2020 17:54:08 +0100 Subject: [PATCH 03/10] Run update_lints --- CHANGELOG.md | 1 + README.md | 2 +- clippy_lints/src/lib.rs | 4 ++++ src/lintlist/mod.rs | 9 ++++++++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05ebe97d7b01..4e99342e4a42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1419,6 +1419,7 @@ Released 2018-09-13 [`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator [`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies [`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm +[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports [`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns [`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal [`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline diff --git a/README.md b/README.md index f2ffea7d23cf..3103f9608398 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code. -[There are 356 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) +[There are 357 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html) We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you: diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 325f07eb6cf6..77d33e6a0db6 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -311,6 +311,7 @@ pub mod unwrap; pub mod use_self; pub mod vec; pub mod wildcard_dependencies; +pub mod wildcard_imports; pub mod write; pub mod zero_div_zero; // end lints modules, do not remove this comment, it’s used in `update_lints` @@ -813,6 +814,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &use_self::USE_SELF, &vec::USELESS_VEC, &wildcard_dependencies::WILDCARD_DEPENDENCIES, + &wildcard_imports::WILDCARD_IMPORTS, &write::PRINTLN_EMPTY_STRING, &write::PRINT_LITERAL, &write::PRINT_STDOUT, @@ -1009,6 +1011,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: let max_struct_bools = conf.max_struct_bools; store.register_early_pass(move || box excessive_bools::ExcessiveBools::new(max_struct_bools, max_fn_params_bools)); store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap); + store.register_late_pass(|| box wildcard_imports::WildcardImports); store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![ LintId::of(&arithmetic::FLOAT_ARITHMETIC), @@ -1105,6 +1108,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&unicode::NON_ASCII_LITERAL), LintId::of(&unicode::UNICODE_NOT_NFC), LintId::of(&unused_self::UNUSED_SELF), + LintId::of(&wildcard_imports::WILDCARD_IMPORTS), ]); store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![ diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 5fdcf08072db..6f6674488b54 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -6,7 +6,7 @@ pub use lint::Lint; pub use lint::LINT_LEVELS; // begin lint list, do not remove this comment, it’s used in `update_lints` -pub const ALL_LINTS: [Lint; 356] = [ +pub const ALL_LINTS: [Lint; 357] = [ Lint { name: "absurd_extreme_comparisons", group: "correctness", @@ -2415,6 +2415,13 @@ pub const ALL_LINTS: [Lint; 356] = [ deprecation: None, module: "matches", }, + Lint { + name: "wildcard_imports", + group: "pedantic", + desc: "lint `use _::*` statements", + deprecation: None, + module: "wildcard_imports", + }, Lint { name: "wildcard_in_or_patterns", group: "complexity", From 3f5ed285249b7222d05051b16c97e25b7bbd086d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Thu, 9 Jan 2020 18:12:54 +0100 Subject: [PATCH 04/10] Let's do it the easy way Queries are cool, but too hard to find. --- clippy_lints/src/wildcard_imports.rs | 242 +++++---------------------- 1 file changed, 40 insertions(+), 202 deletions(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 70098f31aef7..597552f033eb 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,14 +1,10 @@ use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; use if_chain::if_chain; -use rustc::ty::DefIdTree; -use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::intravisit::{walk_item, NestedVisitorMap, Visitor}; use rustc_hir::*; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::{symbol::Symbol, BytePos}; +use rustc_span::BytePos; declare_clippy_lint! { /// **What it does:** Checks for wildcard imports `use _::*`. @@ -59,213 +55,55 @@ impl LateLintPass<'_, '_> for WildcardImports { if_chain! { if !in_macro(item.span); if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; - if let Some(def_id) = use_path.res.opt_def_id(); + let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner_def_id()); + if !used_imports.is_empty(); // Already handled by `unused_imports` then { - let hir = cx.tcx.hir(); - let parent_id = hir.get_parent_item(item.hir_id); - let (items, in_module) = if parent_id == CRATE_HIR_ID { - let items = hir - .krate() - .module - .item_ids - .iter() - .map(|item_id| hir.get(item_id.id)) - .filter_map(|node| { - if let Node::Item(item) = node { - Some(item) - } else { - None - } - }) - .collect(); - (items, true) - } else if let Node::Item(item) = hir.get(parent_id) { - (vec![item], false) + let mut applicability = Applicability::MachineApplicable; + let import_source = snippet_with_applicability(cx, use_path.span, "..", &mut applicability); + let (span, braced_glob) = if import_source.is_empty() { + // This is a `_::{_, *}` import + ( + use_path.span.with_hi(use_path.span.hi() + BytePos(1)), + true, + ) } else { - (vec![], false) + ( + use_path.span.with_hi(use_path.span.hi() + BytePos(3)), + false, + ) }; - let mut import_used_visitor = ImportsUsedVisitor { - cx, - wildcard_def_id: def_id, - in_module, - used_imports: FxHashSet::default(), - }; - for item in items { - import_used_visitor.visit_item(item); - } - - if !import_used_visitor.used_imports.is_empty() { - let module_name = use_path - .segments + let imports_string = if used_imports.len() == 1 { + used_imports.iter().next().unwrap().to_string() + } else { + let mut imports = used_imports .iter() - .last() - .expect("path has at least one segment") - .ident - .name; - - let mut applicability = Applicability::MachineApplicable; - let import_source = snippet_with_applicability(cx, use_path.span, "..", &mut applicability); - let (span, braced_glob) = if import_source.is_empty() { - // This is a `_::{_, *}` import - // Probably it's `_::{self, *}`, in that case we don't want to suggest to - // import `self`. - // If it is something else, we also don't want to include `self` in the - // suggestion, since either it was imported through another use statement: - // ``` - // use foo::bar; - // use foo::bar::{baz, *}; - // ``` - // or it couldn't be used anywhere. - ( - use_path.span.with_hi(use_path.span.hi() + BytePos(1)), - true, - ) - } else { - ( - use_path.span.with_hi(use_path.span.hi() + BytePos(3)), - false, - ) - }; - - let imports_string = if import_used_visitor.used_imports.len() == 1 { - // We don't need to check for accidental suggesting the module name instead - // of `self` here, since if `used_imports.len() == 1`, and the only usage - // is `self`, then it's not through a `*` and if there is a `*`, it gets - // already linted by `unused_imports` of rustc. - import_used_visitor.used_imports.iter().next().unwrap().to_string() - } else { - let mut imports = import_used_visitor - .used_imports - .iter() - .filter_map(|import_name| { - if braced_glob && *import_name == module_name { - None - } else if *import_name == module_name { - Some("self".to_string()) - } else { - Some(import_name.to_string()) - } - }) - .collect::>(); - imports.sort(); - if braced_glob { - imports.join(", ") - } else { - format!("{{{}}}", imports.join(", ")) - } - }; - - let sugg = if import_source.is_empty() { - imports_string + .map(ToString::to_string) + .collect::>(); + imports.sort(); + if braced_glob { + imports.join(", ") } else { - format!("{}::{}", import_source, imports_string) - }; - - span_lint_and_sugg( - cx, - WILDCARD_IMPORTS, - span, - "usage of wildcard import", - "try", - sugg, - applicability, - ); - } - } - } - } -} - -struct ImportsUsedVisitor<'a, 'tcx> { - cx: &'a LateContext<'a, 'tcx>, - wildcard_def_id: def_id::DefId, - in_module: bool, - used_imports: FxHashSet, -} - -impl<'a, 'tcx> Visitor<'tcx> for ImportsUsedVisitor<'a, 'tcx> { - type Map = Map<'tcx>; - - fn visit_item(&mut self, item: &'tcx Item<'_>) { - match item.kind { - ItemKind::Use(..) => {}, - ItemKind::Mod(..) if self.in_module => {}, - ItemKind::Mod(..) => self.in_module = true, - _ => walk_item(self, item), - } - } - - fn visit_path(&mut self, path: &Path<'_>, _: HirId) { - if let Some(def_id) = self.first_path_segment_def_id(path) { - // Check if the function/enum/... was exported - if let Some(exports) = self.cx.tcx.module_exports(self.wildcard_def_id) { - for export in exports { - if let Some(export_def_id) = export.res.opt_def_id() { - if export_def_id == def_id { - self.used_imports.insert( - path.segments - .iter() - .next() - .expect("path has at least one segment") - .ident - .name, - ); - return; - } + format!("{{{}}}", imports.join(", ")) } - } - } - - // Check if it is directly in the module - if let Some(parent_def_id) = self.cx.tcx.parent(def_id) { - if self.wildcard_def_id == parent_def_id { - self.used_imports.insert( - path.segments - .iter() - .next() - .expect("path has at least one segment") - .ident - .name, - ); - } - } - } - } - - fn nested_visit_map(&mut self) -> NestedVisitorMap<'_, Self::Map> { - NestedVisitorMap::All(&self.cx.tcx.hir()) - } -} + }; -impl ImportsUsedVisitor<'_, '_> { - fn skip_def_id(&self, def_id: DefId) -> DefId { - let def_key = self.cx.tcx.def_key(def_id); - match def_key.disambiguated_data.data { - DefPathData::Ctor => { - if let Some(def_id) = self.cx.tcx.parent(def_id) { - self.skip_def_id(def_id) + let sugg = if import_source.is_empty() { + imports_string } else { - def_id - } - }, - _ => def_id, - } - } + format!("{}::{}", import_source, imports_string) + }; - fn first_path_segment_def_id(&self, path: &Path<'_>) -> Option { - path.res.opt_def_id().and_then(|mut def_id| { - def_id = self.skip_def_id(def_id); - for _ in path.segments.iter().skip(1) { - def_id = self.skip_def_id(def_id); - if let Some(parent_def_id) = self.cx.tcx.parent(def_id) { - def_id = parent_def_id; - } else { - return None; - } + span_lint_and_sugg( + cx, + WILDCARD_IMPORTS, + span, + "usage of wildcard import", + "try", + sugg, + applicability, + ); } - - Some(def_id) - }) + } } } From 06a6189376975ddff0d8db2fb20ab407066357b4 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Tue, 14 Jan 2020 13:52:08 +0100 Subject: [PATCH 05/10] Move enum_glob_use lint into wildcard_imports pass --- clippy_lints/src/enum_glob_use.rs | 49 ---------------------------- clippy_lints/src/lib.rs | 6 ++-- clippy_lints/src/wildcard_imports.rs | 35 +++++++++++++++++--- src/lintlist/mod.rs | 2 +- tests/ui/enum_glob_use.fixed | 30 +++++++++++++++++ tests/ui/enum_glob_use.rs | 29 ++++++++-------- tests/ui/enum_glob_use.stderr | 20 ++++++++---- 7 files changed, 92 insertions(+), 79 deletions(-) delete mode 100644 clippy_lints/src/enum_glob_use.rs create mode 100644 tests/ui/enum_glob_use.fixed diff --git a/clippy_lints/src/enum_glob_use.rs b/clippy_lints/src/enum_glob_use.rs deleted file mode 100644 index 4ffc73961a8c..000000000000 --- a/clippy_lints/src/enum_glob_use.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! lint on `use`ing all variants of an enum - -use crate::utils::span_lint; -use rustc_hir::def::{DefKind, Res}; -use rustc_hir::*; -use rustc_lint::{LateContext, LateLintPass}; -use rustc_session::{declare_lint_pass, declare_tool_lint}; -use rustc_span::source_map::Span; - -declare_clippy_lint! { - /// **What it does:** Checks for `use Enum::*`. - /// - /// **Why is this bad?** It is usually better style to use the prefixed name of - /// an enumeration variant, rather than importing variants. - /// - /// **Known problems:** Old-style enumerations that prefix the variants are - /// still around. - /// - /// **Example:** - /// ```rust - /// use std::cmp::Ordering::*; - /// ``` - pub ENUM_GLOB_USE, - pedantic, - "use items that import all variants of an enum" -} - -declare_lint_pass!(EnumGlobUse => [ENUM_GLOB_USE]); - -impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EnumGlobUse { - fn check_mod(&mut self, cx: &LateContext<'a, 'tcx>, m: &'tcx Mod<'_>, _: Span, _: HirId) { - let map = cx.tcx.hir(); - // only check top level `use` statements - for item in m.item_ids { - lint_item(cx, map.expect_item(item.id)); - } - } -} - -fn lint_item(cx: &LateContext<'_, '_>, item: &Item<'_>) { - if item.vis.node.is_pub() { - return; // re-exports are fine - } - if let ItemKind::Use(ref path, UseKind::Glob) = item.kind { - if let Res::Def(DefKind::Enum, _) = path.res { - span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants"); - } - } -} diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 77d33e6a0db6..2b5691f92555 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -197,7 +197,6 @@ pub mod else_if_without_else; pub mod empty_enum; pub mod entry; pub mod enum_clike; -pub mod enum_glob_use; pub mod enum_variants; pub mod eq_op; pub mod erasing_op; @@ -520,7 +519,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &empty_enum::EMPTY_ENUM, &entry::MAP_ENTRY, &enum_clike::ENUM_CLIKE_UNPORTABLE_VARIANT, - &enum_glob_use::ENUM_GLOB_USE, &enum_variants::ENUM_VARIANT_NAMES, &enum_variants::MODULE_INCEPTION, &enum_variants::MODULE_NAME_REPETITIONS, @@ -814,6 +812,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &use_self::USE_SELF, &vec::USELESS_VEC, &wildcard_dependencies::WILDCARD_DEPENDENCIES, + &wildcard_imports::ENUM_GLOB_USE, &wildcard_imports::WILDCARD_IMPORTS, &write::PRINTLN_EMPTY_STRING, &write::PRINT_LITERAL, @@ -837,7 +836,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: store.register_late_pass(move || box types::Types::new(vec_box_size_threshold)); store.register_late_pass(|| box booleans::NonminimalBool); store.register_late_pass(|| box eq_op::EqOp); - store.register_late_pass(|| box enum_glob_use::EnumGlobUse); store.register_late_pass(|| box enum_clike::UnportableVariant); store.register_late_pass(|| box float_literal::FloatLiteral); let verbose_bit_mask_threshold = conf.verbose_bit_mask_threshold; @@ -1064,7 +1062,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&doc::DOC_MARKDOWN), LintId::of(&doc::MISSING_ERRORS_DOC), LintId::of(&empty_enum::EMPTY_ENUM), - LintId::of(&enum_glob_use::ENUM_GLOB_USE), LintId::of(&enum_variants::MODULE_NAME_REPETITIONS), LintId::of(&enum_variants::PUB_ENUM_VARIANT_NAMES), LintId::of(&eta_reduction::REDUNDANT_CLOSURE_FOR_METHOD_CALLS), @@ -1108,6 +1105,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: LintId::of(&unicode::NON_ASCII_LITERAL), LintId::of(&unicode::UNICODE_NOT_NFC), LintId::of(&unused_self::UNUSED_SELF), + LintId::of(&wildcard_imports::ENUM_GLOB_USE), LintId::of(&wildcard_imports::WILDCARD_IMPORTS), ]); diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 597552f033eb..584e7adfccc7 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,11 +1,32 @@ use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{ + def::{DefKind, Res}, + Item, ItemKind, UseKind, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::BytePos; +declare_clippy_lint! { + /// **What it does:** Checks for `use Enum::*`. + /// + /// **Why is this bad?** It is usually better style to use the prefixed name of + /// an enumeration variant, rather than importing variants. + /// + /// **Known problems:** Old-style enumerations that prefix the variants are + /// still around. + /// + /// **Example:** + /// ```rust + /// use std::cmp::Ordering::*; + /// ``` + pub ENUM_GLOB_USE, + pedantic, + "use items that import all variants of an enum" +} + declare_clippy_lint! { /// **What it does:** Checks for wildcard imports `use _::*`. /// @@ -45,7 +66,7 @@ declare_clippy_lint! { "lint `use _::*` statements" } -declare_lint_pass!(WildcardImports => [WILDCARD_IMPORTS]); +declare_lint_pass!(WildcardImports => [ENUM_GLOB_USE, WILDCARD_IMPORTS]); impl LateLintPass<'_, '_> for WildcardImports { fn check_item(&mut self, cx: &LateContext<'_, '_>, item: &Item<'_>) { @@ -94,11 +115,17 @@ impl LateLintPass<'_, '_> for WildcardImports { format!("{}::{}", import_source, imports_string) }; + let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res { + (ENUM_GLOB_USE, "usage of wildcard import for enum variants") + } else { + (WILDCARD_IMPORTS, "usage of wildcard import") + }; + span_lint_and_sugg( cx, - WILDCARD_IMPORTS, + lint, span, - "usage of wildcard import", + message, "try", sugg, applicability, diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs index 6f6674488b54..29b5a7ba08a2 100644 --- a/src/lintlist/mod.rs +++ b/src/lintlist/mod.rs @@ -460,7 +460,7 @@ pub const ALL_LINTS: [Lint; 357] = [ group: "pedantic", desc: "use items that import all variants of an enum", deprecation: None, - module: "enum_glob_use", + module: "wildcard_imports", }, Lint { name: "enum_variant_names", diff --git a/tests/ui/enum_glob_use.fixed b/tests/ui/enum_glob_use.fixed new file mode 100644 index 000000000000..a98216758bb9 --- /dev/null +++ b/tests/ui/enum_glob_use.fixed @@ -0,0 +1,30 @@ +// run-rustfix + +#![warn(clippy::enum_glob_use)] +#![allow(unused)] +#![warn(unused_imports)] + +use std::cmp::Ordering::Less; + +enum Enum { + Foo, +} + +use self::Enum::Foo; + +mod in_fn_test { + fn blarg() { + use crate::Enum::Foo; + + let _ = Foo; + } +} + +mod blurg { + pub use std::cmp::Ordering::*; // ok, re-export +} + +fn main() { + let _ = Foo; + let _ = Less; +} diff --git a/tests/ui/enum_glob_use.rs b/tests/ui/enum_glob_use.rs index e7b2526ca50b..5d929c9731d3 100644 --- a/tests/ui/enum_glob_use.rs +++ b/tests/ui/enum_glob_use.rs @@ -1,29 +1,30 @@ -#![warn(clippy::all, clippy::pedantic)] -#![allow(unused_imports, dead_code, clippy::missing_docs_in_private_items)] +// run-rustfix + +#![warn(clippy::enum_glob_use)] +#![allow(unused)] +#![warn(unused_imports)] use std::cmp::Ordering::*; enum Enum { - _Foo, + Foo, } use self::Enum::*; -fn blarg() { - use self::Enum::*; // ok, just for a function +mod in_fn_test { + fn blarg() { + use crate::Enum::*; + + let _ = Foo; + } } mod blurg { pub use std::cmp::Ordering::*; // ok, re-export } -mod tests { - use super::*; +fn main() { + let _ = Foo; + let _ = Less; } - -#[allow(non_snake_case)] -mod CamelCaseName {} - -use CamelCaseName::*; - -fn main() {} diff --git a/tests/ui/enum_glob_use.stderr b/tests/ui/enum_glob_use.stderr index a301703c2988..69531aed39bd 100644 --- a/tests/ui/enum_glob_use.stderr +++ b/tests/ui/enum_glob_use.stderr @@ -1,16 +1,22 @@ -error: don't use glob imports for enum variants - --> $DIR/enum_glob_use.rs:4:1 +error: usage of wildcard import for enum variants + --> $DIR/enum_glob_use.rs:7:5 | LL | use std::cmp::Ordering::*; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^ help: try: `std::cmp::Ordering::Less` | = note: `-D clippy::enum-glob-use` implied by `-D warnings` -error: don't use glob imports for enum variants - --> $DIR/enum_glob_use.rs:10:1 +error: usage of wildcard import for enum variants + --> $DIR/enum_glob_use.rs:13:5 | LL | use self::Enum::*; - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ help: try: `self::Enum::Foo` -error: aborting due to 2 previous errors +error: usage of wildcard import for enum variants + --> $DIR/enum_glob_use.rs:17:13 + | +LL | use crate::Enum::*; + | ^^^^^^^^^^^^^^ help: try: `crate::Enum::Foo` + +error: aborting due to 3 previous errors From f4f781d5cfd7a572006a8721c7998d13c378647d Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sun, 9 Feb 2020 12:23:13 +0100 Subject: [PATCH 06/10] Filter prelude glob imports --- clippy_lints/src/wildcard_imports.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 584e7adfccc7..3e8d28a22932 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -76,6 +76,8 @@ impl LateLintPass<'_, '_> for WildcardImports { if_chain! { if !in_macro(item.span); if let ItemKind::Use(use_path, UseKind::Glob) = &item.kind; + // don't lint prelude glob imports + if !use_path.segments.iter().last().map_or(false, |ps| ps.ident.as_str() == "prelude"); let used_imports = cx.tcx.names_imported_by_glob_use(item.hir_id.owner_def_id()); if !used_imports.is_empty(); // Already handled by `unused_imports` then { From b67764d5cb067aaa3ee53168855959465a8a7267 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Sun, 9 Feb 2020 12:55:20 +0100 Subject: [PATCH 07/10] Add test for prelude import --- tests/ui/wildcard_imports.fixed | 10 ++++++++++ tests/ui/wildcard_imports.rs | 10 ++++++++++ tests/ui/wildcard_imports.stderr | 14 +++++++------- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed index 97c8c6068e55..398c3b56572b 100644 --- a/tests/ui/wildcard_imports.fixed +++ b/tests/ui/wildcard_imports.fixed @@ -18,6 +18,16 @@ use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::inner_extern_bar; use wildcard_imports_helper::{ExternA, extern_foo}; +use std::io::prelude::*; + +struct ReadFoo; + +impl Read for ReadFoo { + fn read(&mut self, _buf: &mut [u8]) -> std::io::Result { + Ok(0) + } +} + mod fn_mod { pub fn foo() {} } diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 045356672e3a..10ab25e02ade 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -18,6 +18,16 @@ use wildcard_imports_helper::inner::inner_for_self_import; use wildcard_imports_helper::inner::inner_for_self_import::*; use wildcard_imports_helper::*; +use std::io::prelude::*; + +struct ReadFoo; + +impl Read for ReadFoo { + fn read(&mut self, _buf: &mut [u8]) -> std::io::Result { + Ok(0) + } +} + mod fn_mod { pub fn foo() {} } diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr index 111481e52d03..ca300fbaad49 100644 --- a/tests/ui/wildcard_imports.stderr +++ b/tests/ui/wildcard_imports.stderr @@ -37,43 +37,43 @@ LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:78:13 + --> $DIR/wildcard_imports.rs:88:13 | LL | use crate::fn_mod::*; | ^^^^^^^^^^^^^^^^ help: try: `crate::fn_mod::foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:84:75 + --> $DIR/wildcard_imports.rs:94: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:85:13 + --> $DIR/wildcard_imports.rs:95:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternA, extern_foo}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:96:20 + --> $DIR/wildcard_imports.rs:106:20 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^ help: try: `inner::inner_foo` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:96:30 + --> $DIR/wildcard_imports.rs:106:30 | LL | use self::{inner::*, inner2::*}; | ^^^^^^^^^ help: try: `inner2::inner_bar` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:103:13 + --> $DIR/wildcard_imports.rs:113:13 | LL | use wildcard_imports_helper::*; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `wildcard_imports_helper::{ExternExportedEnum, ExternExportedStruct, extern_exported}` error: usage of wildcard import - --> $DIR/wildcard_imports.rs:132:9 + --> $DIR/wildcard_imports.rs:142:9 | LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` From 8472ecda0f18a2b1045d4b8736e06e774ab1c73a Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 21 Feb 2020 09:39:38 +0100 Subject: [PATCH 08/10] Fix fallout --- clippy_dev/src/main.rs | 5 ++++- clippy_lints/src/approx_const.rs | 2 +- clippy_lints/src/as_conversions.rs | 2 +- clippy_lints/src/assertions_on_constants.rs | 2 +- clippy_lints/src/assign_ops.rs | 4 +++- clippy_lints/src/atomic_ordering.rs | 2 +- clippy_lints/src/attrs.rs | 6 +++-- clippy_lints/src/bit_mask.rs | 2 +- clippy_lints/src/blacklisted_name.rs | 2 +- clippy_lints/src/block_in_if_condition.rs | 4 ++-- clippy_lints/src/booleans.rs | 10 ++++----- clippy_lints/src/bytecount.rs | 2 +- clippy_lints/src/cargo_common_metadata.rs | 2 +- clippy_lints/src/checked_conversions.rs | 2 +- clippy_lints/src/cognitive_complexity.rs | 2 +- clippy_lints/src/comparison_chain.rs | 2 +- clippy_lints/src/consts.rs | 10 ++++----- clippy_lints/src/copies.rs | 2 +- clippy_lints/src/default_trait_access.rs | 2 +- clippy_lints/src/derive.rs | 2 +- clippy_lints/src/doc.rs | 8 ++++--- clippy_lints/src/double_comparison.rs | 2 +- clippy_lints/src/double_parens.rs | 2 +- clippy_lints/src/drop_bounds.rs | 2 +- clippy_lints/src/drop_forget_ref.rs | 2 +- clippy_lints/src/duration_subsec.rs | 2 +- clippy_lints/src/else_if_without_else.rs | 2 +- clippy_lints/src/empty_enum.rs | 2 +- clippy_lints/src/entry.rs | 2 +- clippy_lints/src/enum_clike.rs | 2 +- clippy_lints/src/enum_variants.rs | 2 +- clippy_lints/src/eq_op.rs | 2 +- clippy_lints/src/erasing_op.rs | 2 +- clippy_lints/src/escape.rs | 4 ++-- clippy_lints/src/eta_reduction.rs | 2 +- clippy_lints/src/eval_order_dependence.rs | 2 +- clippy_lints/src/explicit_write.rs | 2 +- clippy_lints/src/fallible_impl_from.rs | 2 +- clippy_lints/src/float_literal.rs | 2 +- clippy_lints/src/format.rs | 2 +- clippy_lints/src/formatting.rs | 2 +- clippy_lints/src/functions.rs | 6 ++--- clippy_lints/src/identity_conversion.rs | 2 +- clippy_lints/src/identity_op.rs | 2 +- clippy_lints/src/if_let_some_result.rs | 2 +- clippy_lints/src/if_not_else.rs | 2 +- clippy_lints/src/indexing_slicing.rs | 2 +- clippy_lints/src/infinite_iter.rs | 2 +- clippy_lints/src/inherent_impl.rs | 2 +- clippy_lints/src/inline_fn_without_body.rs | 2 +- clippy_lints/src/int_plus_one.rs | 2 +- clippy_lints/src/items_after_statements.rs | 2 +- clippy_lints/src/large_enum_variant.rs | 2 +- clippy_lints/src/large_stack_arrays.rs | 2 +- clippy_lints/src/len_zero.rs | 2 +- clippy_lints/src/let_underscore.rs | 2 +- clippy_lints/src/lifetimes.rs | 12 +++++++--- clippy_lints/src/literal_representation.rs | 2 +- clippy_lints/src/loops.rs | 9 +++++--- clippy_lints/src/matches.rs | 5 ++++- .../methods/manual_saturating_arithmetic.rs | 5 ++++- .../src/methods/option_map_unwrap_or.rs | 2 +- clippy_lints/src/minmax.rs | 2 +- clippy_lints/src/misc.rs | 5 ++++- clippy_lints/src/misc_early.rs | 5 ++++- clippy_lints/src/modulo_arithmetic.rs | 2 +- clippy_lints/src/mul_add.rs | 4 ++-- clippy_lints/src/multiple_crate_versions.rs | 2 +- clippy_lints/src/mut_reference.rs | 2 +- clippy_lints/src/needless_bool.rs | 6 ++--- clippy_lints/src/needless_pass_by_value.rs | 2 +- clippy_lints/src/neg_cmp_op_on_partial_ord.rs | 2 +- clippy_lints/src/neg_multiply.rs | 2 +- clippy_lints/src/non_copy_const.rs | 2 +- clippy_lints/src/non_expressive_names.rs | 4 +++- clippy_lints/src/option_env_unwrap.rs | 2 +- .../src/overflow_check_conditional.rs | 2 +- clippy_lints/src/panic_unimplemented.rs | 2 +- clippy_lints/src/partialeq_ne_impl.rs | 2 +- clippy_lints/src/path_buf_push_overwrite.rs | 2 +- clippy_lints/src/precedence.rs | 6 ++--- clippy_lints/src/ptr.rs | 5 ++++- clippy_lints/src/question_mark.rs | 4 ++-- clippy_lints/src/ranges.rs | 2 +- clippy_lints/src/redundant_clone.rs | 2 +- clippy_lints/src/redundant_field_names.rs | 2 +- .../src/redundant_pattern_matching.rs | 2 +- .../src/redundant_static_lifetimes.rs | 2 +- clippy_lints/src/regex.rs | 6 ++--- clippy_lints/src/replace_consts.rs | 2 +- clippy_lints/src/serde_api.rs | 2 +- clippy_lints/src/shadow.rs | 7 ++++-- .../src/slow_vector_initialization.rs | 2 +- clippy_lints/src/strings.rs | 2 +- clippy_lints/src/swap.rs | 2 +- clippy_lints/src/trait_bounds.rs | 2 +- clippy_lints/src/transmute.rs | 2 +- .../src/trivially_copy_pass_by_ref.rs | 2 +- clippy_lints/src/try_err.rs | 2 +- clippy_lints/src/types.rs | 22 +++++++++++-------- clippy_lints/src/unicode.rs | 2 +- clippy_lints/src/unsafe_removed_from_name.rs | 2 +- clippy_lints/src/unwrap.rs | 4 ++-- clippy_lints/src/use_self.rs | 5 ++++- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 6 ++++- clippy_lints/src/utils/internal_lints.rs | 2 +- clippy_lints/src/utils/mod.rs | 9 +++++--- clippy_lints/src/utils/ptr.rs | 2 +- clippy_lints/src/utils/sugg.rs | 11 +++++++--- clippy_lints/src/utils/usage.rs | 4 ++-- clippy_lints/src/vec.rs | 2 +- clippy_lints/src/wildcard_dependencies.rs | 2 +- clippy_lints/src/write.rs | 6 +++-- clippy_lints/src/zero_div_zero.rs | 2 +- src/driver.rs | 4 ++-- src/main.rs | 2 +- 117 files changed, 219 insertions(+), 162 deletions(-) diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index ec0c33109ba9..901e663ded38 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -1,7 +1,10 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] use clap::{App, Arg, SubCommand}; -use clippy_dev::*; +use clippy_dev::{ + gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list, + replace_region_in_file, Lint, DOCS_LINK, +}; use std::path::Path; mod fmt; diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs index 51b6f2f0688f..042b83dc386d 100644 --- a/clippy_lints/src/approx_const.rs +++ b/clippy_lints/src/approx_const.rs @@ -1,5 +1,5 @@ use crate::utils::span_lint; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol; diff --git a/clippy_lints/src/as_conversions.rs b/clippy_lints/src/as_conversions.rs index d90a0d67d5a5..5c584b18f4c3 100644 --- a/clippy_lints/src/as_conversions.rs +++ b/clippy_lints/src/as_conversions.rs @@ -1,7 +1,7 @@ use rustc::lint::in_external_macro; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind}; use crate::utils::span_lint_and_help; diff --git a/clippy_lints/src/assertions_on_constants.rs b/clippy_lints/src/assertions_on_constants.rs index e399229b43ca..8a7a48aebf9b 100644 --- a/clippy_lints/src/assertions_on_constants.rs +++ b/clippy_lints/src/assertions_on_constants.rs @@ -2,7 +2,7 @@ use crate::consts::{constant, Constant}; use crate::utils::paths; use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_lint_and_help}; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, PatKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs index 7ad0ce232023..bc4e47340c69 100644 --- a/clippy_lints/src/assign_ops.rs +++ b/clippy_lints/src/assign_ops.rs @@ -231,7 +231,9 @@ fn lint_misrefactored_assign_op( #[must_use] fn is_commutative(op: hir::BinOpKind) -> bool { - use rustc_hir::BinOpKind::*; + use rustc_hir::BinOpKind::{ + Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub, + }; match op { Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true, Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false, diff --git a/clippy_lints/src/atomic_ordering.rs b/clippy_lints/src/atomic_ordering.rs index 178ee45298e3..871ca029b1aa 100644 --- a/clippy_lints/src/atomic_ordering.rs +++ b/clippy_lints/src/atomic_ordering.rs @@ -2,7 +2,7 @@ use crate::utils::{match_def_path, span_lint_and_help}; use if_chain::if_chain; use rustc::ty; use rustc_hir::def_id::DefId; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs index 6f67acb29219..5c083cefc8d1 100644 --- a/clippy_lints/src/attrs.rs +++ b/clippy_lints/src/attrs.rs @@ -1,6 +1,6 @@ //! checks for attributes -use crate::reexport::*; +use crate::reexport::Name; use crate::utils::{ first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg, span_lint_and_then, without_block_comments, @@ -9,7 +9,9 @@ use if_chain::if_chain; use rustc::lint::in_external_macro; use rustc::ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{ + Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitItem, TraitItemKind, TraitMethod, +}; use rustc_lint::{CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/bit_mask.rs b/clippy_lints/src/bit_mask.rs index 926b1c63ad12..05f85e929614 100644 --- a/clippy_lints/src/bit_mask.rs +++ b/clippy_lints/src/bit_mask.rs @@ -3,7 +3,7 @@ use crate::utils::sugg::Sugg; use crate::utils::{span_lint, span_lint_and_then}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/blacklisted_name.rs b/clippy_lints/src/blacklisted_name.rs index cb68ba598868..6f26f031431d 100644 --- a/clippy_lints/src/blacklisted_name.rs +++ b/clippy_lints/src/blacklisted_name.rs @@ -1,6 +1,6 @@ use crate::utils::span_lint; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::*; +use rustc_hir::{Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/block_in_if_condition.rs b/clippy_lints/src/block_in_if_condition.rs index 325e12617142..d004dcddfea0 100644 --- a/clippy_lints/src/block_in_if_condition.rs +++ b/clippy_lints/src/block_in_if_condition.rs @@ -1,10 +1,10 @@ -use crate::utils::*; +use crate::utils::{differing_macro_contexts, higher, snippet_block_with_applicability, span_lint, span_lint_and_sugg}; use matches::matches; use rustc::hir::map::Map; use rustc::lint::in_external_macro; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{BlockCheckMode, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/booleans.rs b/clippy_lints/src/booleans.rs index d37f77cf6cc3..07b4f572dd54 100644 --- a/clippy_lints/src/booleans.rs +++ b/clippy_lints/src/booleans.rs @@ -5,8 +5,8 @@ use crate::utils::{ use if_chain::if_chain; use rustc::hir::map::Map; use rustc_errors::Applicability; -use rustc_hir::intravisit::*; -use rustc_hir::*; +use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -161,7 +161,7 @@ struct SuggestContext<'a, 'tcx, 'v> { impl<'a, 'tcx, 'v> SuggestContext<'a, 'tcx, 'v> { fn recurse(&mut self, suggestion: &Bool) -> Option<()> { - use quine_mc_cluskey::Bool::*; + use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; match suggestion { True => { self.output.push_str("true"); @@ -277,7 +277,7 @@ fn suggest(cx: &LateContext<'_, '_>, suggestion: &Bool, terminals: &[&Expr<'_>]) } fn simple_negate(b: Bool) -> Bool { - use quine_mc_cluskey::Bool::*; + use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; match b { True => False, False => True, @@ -325,7 +325,7 @@ fn terminal_stats(b: &Bool) -> Stats { &Term(n) => stats.terminals[n as usize] += 1, } } - use quine_mc_cluskey::Bool::*; + use quine_mc_cluskey::Bool::{And, False, Not, Or, Term, True}; let mut stats = Stats::default(); recurse(b, &mut stats); stats diff --git a/clippy_lints/src/bytecount.rs b/clippy_lints/src/bytecount.rs index 2adc3b429067..e8168cb7393a 100644 --- a/clippy_lints/src/bytecount.rs +++ b/clippy_lints/src/bytecount.rs @@ -5,7 +5,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc::ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::{Name, UintTy}; diff --git a/clippy_lints/src/cargo_common_metadata.rs b/clippy_lints/src/cargo_common_metadata.rs index ec53e08f50cd..9e0e9d7dd6a0 100644 --- a/clippy_lints/src/cargo_common_metadata.rs +++ b/clippy_lints/src/cargo_common_metadata.rs @@ -6,7 +6,7 @@ use crate::utils::span_lint; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; -use syntax::ast::*; +use syntax::ast::Crate; declare_clippy_lint! { /// **What it does:** Checks to see if all common metadata is defined in diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 88df0772ae5e..835f8b7f902a 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::lint::in_external_macro; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOp, BinOpKind, Expr, ExprKind, QPath, TyKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; diff --git a/clippy_lints/src/cognitive_complexity.rs b/clippy_lints/src/cognitive_complexity.rs index 2b6315255016..ecae13a49708 100644 --- a/clippy_lints/src/cognitive_complexity.rs +++ b/clippy_lints/src/cognitive_complexity.rs @@ -2,7 +2,7 @@ use rustc::hir::map::Map; use rustc_hir::intravisit::{walk_expr, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/comparison_chain.rs b/clippy_lints/src/comparison_chain.rs index 684d3448ea43..e0c381ddbfc4 100644 --- a/clippy_lints/src/comparison_chain.rs +++ b/clippy_lints/src/comparison_chain.rs @@ -1,7 +1,7 @@ use crate::utils::{ get_trait_def_id, if_sequence, implements_trait, parent_node_is_if_expr, paths, span_lint_and_help, SpanlessEq, }; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 7efc62d4c2e1..edfd2486be28 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -7,13 +7,13 @@ use rustc::ty::{self, Ty, TyCtxt}; use rustc::{bug, span_bug}; use rustc_data_structures::sync::Lrc; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::*; +use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp}; use rustc_lint::LateContext; use rustc_span::symbol::Symbol; use std::cmp::Ordering::{self, Equal}; use std::convert::TryInto; use std::hash::{Hash, Hasher}; -use syntax::ast::{FloatTy, LitKind}; +use syntax::ast::{FloatTy, LitFloatType, LitKind}; /// A `LitKind`-like enum to fold constant `Expr`s into. #[derive(Debug, Clone)] @@ -152,8 +152,6 @@ impl Constant { /// Parses a `LitKind` to a `Constant`. pub fn lit_to_constant(lit: &LitKind, ty: Option>) -> Constant { - use syntax::ast::*; - match *lit { LitKind::Str(ref is, _) => Constant::Str(is.to_string()), LitKind::Byte(b) => Constant::Int(u128::from(b)), @@ -277,7 +275,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { #[allow(clippy::cast_possible_wrap)] fn constant_not(&self, o: &Constant, ty: Ty<'_>) -> Option { - use self::Constant::*; + use self::Constant::{Bool, Int}; match *o { Bool(b) => Some(Bool(!b)), Int(value) => { @@ -293,7 +291,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } fn constant_negate(&self, o: &Constant, ty: Ty<'_>) -> Option { - use self::Constant::*; + use self::Constant::{Int, F32, F64}; match *o { Int(value) => { let ity = match ty.kind { diff --git a/clippy_lints/src/copies.rs b/clippy_lints/src/copies.rs index d2d20375dafa..996f80a757e7 100644 --- a/clippy_lints/src/copies.rs +++ b/clippy_lints/src/copies.rs @@ -2,7 +2,7 @@ use crate::utils::{get_parent_expr, higher, if_sequence, same_tys, snippet, span use crate::utils::{SpanlessEq, SpanlessHash}; use rustc::ty::Ty; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::*; +use rustc_hir::{Arm, Block, Expr, ExprKind, MatchSource, Pat, PatKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/default_trait_access.rs b/clippy_lints/src/default_trait_access.rs index 0e1380df9216..f99e6d96e030 100644 --- a/clippy_lints/src/default_trait_access.rs +++ b/clippy_lints/src/default_trait_access.rs @@ -1,7 +1,7 @@ use if_chain::if_chain; use rustc::ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index efb44ab6dbb9..f130a69778f6 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -2,7 +2,7 @@ use crate::utils::paths; use crate::utils::{is_automatically_derived, is_copy, match_path, span_lint_and_then}; use if_chain::if_chain; use rustc::ty::{self, Ty}; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind, TraitRef}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 9b8664c13206..be65fd21a68e 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -350,7 +350,7 @@ fn check_attrs<'a>(cx: &LateContext<'_, '_>, valid_idents: &FxHashSet, a let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter(); // Iterate over all `Events` and combine consecutive events into one let events = parser.coalesce(|previous, current| { - use pulldown_cmark::Event::*; + use pulldown_cmark::Event::Text; let previous_range = previous.1; let current_range = current.1; @@ -374,8 +374,10 @@ fn check_doc<'a, Events: Iterator, Range DocHeaders { // true if a safety header was found - use pulldown_cmark::Event::*; - use pulldown_cmark::Tag::*; + use pulldown_cmark::Event::{ + Code, End, FootnoteReference, HardBreak, Html, Rule, SoftBreak, Start, TaskListMarker, Text, + }; + use pulldown_cmark::Tag::{CodeBlock, Heading, Link}; let mut headers = DocHeaders { safety: false, diff --git a/clippy_lints/src/double_comparison.rs b/clippy_lints/src/double_comparison.rs index 934e3ccdf87c..44f85d1ea6e1 100644 --- a/clippy_lints/src/double_comparison.rs +++ b/clippy_lints/src/double_comparison.rs @@ -1,7 +1,7 @@ //! Lint on unnecessary double comparisons. Some examples: use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/double_parens.rs b/clippy_lints/src/double_parens.rs index d08981e8badc..c4c4758ebb78 100644 --- a/clippy_lints/src/double_parens.rs +++ b/clippy_lints/src/double_parens.rs @@ -1,7 +1,7 @@ use crate::utils::span_lint; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind}; declare_clippy_lint! { /// **What it does:** Checks for unnecessary double parentheses. diff --git a/clippy_lints/src/drop_bounds.rs b/clippy_lints/src/drop_bounds.rs index 1d445a153231..f49668082791 100644 --- a/clippy_lints/src/drop_bounds.rs +++ b/clippy_lints/src/drop_bounds.rs @@ -1,6 +1,6 @@ use crate::utils::{match_def_path, paths, span_lint}; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{GenericBound, GenericParam, WhereBoundPredicate, WherePredicate}; use rustc_lint::LateLintPass; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/drop_forget_ref.rs b/clippy_lints/src/drop_forget_ref.rs index 29351deea286..bd9bdfef090b 100644 --- a/clippy_lints/src/drop_forget_ref.rs +++ b/clippy_lints/src/drop_forget_ref.rs @@ -1,7 +1,7 @@ use crate::utils::{is_copy, match_def_path, paths, qpath_res, span_lint_and_note}; use if_chain::if_chain; use rustc::ty; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/duration_subsec.rs b/clippy_lints/src/duration_subsec.rs index 366996fb381b..b35a8facf8b9 100644 --- a/clippy_lints/src/duration_subsec.rs +++ b/clippy_lints/src/duration_subsec.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; diff --git a/clippy_lints/src/else_if_without_else.rs b/clippy_lints/src/else_if_without_else.rs index b87900180f26..c41c5aadbee7 100644 --- a/clippy_lints/src/else_if_without_else.rs +++ b/clippy_lints/src/else_if_without_else.rs @@ -3,7 +3,7 @@ use rustc::lint::in_external_macro; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind}; use crate::utils::span_lint_and_help; diff --git a/clippy_lints/src/empty_enum.rs b/clippy_lints/src/empty_enum.rs index c43db68d20f2..010d208c9e79 100644 --- a/clippy_lints/src/empty_enum.rs +++ b/clippy_lints/src/empty_enum.rs @@ -1,7 +1,7 @@ //! lint when there is an enum with no variants use crate::utils::span_lint_and_then; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/entry.rs b/clippy_lints/src/entry.rs index d32e78798afe..19da4c4bc9a5 100644 --- a/clippy_lints/src/entry.rs +++ b/clippy_lints/src/entry.rs @@ -5,7 +5,7 @@ use if_chain::if_chain; use rustc::hir::map::Map; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{BorrowKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 2e14956ecd7b..e8063ac3006c 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -5,7 +5,7 @@ use crate::consts::{miri_to_const, Constant}; use crate::utils::span_lint; use rustc::ty; use rustc::ty::util::IntTypeExt; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::convert::TryFrom; diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 75205f964008..0d14b8a75e8a 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -6,7 +6,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, Lint}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; -use syntax::ast::*; +use syntax::ast::{EnumDef, Item, ItemKind, VisibilityKind}; declare_clippy_lint! { /// **What it does:** Detects enumeration variants that are prefixed or suffixed diff --git a/clippy_lints/src/eq_op.rs b/clippy_lints/src/eq_op.rs index 01b04220a069..1df0bcc6b7e8 100644 --- a/clippy_lints/src/eq_op.rs +++ b/clippy_lints/src/eq_op.rs @@ -2,7 +2,7 @@ use crate::utils::{ implements_trait, in_macro, is_copy, multispan_sugg, snippet, span_lint, span_lint_and_then, SpanlessEq, }; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOp, BinOpKind, BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/erasing_op.rs b/clippy_lints/src/erasing_op.rs index e08e01c1d67e..3ff0506e28d0 100644 --- a/clippy_lints/src/erasing_op.rs +++ b/clippy_lints/src/erasing_op.rs @@ -1,4 +1,4 @@ -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs index 73bd7b3a143c..850c7f728bd2 100644 --- a/clippy_lints/src/escape.rs +++ b/clippy_lints/src/escape.rs @@ -1,12 +1,12 @@ use rustc::ty::layout::LayoutOf; use rustc::ty::{self, Ty}; use rustc_hir::intravisit; -use rustc_hir::{self, *}; +use rustc_hir::{self, Body, FnDecl, HirId, HirIdSet, ItemKind, Node}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; -use rustc_typeck::expr_use_visitor::*; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; use crate::utils::span_lint; diff --git a/clippy_lints/src/eta_reduction.rs b/clippy_lints/src/eta_reduction.rs index 5ef933845005..8c324e09df55 100644 --- a/clippy_lints/src/eta_reduction.rs +++ b/clippy_lints/src/eta_reduction.rs @@ -3,7 +3,7 @@ use matches::matches; use rustc::lint::in_external_macro; use rustc::ty::{self, Ty}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{def_id, Expr, ExprKind, Param, PatKind, QPath}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/eval_order_dependence.rs b/clippy_lints/src/eval_order_dependence.rs index f143c7462ad2..d6b847d1dbb1 100644 --- a/clippy_lints/src/eval_order_dependence.rs +++ b/clippy_lints/src/eval_order_dependence.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::hir::map::Map; use rustc::ty; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{def, BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/explicit_write.rs b/clippy_lints/src/explicit_write.rs index 4aefa941dabe..a3005d8bd82a 100644 --- a/clippy_lints/src/explicit_write.rs +++ b/clippy_lints/src/explicit_write.rs @@ -1,7 +1,7 @@ use crate::utils::{is_expn_of, match_function_call, paths, span_lint, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; diff --git a/clippy_lints/src/fallible_impl_from.rs b/clippy_lints/src/fallible_impl_from.rs index 87792b9fba47..19a122594cb7 100644 --- a/clippy_lints/src/fallible_impl_from.rs +++ b/clippy_lints/src/fallible_impl_from.rs @@ -48,7 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for FallibleImplFrom { fn lint_impl_body<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, impl_span: Span, impl_items: &[hir::ImplItemRef<'_>]) { use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; - use rustc_hir::*; + use rustc_hir::{Expr, ExprKind, ImplItemKind, QPath}; struct FindPanicUnwrap<'a, 'tcx> { lcx: &'a LateContext<'a, 'tcx>, diff --git a/clippy_lints/src/float_literal.rs b/clippy_lints/src/float_literal.rs index 8707259a2c88..18006f0534f0 100644 --- a/clippy_lints/src/float_literal.rs +++ b/clippy_lints/src/float_literal.rs @@ -7,7 +7,7 @@ use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::{f32, f64, fmt}; -use syntax::ast::*; +use syntax::ast::{FloatTy, LitFloatType, LitKind}; declare_clippy_lint! { /// **What it does:** Checks for float literals with a precision greater diff --git a/clippy_lints/src/format.rs b/clippy_lints/src/format.rs index 36ed7c475ed3..6c80b6525bb5 100644 --- a/clippy_lints/src/format.rs +++ b/clippy_lints/src/format.rs @@ -5,7 +5,7 @@ use crate::utils::{ }; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Arm, BorrowKind, Expr, ExprKind, MatchSource, PatKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 31e924e36abe..0ab6b1242b3f 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -4,7 +4,7 @@ use rustc::lint::in_external_macro; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use syntax::ast::*; +use syntax::ast::{BinOpKind, Block, Expr, ExprKind, StmtKind, UnOp}; declare_clippy_lint! { /// **What it does:** Checks for use of the non-existent `=*`, `=!` and `=-` diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index ce0bfea5160e..26b9f2cd613f 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -497,7 +497,7 @@ fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHash static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]]; fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { - use ty::TyKind::*; + use ty::TyKind::{Adt, Array, Bool, Char, Float, Int, RawPtr, Ref, Slice, Str, Tuple, Uint}; match ty.kind { // primitive types are never mutable Bool | Char | Int(_) | Uint(_) | Float(_) | Str => false, @@ -593,7 +593,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { type Map = Map<'tcx>; fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) { - use hir::ExprKind::*; + use hir::ExprKind::{AddrOf, Assign, AssignOp, Call, MethodCall}; if self.mutates_static { return; @@ -631,7 +631,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for StaticMutVisitor<'a, 'tcx> { } fn is_mutated_static(cx: &LateContext<'_, '_>, e: &hir::Expr<'_>) -> bool { - use hir::ExprKind::*; + use hir::ExprKind::{Field, Index, Path}; match e.kind { Path(ref qpath) => { diff --git a/clippy_lints/src/identity_conversion.rs b/clippy_lints/src/identity_conversion.rs index 86478f093c9e..3d0734219846 100644 --- a/clippy_lints/src/identity_conversion.rs +++ b/clippy_lints/src/identity_conversion.rs @@ -2,7 +2,7 @@ use crate::utils::{ match_def_path, match_trait_method, paths, same_tys, snippet, snippet_with_macro_callsite, span_lint_and_then, }; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, HirId, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/identity_op.rs b/clippy_lints/src/identity_op.rs index 1896751ff6ff..abd546870aae 100644 --- a/clippy_lints/src/identity_op.rs +++ b/clippy_lints/src/identity_op.rs @@ -1,5 +1,5 @@ use rustc::ty; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/if_let_some_result.rs b/clippy_lints/src/if_let_some_result.rs index a9826d586339..33e2471d5b8f 100644 --- a/clippy_lints/src/if_let_some_result.rs +++ b/clippy_lints/src/if_let_some_result.rs @@ -1,7 +1,7 @@ use crate::utils::{match_type, method_chain_args, paths, snippet_with_applicability, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{print, Expr, ExprKind, MatchSource, PatKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/if_not_else.rs b/clippy_lints/src/if_not_else.rs index 8deed2142038..4689e24f368e 100644 --- a/clippy_lints/src/if_not_else.rs +++ b/clippy_lints/src/if_not_else.rs @@ -4,7 +4,7 @@ use rustc::lint::in_external_macro; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{BinOpKind, Expr, ExprKind, UnOp}; use crate::utils::span_lint_and_help; diff --git a/clippy_lints/src/indexing_slicing.rs b/clippy_lints/src/indexing_slicing.rs index ac9442e96078..f4a7b798521f 100644 --- a/clippy_lints/src/indexing_slicing.rs +++ b/clippy_lints/src/indexing_slicing.rs @@ -3,7 +3,7 @@ use crate::consts::{constant, Constant}; use crate::utils::{higher, span_lint, span_lint_and_help}; use rustc::ty; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::RangeLimits; diff --git a/clippy_lints/src/infinite_iter.rs b/clippy_lints/src/infinite_iter.rs index cee54488df48..cd989c0ea6f6 100644 --- a/clippy_lints/src/infinite_iter.rs +++ b/clippy_lints/src/infinite_iter.rs @@ -1,4 +1,4 @@ -use rustc_hir::*; +use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/inherent_impl.rs b/clippy_lints/src/inherent_impl.rs index 058ee7265fbc..355e75d0d559 100644 --- a/clippy_lints/src/inherent_impl.rs +++ b/clippy_lints/src/inherent_impl.rs @@ -2,7 +2,7 @@ use crate::utils::{in_macro, span_lint_and_then}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::*; +use rustc_hir::{def_id, Crate, Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; diff --git a/clippy_lints/src/inline_fn_without_body.rs b/clippy_lints/src/inline_fn_without_body.rs index ed9a958f91b6..85c61ba23964 100644 --- a/clippy_lints/src/inline_fn_without_body.rs +++ b/clippy_lints/src/inline_fn_without_body.rs @@ -3,7 +3,7 @@ use crate::utils::span_lint_and_then; use crate::utils::sugg::DiagnosticBuilderExt; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{TraitItem, TraitItemKind, TraitMethod}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::{Attribute, Name}; diff --git a/clippy_lints/src/int_plus_one.rs b/clippy_lints/src/int_plus_one.rs index cb2d62407ce8..c6734427dab7 100644 --- a/clippy_lints/src/int_plus_one.rs +++ b/clippy_lints/src/int_plus_one.rs @@ -3,7 +3,7 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{BinOpKind, Expr, ExprKind, Lit, LitKind}; use crate::utils::{snippet_opt, span_lint_and_then}; diff --git a/clippy_lints/src/items_after_statements.rs b/clippy_lints/src/items_after_statements.rs index 6d944ae8c33a..13da725393b3 100644 --- a/clippy_lints/src/items_after_statements.rs +++ b/clippy_lints/src/items_after_statements.rs @@ -4,7 +4,7 @@ use crate::utils::span_lint; use matches::matches; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Block, ItemKind, StmtKind}; declare_clippy_lint! { /// **What it does:** Checks for items declared after some statement in a block. diff --git a/clippy_lints/src/large_enum_variant.rs b/clippy_lints/src/large_enum_variant.rs index 0cd02f21238d..39c8c4cfa693 100644 --- a/clippy_lints/src/large_enum_variant.rs +++ b/clippy_lints/src/large_enum_variant.rs @@ -3,7 +3,7 @@ use crate::utils::{snippet_opt, span_lint_and_then}; use rustc::ty::layout::LayoutOf; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind, VariantData}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/large_stack_arrays.rs b/clippy_lints/src/large_stack_arrays.rs index aa394c85e308..e08042bcbb26 100644 --- a/clippy_lints/src/large_stack_arrays.rs +++ b/clippy_lints/src/large_stack_arrays.rs @@ -1,6 +1,6 @@ use rustc::mir::interpret::ConstValue; use rustc::ty::{self, ConstKind}; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/len_zero.rs b/clippy_lints/src/len_zero.rs index aa538a4be9de..821ca2fefa4e 100644 --- a/clippy_lints/src/len_zero.rs +++ b/clippy_lints/src/len_zero.rs @@ -3,7 +3,7 @@ use rustc::ty; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::def_id::DefId; -use rustc_hir::*; +use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{Span, Spanned}; diff --git a/clippy_lints/src/let_underscore.rs b/clippy_lints/src/let_underscore.rs index c2a404ebee7c..5690a12141b9 100644 --- a/clippy_lints/src/let_underscore.rs +++ b/clippy_lints/src/let_underscore.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc::lint::in_external_macro; -use rustc_hir::*; +use rustc_hir::{PatKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index f98021bca459..a120e3a7517f 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -3,15 +3,21 @@ use rustc::hir::map::Map; use rustc::lint::in_external_macro; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::intravisit::*; +use rustc_hir::intravisit::{ + walk_fn_decl, walk_generic_param, walk_generics, walk_param_bound, walk_ty, NestedVisitorMap, Visitor, +}; use rustc_hir::FnRetTy::Return; -use rustc_hir::*; +use rustc_hir::{ + BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, + ItemKind, Lifetime, LifetimeName, ParamName, QPath, TraitBoundModifier, TraitItem, TraitItemKind, TraitMethod, Ty, + TyKind, WhereClause, WherePredicate, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::kw; -use crate::reexport::*; +use crate::reexport::Name; use crate::utils::{last_path_segment, span_lint, trait_ref_of_method}; declare_clippy_lint! { diff --git a/clippy_lints/src/literal_representation.rs b/clippy_lints/src/literal_representation.rs index 2419d42394e3..7c8001eebd47 100644 --- a/clippy_lints/src/literal_representation.rs +++ b/clippy_lints/src/literal_representation.rs @@ -7,7 +7,7 @@ use rustc::lint::in_external_macro; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind, Lit, LitFloatType, LitIntType, LitKind}; declare_clippy_lint! { /// **What it does:** Warns if a long integral or floating-point constant does diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index 393fbd2aaefc..eb15b104bea6 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1,5 +1,5 @@ use crate::consts::{constant, Constant}; -use crate::reexport::*; +use crate::reexport::Name; use crate::utils::paths; use crate::utils::usage::{is_unused, mutated_variables}; use crate::utils::{ @@ -19,13 +19,16 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{ + def_id, BinOpKind, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, GenericArg, HirId, LoopSource, + MatchSource, Mutability, Node, Pat, PatKind, QPath, Stmt, StmtKind, +}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::{BytePos, Symbol}; -use rustc_typeck::expr_use_visitor::*; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; use std::iter::{once, Iterator}; use std::mem; use syntax::ast; diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs index 72131084311a..d9d3611bc5a0 100644 --- a/clippy_lints/src/matches.rs +++ b/clippy_lints/src/matches.rs @@ -12,7 +12,10 @@ use rustc::lint::in_external_macro; use rustc::ty::{self, Ty}; use rustc_errors::Applicability; use rustc_hir::def::CtorKind; -use rustc_hir::*; +use rustc_hir::{ + print, Arm, BindingAnnotation, Block, BorrowKind, Expr, ExprKind, Local, MatchSource, Mutability, PatKind, QPath, + RangeEnd, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/methods/manual_saturating_arithmetic.rs b/clippy_lints/src/methods/manual_saturating_arithmetic.rs index 4e3c95f9f739..19f3c4478616 100644 --- a/clippy_lints/src/methods/manual_saturating_arithmetic.rs +++ b/clippy_lints/src/methods/manual_saturating_arithmetic.rs @@ -23,7 +23,10 @@ pub fn lint(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr< }; if ty.is_signed() { - use self::{MinMax::*, Sign::*}; + use self::{ + MinMax::{Max, Min}, + Sign::{Neg, Pos}, + }; let sign = if let Some(sign) = lit_sign(arith_rhs) { sign diff --git a/clippy_lints/src/methods/option_map_unwrap_or.rs b/clippy_lints/src/methods/option_map_unwrap_or.rs index 80a937aadb06..4df963a4f796 100644 --- a/clippy_lints/src/methods/option_map_unwrap_or.rs +++ b/clippy_lints/src/methods/option_map_unwrap_or.rs @@ -4,7 +4,7 @@ use rustc::hir::map::Map; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_path, NestedVisitorMap, Visitor}; -use rustc_hir::{self, *}; +use rustc_hir::{self, HirId, Path}; use rustc_lint::LateContext; use rustc_span::source_map::Span; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/minmax.rs b/clippy_lints/src/minmax.rs index b3431c053783..b02c993de526 100644 --- a/clippy_lints/src/minmax.rs +++ b/clippy_lints/src/minmax.rs @@ -1,6 +1,6 @@ use crate::consts::{constant_simple, Constant}; use crate::utils::{match_def_path, paths, span_lint}; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::cmp::Ordering; diff --git a/clippy_lints/src/misc.rs b/clippy_lints/src/misc.rs index 583bdd43df83..85d66db83b15 100644 --- a/clippy_lints/src/misc.rs +++ b/clippy_lints/src/misc.rs @@ -3,7 +3,10 @@ use matches::matches; use rustc::ty; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::*; +use rustc_hir::{ + def, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnDecl, HirId, Mutability, PatKind, Stmt, StmtKind, Ty, + TyKind, UnOp, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::{ExpnKind, Span}; diff --git a/clippy_lints/src/misc_early.rs b/clippy_lints/src/misc_early.rs index 3f17ac3de228..6e89f35143be 100644 --- a/clippy_lints/src/misc_early.rs +++ b/clippy_lints/src/misc_early.rs @@ -9,7 +9,10 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; -use syntax::ast::*; +use syntax::ast::{ + Block, Expr, ExprKind, GenericParamKind, Generics, Lit, LitFloatType, LitIntType, LitKind, NodeId, Pat, PatKind, + StmtKind, UnOp, +}; use syntax::visit::{walk_expr, FnKind, Visitor}; declare_clippy_lint! { diff --git a/clippy_lints/src/modulo_arithmetic.rs b/clippy_lints/src/modulo_arithmetic.rs index 238863e8c67b..7446b732c4b2 100644 --- a/clippy_lints/src/modulo_arithmetic.rs +++ b/clippy_lints/src/modulo_arithmetic.rs @@ -2,7 +2,7 @@ use crate::consts::{constant, Constant}; use crate::utils::{sext, span_lint_and_then}; use if_chain::if_chain; use rustc::ty::{self}; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::fmt::Display; diff --git a/clippy_lints/src/mul_add.rs b/clippy_lints/src/mul_add.rs index 5de936634991..57e56d8f959a 100644 --- a/clippy_lints/src/mul_add.rs +++ b/clippy_lints/src/mul_add.rs @@ -1,9 +1,9 @@ use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::*; +use crate::utils::{snippet, span_lint_and_sugg}; declare_clippy_lint! { /// **What it does:** Checks for expressions of the form `a * b + c` diff --git a/clippy_lints/src/multiple_crate_versions.rs b/clippy_lints/src/multiple_crate_versions.rs index d07b21bfa991..0bcce04e8120 100644 --- a/clippy_lints/src/multiple_crate_versions.rs +++ b/clippy_lints/src/multiple_crate_versions.rs @@ -4,7 +4,7 @@ use crate::utils::span_lint; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; -use syntax::ast::*; +use syntax::ast::Crate; use itertools::Itertools; diff --git a/clippy_lints/src/mut_reference.rs b/clippy_lints/src/mut_reference.rs index 2d70b65bb1ee..aeffcd34110e 100644 --- a/clippy_lints/src/mut_reference.rs +++ b/clippy_lints/src/mut_reference.rs @@ -1,7 +1,7 @@ use crate::utils::span_lint; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty}; -use rustc_hir::*; +use rustc_hir::{print, BorrowKind, Expr, ExprKind, Mutability}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/needless_bool.rs b/clippy_lints/src/needless_bool.rs index db4012146dff..7282874fdbd0 100644 --- a/clippy_lints/src/needless_bool.rs +++ b/clippy_lints/src/needless_bool.rs @@ -5,7 +5,7 @@ use crate::utils::sugg::Sugg; use crate::utils::{higher, parent_node_is_if_expr, span_lint, span_lint_and_sugg}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Block, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; @@ -62,7 +62,7 @@ declare_lint_pass!(NeedlessBool => [NEEDLESS_BOOL]); impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NeedlessBool { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) { - use self::Expression::*; + use self::Expression::{Bool, RetBool}; if let Some((ref pred, ref then_block, Some(ref else_expr))) = higher::if_block(&e) { let reduce = |ret, not| { let mut applicability = Applicability::MachineApplicable; @@ -191,7 +191,7 @@ fn check_comparison<'a, 'tcx>( right_false: Option<(impl FnOnce(Sugg<'a>) -> Sugg<'a>, &str)>, no_literal: Option<(impl FnOnce(Sugg<'a>, Sugg<'a>) -> Sugg<'a>, &str)>, ) { - use self::Expression::*; + use self::Expression::{Bool, Other}; if let ExprKind::Binary(_, ref left_side, ref right_side) = e.kind { let (l_ty, r_ty) = (cx.tables.expr_ty(left_side), cx.tables.expr_ty(right_side)); diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs index 7a0f3bdd3558..10782b9f3b4d 100644 --- a/clippy_lints/src/needless_pass_by_value.rs +++ b/clippy_lints/src/needless_pass_by_value.rs @@ -9,7 +9,7 @@ use rustc::ty::{self, TypeFoldable}; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir::intravisit::FnKind; -use rustc_hir::*; +use rustc_hir::{BindingAnnotation, Body, FnDecl, GenericArg, HirId, ItemKind, Node, PatKind, QPath, TyKind}; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits; use rustc_infer::traits::misc::can_type_implement_copy; diff --git a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs index efe5f26c4239..65643d89df57 100644 --- a/clippy_lints/src/neg_cmp_op_on_partial_ord.rs +++ b/clippy_lints/src/neg_cmp_op_on_partial_ord.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc::lint::in_external_macro; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/neg_multiply.rs b/clippy_lints/src/neg_multiply.rs index bd4ada23762b..4681e990df88 100644 --- a/clippy_lints/src/neg_multiply.rs +++ b/clippy_lints/src/neg_multiply.rs @@ -1,5 +1,5 @@ use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/non_copy_const.rs b/clippy_lints/src/non_copy_const.rs index 48ffc113546f..46e26b326971 100644 --- a/clippy_lints/src/non_copy_const.rs +++ b/clippy_lints/src/non_copy_const.rs @@ -7,7 +7,7 @@ use std::ptr; use rustc::ty::adjustment::Adjust; use rustc::ty::{Ty, TypeFlags}; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp}; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{InnerSpan, Span, DUMMY_SP}; diff --git a/clippy_lints/src/non_expressive_names.rs b/clippy_lints/src/non_expressive_names.rs index 5411e3246159..de5ae5d30322 100644 --- a/clippy_lints/src/non_expressive_names.rs +++ b/clippy_lints/src/non_expressive_names.rs @@ -4,7 +4,9 @@ use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::Span; use rustc_span::symbol::SymbolStr; use std::cmp::Ordering; -use syntax::ast::*; +use syntax::ast::{ + Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Ident, Item, ItemKind, Local, Mac, Pat, PatKind, +}; use syntax::attr; use syntax::visit::{walk_block, walk_expr, walk_pat, Visitor}; diff --git a/clippy_lints/src/option_env_unwrap.rs b/clippy_lints/src/option_env_unwrap.rs index 1af7793499f6..6dc6893bf71c 100644 --- a/clippy_lints/src/option_env_unwrap.rs +++ b/clippy_lints/src/option_env_unwrap.rs @@ -2,7 +2,7 @@ use crate::utils::{is_direct_expn_of, span_lint_and_help}; use if_chain::if_chain; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind}; declare_clippy_lint! { /// **What it does:** Checks for usage of `option_env!(...).unwrap()` and diff --git a/clippy_lints/src/overflow_check_conditional.rs b/clippy_lints/src/overflow_check_conditional.rs index df3f588f38a1..b90fdc232e72 100644 --- a/clippy_lints/src/overflow_check_conditional.rs +++ b/clippy_lints/src/overflow_check_conditional.rs @@ -1,6 +1,6 @@ use crate::utils::{span_lint, SpanlessEq}; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/panic_unimplemented.rs b/clippy_lints/src/panic_unimplemented.rs index b26ad1a5b45d..76a77e25de3c 100644 --- a/clippy_lints/src/panic_unimplemented.rs +++ b/clippy_lints/src/panic_unimplemented.rs @@ -1,6 +1,6 @@ use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, paths, span_lint}; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Span; diff --git a/clippy_lints/src/partialeq_ne_impl.rs b/clippy_lints/src/partialeq_ne_impl.rs index dfd25f1c9db6..1445df41c452 100644 --- a/clippy_lints/src/partialeq_ne_impl.rs +++ b/clippy_lints/src/partialeq_ne_impl.rs @@ -1,6 +1,6 @@ use crate::utils::{is_automatically_derived, span_lint_hir}; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/path_buf_push_overwrite.rs b/clippy_lints/src/path_buf_push_overwrite.rs index adaf8bb77a20..775a8ad0b933 100644 --- a/clippy_lints/src/path_buf_push_overwrite.rs +++ b/clippy_lints/src/path_buf_push_overwrite.rs @@ -1,7 +1,7 @@ use crate::utils::{match_type, paths, span_lint_and_sugg, walk_ptrs_ty}; use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::path::{Component, Path}; diff --git a/clippy_lints/src/precedence.rs b/clippy_lints/src/precedence.rs index 27e67bbe718c..8ba4e10c9660 100644 --- a/clippy_lints/src/precedence.rs +++ b/clippy_lints/src/precedence.rs @@ -3,7 +3,7 @@ use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; -use syntax::ast::*; +use syntax::ast::{BinOpKind, Expr, ExprKind, LitKind, UnOp}; declare_clippy_lint! { /// **What it does:** Checks for operations where precedence may be unclear @@ -123,7 +123,7 @@ fn is_arith_expr(expr: &Expr) -> bool { #[must_use] fn is_bit_op(op: BinOpKind) -> bool { - use syntax::ast::BinOpKind::*; + use syntax::ast::BinOpKind::{BitAnd, BitOr, BitXor, Shl, Shr}; match op { BitXor | BitAnd | BitOr | Shl | Shr => true, _ => false, @@ -132,7 +132,7 @@ fn is_bit_op(op: BinOpKind) -> bool { #[must_use] fn is_arith_op(op: BinOpKind) -> bool { - use syntax::ast::BinOpKind::*; + use syntax::ast::BinOpKind::{Add, Div, Mul, Rem, Sub}; match op { Add | Sub | Mul | Div | Rem => true, _ => false, diff --git a/clippy_lints/src/ptr.rs b/clippy_lints/src/ptr.rs index d868253b85cd..c1aee94aa421 100644 --- a/clippy_lints/src/ptr.rs +++ b/clippy_lints/src/ptr.rs @@ -8,7 +8,10 @@ use crate::utils::{ use if_chain::if_chain; use rustc::ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{ + BinOpKind, BodyId, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, + Lifetime, MutTy, Mutability, Node, PathSegment, QPath, TraitItem, TraitItemKind, TraitMethod, Ty, TyKind, +}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index 46c4746d2f56..f21c2985d194 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -1,11 +1,11 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::*; +use rustc_hir::{def, Block, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use crate::utils::paths::*; +use crate::utils::paths::{OPTION, OPTION_NONE}; use crate::utils::sugg::Sugg; use crate::utils::{higher, match_def_path, match_type, span_lint_and_then, SpanlessEq}; diff --git a/clippy_lints/src/ranges.rs b/clippy_lints/src/ranges.rs index 1be597877213..f1a93d508ce2 100644 --- a/clippy_lints/src/ranges.rs +++ b/clippy_lints/src/ranges.rs @@ -1,6 +1,6 @@ use if_chain::if_chain; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; diff --git a/clippy_lints/src/redundant_clone.rs b/clippy_lints/src/redundant_clone.rs index e419ae09a3f9..ddb0c7484348 100644 --- a/clippy_lints/src/redundant_clone.rs +++ b/clippy_lints/src/redundant_clone.rs @@ -529,7 +529,7 @@ impl TypeVisitor<'_> for ContainsRegion { } fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) { - use rustc::mir::Rvalue::*; + use rustc::mir::Rvalue::{Aggregate, BinaryOp, Cast, CheckedBinaryOp, Repeat, UnaryOp, Use}; let mut visit_op = |op: &mir::Operand<'_>| match op { mir::Operand::Copy(p) | mir::Operand::Move(p) => visit(p.local), diff --git a/clippy_lints/src/redundant_field_names.rs b/clippy_lints/src/redundant_field_names.rs index 57349715c784..a839a023e525 100644 --- a/clippy_lints/src/redundant_field_names.rs +++ b/clippy_lints/src/redundant_field_names.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint_and_sugg; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind}; declare_clippy_lint! { /// **What it does:** Checks for fields in struct literals where shorthands diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs index f0acd993480b..c8706c2b363b 100644 --- a/clippy_lints/src/redundant_pattern_matching.rs +++ b/clippy_lints/src/redundant_pattern_matching.rs @@ -1,6 +1,6 @@ use crate::utils::{match_qpath, paths, snippet, span_lint_and_then}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Arm, Expr, ExprKind, MatchSource, PatKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use syntax::ast::LitKind; diff --git a/clippy_lints/src/redundant_static_lifetimes.rs b/clippy_lints/src/redundant_static_lifetimes.rs index 9cebe310d5fe..98ec793de7c1 100644 --- a/clippy_lints/src/redundant_static_lifetimes.rs +++ b/clippy_lints/src/redundant_static_lifetimes.rs @@ -2,7 +2,7 @@ use crate::utils::{snippet, span_lint_and_then}; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; -use syntax::ast::*; +use syntax::ast::{Item, ItemKind, Ty, TyKind}; declare_clippy_lint! { /// **What it does:** Checks for constants and statics with an explicit `'static` lifetime. diff --git a/clippy_lints/src/regex.rs b/clippy_lints/src/regex.rs index 5de0e441367a..028b89b39b94 100644 --- a/clippy_lints/src/regex.rs +++ b/clippy_lints/src/regex.rs @@ -2,7 +2,7 @@ use crate::consts::{constant, Constant}; use crate::utils::{is_expn_of, match_def_path, match_type, paths, span_lint, span_lint_and_help}; use if_chain::if_chain; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::*; +use rustc_hir::{Block, BorrowKind, Crate, Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{BytePos, Span}; @@ -145,8 +145,8 @@ fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr<'_>) -> Option< } fn is_trivial_regex(s: ®ex_syntax::hir::Hir) -> Option<&'static str> { - use regex_syntax::hir::Anchor::*; - use regex_syntax::hir::HirKind::*; + use regex_syntax::hir::Anchor::{EndText, StartText}; + use regex_syntax::hir::HirKind::{Alternation, Anchor, Concat, Empty, Literal}; let is_literal = |e: &[regex_syntax::hir::Hir]| { e.iter().all(|e| match *e.kind() { diff --git a/clippy_lints/src/replace_consts.rs b/clippy_lints/src/replace_consts.rs index 66e1df72b25f..aca1ebbd5080 100644 --- a/clippy_lints/src/replace_consts.rs +++ b/clippy_lints/src/replace_consts.rs @@ -2,7 +2,7 @@ use crate::utils::{match_def_path, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/serde_api.rs b/clippy_lints/src/serde_api.rs index 63fdd599b51e..6820d1620bd1 100644 --- a/clippy_lints/src/serde_api.rs +++ b/clippy_lints/src/serde_api.rs @@ -1,5 +1,5 @@ use crate::utils::{get_trait_def_id, paths, span_lint}; -use rustc_hir::*; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/shadow.rs b/clippy_lints/src/shadow.rs index 8e2ede04476e..0dc2705550b9 100644 --- a/clippy_lints/src/shadow.rs +++ b/clippy_lints/src/shadow.rs @@ -1,9 +1,12 @@ -use crate::reexport::*; +use crate::reexport::Name; use crate::utils::{contains_name, higher, iter_input_pats, snippet, span_lint_and_then}; use rustc::lint::in_external_macro; use rustc::ty; use rustc_hir::intravisit::FnKind; -use rustc_hir::*; +use rustc_hir::{ + Block, Body, Expr, ExprKind, FnDecl, Guard, HirId, Local, MutTy, Pat, PatKind, Path, QPath, StmtKind, Ty, TyKind, + UnOp, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/slow_vector_initialization.rs b/clippy_lints/src/slow_vector_initialization.rs index 48d0e53d163e..71fcff33544e 100644 --- a/clippy_lints/src/slow_vector_initialization.rs +++ b/clippy_lints/src/slow_vector_initialization.rs @@ -4,7 +4,7 @@ use if_chain::if_chain; use rustc::hir::map::Map; use rustc_errors::Applicability; use rustc_hir::intravisit::{walk_block, walk_expr, walk_stmt, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{BindingAnnotation, Block, Expr, ExprKind, HirId, PatKind, QPath, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Symbol; diff --git a/clippy_lints/src/strings.rs b/clippy_lints/src/strings.rs index ffe7c13ec575..20ed4d9aac05 100644 --- a/clippy_lints/src/strings.rs +++ b/clippy_lints/src/strings.rs @@ -1,6 +1,6 @@ use rustc::lint::in_external_macro; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Spanned; diff --git a/clippy_lints/src/swap.rs b/clippy_lints/src/swap.rs index 7e699844ef23..a1f5dee2a9c3 100644 --- a/clippy_lints/src/swap.rs +++ b/clippy_lints/src/swap.rs @@ -7,7 +7,7 @@ use if_chain::if_chain; use matches::matches; use rustc::ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Block, Expr, ExprKind, PatKind, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::Symbol; diff --git a/clippy_lints/src/trait_bounds.rs b/clippy_lints/src/trait_bounds.rs index 858b505712d3..d343ec4a8483 100644 --- a/clippy_lints/src/trait_bounds.rs +++ b/clippy_lints/src/trait_bounds.rs @@ -1,6 +1,6 @@ use crate::utils::{in_macro, snippet, span_lint_and_help, SpanlessHash}; use rustc_data_structures::fx::FxHashMap; -use rustc_hir::*; +use rustc_hir::{GenericBound, Generics, WherePredicate}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; diff --git a/clippy_lints/src/transmute.rs b/clippy_lints/src/transmute.rs index e6a9aa3c9a63..68c924cea475 100644 --- a/clippy_lints/src/transmute.rs +++ b/clippy_lints/src/transmute.rs @@ -4,7 +4,7 @@ use crate::utils::{ use if_chain::if_chain; use rustc::ty::{self, Ty}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, TyKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use std::borrow::Cow; diff --git a/clippy_lints/src/trivially_copy_pass_by_ref.rs b/clippy_lints/src/trivially_copy_pass_by_ref.rs index 1bacb4683c38..e00bc2e090ae 100644 --- a/clippy_lints/src/trivially_copy_pass_by_ref.rs +++ b/clippy_lints/src/trivially_copy_pass_by_ref.rs @@ -8,7 +8,7 @@ use rustc::ty; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::intravisit::FnKind; -use rustc_hir::*; +use rustc_hir::{Body, FnDecl, HirId, ItemKind, MutTy, Mutability, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; diff --git a/clippy_lints/src/try_err.rs b/clippy_lints/src/try_err.rs index 15f77d62201d..a6624408ce05 100644 --- a/clippy_lints/src/try_err.rs +++ b/clippy_lints/src/try_err.rs @@ -3,7 +3,7 @@ use if_chain::if_chain; use rustc::lint::in_external_macro; use rustc::ty::Ty; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Arm, Expr, ExprKind, MatchSource}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index d23487b5b334..e9c0b0935fa9 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -12,7 +12,11 @@ use rustc::ty::{self, InferTy, Ty, TyCtxt, TypeckTables}; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_hir as hir; use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{ + BinOpKind, Body, Expr, ExprKind, FnDecl, FnRetTy, FnSig, GenericArg, GenericParamKind, HirId, ImplItem, + ImplItemKind, Item, ItemKind, Lifetime, Local, MatchSource, MutTy, Mutability, QPath, Stmt, StmtKind, TraitItem, + TraitItemKind, TraitMethod, TyKind, UnOp, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -1679,9 +1683,9 @@ fn detect_absurd_comparison<'a, 'tcx>( lhs: &'tcx Expr<'_>, rhs: &'tcx Expr<'_>, ) -> Option<(ExtremeExpr<'tcx>, AbsurdComparisonResult)> { - use crate::types::AbsurdComparisonResult::*; - use crate::types::ExtremeType::*; - use crate::utils::comparisons::*; + use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; + use crate::types::ExtremeType::{Maximum, Minimum}; + use crate::utils::comparisons::{normalize_comparison, Rel}; // absurd comparison only makes sense on primitive types // primitive types don't implement comparison operators with each other @@ -1726,7 +1730,7 @@ fn detect_absurd_comparison<'a, 'tcx>( } fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) -> Option> { - use crate::types::ExtremeType::*; + use crate::types::ExtremeType::{Maximum, Minimum}; let ty = cx.tables.expr_ty(expr); @@ -1755,8 +1759,8 @@ fn detect_extreme_expr<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AbsurdExtremeComparisons { fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr<'_>) { - use crate::types::AbsurdComparisonResult::*; - use crate::types::ExtremeType::*; + use crate::types::AbsurdComparisonResult::{AlwaysFalse, AlwaysTrue, InequalityImpossible}; + use crate::types::ExtremeType::{Maximum, Minimum}; if let ExprKind::Binary(ref cmp, ref lhs, ref rhs) = expr.kind { if let Some((culprit, result)) = detect_absurd_comparison(cx, cmp.node, lhs, rhs) { @@ -1863,7 +1867,7 @@ impl Ord for FullInt { } fn numeric_cast_precast_bounds<'a>(cx: &LateContext<'_, '_>, expr: &'a Expr<'_>) -> Option<(FullInt, FullInt)> { - use std::*; + use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize}; if let ExprKind::Cast(ref cast_exp, _) = expr.kind { let pre_cast_ty = cx.tables.expr_ty(cast_exp); @@ -1963,7 +1967,7 @@ fn upcast_comparison_bounds_err<'a, 'tcx>( rhs: &'tcx Expr<'_>, invert: bool, ) { - use crate::utils::comparisons::*; + use crate::utils::comparisons::Rel; if let Some((lb, ub)) = lhs_bounds { if let Some(norm_rhs_val) = node_as_const_fullint(cx, rhs) { diff --git a/clippy_lints/src/unicode.rs b/clippy_lints/src/unicode.rs index eaf9f2e85cb6..355d2ec0f1c7 100644 --- a/clippy_lints/src/unicode.rs +++ b/clippy_lints/src/unicode.rs @@ -1,6 +1,6 @@ use crate::utils::{is_allowed, snippet, span_lint_and_sugg}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{Expr, ExprKind, HirId}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/unsafe_removed_from_name.rs b/clippy_lints/src/unsafe_removed_from_name.rs index 023096398756..2b2df4241505 100644 --- a/clippy_lints/src/unsafe_removed_from_name.rs +++ b/clippy_lints/src/unsafe_removed_from_name.rs @@ -3,7 +3,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; use rustc_span::symbol::SymbolStr; -use syntax::ast::*; +use syntax::ast::{Ident, Item, ItemKind, UseTree, UseTreeKind}; declare_clippy_lint! { /// **What it does:** Checks for imports that remove "unsafe" from an item's diff --git a/clippy_lints/src/unwrap.rs b/clippy_lints/src/unwrap.rs index 4fd421e4af94..79dd93e64ff8 100644 --- a/clippy_lints/src/unwrap.rs +++ b/clippy_lints/src/unwrap.rs @@ -2,8 +2,8 @@ use crate::utils::{higher::if_block, match_type, paths, span_lint_and_then, usag use if_chain::if_chain; use rustc::hir::map::Map; use rustc::lint::in_external_macro; -use rustc_hir::intravisit::*; -use rustc_hir::*; +use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, NestedVisitorMap, Visitor}; +use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, HirId, Path, QPath, UnOp}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/use_self.rs b/clippy_lints/src/use_self.rs index f1d66c1bc25c..4170dcc7fadf 100644 --- a/clippy_lints/src/use_self.rs +++ b/clippy_lints/src/use_self.rs @@ -7,7 +7,10 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_item, walk_path, walk_ty, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{ + def, FnDecl, FnRetTy, FnSig, GenericArg, HirId, ImplItem, ImplItemKind, Item, ItemKind, Path, PathSegment, QPath, + TyKind, +}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::kw; diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 52ccdf95d57b..a4dc24cecc22 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -157,7 +157,7 @@ impl PrintVisitor { } fn next(&mut self, s: &'static str) -> String { - use std::collections::hash_map::Entry::*; + use std::collections::hash_map::Entry::{Occupied, Vacant}; match self.ids.entry(s) { // already there: start numbering from `1` Occupied(mut occ) => { diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index f5f35afa9baa..c62f95cd5624 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -3,7 +3,11 @@ use crate::utils::differing_macro_contexts; use rustc::ich::StableHashingContextProvider; use rustc::ty::TypeckTables; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; -use rustc_hir::*; +use rustc_hir::{ + BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg, + GenericArgs, Guard, Lifetime, LifetimeName, ParamName, Pat, PatKind, Path, PathSegment, QPath, Stmt, StmtKind, Ty, + TyKind, TypeBinding, +}; use rustc_lint::LateContext; use std::hash::Hash; use syntax::ast::Name; diff --git a/clippy_lints/src/utils/internal_lints.rs b/clippy_lints/src/utils/internal_lints.rs index 759feafc75b7..85fee84cb3b9 100644 --- a/clippy_lints/src/utils/internal_lints.rs +++ b/clippy_lints/src/utils/internal_lints.rs @@ -9,7 +9,7 @@ use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{Crate, Expr, ExprKind, HirId, Item, MutTy, Mutability, Path, Ty, TyKind}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass}; use rustc_span::source_map::{Span, Spanned}; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index b13648afda9e..2689cab2817f 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -40,7 +40,10 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; use rustc_hir::intravisit::{NestedVisitorMap, Visitor}; use rustc_hir::Node; -use rustc_hir::*; +use rustc_hir::{ + def, Arm, Block, Body, Constness, Crate, Expr, ExprKind, FnDecl, HirId, ImplItem, ImplItemKind, Item, ItemKind, + MatchSource, Param, Pat, PatKind, Path, PathSegment, QPath, TraitItem, TraitItemKind, TraitRef, TyKind, Unsafety, +}; use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::predicate_for_trait_def; use rustc_lint::{LateContext, Level, Lint, LintContext}; @@ -52,7 +55,7 @@ use smallvec::SmallVec; use syntax::ast::{self, Attribute, LitKind}; use crate::consts::{constant, Constant}; -use crate::reexport::*; +use crate::reexport::Name; /// Returns `true` if the two spans come from differing expansions (i.e., one is /// from a macro and one isn't). @@ -1289,7 +1292,7 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> { // Returns whether the type has #[must_use] attribute pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { - use ty::TyKind::*; + use ty::TyKind::{Adt, Array, Dynamic, Foreign, Opaque, RawPtr, Ref, Slice, Tuple}; match ty.kind { Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(), Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(), diff --git a/clippy_lints/src/utils/ptr.rs b/clippy_lints/src/utils/ptr.rs index 8a59bcc98549..3d97c18e9b4e 100644 --- a/clippy_lints/src/utils/ptr.rs +++ b/clippy_lints/src/utils/ptr.rs @@ -1,7 +1,7 @@ use crate::utils::{get_pat_name, match_var, snippet}; use rustc::hir::map::Map; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{Body, BodyId, Expr, ExprKind, Param}; use rustc_lint::LateContext; use rustc_span::source_map::Span; use std::borrow::Cow; diff --git a/clippy_lints/src/utils/sugg.rs b/clippy_lints/src/utils/sugg.rs index 5c9e3ab80bb5..278505859b72 100644 --- a/clippy_lints/src/utils/sugg.rs +++ b/clippy_lints/src/utils/sugg.rs @@ -426,7 +426,10 @@ enum Associativity { /// associative. #[must_use] fn associativity(op: &AssocOp) -> Associativity { - use syntax::util::parser::AssocOp::*; + use syntax::util::parser::AssocOp::{ + Add, As, Assign, AssignOp, BitAnd, BitOr, BitXor, Colon, Divide, DotDot, DotDotEq, Equal, Greater, + GreaterEqual, LAnd, LOr, Less, LessEqual, Modulus, Multiply, NotEqual, ShiftLeft, ShiftRight, Subtract, + }; match *op { Assign | AssignOp(_) => Associativity::Right, @@ -439,7 +442,7 @@ fn associativity(op: &AssocOp) -> Associativity { /// Converts a `hir::BinOp` to the corresponding assigning binary operator. fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { - use syntax::token::BinOpToken::*; + use syntax::token::BinOpToken::{And, Caret, Minus, Or, Percent, Plus, Shl, Shr, Slash, Star}; AssocOp::AssignOp(match op.node { hir::BinOpKind::Add => Plus, @@ -466,7 +469,9 @@ fn hirbinop2assignop(op: hir::BinOp) -> AssocOp { /// Converts an `ast::BinOp` to the corresponding assigning binary operator. fn astbinop2assignop(op: ast::BinOp) -> AssocOp { - use syntax::ast::BinOpKind::*; + use syntax::ast::BinOpKind::{ + Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub, + }; use syntax::token::BinOpToken; AssocOp::AssignOp(match op.node { diff --git a/clippy_lints/src/utils/usage.rs b/clippy_lints/src/utils/usage.rs index 8fff1c7a16cb..3e8b29295f39 100644 --- a/clippy_lints/src/utils/usage.rs +++ b/clippy_lints/src/utils/usage.rs @@ -4,11 +4,11 @@ use rustc::ty; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::Res; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; -use rustc_hir::*; +use rustc_hir::{def_id, Expr, HirId, Path}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_span::symbol::Ident; -use rustc_typeck::expr_use_visitor::*; +use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase}; use syntax::ast; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. diff --git a/clippy_lints/src/vec.rs b/clippy_lints/src/vec.rs index bc2c827b0afd..726a34856aeb 100644 --- a/clippy_lints/src/vec.rs +++ b/clippy_lints/src/vec.rs @@ -3,7 +3,7 @@ use crate::utils::{higher, is_copy, snippet_with_applicability, span_lint_and_su use if_chain::if_chain; use rustc::ty::{self, Ty}; use rustc_errors::Applicability; -use rustc_hir::*; +use rustc_hir::{BorrowKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; diff --git a/clippy_lints/src/wildcard_dependencies.rs b/clippy_lints/src/wildcard_dependencies.rs index 2aa68842da41..0be168d563ab 100644 --- a/clippy_lints/src/wildcard_dependencies.rs +++ b/clippy_lints/src/wildcard_dependencies.rs @@ -2,7 +2,7 @@ use crate::utils::span_lint; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::DUMMY_SP; -use syntax::ast::*; +use syntax::ast::Crate; use if_chain::if_chain; diff --git a/clippy_lints/src/write.rs b/clippy_lints/src/write.rs index 0be52c2aa3d6..904e2fab07ad 100644 --- a/clippy_lints/src/write.rs +++ b/clippy_lints/src/write.rs @@ -9,7 +9,7 @@ use rustc_parse::parser; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::symbol::Symbol; use rustc_span::{BytePos, Span}; -use syntax::ast::*; +use syntax::ast::{Expr, ExprKind, Mac, StrLit, StrStyle}; use syntax::token; use syntax::tokenstream::TokenStream; @@ -317,7 +317,9 @@ fn newline_span(fmtstr: &StrLit) -> Span { /// ``` #[allow(clippy::too_many_lines)] fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &TokenStream, is_write: bool) -> (Option, Option) { - use fmt_macros::*; + use fmt_macros::{ + AlignUnknown, ArgumentImplicitlyIs, ArgumentIs, ArgumentNamed, CountImplied, FormatSpec, Parser, Piece, + }; let tts = tts.clone(); let mut parser = parser::Parser::new(&cx.sess.parse_sess, tts, None, false, false, None); diff --git a/clippy_lints/src/zero_div_zero.rs b/clippy_lints/src/zero_div_zero.rs index f36da58843f3..42cb9a77db02 100644 --- a/clippy_lints/src/zero_div_zero.rs +++ b/clippy_lints/src/zero_div_zero.rs @@ -1,7 +1,7 @@ use crate::consts::{constant_simple, Constant}; use crate::utils::span_lint_and_help; use if_chain::if_chain; -use rustc_hir::*; +use rustc_hir::{BinOpKind, Expr, ExprKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; diff --git a/src/driver.rs b/src/driver.rs index 097b796e785b..7865f6bb9dd0 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -15,7 +15,7 @@ extern crate rustc_interface; use rustc::ty::TyCtxt; use rustc_interface::interface; -use rustc_tools_util::*; +use rustc_tools_util::VersionInfo; use lazy_static::lazy_static; use std::borrow::Cow; @@ -93,7 +93,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks { #[allow(clippy::find_map, clippy::filter_map)] fn describe_lints() { - use lintlist::*; + use lintlist::{Level, Lint, ALL_LINTS, LINT_LEVELS}; use std::collections::HashSet; println!( diff --git a/src/main.rs b/src/main.rs index 8f9afb95337d..93e6996be069 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] -use rustc_tools_util::*; +use rustc_tools_util::VersionInfo; const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. From b562a519e69847d918d117dd9b729f92c7749d34 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 21 Feb 2020 09:40:13 +0100 Subject: [PATCH 09/10] Don't use use ty::TyKind::* --- clippy_lints/src/functions.rs | 11 +++++------ clippy_lints/src/utils/mod.rs | 16 +++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 26b9f2cd613f..620ec1f49510 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -497,18 +497,17 @@ fn is_mutable_pat(cx: &LateContext<'_, '_>, pat: &hir::Pat<'_>, tys: &mut FxHash static KNOWN_WRAPPER_TYS: &[&[&str]] = &[&["alloc", "rc", "Rc"], &["std", "sync", "Arc"]]; fn is_mutable_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, span: Span, tys: &mut FxHashSet) -> bool { - use ty::TyKind::{Adt, Array, Bool, Char, Float, Int, RawPtr, Ref, Slice, Str, Tuple, Uint}; match ty.kind { // primitive types are never mutable - Bool | Char | Int(_) | Uint(_) | Float(_) | Str => false, - Adt(ref adt, ref substs) => { + ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, + ty::Adt(ref adt, ref substs) => { tys.insert(adt.did) && !ty.is_freeze(cx.tcx, cx.param_env, span) || KNOWN_WRAPPER_TYS.iter().any(|path| match_def_path(cx, adt.did, path)) && substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)) }, - Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)), - Array(ty, _) | Slice(ty) => is_mutable_ty(cx, ty, span, tys), - RawPtr(ty::TypeAndMut { ty, mutbl }) | Ref(_, ty, mutbl) => { + ty::Tuple(ref substs) => substs.types().any(|ty| is_mutable_ty(cx, ty, span, tys)), + ty::Array(ty, _) | ty::Slice(ty) => is_mutable_ty(cx, ty, span, tys), + ty::RawPtr(ty::TypeAndMut { ty, mutbl }) | ty::Ref(_, ty, mutbl) => { mutbl == hir::Mutability::Mut || is_mutable_ty(cx, ty, span, tys) }, // calling something constitutes a side effect, so return true on all callables diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 2689cab2817f..708e3feef293 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1292,17 +1292,19 @@ pub fn must_use_attr(attrs: &[Attribute]) -> Option<&Attribute> { // Returns whether the type has #[must_use] attribute pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool { - use ty::TyKind::{Adt, Array, Dynamic, Foreign, Opaque, RawPtr, Ref, Slice, Tuple}; match ty.kind { - Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(), - Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(), - Slice(ref ty) | Array(ref ty, _) | RawPtr(ty::TypeAndMut { ref ty, .. }) | Ref(_, ref ty, _) => { + ty::Adt(ref adt, _) => must_use_attr(&cx.tcx.get_attrs(adt.did)).is_some(), + ty::Foreign(ref did) => must_use_attr(&cx.tcx.get_attrs(*did)).is_some(), + ty::Slice(ref ty) + | ty::Array(ref ty, _) + | ty::RawPtr(ty::TypeAndMut { ref ty, .. }) + | ty::Ref(_, ref ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays is_must_use_ty(cx, *ty) }, - Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), - Opaque(ref def_id, _) => { + ty::Tuple(ref substs) => substs.types().any(|ty| is_must_use_ty(cx, ty)), + ty::Opaque(ref def_id, _) => { for (predicate, _) in cx.tcx.predicates_of(*def_id).predicates { if let ty::Predicate::Trait(ref poly_trait_predicate, _) = predicate { if must_use_attr(&cx.tcx.get_attrs(poly_trait_predicate.skip_binder().trait_ref.def_id)).is_some() { @@ -1312,7 +1314,7 @@ pub fn is_must_use_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> boo } false }, - Dynamic(binder, _) => { + ty::Dynamic(binder, _) => { for predicate in binder.skip_binder().iter() { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate { if must_use_attr(&cx.tcx.get_attrs(trait_ref.def_id)).is_some() { From 4dd2252b17915a6b11b8e9ea4bc4500e80437a60 Mon Sep 17 00:00:00 2001 From: flip1995 Date: Fri, 21 Feb 2020 10:15:38 +0100 Subject: [PATCH 10/10] Fix suggestion for weird formattings --- clippy_lints/src/wildcard_imports.rs | 26 ++++++++++++++++++++------ tests/ui/wildcard_imports.fixed | 9 +++++++++ tests/ui/wildcard_imports.rs | 10 ++++++++++ tests/ui/wildcard_imports.stderr | 16 +++++++++++++++- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/wildcard_imports.rs b/clippy_lints/src/wildcard_imports.rs index 3e8d28a22932..17e067a095de 100644 --- a/clippy_lints/src/wildcard_imports.rs +++ b/clippy_lints/src/wildcard_imports.rs @@ -1,4 +1,4 @@ -use crate::utils::{in_macro, snippet_with_applicability, span_lint_and_sugg}; +use crate::utils::{in_macro, snippet, snippet_with_applicability, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ @@ -46,6 +46,9 @@ declare_clippy_lint! { /// **Known problems:** If macros are imported through the wildcard, this macro is not included /// by the suggestion and has to be added by hand. /// + /// Applying the suggestion when explicit imports of the things imported with a glob import + /// exist, may result in `unused_imports` warnings. + /// /// **Example:** /// /// Bad: @@ -82,16 +85,27 @@ impl LateLintPass<'_, '_> for WildcardImports { if !used_imports.is_empty(); // Already handled by `unused_imports` then { let mut applicability = Applicability::MachineApplicable; - let import_source = snippet_with_applicability(cx, use_path.span, "..", &mut applicability); - let (span, braced_glob) = if import_source.is_empty() { + let import_source_snippet = snippet_with_applicability(cx, use_path.span, "..", &mut applicability); + let (span, braced_glob) = if import_source_snippet.is_empty() { // This is a `_::{_, *}` import + // In this case `use_path.span` is empty and ends directly in front of the `*`, + // so we need to extend it by one byte. ( use_path.span.with_hi(use_path.span.hi() + BytePos(1)), true, ) } else { + // In this case, the `use_path.span` ends right before the `::*`, so we need to + // extend it up to the `*`. Since it is hard to find the `*` in weird + // formattings like `use _ :: *;`, we extend it up to, but not including the + // `;`. In nested imports, like `use _::{inner::*, _}` there is no `;` and we + // can just use the end of the item span + let mut span = use_path.span.with_hi(item.span.hi()); + if snippet(cx, span, "").ends_with(';') { + span = use_path.span.with_hi(item.span.hi() - BytePos(1)); + } ( - use_path.span.with_hi(use_path.span.hi() + BytePos(3)), + span, false, ) }; @@ -111,10 +125,10 @@ impl LateLintPass<'_, '_> for WildcardImports { } }; - let sugg = if import_source.is_empty() { + let sugg = if braced_glob { imports_string } else { - format!("{}::{}", import_source, imports_string) + format!("{}::{}", import_source_snippet, imports_string) }; let (lint, message) = if let Res::Def(DefKind::Enum, _) = use_path.res { diff --git a/tests/ui/wildcard_imports.fixed b/tests/ui/wildcard_imports.fixed index 398c3b56572b..f447a92715dc 100644 --- a/tests/ui/wildcard_imports.fixed +++ b/tests/ui/wildcard_imports.fixed @@ -145,3 +145,12 @@ fn test_reexported() { let _ = ExportedStruct; let _ = ExportedEnum::A; } + +#[rustfmt::skip] +fn test_weird_formatting() { + use crate:: in_fn_test::exported; + use crate:: fn_mod::foo; + + exported(); + foo(); +} diff --git a/tests/ui/wildcard_imports.rs b/tests/ui/wildcard_imports.rs index 10ab25e02ade..3fd66763a9fc 100644 --- a/tests/ui/wildcard_imports.rs +++ b/tests/ui/wildcard_imports.rs @@ -145,3 +145,13 @@ fn test_reexported() { let _ = ExportedStruct; let _ = ExportedEnum::A; } + +#[rustfmt::skip] +fn test_weird_formatting() { + use crate:: in_fn_test:: * ; + use crate:: fn_mod:: + *; + + exported(); + foo(); +} diff --git a/tests/ui/wildcard_imports.stderr b/tests/ui/wildcard_imports.stderr index ca300fbaad49..bebd9c1f8520 100644 --- a/tests/ui/wildcard_imports.stderr +++ b/tests/ui/wildcard_imports.stderr @@ -78,5 +78,19 @@ error: usage of wildcard import LL | use crate::in_fn_test::*; | ^^^^^^^^^^^^^^^^^^^^ help: try: `crate::in_fn_test::{ExportedEnum, ExportedStruct, exported}` -error: aborting due to 13 previous errors +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:151:9 + | +LL | use crate:: in_fn_test:: * ; + | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `crate:: in_fn_test::exported` + +error: usage of wildcard import + --> $DIR/wildcard_imports.rs:152:9 + | +LL | use crate:: fn_mod:: + | _________^ +LL | | *; + | |_________^ help: try: `crate:: fn_mod::foo` + +error: aborting due to 15 previous errors