Possible to print full paths for errors?


#1

Hi,

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?

Cheers!


#2

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)]
  | ^

#3

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


#4

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


#5

Alright. Thanks!


#6

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