Skip to content

Commit 5bbc240

Browse files
committed
Fix unused attributes on macro_rules.
1 parent 17f30e5 commit 5bbc240

File tree

4 files changed

+70
-3
lines changed

4 files changed

+70
-3
lines changed

compiler/rustc_lint/src/late.rs

+4
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
448448
lint_callback!(cx, check_crate, krate);
449449

450450
hir_visit::walk_crate(cx, krate);
451+
for attr in krate.non_exported_macro_attrs {
452+
// This HIR ID is a lie, since the macro ID isn't available.
453+
cx.visit_attribute(hir::CRATE_HIR_ID, attr);
454+
}
451455

452456
lint_callback!(cx, check_crate_post, krate);
453457
})

compiler/rustc_target/src/asm/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_span::Symbol;
66
use std::fmt;
77
use std::str::FromStr;
88

9-
#[macro_use]
109
macro_rules! def_reg_class {
1110
($arch:ident $arch_regclass:ident {
1211
$(
@@ -51,7 +50,6 @@ macro_rules! def_reg_class {
5150
}
5251
}
5352

54-
#[macro_use]
5553
macro_rules! def_regs {
5654
($arch:ident $arch_reg:ident $arch_regclass:ident {
5755
$(
@@ -129,7 +127,6 @@ macro_rules! def_regs {
129127
}
130128
}
131129

132-
#[macro_use]
133130
macro_rules! types {
134131
(
135132
$(_ : $($ty:expr),+;)?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![deny(unused_attributes)]
2+
// Unused attributes on macro_rules requires special handling since the
3+
// macro_rules definition does not survive towards HIR.
4+
5+
// A sample of various built-in attributes.
6+
#[macro_export]
7+
#[macro_use] //~ ERROR unused attribute
8+
#[path="foo"] //~ ERROR unused attribute
9+
#[recursion_limit="1"] //~ ERROR unused attribute
10+
//~| ERROR crate-level attribute should be an inner attribute
11+
macro_rules! foo {
12+
() => {};
13+
}
14+
15+
// The following should not warn about unused attributes.
16+
#[allow(unused)]
17+
macro_rules! foo2 {
18+
() => {};
19+
}
20+
21+
#[cfg(FALSE)]
22+
macro_rules! foo {
23+
() => {};
24+
}
25+
26+
/// Some docs
27+
#[deprecated]
28+
#[doc = "more docs"]
29+
#[macro_export]
30+
macro_rules! bar {
31+
() => {};
32+
}
33+
34+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: unused attribute
2+
--> $DIR/unused-attr-macro-rules.rs:7:1
3+
|
4+
LL | #[macro_use]
5+
| ^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/unused-attr-macro-rules.rs:1:9
9+
|
10+
LL | #![deny(unused_attributes)]
11+
| ^^^^^^^^^^^^^^^^^
12+
13+
error: unused attribute
14+
--> $DIR/unused-attr-macro-rules.rs:8:1
15+
|
16+
LL | #[path="foo"]
17+
| ^^^^^^^^^^^^^
18+
19+
error: unused attribute
20+
--> $DIR/unused-attr-macro-rules.rs:9:1
21+
|
22+
LL | #[recursion_limit="1"]
23+
| ^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
26+
--> $DIR/unused-attr-macro-rules.rs:9:1
27+
|
28+
LL | #[recursion_limit="1"]
29+
| ^^^^^^^^^^^^^^^^^^^^^^
30+
31+
error: aborting due to 4 previous errors
32+

0 commit comments

Comments
 (0)