rust-lang / rust-lang/rust-analyzer

Our module path exploration does not match rustc's

Open
#11,682 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Given a lib.rs or main.rs with:

mod outline;

With outline.rs defined as:

const _: () = {
    mod inline {
        #[path = "pathed.rs"]
        mod pathed;
    }
};

rustc attempts to load: src/inline/pathed.rs
r-a attempts to load: src/inline/pathed.rs

But with outline.rs defined as:

mod inline {
    const _: () = {
        mod inline {
            #[path = "pathed.rs"]
            mod pathed;
        }
    };
}

rustc attempts to load: src/outline/inline/inline/pathed.rs
r-a attempts to load: src/inline/inline/pathed.rs

This is apparently expected behaviour (I'd like to say it is not), though I don't quite fully grasp why: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/Surprising.20behaviour.20with.20.23.5Bpath.5D.20and.20block.20scopes

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 linked Zulip discussion, then reproduce the two module layouts using lib.rs or main.rs and outline.rs. Compare rustc's and rust-analyzer's attempted paths; done means rust-analyzer resolves the nested #[path] module to the same path as rustc.

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.