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

Update Clippy #84610

Merged
merged 23 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b48699e
`single_component_path_imports`: ignore `pub(crate) use some_macro;` …
cherryblossom000 Apr 22, 2021
5625d58
add detection unused_io_amount of "or", "or_else" and "ok"
ABouttefeux Apr 16, 2021
0ab7acc
Auto merge of #7100 - ABouttefeux:unused_io_amount, r=camsteffen
bors Apr 22, 2021
74f5599
Auto merge of #7120 - cherryblossom000:7106, r=Manishearth
bors Apr 22, 2021
6c42375
Fix lintcheck on windows
Jarcho Apr 22, 2021
08e36d7
Auto merge of #7124 - Jarcho:lintcheck-windows, r=phansch
bors Apr 23, 2021
db7ad64
Fix ICE checking for feature gated const fn
Jarcho Apr 25, 2021
3f5be5e
Fix cloned_instead_of_copied MSRV
camsteffen Apr 25, 2021
c4e2d36
Auto merge of #7129 - camsteffen:copied-msrv, r=Manishearth
bors Apr 25, 2021
efc4c6c
extend `single_element_loop` to match `.iter()`
llogiq Apr 25, 2021
1bb3b12
Auto merge of #7132 - rust-lang:single_element_loop_iter, r=Manishearth
bors Apr 26, 2021
dcf4e07
Finish MSRV for cloned_instead_of_copied
camsteffen Apr 26, 2021
a362a4d
Auto merge of #7134 - camsteffen:copied-msrv, r=Manishearth
bors Apr 26, 2021
84003aa
fix invalid code suggestion in `manual_unwrap_or`, due to macro expan…
mgacek8 Apr 26, 2021
d7627dc
Fix FN in `iter_cloned_collect` with a large array
mgacek8 Apr 26, 2021
33ed8b5
Remove needless_question_mark MSRV
camsteffen Apr 26, 2021
340b570
Refactor MSRV aliases
camsteffen Apr 26, 2021
3a8e759
Update MSRV contribution docs
camsteffen Apr 26, 2021
f33d86d
Auto merge of #7137 - camsteffen:msrv-mod, r=llogiq
bors Apr 26, 2021
0a330e6
Auto merge of #7136 - mgacek8:issue6965_manual_unwrap_or_invalid_sugg…
bors Apr 26, 2021
9af07e6
Auto merge of #7138 - mgacek8:issue6808_iter_cloned_collect_FN_with_l…
bors Apr 27, 2021
7c7683c
Auto merge of #7128 - Jarcho:const_fn_ice, r=flip1995
bors Apr 27, 2021
d4af90e
Merge commit '7c7683c8efe447b251d6c5ca6cce51233060f6e8' into clippyup
flip1995 Apr 27, 2021
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
Next Next commit
single_component_path_imports: ignore pub(crate) use some_macro; (f…
…ixes #7106)
  • Loading branch information
cherryblossom000 committed Apr 22, 2021
commit b48699e4cfd8af15669227049f3c6056d4084aba
36 changes: 30 additions & 6 deletions clippy_lints/src/single_component_path_imports.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg};
use clippy_utils::in_macro;
use rustc_ast::{ptr::P, Crate, Item, ItemKind, ModKind, UseTreeKind};
use rustc_ast::{ptr::P, Crate, Item, ItemKind, MacroDef, ModKind, UseTreeKind, VisibilityKind};
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -60,8 +60,21 @@ fn check_mod(cx: &EarlyContext<'_>, items: &[P<Item>]) {
// ```
let mut single_use_usages = Vec::new();

// keep track of macros defined in the module as we don't want it to trigger on this (#7106)
// ```rust,ignore
// macro_rules! foo { () => {} };
// pub(crate) use foo;
// ```
let mut macros = Vec::new();

for item in items {
track_uses(cx, &item, &mut imports_reused_with_self, &mut single_use_usages);
track_uses(
cx,
&item,
&mut imports_reused_with_self,
&mut single_use_usages,
&mut macros,
);
}

for single_use in &single_use_usages {
Expand Down Expand Up @@ -96,6 +109,7 @@ fn track_uses(
item: &Item,
imports_reused_with_self: &mut Vec<Symbol>,
single_use_usages: &mut Vec<(Symbol, Span, bool)>,
macros: &mut Vec<Symbol>,
) {
if in_macro(item.span) || item.vis.kind.is_pub() {
return;
Expand All @@ -105,14 +119,22 @@ fn track_uses(
ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) => {
check_mod(cx, &items);
},
ItemKind::MacroDef(MacroDef { macro_rules: true, .. }) => {
macros.push(item.ident.name);
},
ItemKind::Use(use_tree) => {
let segments = &use_tree.prefix.segments;

let should_report =
|name: &Symbol| !macros.contains(name) || matches!(item.vis.kind, VisibilityKind::Inherited);

// keep track of `use some_module;` usages
if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = use_tree.kind {
let ident = &segments[0].ident;
single_use_usages.push((ident.name, item.span, true));
let name = segments[0].ident.name;
if should_report(&name) {
single_use_usages.push((name, item.span, true));
}
}
return;
}
Expand All @@ -124,8 +146,10 @@ fn track_uses(
let segments = &tree.0.prefix.segments;
if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = tree.0.kind {
let ident = &segments[0].ident;
single_use_usages.push((ident.name, tree.0.span, false));
let name = segments[0].ident.name;
if should_report(&name) {
single_use_usages.push((name, tree.0.span, false));
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/single_component_path_imports_macro.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-rustfix
// edition:2018
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]

// #7106: use statements exporting a macro within a crate should not trigger lint

macro_rules! m1 {
() => {};
}
pub(crate) use m1; // ok

macro_rules! m2 {
() => {};
}
// fail

fn main() {
m1!();
m2!();
}
21 changes: 21 additions & 0 deletions tests/ui/single_component_path_imports_macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// run-rustfix
// edition:2018
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]

// #7106: use statements exporting a macro within a crate should not trigger lint

macro_rules! m1 {
() => {};
}
pub(crate) use m1; // ok

macro_rules! m2 {
() => {};
}
use m2; // fail

fn main() {
m1!();
m2!();
}
10 changes: 10 additions & 0 deletions tests/ui/single_component_path_imports_macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: this import is redundant
--> $DIR/single_component_path_imports_macro.rs:16:1
|
LL | use m2; // fail
| ^^^^^^^ help: remove it entirely
|
= note: `-D clippy::single-component-path-imports` implied by `-D warnings`

error: aborting due to previous error