Skip to content

Commit e342047

Browse files
committed
Auto merge of #5029 - flip1995:wildcard_imports, r=phansch
New Lint: `wildcard imports` Fixes #1228 ### A few notes: - I put this lint in the pedantic group, even though in the issue restriction was mentioned. - Every fallout fix was automatically applied by `cargo fix` (This produced 3 `unused_imports` warnings) and are in commit 7e834c8. So reverting these changes wouldn't be a problem. ### A few ideas: - A configuration to specify the amount of imported Items, where a `*` might be better. - ~~A configuration to disable the lint for enums. Or just disable the lint for enums, since there is [`enum_glob_use`](https://rust-lang.github.io/rust-clippy/master/index.html#enum_glob_use)~~ I moved `enum_glob_use` into this lint in 12937f0 ### A few quotes from the issue: > Is there a way to ask the compiler about the modules or symbols that the current file is using? Yes there is. I found it, once I was nearly finished implementing it myself. See 321d64a > one hard optional feature would be to figure out what is currently used and add a suggestion to replace it with a full import list. Yeah that was pretty hard, until I found the query for this. Queries are cool, but too hard to find. > FWIW VS Code and Intellij IDEA both offer imports deglobbing which replace * with required imports. And now, Clippy can do this too! 🎉 --- Your thoughts on the notes/ideas? changelog: Add new lint [`wildcard imports`]. Add suggestion to [`enum_glob_use`]
2 parents acfcbee + 4dd2252 commit e342047

File tree

130 files changed

+888
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+888
-250
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ Released 2018-09-13
14191419
[`while_let_on_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#while_let_on_iterator
14201420
[`wildcard_dependencies`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_dependencies
14211421
[`wildcard_enum_match_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_enum_match_arm
1422+
[`wildcard_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports
14221423
[`wildcard_in_or_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_in_or_patterns
14231424
[`write_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_literal
14241425
[`write_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#write_with_newline

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
77

8-
[There are 356 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are 357 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

1010
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1111

clippy_dev/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

33
use clap::{App, Arg, SubCommand};
4-
use clippy_dev::*;
4+
use clippy_dev::{
5+
gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
6+
replace_region_in_file, Lint, DOCS_LINK,
7+
};
58
use std::path::Path;
69

710
mod fmt;

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::utils::span_lint;
2-
use rustc_hir::*;
2+
use rustc_hir::{Expr, ExprKind};
33
use rustc_lint::{LateContext, LateLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55
use rustc_span::symbol;

clippy_lints/src/as_conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc::lint::in_external_macro;
22
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
33
use rustc_session::{declare_lint_pass, declare_tool_lint};
4-
use syntax::ast::*;
4+
use syntax::ast::{Expr, ExprKind};
55

66
use crate::utils::span_lint_and_help;
77

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::consts::{constant, Constant};
22
use crate::utils::paths;
33
use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_lint_and_help};
44
use if_chain::if_chain;
5-
use rustc_hir::*;
5+
use rustc_hir::{Expr, ExprKind, PatKind, UnOp};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use syntax::ast::LitKind;

clippy_lints/src/assign_ops.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ fn lint_misrefactored_assign_op(
231231

232232
#[must_use]
233233
fn is_commutative(op: hir::BinOpKind) -> bool {
234-
use rustc_hir::BinOpKind::*;
234+
use rustc_hir::BinOpKind::{
235+
Add, And, BitAnd, BitOr, BitXor, Div, Eq, Ge, Gt, Le, Lt, Mul, Ne, Or, Rem, Shl, Shr, Sub,
236+
};
235237
match op {
236238
Add | Mul | And | Or | BitXor | BitAnd | BitOr | Eq | Ne => true,
237239
Sub | Div | Rem | Shl | Shr | Lt | Le | Ge | Gt => false,

clippy_lints/src/atomic_ordering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::utils::{match_def_path, span_lint_and_help};
22
use if_chain::if_chain;
33
use rustc::ty;
44
use rustc_hir::def_id::DefId;
5-
use rustc_hir::*;
5+
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88

clippy_lints/src/attrs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! checks for attributes
22
3-
use crate::reexport::*;
3+
use crate::reexport::Name;
44
use crate::utils::{
55
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_sugg,
66
span_lint_and_then, without_block_comments,
@@ -9,7 +9,9 @@ use if_chain::if_chain;
99
use rustc::lint::in_external_macro;
1010
use rustc::ty;
1111
use rustc_errors::Applicability;
12-
use rustc_hir::*;
12+
use rustc_hir::{
13+
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitItem, TraitItemKind, TraitMethod,
14+
};
1315
use rustc_lint::{CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
1416
use rustc_session::{declare_lint_pass, declare_tool_lint};
1517
use rustc_span::source_map::Span;

clippy_lints/src/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::utils::sugg::Sugg;
33
use crate::utils::{span_lint, span_lint_and_then};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
6-
use rustc_hir::*;
6+
use rustc_hir::{BinOpKind, Expr, ExprKind};
77
use rustc_lint::{LateContext, LateLintPass};
88
use rustc_session::{declare_tool_lint, impl_lint_pass};
99
use rustc_span::source_map::Span;

0 commit comments

Comments
 (0)