rust-lang / rust-lang/rust-analyzer

`cfg_eval` breaks type signature & completions

Open
#15,800 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Using cfg_eval causes the type it's applied to to essentially not exist anymore in user-facing operations.
Neither type signature nor completions or any other LSP methods work for these types.

I've found this issue with both the core & cfg_eval crate implementations.

Adding cfg_eval to procMacro.ignored solves this issue, but can cause rust-analyzer to report errors that don't appear when compiling.

I'm guessing this is not strictly an issue with cfg_eval itself but a general issue with how proc macros are evaluated.
But since I haven't found a related issue so far & to help other people encountering issues with cfg_eval I've decided to create a new issue.

Here is a short example to reproduce the issue:

use serde::{Deserialize, Serialize};
use serde_with::{serde_as, DurationMilliSeconds};
use time::Duration;

#[cfg_eval]
#[serde_as]
#[derive(Serialize, Deserialize)]
pub struct Exercise {
    pub id: String,
    #[cfg_attr(feature = "serde", serde_as(as = "Option<DurationMilliSeconds<i64>>"))]
    pub duration: Option<Duration>,
}

fn test() {
    let exercise = Exercise {
        id: "an-id".to_string(),
        duration: Some(Duration::new(10, 0)),
    };
    let duration = exercise.duration;
}

rust-analyzer version: 1.72.0 (5680fa1 2023-08-23)

rustc version: 1.72.0 (5680fa18f 2023-08-23)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the provided Rust example with cfg_eval, serde_as, and the Exercise type, then trace how proc macros are evaluated for user-facing operations. Verify whether type signatures and completions work without adding cfg_eval to procMacro.ignored, while ensuring the result does not introduce false errors compared with compilation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.