rust-lang / rust-lang/rust-analyzer
"failed to load file" when including build script output from cargo workspace root
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I am trying to use prost_build to generate rust structs from a .proto file. I've got it working to the point that cargo build succeeds, but rust-analyzer is giving me a "failed to load file .../out/cobalt.event_type.rs" error. I've checked the path in the error and the file does exist and is valid rust code.
In my case, the crate I'm working in is part of a cargo workspace, so the target directory is a sibling of my crate root. It appears from followup comments on #17828 that this might be a bug in rust-analyzer, where it fails to load included source files which are outside of the crate root. That issue was originally regarding non-rust included files, but in this case the included file ends with .rs, so a new issue seemed appropriate.
rust-analyzer version: 1.85.1
rustc version: 1.85.1
editor or extension: emacs-lsp
relevant settings:
code snippet to reproduce:
build.rs:
println!("cargo:rerun-if-changed=../../libraries/cobalt_protobuf/src");
prost_build::compile_protos(
&["../../libraries/cobalt_protobuf/src/event_type.proto"],
&["../../libraries/cobalt_protobuf/src"],
)?;
production code:
pub mod cobalt {
pub mod event_type {
include!(concat!(env!("OUT_DIR"), "/cobalt.event_type.rs"));
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the build.rs and production include! snippet, then reproduce the rust-analyzer error in the described Cargo workspace layout. Trace how rust-analyzer handles the generated cobalt.event_type.rs file under OUT_DIR when it is outside the crate root. Done means the existing generated Rust file loads without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 62/100