rust-lang / rust-lang/rust-analyzer

Generated mod via build.rs not properly picked up

Open
#19,481 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
rust-analyzer version: 0.3.2353-standalone (37acea8052 2025-03-23) [/home/andreas/.vscode/extensions/rust-lang.rust-analyzer-0.3.2353-linux-x64/server/rust-analyzer]

rustc version: (eg. output of rustc -V)
rustc 1.85.1 (4eb161250 2025-03-15)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
VSC 0.3.2353

The build.rs generates a mod with consts.
In the screenshot the interesting thing is that the const is evaluated correctly. In the editor though, the mod is marked as unknown.

code snippet to reproduce:

use std::{
    env,
    fs,
    io::Write,
    path::Path,
};

use mixlib::MixFilename;

fn main() {
    println!("cargo::rerun-if-changed=td.csv");
    println!("cargo::rerun-if-changed=build.rs");

    let mut reader = csv::ReaderBuilder::new().delimiter(b' ').from_path("td.csv").unwrap();
    let iter = reader.records();
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let dest_path = Path::new(&out_dir).join("crcs.rs");
    let mut w = fs::File::create(&dest_path).unwrap();
    writeln!(&mut w, "pub mod known_files {{").unwrap();
    writeln!(&mut w, "  use mixlib::MixFilename;").unwrap();

    for result in iter {
        let result = result.unwrap();
        let crc: u32 = result.get(0).unwrap().parse().unwrap();
        let filename = result.get(1).unwrap();
        let mf = MixFilename::new(filename);
        if mf.crc != crc {
            panic!("CRC value for {filename} seems to diverge: {crc} <-> {}", mf.crc);
        }
        let symbol = filename.replace(".", "_");
        writeln!(
            &mut w,
            "  pub const {symbol}: MixFilename = MixFilename::new(\"{filename}\");"
        )
        .unwrap();
    }
    writeln!(&mut w, "}}").unwrap();
}

Image

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 provided build.rs reproducer, which writes crcs.rs under OUT_DIR and declares the known_files module, then investigate how rust-analyzer discovers generated modules. Reproduce the unknown-module diagnostic in the editor and verify that the generated module is recognized while its constants remain available.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.