Skip to content

Commit

Permalink
Restrict lint logic and cargo uitest again.
Browse files Browse the repository at this point in the history
Restrict lint logic to apply on edition2018 only. And update test
reference.
  • Loading branch information
xiongmao86 committed Jan 25, 2020
1 parent 37abf6d commit 7147762
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions clippy_lints/src/single_component_use_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_session::{declare_lint_pass, declare_tool_lint};
use syntax::ast::{Item, ItemKind};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_span::edition::Edition;

declare_clippy_lint! {
/// **What it does:** Checking for imports with single component use path.
Expand Down Expand Up @@ -32,6 +33,7 @@ declare_lint_pass!(SingleComponentUsePath => [SINGLE_COMPONENT_USE_PATH]);
impl EarlyLintPass for SingleComponentUsePath {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
if_chain! {
if cx.sess.opts.edition == Edition::Edition2018;
if let ItemKind::Use(use_tree) = &item.kind;
if let segments = &use_tree.prefix.segments;
if segments.len() == 1;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/single_component_use_path.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-rustfix
// compile-flags: --edition 2018
#![warn(clippy::single_component_use_path)]

extern crate semver;
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/single_component_use_path.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0254]: the name `semver` is defined multiple times
--> $DIR/single_component_use_path.rs:5:5
--> $DIR/single_component_use_path.rs:6:5
|
LL | extern crate semver;
| -------------------- previous import of the extern crate `semver` here
Expand All @@ -9,7 +9,7 @@ LL | use semver;
= note: `semver` must be defined only once in the type namespace of this module

error: this import is redundant
--> $DIR/single_component_use_path.rs:5:1
--> $DIR/single_component_use_path.rs:6:1
|
LL | use semver;
| ^^^^^^^^^^^ help: remove it entirely
Expand Down

0 comments on commit 7147762

Please sign in to comment.