Skip to content

Attribute suggestions are not sensable in combination with cfg_attr #147693

@JonathanBrouwer

Description

@JonathanBrouwer

Code

#[cfg_attr(true, inline())]
fn f1() {}

Current output

error[E0805]: malformed `inline` attribute input
  --> $DIR/cfg_attr-attr-syntax-validation.rs:47:18
   |
LL | #[cfg_attr(true, inline())]
   |                  ^^^^^^--
   |                        |
   |                        expected a single argument here
   |
   = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute>
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, #[inline(always)])]
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, #[inline(never)])]
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, #[inline])]
   |

Desired output

error[E0805]: malformed `inline` attribute input
  --> $DIR/cfg_attr-attr-syntax-validation.rs:47:18
   |
LL | #[cfg_attr(true, inline())]
   |                  ^^^^^^--
   |                        |
   |                        expected a single argument here
   |
   = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute>
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, inline(always))]
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, inline(never))]
   |
LL - #[cfg_attr(true, inline())]
LL + #[cfg_attr(true, inline)]
   |

Rationale and extra context

No response

Other cases

This also applies to a few other attributes, like `link`

Rust Version

rustc 1.92.0-nightly (5c7ae0c7e 2025-10-02)
binary: rustc
commit-hash: 5c7ae0c7ed184c603e5224604a9f33ca0e8e0b36
commit-date: 2025-10-02
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Anything else?

No response

Metadata

Metadata

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-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

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions