rust-analyzer: `#[path = "../XXXXXX"]` attribute on modules gives false `unresolved-module` error

image

image

Example: https://github.com/WilliamVenner/rust-analyzer-broken-example

Code:

./package/src/main.rs

#[path = "../../silly_mod/mod.rs"]
mod silly_mod;

fn main() {
    silly_mod::hello();
}

./silly_mod/mod.rs

pub fn hello() {
	println!("Hello, world!");
}

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 4
  • Comments: 17 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Is there any way to suppress the error? I can live with “unknown” for the module content, but the red squiggles are distracting. 😃

Yeah, I have this in my settings

    "rust-analyzer.diagnostics.disabled": [
        "unlinked-file", // I guess for "normal" projects unlinked files are strange, for me they are common
        "missing-match-arm", // https://github.com/rust-lang/rust-analyzer/issues/4896
        "type-mismatch", // https://github.com/rust-lang/rust-analyzer/issues/1109
        "unresolved-module", // https://github.com/rust-lang/rust-analyzer/issues/9173
        "unresolved-extern-crate", // https://github.com/rust-lang/rust-analyzer/issues/12926
    ],

I’ve also just run into this issue, I guess the more idiomatic way to handle this situation is to make the referenced module into a full blown library referenced by path = "../path/to/module" in Cargo.toml?