forked from rust-lang/rust
-
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.
Warn on inert attributes used on bang macro invocation
These attributes are currently discarded. This may change in the future (see rust-lang#63221), but for now, placing inert attributes on a macro invocation does nothing, so we should warn users about it. Technically, it's possible for there to be attribute macro on the same macro invocation (or at a higher scope), which inspects the inert attribute. For example: ```rust #[look_for_inline_attr] #[inline] my_macro!() #[look_for_nested_inline] mod foo { #[inline] my_macro!() } ``` However, this would be a very strange thing to do. Anyone running into this can manually suppress the warning.
- Loading branch information
Showing
6 changed files
with
109 additions
and
16 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
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,20 @@ | ||
// check-pass | ||
|
||
#![warn(unused)] | ||
|
||
macro_rules! foo { | ||
() => {} | ||
} | ||
|
||
fn main() { | ||
#[inline] foo!(); //~ WARN unused attribute `inline` | ||
|
||
// This does nothing, since `#[allow(warnings)]` is itself | ||
// an inert attribute on a macro call | ||
#[allow(warnings)] #[inline] foo!(); //~ WARN unused attribute `allow` | ||
//~^ WARN unused attribute `inline` | ||
|
||
// This does work, since the attribute is on a parent | ||
// of the macro invocation. | ||
#[allow(warnings)] { #[inline] 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,44 @@ | ||
warning: unused attribute `inline` | ||
--> $DIR/inert-attr-macro.rs:10:5 | ||
| | ||
LL | #[inline] foo!(); | ||
| ^^^^^^^^^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/inert-attr-macro.rs:3:9 | ||
| | ||
LL | #![warn(unused)] | ||
| ^^^^^^ | ||
= note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]` | ||
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo` | ||
--> $DIR/inert-attr-macro.rs:10:15 | ||
| | ||
LL | #[inline] foo!(); | ||
| ^^^ | ||
|
||
warning: unused attribute `allow` | ||
--> $DIR/inert-attr-macro.rs:14:5 | ||
| | ||
LL | #[allow(warnings)] #[inline] foo!(); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo` | ||
--> $DIR/inert-attr-macro.rs:14:34 | ||
| | ||
LL | #[allow(warnings)] #[inline] foo!(); | ||
| ^^^ | ||
|
||
warning: unused attribute `inline` | ||
--> $DIR/inert-attr-macro.rs:14:24 | ||
| | ||
LL | #[allow(warnings)] #[inline] foo!(); | ||
| ^^^^^^^^^ | ||
| | ||
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo` | ||
--> $DIR/inert-attr-macro.rs:14:34 | ||
| | ||
LL | #[allow(warnings)] #[inline] foo!(); | ||
| ^^^ | ||
|
||
warning: 3 warnings emitted | ||
|