1 use crate::utils::{snippet, span_lint_and_sugg};
2 use if_chain::if_chain;
4 use rustc_errors::Applicability;
5 use rustc_lint::{EarlyContext, EarlyLintPass};
6 use rustc_session::{declare_lint_pass, declare_tool_lint};
7 use rustc_span::edition::Edition;
10 /// **What it does:** Checks for `#[macro_use] use...`.
12 /// **Why is this bad?** Since the Rust 2018 edition you can import
13 /// macro's directly, this is considered idiomatic.
15 /// **Known problems:** This lint does not generate an auto-applicable suggestion.
22 pub MACRO_USE_IMPORTS,
24 "#[macro_use] is no longer needed"
27 declare_lint_pass!(MacroUseImports => [MACRO_USE_IMPORTS]);
29 impl EarlyLintPass for MacroUseImports {
30 fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) {
32 if ecx.sess.opts.edition == Edition::Edition2018;
33 if let ast::ItemKind::Use(use_tree) = &item.kind;
34 if let Some(mac_attr) = item
37 .find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
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, "_"));
46 "remove the attribute and import the macro directly, try",
48 Applicability::HasPlaceholders,