From 71477620220e28a47964e73dfd73e149f77bf0fa Mon Sep 17 00:00:00 2001 From: xiongmao86 Date: Sat, 25 Jan 2020 21:15:06 +0800 Subject: [PATCH] Restrict lint logic and cargo uitest again. Restrict lint logic to apply on edition2018 only. And update test reference. --- clippy_lints/src/single_component_use_path.rs | 2 ++ tests/ui/single_component_use_path.fixed | 1 + tests/ui/single_component_use_path.stderr | 4 ++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/clippy_lints/src/single_component_use_path.rs b/clippy_lints/src/single_component_use_path.rs index 5c3cfc8d4919..29afd2c9434b 100644 --- a/clippy_lints/src/single_component_use_path.rs +++ b/clippy_lints/src/single_component_use_path.rs @@ -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. @@ -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; diff --git a/tests/ui/single_component_use_path.fixed b/tests/ui/single_component_use_path.fixed index 3e806fcfe9d9..06b3aedc257b 100644 --- a/tests/ui/single_component_use_path.fixed +++ b/tests/ui/single_component_use_path.fixed @@ -1,4 +1,5 @@ // run-rustfix +// compile-flags: --edition 2018 #![warn(clippy::single_component_use_path)] extern crate semver; diff --git a/tests/ui/single_component_use_path.stderr b/tests/ui/single_component_use_path.stderr index f2cef94b13ba..1dc77b52b27c 100644 --- a/tests/ui/single_component_use_path.stderr +++ b/tests/ui/single_component_use_path.stderr @@ -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 @@ -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