Skip to content

Commit

Permalink
clean up alot, span_lint_and_sugg
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Mar 3, 2020
1 parent ee766bb commit 42637ac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
32 changes: 13 additions & 19 deletions clippy_lints/src/macro_use.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::span_lint_and_help;
use crate::utils::{snippet, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_ast::ast;
use rustc_errors::Applicability;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::edition::Edition;
Expand Down Expand Up @@ -35,24 +36,17 @@ impl EarlyLintPass for MacroUseImport {
.iter()
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
then {
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
let help = format!(
"remove the attribute and import the macro directly `use {}::<macro name>`",
use_tree
.clone()
.into_inner()
.prefix
.segments
.iter()
.enumerate()
.map(|(i, s)| if i == 0 {
s.ident.to_string()
} else {
format!("::{}", s.ident)
})
.collect::<String>(),
);
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
let msg = "`macro_use` attributes are no longer needed in the Rust 2018 edition";
let help = format!("use {}::<macro name>", snippet(ecx, use_tree.span, "_"));
span_lint_and_sugg(
ecx,
MACRO_USE_IMPORT,
mac_attr.span,
msg,
"remove the attribute and import the macro directly, try",
help,
Applicability::HasPlaceholders,
);
}
}
}
Expand Down
Binary file added macro_use_import
Binary file not shown.
5 changes: 2 additions & 3 deletions tests/ui/macro_use_import.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
error: `macro_use` attribute's are no longer needed in the Rust 2018 edition
error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_import.rs:5:1
|
LL | #[macro_use]
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use std::prelude::<macro name>`
|
= note: `-D clippy::macro-use-import` implied by `-D warnings`
= help: remove the attribute and import the macro directly `use std::prelude::<macro name>`

error: aborting due to previous error

Empty file.

0 comments on commit 42637ac

Please sign in to comment.