Skip to content

Commit 331b504

Browse files
committed
Exclude reexport imports.
1 parent 4c63760 commit 331b504

File tree

6 files changed

+19
-7
lines changed

6 files changed

+19
-7
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
23102310
&format!("used `unwrap()` on `{}` value", kind,),
23112311
&format!(
23122312
"if you don't want to handle the `{}` case gracefully, consider \
2313-
using `expect()` to provide a better panic message",
2313+
using `expect()` to provide a better panic message",
23142314
none_value,
23152315
),
23162316
);
@@ -2679,7 +2679,7 @@ fn lint_filter_flat_map<'a, 'tcx>(
26792679
if match_trait_method(cx, expr, &paths::ITERATOR) {
26802680
let msg = "called `filter(p).flat_map(q)` on an `Iterator`";
26812681
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
2682-
and filtering by returning `iter::empty()`";
2682+
and filtering by returning `iter::empty()`";
26832683
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
26842684
}
26852685
}
@@ -2695,7 +2695,7 @@ fn lint_filter_map_flat_map<'a, 'tcx>(
26952695
if match_trait_method(cx, expr, &paths::ITERATOR) {
26962696
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`";
26972697
let hint = "this is more succinctly expressed by calling `.flat_map(..)` \
2698-
and filtering by returning `iter::empty()`";
2698+
and filtering by returning `iter::empty()`";
26992699
span_lint_and_help(cx, FILTER_MAP, expr.span, msg, hint);
27002700
}
27012701
}
@@ -3148,7 +3148,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
31483148

31493149
let msg = format!(
31503150
"called `{0}` (or with one of deref aliases) on an Option value. \
3151-
This can be done more directly by calling `{1}` instead",
3151+
This can be done more directly by calling `{1}` instead",
31523152
current_method, hint
31533153
);
31543154
span_lint_and_sugg(

clippy_lints/src/single_component_path_imports.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ declare_clippy_lint! {
2222
/// fn main() {
2323
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
2424
/// }
25-
///```
25+
/// ```
26+
/// Better as
27+
/// ```rust, ignore
28+
/// fn main() {
29+
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
30+
/// }
31+
/// ```
2632
pub SINGLE_COMPONENT_PATH_IMPORTS,
2733
style,
2834
"imports with single component path are redundant"
@@ -34,6 +40,7 @@ impl EarlyLintPass for SingleComponentPathImports {
3440
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
3541
if_chain! {
3642
if cx.sess.opts.edition == Edition::Edition2018;
43+
if !item.vis.node.is_pub();
3744
if let ItemKind::Use(use_tree) = &item.kind;
3845
if let segments = &use_tree.prefix.segments;
3946
if segments.len() == 1;

clippy_lints/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl Types {
316316
OPTION_OPTION,
317317
hir_ty.span,
318318
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
319-
enum if you need to distinguish all 3 cases",
319+
enum if you need to distinguish all 3 cases",
320320
);
321321
return; // don't recurse into the type
322322
}

tests/ui/single_component_path_imports.fixed

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// run-rustfix
22
// compile-flags: --edition 2018
33
#![warn(clippy::single_component_path_imports)]
4+
#![allow(unused_imports)]
45

56

7+
use serde as edres;
8+
pub use serde;
69

710
fn main() {
811
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();

tests/ui/single_component_path_imports.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// run-rustfix
22
// compile-flags: --edition 2018
33
#![warn(clippy::single_component_path_imports)]
4+
#![allow(unused_imports)]
45

56
use regex;
67
use serde as edres;
8+
pub use serde;
79

810
fn main() {
911
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();

tests/ui/single_component_path_imports.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this import is redundant
2-
--> $DIR/single_component_path_imports.rs:5:1
2+
--> $DIR/single_component_path_imports.rs:6:1
33
|
44
LL | use regex;
55
| ^^^^^^^^^^ help: remove it entirely

0 commit comments

Comments
 (0)