rust-lang / rust-lang/rust-analyzer

Macro v2 can see private items, but we don't name resolve it

Open
#15,192 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Rustc accepts this code, but we don't:

#![feature(decl_macro)]

mod privacy_boundary {
    mod inner {
        pub fn x() -> i32 {
            5
        }
    }

    pub macro m() {
        $crate::privacy_boundary::inner::x()
    }
}

use privacy_boundary::m;

fn main() {
    let v = m!(); // we report the type of v as {unknown}
    dbg!(v);
}

Somehow unrelated: maybe we should resolve names even if they are private?

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 supplied Rust reproducer and compare rust-analyzer's result with rustc's accepted behavior; no file or test is named. Trace macro v2 name resolution across the privacy boundary, and consider the issue complete when the example resolves v as i32 instead of {unknown}, with the behavior covered by a test.

Written by the indexing model from the issue text.

Assessment

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