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

Closed
taiki-e opened this issue Mar 21, 2025 · 3 comments · Fixed by #138794
Closed
Assignees
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unused_attributes Lint: unused_attributes regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

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.

@bors bors closed this as completed in 66c3566 Mar 22, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 22, 2025
Rollup merge of rust-lang#138794 - petrochenkov:cfgtracefix, r=jieyouxu

expand: Do not report `cfg_attr` traces on macros as unused attributes

Fixes rust-lang#138779
@jieyouxu jieyouxu added A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. L-unused_attributes Lint: unused_attributes T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. L-unused_attributes Lint: unused_attributes regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants