rust-lang / rust-lang/rust-analyzer

Unresolved import with `macro_rules_attribute`

Open
#14,117 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer 1.69.0-nightly (8996ea9 2023-02-09)

rustc version: rustc 1.67.1 (d5a82bbd2 2023-02-07)

The following code runs/compiles fine, but in rust-analyzer yields an unresoved import error on use module::Struct, that seems to be caused by apply. Importing from the parent module works without error (i.e. use crate::NonModule does not produce any error).

#[macro_use]
extern crate macro_rules_attribute;

attribute_alias! {
    #[apply(Test)] = #[derive(Debug)];
}

mod module {
    use crate::NonModule;

    #[apply(Test)]
    pub struct Struct(pub NonModule);
}

use module::Struct;

#[apply(Test)]
pub struct NonModule;

fn main() {
    println!("{:?}", Struct(NonModule));
    println!("{NonModule:?}");
}

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 with the minimal Rust reproducer in the issue and run rust-analyzer against it with the shown macro_rules_attribute and #[apply(Test)] usage. Trace how the analyzer resolves use module::Struct versus use crate::NonModule. Done means the reproducer compiles without an erroneous unresolved-import diagnostic while preserving the existing valid behavior.

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.