Skip to content

Commit 90ff6d5

Browse files
committed
Don't handle renaming imports.
1 parent baf3b07 commit 90ff6d5

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

clippy_lints/src/single_component_use_path.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::span_lint_and_sugg;
22
use rustc_lint::{EarlyLintPass, EarlyContext};
33
use rustc_session::{declare_lint_pass, declare_tool_lint};
4-
use syntax::ast::{Item, ItemKind};
4+
use syntax::ast::{Item, ItemKind, UseTreeKind};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_span::edition::Edition;
@@ -17,11 +17,11 @@ declare_clippy_lint! {
1717
/// **Example:**
1818
///
1919
/// ```rust, ignore
20-
/// use bit_vec;
20+
/// use regex;
2121
///
2222
/// fn main() {
23-
/// bit_vec::BitVec::new();
24-
///}
23+
/// regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$");
24+
/// }
2525
///```
2626
pub SINGLE_COMPONENT_USE_PATH,
2727
style,
@@ -37,6 +37,7 @@ impl EarlyLintPass for SingleComponentUsePath {
3737
if let ItemKind::Use(use_tree) = &item.kind;
3838
if let segments = &use_tree.prefix.segments;
3939
if segments.len() == 1;
40+
if let UseTreeKind::Simple(None, _, _) = use_tree.kind;
4041
then {
4142
span_lint_and_sugg(
4243
cx,

tests/ui/single_component_use_path.fixed

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@
55

66

77
fn main() {
8-
let version = semver::Version::parse("1.2.3").unwrap();
9-
println!("Version: {}", version);
8+
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
109
}

tests/ui/single_component_use_path.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// compile-flags: --edition 2018
33
#![warn(clippy::single_component_use_path)]
44

5-
use semver;
5+
use regex;
66

77
fn main() {
8-
let version = semver::Version::parse("1.2.3").unwrap();
9-
println!("Version: {}", version);
8+
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
109
}
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
error[E0432]: unresolved import `semver`
2-
--> $DIR/single_component_use_path.rs:5:5
3-
|
4-
LL | use semver;
5-
| ^^^^^^ no `semver` external crate
6-
71
error: this import is redundant
82
--> $DIR/single_component_use_path.rs:5:1
93
|
10-
LL | use semver;
11-
| ^^^^^^^^^^^ help: remove it entirely
4+
LL | use regex;
5+
| ^^^^^^^^^^ help: remove it entirely
126
|
137
= note: `-D clippy::single-component-use-path` implied by `-D warnings`
148

15-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1610

17-
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)