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

unused_attributes: false positive since nightly-2025-03-21 "unused attribute <cfg_attr>" #138779

Open
taiki-e opened this issue Mar 21, 2025 · 3 comments · May be fixed by #138794
Open

unused_attributes: false positive since nightly-2025-03-21 "unused attribute <cfg_attr>" #138779

taiki-e opened this issue Mar 21, 2025 · 3 comments · May be fixed by #138794
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@taiki-e
Copy link
Member

taiki-e commented Mar 21, 2025

Code

I tried this code:

macro_rules! mac {
    () => {};
}

#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
mac!();

I expected to see this happen: no warning

Instead, this happened: unused_attributes warns cfg_attr

warning: unused attribute `<cfg_attr>`
 --> src/lib.rs:5:1
  |
5 | #[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the built-in attribute `<cfg_attr>` will be ignored, since it's applied to the macro invocation `mac`
 --> src/lib.rs:6:1
  |
6 | mac!();
  | ^^^
  = note: `#[warn(unused_attributes)]` on by default

Version it worked on

It most recently worked on: nightly-2025-03-20

Version with regression

nightly-2025-03-21

rustc --version --verbose:

rustc 1.87.0-nightly (78948ac25 2025-03-20)
binary: rustc
commit-hash: 78948ac259253ce89effca1e8bb64d16f4684aa4
commit-date: 2025-03-20
host: aarch64-apple-darwin
release: 1.87.0-nightly
LLVM version: 20.1.1

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged +A-attributes

@taiki-e taiki-e added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Mar 21, 2025
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Mar 21, 2025
@taiki-e
Copy link
Member Author

taiki-e commented Mar 21, 2025

Probably related to #138515 which added <cfg_attr>.

cc @petrochenkov

@petrochenkov petrochenkov self-assigned this Mar 21, 2025
@petrochenkov
Copy link
Contributor

I'll fix it today or tomorrow.

@petrochenkov
Copy link
Contributor

Fixed in #138794.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 22, 2025
expand: Do not report `cfg_attr` traces on macros as unused attributes

Fixes rust-lang#138779
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) C-bug Category: This is a bug. I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants