forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cargo dev update lints fixed suggestion, check edition, ran `tests/ui/update-all-references.sh` fixed failing tests with update-references.sh warn on macro_use attr (issue rust-lang#5179) fixed suggestion, check edition, ran `tests/ui/update-all-references.sh` fixed failing tests with update-references.sh update-references.sh for missing-doc-impl.rs use if_chain cargo dev fmt
- Loading branch information
Showing
8 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::utils::span_lint_and_help; | ||
use if_chain::if_chain; | ||
use rustc_ast::ast; | ||
use rustc_lint::{EarlyContext, EarlyLintPass}; | ||
use rustc_session::{declare_lint_pass, declare_tool_lint}; | ||
use rustc_span::edition::Edition; | ||
|
||
declare_clippy_lint! { | ||
/// **What it does:** Checks for `#[macro_use] use...`. | ||
/// | ||
/// **Why is this bad?** Since the Rust 2018 edition you can import | ||
/// macro's directly, this is considered idiomatic. | ||
/// | ||
/// **Known problems:** None. | ||
/// | ||
/// **Example:** | ||
/// ```rust | ||
/// #[macro_use] | ||
/// use lazy_static; | ||
/// ``` | ||
pub MACRO_USE_IMPORT, | ||
pedantic, | ||
"#[macro_use] is no longer needed" | ||
} | ||
|
||
declare_lint_pass!(MacroUseImport => [MACRO_USE_IMPORT]); | ||
|
||
impl EarlyLintPass for MacroUseImport { | ||
fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) { | ||
if_chain! { | ||
if ecx.sess.opts.edition == Edition::Edition2018; | ||
if let ast::ItemKind::Use(use_tree) = &item.kind; | ||
if let Some(mac_attr) = item | ||
.attrs | ||
.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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// compile-flags: --edition 2018 | ||
#![warn(clippy::macro_use_import)] | ||
|
||
use std::collections::HashMap; | ||
#[macro_use] | ||
use std::prelude; | ||
|
||
fn main() { | ||
let _ = HashMap::<u8, u8>::new(); | ||
println!(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: `macro_use` attribute's are no longer needed in the Rust 2018 edition | ||
--> $DIR/macro_use_import.rs:5:1 | ||
| | ||
LL | #[macro_use] | ||
| ^^^^^^^^^^^^ | ||
| | ||
= 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 | ||
|