rust-lang / rust-lang/rust-analyzer

RA indicates error when using generated macros by proc-macros

Open
#10,675 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Small example project

Hi! I'm not sure if this is related to some WIP or other issues, but I've created a small example of this problem: swfsql/test-macros-ra

My env

rustup show: 1.55.0-x86_64-unknown-linux-gnu
Rust Analyzer: Show RA Version: 04f03a360 2021-11-01 stable
VsCode settings:
  "rust-analyzer.procMacro.enable": true
  "rust-analyzer.experimental.procAttrMacros": true

Problem

I'm using proc-macros to create new macro_rules! macros, and while I'm #[macro_export]ing them, I also want to use them by my modules in the library.
I believe that the linked example will contain other necessary information, but the problem is that while cargo check passes, RA indicates an error (unresolved import - while this isn't so bad, I think it would be better to not have a permanent false-positive XD but perhaps this is an uncommon case).

Thanks in advance, for anyone who are able to take a look!

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 unresolved-import diagnostic using the linked swfsql/test-macros-ra example with rust-analyzer.procMacro.enable and experimental.procAttrMacros enabled. Compare rust-analyzer's result with cargo check; done means the generated macro import no longer produces a false-positive error while the existing example continues to work.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.