-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #52275 - alexcrichton:no-macro-use, r=nrc
rustc: Lint against `#[macro_use]` in 2018 idioms This commit adds a lint to the compiler to warn against the `#[macro_use]` directive as part of the `rust_2018_idioms` lint. This lint is turned off by default and is only enabled when the `use_extern_macros` feature is also enabled. The lint here isn't fully fleshed out as it's just a simple warning rather than suggestions of how to actually import the macro, but hopefully it's a good base to start from! cc #52043
- Loading branch information
Showing
7 changed files
with
99 additions
and
1 deletion.
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
12 changes: 12 additions & 0 deletions
12
src/test/ui/rust-2018/auxiliary/macro-use-warned-against.rs
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,12 @@ | ||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[macro_export] | ||
macro_rules! foo { () => () } |
10 changes: 10 additions & 0 deletions
10
src/test/ui/rust-2018/auxiliary/macro-use-warned-against2.rs
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,10 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
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,25 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// aux-build:macro-use-warned-against.rs | ||
// aux-build:macro-use-warned-against2.rs | ||
// compile-pass | ||
|
||
#![warn(rust_2018_idioms, unused)] | ||
#![feature(use_extern_macros)] | ||
|
||
#[macro_use] //~ WARN should be replaced at use sites with a `use` statement | ||
extern crate macro_use_warned_against; | ||
#[macro_use] //~ WARN unused `#[macro_use]` | ||
extern crate macro_use_warned_against2; | ||
|
||
fn main() { | ||
foo!(); | ||
} |
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,26 @@ | ||
warning: deprecated `#[macro_use]` directive used to import macros should be replaced at use sites with a `use` statement to import the macro instead | ||
--> $DIR/macro-use-warned-against.rs:18:1 | ||
| | ||
LL | #[macro_use] //~ WARN should be replaced at use sites with a `use` statement | ||
| ^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/macro-use-warned-against.rs:15:9 | ||
| | ||
LL | #![warn(rust_2018_idioms, unused)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: #[warn(macro_use_extern_crate)] implied by #[warn(rust_2018_idioms)] | ||
|
||
warning: unused `#[macro_use]` import | ||
--> $DIR/macro-use-warned-against.rs:20:1 | ||
| | ||
LL | #[macro_use] //~ WARN unused `#[macro_use]` | ||
| ^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/macro-use-warned-against.rs:15:27 | ||
| | ||
LL | #![warn(rust_2018_idioms, unused)] | ||
| ^^^^^^ | ||
= note: #[warn(unused_imports)] implied by #[warn(unused)] | ||
|