Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unused attributes on macro_rules. #85312

Merged
merged 1 commit into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ fn late_lint_pass_crate<'tcx, T: LateLintPass<'tcx>>(tcx: TyCtxt<'tcx>, pass: T)
lint_callback!(cx, check_crate, krate);

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

lint_callback!(cx, check_crate_post, krate);
})
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_span::Symbol;
use std::fmt;
use std::str::FromStr;

#[macro_use]
macro_rules! def_reg_class {
($arch:ident $arch_regclass:ident {
$(
Expand Down Expand Up @@ -51,7 +50,6 @@ macro_rules! def_reg_class {
}
}

#[macro_use]
macro_rules! def_regs {
($arch:ident $arch_reg:ident $arch_regclass:ident {
$(
Expand Down Expand Up @@ -129,7 +127,6 @@ macro_rules! def_regs {
}
}

#[macro_use]
macro_rules! types {
(
$(_ : $($ty:expr),+;)?
Expand Down
34 changes: 34 additions & 0 deletions src/test/ui/unused/unused-attr-macro-rules.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![deny(unused_attributes)]
// Unused attributes on macro_rules requires special handling since the
// macro_rules definition does not survive towards HIR.

// A sample of various built-in attributes.
#[macro_export]
#[macro_use] //~ ERROR unused attribute
#[path="foo"] //~ ERROR unused attribute
#[recursion_limit="1"] //~ ERROR unused attribute
//~| ERROR crate-level attribute should be an inner attribute
macro_rules! foo {
() => {};
}

// The following should not warn about unused attributes.
#[allow(unused)]
macro_rules! foo2 {
() => {};
}

#[cfg(FALSE)]
macro_rules! foo {
() => {};
}

/// Some docs
#[deprecated]
#[doc = "more docs"]
#[macro_export]
macro_rules! bar {
() => {};
}

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/unused/unused-attr-macro-rules.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:7:1
|
LL | #[macro_use]
| ^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/unused-attr-macro-rules.rs:1:9
|
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^

error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:8:1
|
LL | #[path="foo"]
| ^^^^^^^^^^^^^

error: unused attribute
--> $DIR/unused-attr-macro-rules.rs:9:1
|
LL | #[recursion_limit="1"]
| ^^^^^^^^^^^^^^^^^^^^^^

error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
--> $DIR/unused-attr-macro-rules.rs:9:1
|
LL | #[recursion_limit="1"]
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors