Skip to content

Commit

Permalink
Show paths relative to the source root for diagnostics in sub-workspaces
Browse files Browse the repository at this point in the history
This allows rust-analyzer to show inline errors for the library
workspace. Clippy recently started doing something similar.
  • Loading branch information
bjorn3 committed Aug 9, 2024
1 parent 899eb03 commit 2afd058
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ fn main() {
};
cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());

let rustc_source_dir = env::var_os("RUSTC_SOURCE_DIR").unwrap();
let workspace_prefix =
if let Ok(prefix) = env::current_dir().unwrap().strip_prefix(&rustc_source_dir) {
prefix.to_owned()
} else {
PathBuf::from(".")
};

cmd.arg("--remap-path-prefix");
cmd.arg(format!("={}", workspace_prefix.display()));

// Get the name of the crate we're compiling, if any.
let crate_name = parse_value_from_args(&orig_args, "--crate-name");

Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,8 @@ impl<'a> Builder<'a> {
.env("RUSTDOC", self.bootstrap_out.join("rustdoc"))
.env("RUSTDOC_REAL", rustdoc_path)
.env("RUSTC_ERROR_METADATA_DST", self.extended_error_dir())
.env("RUSTC_BREAK_ON_ICE", "1");
.env("RUSTC_BREAK_ON_ICE", "1")
.env("RUSTC_SOURCE_DIR", &self.src);

// Set RUSTC_WRAPPER to the bootstrap shim, which switches between beta and in-tree
// sysroot depending on whether we're building build scripts.
Expand Down

0 comments on commit 2afd058

Please sign in to comment.