-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Closed as duplicate of#119281
Closed as duplicate of#119281
Copy link
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-cfgArea: `cfg` conditional compilationArea: `cfg` conditional compilationC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Context
I want to use a #[cfg] attribute to conditionally include additional parameters in a struct.
Those parameters sometimes have generics or lifetime that are viral, and need to be attached to the parent.
Code
// This work
struct A<#[cfg(test)] T> {
#[cfg(test)]
pub a: T
}
// This doesn't
impl<#[cfg(test)] T> A<#[cfg(test)] T> {}Expected
The impl block compile successfully.
Being able to put attribute on a struct is an expected feature, so it is unexpected that it does not work correctly for impl block.
Analysis
Rust analyzer syntax tree errors on impl<#[cfg(test)] T> ConditionalGeneric<.
It recognize that the other parameters list have an attribute, but fail to do so at a PATH_SEGMENT for the impl.
Meta
Tested on stable 1.85.1 and 1.87.0-nightly (2025-03-18 75530e9).
Metadata
Metadata
Assignees
Labels
A-attributesArea: Attributes (`#[…]`, `#![…]`)Area: Attributes (`#[…]`, `#![…]`)A-cfgArea: `cfg` conditional compilationArea: `cfg` conditional compilationC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.