Skip to content

Commit ba246c8

Browse files
committed
Auto merge of #5183 - JohnTitor:fix-fp-import, r=matthiaskrgr
Don't lint `single_component_path_imports` in macros Fixes #5154 changelog: Fix false positive in `single_component_path_imports`
2 parents da78c31 + 09165ff commit ba246c8

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

clippy_lints/src/single_component_path_imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::span_lint_and_sugg;
1+
use crate::utils::{in_macro, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_errors::Applicability;
44
use rustc_lint::{EarlyContext, EarlyLintPass};
@@ -39,6 +39,7 @@ declare_lint_pass!(SingleComponentPathImports => [SINGLE_COMPONENT_PATH_IMPORTS]
3939
impl EarlyLintPass for SingleComponentPathImports {
4040
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) {
4141
if_chain! {
42+
if !in_macro(item.span);
4243
if cx.sess.opts.edition == Edition::Edition2018;
4344
if !item.vis.node.is_pub();
4445
if let ItemKind::Use(use_tree) = &item.kind;

tests/ui/single_component_path_imports.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77
use serde as edres;
88
pub use serde;
99

10+
macro_rules! m {
11+
() => {
12+
use regex;
13+
};
14+
}
15+
1016
fn main() {
1117
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
18+
19+
// False positive #5154, shouldn't trigger lint.
20+
m!();
1221
}

tests/ui/single_component_path_imports.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ use regex;
77
use serde as edres;
88
pub use serde;
99

10+
macro_rules! m {
11+
() => {
12+
use regex;
13+
};
14+
}
15+
1016
fn main() {
1117
regex::Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
18+
19+
// False positive #5154, shouldn't trigger lint.
20+
m!();
1221
}

0 commit comments

Comments
 (0)