mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-16 05:58:41 +00:00
Fix suggestion output, add run-rustfix to test file, stop sorting import segments duh
This commit is contained in:
parent
8c5a5a92ec
commit
288df59b25
4 changed files with 68 additions and 25 deletions
|
@ -167,32 +167,33 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
|
|||
[] => unreachable!("this should never be empty"),
|
||||
[_] => unreachable!("path must have two segments ?"),
|
||||
[root, item] => {
|
||||
if !check_dup.contains(&item.to_string()) {
|
||||
if !check_dup.contains(&(*item).to_string()) {
|
||||
used.entry((root.to_string(), span))
|
||||
.or_insert(vec![])
|
||||
.or_insert_with(|| vec![])
|
||||
.push(item.to_string());
|
||||
check_dup.push(item.to_string());
|
||||
}
|
||||
},
|
||||
[root, rest @ ..] => {
|
||||
if !rest.iter().all(|item| !check_dup.contains(&item.to_string())) {
|
||||
let mut rest = rest.to_vec();
|
||||
rest.sort();
|
||||
used.entry((root.to_string(), span))
|
||||
.or_insert(vec![])
|
||||
.push(rest.join("::"));
|
||||
check_dup.extend(rest.iter().map(ToString::to_string));
|
||||
} else {
|
||||
let mut filtered = rest
|
||||
if rest.iter().all(|item| !check_dup.contains(&(*item).to_string())) {
|
||||
let filtered = rest
|
||||
.iter()
|
||||
.filter(|item| !check_dup.contains(&item.to_string()))
|
||||
.map(ToString::to_string)
|
||||
.filter_map(|item| if check_dup.contains(&(*item).to_string()) {
|
||||
None
|
||||
} else {
|
||||
Some(item.to_string())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
filtered.sort();
|
||||
used.entry((root.to_string(), span))
|
||||
.or_insert(vec![])
|
||||
used.entry(((*root).to_string(), span))
|
||||
.or_insert_with(|| vec![])
|
||||
.push(filtered.join("::"));
|
||||
check_dup.extend(filtered);
|
||||
} else {
|
||||
let rest = rest.to_vec();
|
||||
used.entry((root.to_string(), span))
|
||||
.or_insert_with(|| vec![])
|
||||
.push(rest.join("::"));
|
||||
check_dup.extend(rest.iter().map(ToString::to_string));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -212,7 +213,7 @@ impl<'l, 'txc> LateLintPass<'l, 'txc> for MacroUseImports {
|
|||
// such as `std::prelude::v1::foo` or some other macro that expands to an import.
|
||||
if self.mac_refs.is_empty() {
|
||||
for (span, import) in suggestions {
|
||||
let help = format!("use {}", import);
|
||||
let help = format!("use {};", import);
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
MACRO_USE_IMPORTS,
|
||||
|
|
41
tests/ui/macro_use_imports.fixed
Normal file
41
tests/ui/macro_use_imports.fixed
Normal file
|
@ -0,0 +1,41 @@
|
|||
// compile-flags: --edition 2018
|
||||
// aux-build:macro_rules.rs
|
||||
// aux-build:macro_use_helper.rs
|
||||
// run-rustfix
|
||||
|
||||
#![allow(clippy::single_component_path_imports)]
|
||||
#![warn(clippy::macro_use_imports)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate macro_use_helper as mac;
|
||||
|
||||
#[macro_use]
|
||||
extern crate clippy_mini_macro_test as mini_mac;
|
||||
|
||||
mod a {
|
||||
use mac::{pub_macro, inner_mod_macro, function_macro, ty_macro, pub_in_private_macro};
|
||||
use mac;
|
||||
use mini_mac::ClippyMiniMacroTest;
|
||||
use mini_mac;
|
||||
use mac::{inner::foofoo, inner::try_err};
|
||||
use mac::inner;
|
||||
use mac::inner::nested::string_add;
|
||||
use mac::inner::nested;
|
||||
|
||||
#[derive(ClippyMiniMacroTest)]
|
||||
struct Test;
|
||||
|
||||
fn test() {
|
||||
pub_macro!();
|
||||
inner_mod_macro!();
|
||||
pub_in_private_macro!(_var);
|
||||
function_macro!();
|
||||
let v: ty_macro!() = Vec::default();
|
||||
|
||||
inner::try_err!();
|
||||
inner::foofoo!();
|
||||
nested::string_add!();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -1,6 +1,7 @@
|
|||
// compile-flags: --edition 2018
|
||||
// aux-build:macro_rules.rs
|
||||
// aux-build:macro_use_helper.rs
|
||||
// run-rustfix
|
||||
|
||||
#![allow(clippy::single_component_path_imports)]
|
||||
#![warn(clippy::macro_use_imports)]
|
||||
|
|
|
@ -1,28 +1,28 @@
|
|||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:17:5
|
||||
--> $DIR/macro_use_imports.rs:18:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest`
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
|
||||
|
|
||||
= note: `-D clippy::macro-use-imports` implied by `-D warnings`
|
||||
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:21:5
|
||||
--> $DIR/macro_use_imports.rs:20:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add`
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
|
||||
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:19:5
|
||||
--> $DIR/macro_use_imports.rs:16:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{foofoo::inner, inner::try_err}`
|
||||
| ^^^^^^^^^^^^ 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};`
|
||||
|
||||
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
|
||||
--> $DIR/macro_use_imports.rs:15:5
|
||||
--> $DIR/macro_use_imports.rs:22:5
|
||||
|
|
||||
LL | #[macro_use]
|
||||
| ^^^^^^^^^^^^ 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}`
|
||||
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue