rust-lang / rust-lang/rust-analyzer

Expand macro recursively does not work on macro in `cfg_attr` attribute, despite the feature being enabled for r-a

Open
#12,862 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I have a type that is roughly like this:

#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Foo(String, Option<usize>);

If I place my cursor on Clone or Debug and execute the "Rust Analyzer: Expand macro recursively" command in VS Code, I get the expected expanded macro output. However, if I place it on Serialize or Deserialize, I get "Not available" as the output, despite these macros being active due to my Rust analyzer settings:

{
    "rust-analyzer.cargo.features": "all",
    "rust-analyzer.checkOnSave.features": "all"
}

If I change my code to

#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct Foo(String, Option<usize>);

I can expand the macros, but I don't see why they can't also be expanded behind the feature gate when that feature is activated.

rust-analyzer version: rust-analyzer version: 0.3.1131-standalone (897a7ec4b 2022-07-17)

rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)

relevant settings: I think the relevant settings are already put above.

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 in VS Code with the shown cfg_attr derive and all features enabled, then trace rust-analyzer's recursive macro expansion handling for attribute-gated derives. Done means Serialize and Deserialize expand successfully behind cfg_attr, matching the behavior of direct derives.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, vscode
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.