Skip to content

Commit

Permalink
Exclude reexport imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongmao86 committed Jan 29, 2020
1 parent 4c63760 commit 331b504
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2310,7 +2310,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
&format!("used `unwrap()` on `{}` value", kind,),
&format!(
"if you don't want to handle the `{}` case gracefully, consider \
using `expect()` to provide a better panic message",
using `expect()` to provide a better panic message",
none_value,
),
);
Expand Down Expand Up @@ -2679,7 +2679,7 @@ fn lint_filter_flat_map<'a, 'tcx>(
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`";
and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
}
}
Expand All @@ -2695,7 +2695,7 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
and filtering by returning `iter::empty()`";
and filtering by returning `iter::empty()`";
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
}
}
Expand Down Expand Up @@ -3148,7 +3148,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(

let msg = format!(
"called `{0}` (or with one of deref aliases) on an Option value. \
This can be done more directly by calling `{1}` instead",
This can be done more directly by calling `{1}` instead",
current_method, hint
);
span_lint_and_sugg(
Expand Down
9 changes: 8 additions & 1 deletion clippy_lints/src/single_component_path_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ declare_clippy_lint! {
/// fn main() {
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
/// }
///```
/// ```
/// Better as
/// ```rust, ignore
/// fn main() {
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
/// }
/// ```
pub SINGLE_COMPONENT_PATH_IMPORTS,
style,
"imports with single component path are redundant"
Expand All @@ -34,6 +40,7 @@ impl EarlyLintPass for SingleComponentPathImports {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if_chain! {
if cx.sess.opts.edition == Edition::Edition2018;
if !item.vis.node.is_pub();
if let ItemKind::Use(use_tree) = &item.kind;
if let segments = &use_tree.prefix.segments;
if segments.len() == 1;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl Types {
OPTION_OPTION,
hir_ty.span,
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
enum if you need to distinguish all 3 cases",
enum if you need to distinguish all 3 cases",
);
return; // don't recurse into the type
}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/single_component_path_imports.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// run-rustfix
// compile-flags: --edition 2018
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]


use serde as edres;
pub use serde;

fn main() {
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/single_component_path_imports.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-rustfix
// compile-flags: --edition 2018
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]

use regex;
use serde as edres;
pub use serde;

fn main() {
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/single_component_path_imports.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this import is redundant
--> $DIR/single_component_path_imports.rs:5:1
--> $DIR/single_component_path_imports.rs:6:1
|
LL | use regex;
| ^^^^^^^^^^ help: remove it entirely
Expand Down

0 comments on commit 331b504

Please sign in to comment.