Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't lint single_component_path_imports in macros #5183

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also exclude external macros?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in_macro should ignore any macros including external macros.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha! I thought it was meant only for internal macros. My bad.

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!();
}