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

Conditional compilation: E0747 and E0107 on generics and lifetime #138716

Open
IzawGithub opened this issue Mar 19, 2025 · 0 comments
Open

Conditional compilation: E0747 and E0107 on generics and lifetime #138716

IzawGithub opened this issue Mar 19, 2025 · 0 comments
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-cfg Area: `cfg` conditional compilation C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@IzawGithub
Copy link

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> {}

Link to playground

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).

@IzawGithub IzawGithub added the C-bug Category: This is a bug. label Mar 19, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 19, 2025
@jieyouxu jieyouxu added A-attributes Area: Attributes (`#[…]`, `#![…]`) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-cfg Area: `cfg` conditional compilation labels Mar 19, 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-cfg Area: `cfg` conditional compilation C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants