Skip to content

Commit ea55d0c

Browse files
committed
Add enough attrs to the test file so the fix compiles with no errors, fmt/clippy
1 parent 62e14ed commit ea55d0c

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

clippy_lints/src/macro_use.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -164,34 +164,37 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
164164
let seg = import.split("::").collect::<Vec<_>>();
165165

166166
match seg.as_slice() {
167-
[] => unreachable!("this should never be empty"),
168-
[_] => unreachable!("path must have two segments ?"),
167+
// an empty path is impossible
168+
// a path should always consist of 2 or more segments
169+
[] | [_] => return,
169170
[root, item] => {
170171
if !check_dup.contains(&(*item).to_string()) {
171-
used.entry((root.to_string(), span))
172-
.or_insert_with(|| vec![])
173-
.push(item.to_string());
174-
check_dup.push(item.to_string());
172+
used.entry(((*root).to_string(), span))
173+
.or_insert_with(Vec::new)
174+
.push((*item).to_string());
175+
check_dup.push((*item).to_string());
175176
}
176177
},
177178
[root, rest @ ..] => {
178179
if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) {
179180
let filtered = rest
180181
.iter()
181-
.filter_map(|item| if check_dup.contains(&(*item).to_string()) {
182-
None
183-
} else {
184-
Some(item.to_string())
182+
.filter_map(|item| {
183+
if check_dup.contains(&(*item).to_string()) {
184+
None
185+
} else {
186+
Some((*item).to_string())
187+
}
185188
})
186189
.collect::<Vec<_>>();
187190
used.entry(((*root).to_string(), span))
188-
.or_insert_with(|| vec![])
191+
.or_insert_with(Vec::new)
189192
.push(filtered.join("::"));
190193
check_dup.extend(filtered);
191194
} else {
192195
let rest = rest.to_vec();
193-
used.entry((root.to_string(), span))
194-
.or_insert_with(|| vec![])
196+
used.entry(((*root).to_string(), span))
197+
.or_insert_with(Vec::new)
195198
.push(rest.join("::"));
196199
check_dup.extend(rest.iter().map(ToString::to_string));
197200
}

tests/ui/macro_use_imports.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// aux-build:macro_use_helper.rs
44
// run-rustfix
55

6+
#![allow(unused_imports, unreachable_code, unused_variables, dead_code)]
67
#![allow(clippy::single_component_path_imports)]
78
#![warn(clippy::macro_use_imports)]
89

tests/ui/macro_use_imports.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// aux-build:macro_use_helper.rs
44
// run-rustfix
55

6+
#![allow(unused_imports, unreachable_code, unused_variables, dead_code)]
67
#![allow(clippy::single_component_path_imports)]
78
#![warn(clippy::macro_use_imports)]
89

tests/ui/macro_use_imports.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
2-
--> $DIR/macro_use_imports.rs:18:5
2+
--> $DIR/macro_use_imports.rs:17:5
33
|
44
LL | #[macro_use]
5-
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
5+
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};`
66
|
77
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
88

99
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
10-
--> $DIR/macro_use_imports.rs:20:5
10+
--> $DIR/macro_use_imports.rs:19:5
1111
|
1212
LL | #[macro_use]
13-
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
13+
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
1414

1515
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
16-
--> $DIR/macro_use_imports.rs:16:5
16+
--> $DIR/macro_use_imports.rs:21:5
1717
|
1818
LL | #[macro_use]
19-
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};`
19+
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
2020

2121
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
22-
--> $DIR/macro_use_imports.rs:22:5
22+
--> $DIR/macro_use_imports.rs:23:5
2323
|
2424
LL | #[macro_use]
2525
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`

0 commit comments

Comments
 (0)