Skip to content

Commit 7147762

Browse files
committed
Restrict lint logic and cargo uitest again.
Restrict lint logic to apply on edition2018 only. And update test reference.
1 parent 37abf6d commit 7147762

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

clippy_lints/src/single_component_use_path.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
44
use syntax::ast::{Item, ItemKind};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
7+
use rustc_span::edition::Edition;
78

89
declare_clippy_lint! {
910
/// **What it does:** Checking for imports with single component use path.
@@ -32,6 +33,7 @@ declare_lint_pass!(SingleComponentUsePath => [SINGLE_COMPONENT_USE_PATH]);
3233
impl EarlyLintPass for SingleComponentUsePath {
3334
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
3435
if_chain! {
36+
if cx.sess.opts.edition == Edition::Edition2018;
3537
if let ItemKind::Use(use_tree) = &item.kind;
3638
if let segments = &use_tree.prefix.segments;
3739
if segments.len() == 1;

tests/ui/single_component_use_path.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-rustfix
2+
// compile-flags: --edition 2018
23
#![warn(clippy::single_component_use_path)]
34

45
extern crate semver;

tests/ui/single_component_use_path.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0254]: the name `semver` is defined multiple times
2-
--> $DIR/single_component_use_path.rs:5:5
2+
--> $DIR/single_component_use_path.rs:6:5
33
|
44
LL | extern crate semver;
55
| -------------------- previous import of the extern crate `semver` here
@@ -9,7 +9,7 @@ LL | use semver;
99
= note: `semver` must be defined only once in the type namespace of this module
1010

1111
error: this import is redundant
12-
--> $DIR/single_component_use_path.rs:5:1
12+
--> $DIR/single_component_use_path.rs:6:1
1313
|
1414
LL | use semver;
1515
| ^^^^^^^^^^^ help: remove it entirely

0 commit comments

Comments
 (0)