Error messages use relative paths differently if in a workspace · Issue #5895 · rust-lang/cargo (original) (raw)
Error messages printed by rustc
are relative to the path printed by cargo
only when the crate is not part of a workspace. When the crate is a workspace member, rustc
's messages are relative to the workspace directory. This makes it hard for programs like Emacs to find the file to which the error messages apply.
Here's the non-workspace case:
$ pwd
/home/jimb/play
$ cargo new str2
Created binary (application) `str2` project
$ cd str2
$ echo bleah >> src/main.rs
$ cargo check
Checking str2 v0.1.0 (file:///home/jimb/play/str2)
error: expected one of `!` or `::`, found `<eof>`
--> src/main.rs:4:1
|
4 | bleah
| ^^^^^ expected one of `!` or `::` here
The path in the rustc
error message, src/main.rs
, is relative to the path given in the Checking...
message, /home/jimb/play/str2
.
But if we create a workspace, things are different:
$ pwd
/home/jimb/play
$ mkdir str
$ cd str
$ cat > Cargo.toml << EOF
> [workspace]
> members = [ "member" ]
> EOF
$ cargo new member
Created binary (application) `member` project
$ echo bleah >> member/src/main.rs
$ cargo check
Checking member v0.1.0 (file:///home/jimb/play/str/member)
error: expected one of `!` or `::`, found `<eof>`
--> member/src/main.rs:4:1
|
4 | bleah
| ^^^^^ expected one of `!` or `::` here
In this case, rustc
's error message cites member/src/main.rs
, while cargo
's output cites /home/jimb/play/str/member
.
This behavior is consistent regardless of the directory in which one invokes cargo check
, cargo build
, or whatever.
See also