Skip to content

Commit 0ac2801

Browse files
committed
expand: Do not report cfg_attr traces on macros as unused attributes
1 parent 4ac032f commit 0ac2801

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

compiler/rustc_expand/src/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
19411941
let attr_name = attr.ident().unwrap().name;
19421942
// `#[cfg]` and `#[cfg_attr]` are special - they are
19431943
// eagerly evaluated.
1944-
if attr_name != sym::cfg && attr_name != sym::cfg_attr {
1944+
if attr_name != sym::cfg && attr_name != sym::cfg_attr_trace {
19451945
self.cx.sess.psess.buffer_lint(
19461946
UNUSED_ATTRIBUTES,
19471947
attr.span,

tests/ui/lint/inert-attr-macro.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//@ check-pass
22

3+
#![feature(cfg_boolean_literals)]
34
#![warn(unused)]
45

56
macro_rules! foo {
@@ -17,4 +18,10 @@ fn main() {
1718
// This does work, since the attribute is on a parent
1819
// of the macro invocation.
1920
#[allow(warnings)] { #[inline] foo!(); }
21+
22+
// Ok, `cfg` and `cfg_attr` are expanded eagerly and do not warn.
23+
#[cfg(true)] foo!();
24+
#[cfg(false)] foo!();
25+
#[cfg_attr(true, cfg(true))] foo!();
26+
#[cfg_attr(false, nonexistent)] foo!();
2027
}

tests/ui/lint/inert-attr-macro.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
warning: unused attribute `inline`
2-
--> $DIR/inert-attr-macro.rs:10:5
2+
--> $DIR/inert-attr-macro.rs:11:5
33
|
44
LL | #[inline] foo!();
55
| ^^^^^^^^^
66
|
77
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
8-
--> $DIR/inert-attr-macro.rs:10:15
8+
--> $DIR/inert-attr-macro.rs:11:15
99
|
1010
LL | #[inline] foo!();
1111
| ^^^
1212
note: the lint level is defined here
13-
--> $DIR/inert-attr-macro.rs:3:9
13+
--> $DIR/inert-attr-macro.rs:4:9
1414
|
1515
LL | #![warn(unused)]
1616
| ^^^^^^
1717
= note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
1818

1919
warning: unused attribute `allow`
20-
--> $DIR/inert-attr-macro.rs:14:5
20+
--> $DIR/inert-attr-macro.rs:15:5
2121
|
2222
LL | #[allow(warnings)] #[inline] foo!();
2323
| ^^^^^^^^^^^^^^^^^^
2424
|
2525
note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
26-
--> $DIR/inert-attr-macro.rs:14:34
26+
--> $DIR/inert-attr-macro.rs:15:34
2727
|
2828
LL | #[allow(warnings)] #[inline] foo!();
2929
| ^^^
3030

3131
warning: unused attribute `inline`
32-
--> $DIR/inert-attr-macro.rs:14:24
32+
--> $DIR/inert-attr-macro.rs:15:24
3333
|
3434
LL | #[allow(warnings)] #[inline] foo!();
3535
| ^^^^^^^^^
3636
|
3737
note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
38-
--> $DIR/inert-attr-macro.rs:14:34
38+
--> $DIR/inert-attr-macro.rs:15:34
3939
|
4040
LL | #[allow(warnings)] #[inline] foo!();
4141
| ^^^

0 commit comments

Comments
 (0)