Skip to content

#[<cfg_trace>] and #[<cfg_attr_trace>] showing up as suggestions #150566

@Bryntet

Description

@Bryntet

Code

#[cfg_trace]
fn main() {}
#[cfg_attr_trace]
fn foo() {}

Current output

error: cannot find attribute `cfg_trace` in this scope
 --> test.rs:3:3
  |
3 | #[cfg_trace]
  |   ^^^^^^^^^
  |
help: a built-in attribute with a similar name exists
  |
3 - #[cfg_trace]
3 + #[<cfg_trace>]
  |

error: cannot find attribute `cfg_attr_trace` in this scope
 --> test.rs:1:3
  |
1 | #[cfg_attr_trace]
  |   ^^^^^^^^^^^^^^
  |
help: a built-in attribute with a similar name exists
  |
1 - #[cfg_attr_trace]
1 + #[<cfg_attr_trace>]
  |

error: aborting due to 2 previous errors

Desired output

error: cannot find attribute `cfg_trace` in this scope
 --> test.rs:3:3
  |
3 | #[cfg_trace]
  |   ^^^^^^^^^

error: cannot find attribute `cfg_attr_trace` in this scope
 --> test.rs:1:3
  |
1 | #[cfg_attr_trace]
  |   ^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Rationale and extra context

this is a diagnostic regression

Other cases

Rust Version

rustc 1.94.0-nightly (8d670b93d 2025-12-31)
binary: rustc
commit-hash: 8d670b93d40737e1b320fd892c6f169ffa35e49e
commit-date: 2025-12-31
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Anything else?

#[cfg_trace] and #[cfg_attr_trace] are really compiler internals, and I think we should maybe change their names to reflect this? i.e. make it #[rustc_cfg_trace] and #[rustc_cfg_attr_trace], this would also lead to better error messages in general if someone tried to use them

other attributes that are added during codegen are marked like this, see for example #[rustc_test_marker]

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-cfgArea: `cfg` conditional compilationA-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

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