Skip to content

Commit 42637ac

Browse files
committed
clean up alot, span_lint_and_sugg
1 parent ee766bb commit 42637ac

File tree

4 files changed

+15
-22
lines changed

4 files changed

+15
-22
lines changed

clippy_lints/src/macro_use.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::utils::span_lint_and_help;
1+
use crate::utils::{snippet, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc_ast::ast;
4+
use rustc_errors::Applicability;
45
use rustc_lint::{EarlyContext, EarlyLintPass};
56
use rustc_session::{declare_lint_pass, declare_tool_lint};
67
use rustc_span::edition::Edition;
@@ -35,24 +36,17 @@ impl EarlyLintPass for MacroUseImport {
3536
.iter()
3637
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
3738
then {
38-
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
39-
let help = format!(
40-
"remove the attribute and import the macro directly `use {}::<macro name>`",
41-
use_tree
42-
.clone()
43-
.into_inner()
44-
.prefix
45-
.segments
46-
.iter()
47-
.enumerate()
48-
.map(|(i, s)| if i == 0 {
49-
s.ident.to_string()
50-
} else {
51-
format!("::{}", s.ident)
52-
})
53-
.collect::<String>(),
54-
);
55-
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
39+
let msg = "`macro_use` attributes are no longer needed in the Rust 2018 edition";
40+
let help = format!("use {}::<macro name>", snippet(ecx, use_tree.span, "_"));
41+
span_lint_and_sugg(
42+
ecx,
43+
MACRO_USE_IMPORT,
44+
mac_attr.span,
45+
msg,
46+
"remove the attribute and import the macro directly, try",
47+
help,
48+
Applicability::HasPlaceholders,
49+
);
5650
}
5751
}
5852
}

macro_use_import

2.69 MB
Binary file not shown.

tests/ui/macro_use_import.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
error: `macro_use` attribute's are no longer needed in the Rust 2018 edition
1+
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
22
--> $DIR/macro_use_import.rs:5:1
33
|
44
LL | #[macro_use]
5-
| ^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use std::prelude::<macro name>`
66
|
77
= note: `-D clippy::macro-use-import` implied by `-D warnings`
8-
= help: remove the attribute and import the macro directly `use std::prelude::<macro name>`
98

109
error: aborting due to previous error
1110

tests/ui/macro_use_import.stdout

Whitespace-only changes.

0 commit comments

Comments
 (0)