Skip to content

Commit

Permalink
Don't lint single_component_path_imports in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Feb 17, 2020
1 parent 578960d commit 09165ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/single_component_path_imports.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/single_component_path_imports.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
9 changes: 9 additions & 0 deletions tests/ui/single_component_path_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}

0 comments on commit 09165ff

Please sign in to comment.