Possible to print full paths for errors?


I build my Rust code as part of another build system which compiles both Rust/C/C++/etc code. The build system invokes Cargo when compiling the code and everything works as expected.

The problem is that error reporting is relative to the source directory. This is usually fine if you work on just one crate but I build several crates from a root directory and when I get a compile error in src/file.rs it makes it really hard to goto that file as the editor has no idea where it actually is.

So I wonder if there is an option for Cargo to always print full paths to files?


1 Like

It does that when cargo's working directory is not a prefix of the crate’s root. For example:

/tmp/a $cargo build --manifest-path /tmp/b/Cargo.toml
   Compiling b v0.1.0 (file:///tmp/b)
error: expected identifier, found `#`
 --> /tmp/b/src/lib.rs:2:1
2 | #[cfg(test)]
  | ^
1 Like

I see. So if I supply the full to Cargo.toml it will print the full path for the filenames?

That’s not sufficient. As I said, the working directory when executing cargo needs to be not a prefix of the crate root.

Alright. Thanks!

FYI I have filed an issue for this over here https://github.com/rust-lang/cargo/issues/5450