diff options
| author | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-02-17 05:44:38 +0900 |
|---|---|---|
| committer | Yuki Okushi <huyuumi.dev@gmail.com> | 2020-02-17 11:13:42 +0900 |
| commit | 09165ff5761bb1f397e37ee2d32d96adf7afdd86 (patch) | |
| tree | 0dbf995bade7922b13f6b45643881c91a9650304 | |
| parent | 578960d61dbc01ff2db05ea818e41414a7acc12e (diff) | |
| download | rust-09165ff5761bb1f397e37ee2d32d96adf7afdd86.tar.gz rust-09165ff5761bb1f397e37ee2d32d96adf7afdd86.zip | |
Don't lint `single_component_path_imports` in macros
| -rw-r--r-- | clippy_lints/src/single_component_path_imports.rs | 3 | ||||
| -rw-r--r-- | tests/ui/single_component_path_imports.fixed | 9 | ||||
| -rw-r--r-- | tests/ui/single_component_path_imports.rs | 9 |
3 files changed, 20 insertions, 1 deletions
diff --git a/clippy_lints/src/single_component_path_imports.rs b/clippy_lints/src/single_component_path_imports.rs index eb3261bebe3..5a9bc73fe42 100644 --- a/clippy_lints/src/single_component_path_imports.rs +++ b/clippy_lints/src/single_component_path_imports.rs @@ -1,4 +1,4 @@ -use crate::utils::span_lint_and_sugg; +use crate::utils::{in_macro, span_lint_and_sugg}; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; @@ -39,6 +39,7 @@ declare_lint_pass!(SingleComponentPathImports => [SINGLE_COMPONENT_PATH_IMPORTS] impl EarlyLintPass for SingleComponentPathImports { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { if_chain! { + if !in_macro(item.span); if cx.sess.opts.edition == Edition::Edition2018; if !item.vis.node.is_pub(); if let ItemKind::Use(use_tree) = &item.kind; diff --git a/tests/ui/single_component_path_imports.fixed b/tests/ui/single_component_path_imports.fixed index 7a882efc4d1..9095069b093 100644 --- a/tests/ui/single_component_path_imports.fixed +++ b/tests/ui/single_component_path_imports.fixed @@ -7,6 +7,15 @@ use serde as edres; pub use serde; +macro_rules! m { + () => { + use regex; + }; +} + fn main() { regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); + + // False positive #5154, shouldn't trigger lint. + m!(); } diff --git a/tests/ui/single_component_path_imports.rs b/tests/ui/single_component_path_imports.rs index d084425cd70..1ebb3ee59b8 100644 --- a/tests/ui/single_component_path_imports.rs +++ b/tests/ui/single_component_path_imports.rs @@ -7,6 +7,15 @@ use regex; use serde as edres; pub use serde; +macro_rules! m { + () => { + use regex; + }; +} + fn main() { regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap(); + + // False positive #5154, shouldn't trigger lint. + m!(); } |
