Skip to content

rustc has stopped emitting unused repr/link/panic_handler attribute lints on macro invocations #156499

@mejrs

Description

@mejrs

Code

I tried this code:

macro_rules! produce_struct {
    ($name: ident) => {
        pub struct $name {}
    };
}

#[repr(align(64))]
produce_struct!(Foo);

const _: () = assert!(align_of::<Foo>() == 1);

I expected to see this happen: program accepted, with warnings

warning: unused attribute `repr`
 --> <source>:7:1
  |
7 | #[repr(align(64))]
  | ^^^^^^^^^^^^^^^^^^
  |
  = note: -Ztrack-diagnostics: created at /rustc-dev/1159e78c4747b02ef996e55082b704c09b970588/compiler/rustc_lint/src/early.rs:40:26
note: the built-in attribute `repr` will be ignored, since it's applied to the macro invocation `produce_struct`
 --> <source>:8:1
  |
8 | produce_struct!(Foo);
  | ^^^^^^^^^^^^^^
  = note: `#[warn(unused_attributes)]` on by default

Instead, this happened: program accepted, no warnings issued

Version it worked on

It most recently worked on: rust 1.90 and earlier: https://rust.godbolt.org/z/Wzf519Wbv

Version with regression

1.91 and up, including current beta and nightly

The following attributes are also affected, this compiles without warnings (save for incomplete_features).

#![allow(incomplete_features)]
#![feature(dropck_eyepatch)]
#![feature(export_stable)]
#![feature(register_tool)]
#![feature(sanitize)]

macro_rules! produce_struct {
    ($name: ident) => {
        pub struct $name {}
    };
}

#[repr(align(64))]
#[sanitize(address = "off")]
#[register_tool(blah)]
#[link(name = "foo")]
#[export_stable]
#[panic_handler]
#[may_dangle]
produce_struct!(Foo);

Metadata

Metadata

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions