rust-lang / rust-lang/rust-analyzer

proc macro attributes considered to be `unresolvedReference`

Open
#10,935 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

consider the following code used w/ the serde library:

use serde::Deserialize;

#[derive(Deserialize)]
struct Foo {
    #[serde(default)]
   // ^^^^^ unresolvedReference 
    bar: u64,
}

We should be able to figure out if this is a valid attribute or not, by looking at the things the structs derive from and looking at the attributes for each proc macro to compute a list of identifiers that are valid within this context:

// in serde_derive/src/lib.rs
#[proc_macro_derive(Deserialize, attributes(serde))]
                                         // ^^^^^ we should find these.
pub fn derive_deserialize(input: TokenStream) -> TokenStream {
    let mut input = parse_macro_input!(input as DeriveInput);
    de::expand_derive_deserialize(&mut input)
        .unwrap_or_else(to_compile_errors)
        .into()
}

Bonus points would be to have a hover implementation that shows which proc macro's are consuming this attribute as well!

rust-analyzer version: 6434ada19 2021-12-05 dev
rustc-version: 1.57.0

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

Start by tracing rust-analyzer's attribute resolution for derived proc macros and compare it with the declaration in serde_derive/src/lib.rs, where #[proc_macro_derive(Deserialize, attributes(serde))] identifies the valid namespace. Done means valid proc-macro attributes no longer appear as unresolvedReference; hover support for the consuming macro is a bonus.

Written by the indexing model from the issue text.

Assessment

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