From 2afd0588df2e7dabe5f0c757d1867bc80cb4e828 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 9 Aug 2024 22:11:54 +0200 Subject: [PATCH] Show paths relative to the source root for diagnostics in sub-workspaces This allows rust-analyzer to show inline errors for the library workspace. Clippy recently started doing something similar. --- src/bootstrap/src/bin/rustc.rs | 11 +++++++++++ src/bootstrap/src/core/builder.rs | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 011c289d932db..107442ccfa2f5 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -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"); diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 84c23c059e97e..4c443707a66f7 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -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.