rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.88k stars 1.54k forks source link

Files included using `include!()` macro in `lib.rs` are still `unlinked-file` #17390

Open NessajCN opened 1 month ago

NessajCN commented 1 month ago

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

rust-analyzer version: 0.4.1994-standalone [/home/nessaj/.vscode/extensions/rust-lang.rust-analyzer-0.4.1994-linux-x64/server/rust-analyzer]

rustc version: (eg. output of rustc -V) rustc 1.78.0 (9b00956e5 2024-04-29)

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)

VSCode 1.90.0 rust-analyzer v0.4.1994 (pre-release)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME)

repository link (if public, optional): (eg. rust-analyzer)

code snippet to reproduce:

// src/lib.rs
include!("xx.rs");
// src/xx.rs
// Statements defined here all indicates: file not included in module tree rust-analyzer (unlinked-file)
// which worked perfect in previous versions.
pub const YY: u8 = 0xff;

Having tested in both Linux (Archlinux+KDE) and MacOS. Reproduced.

Veykril commented 1 month ago

Hmm right, this file is in fact not a module, so when we try to resolve it as one we fail emitting the diagnostic. Semantics::file_to_module_def should probably have a fallback check for files that don't resolve to one and then check if the file is included treating the callee module of the include! as the module maybe.