about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-04 14:10:57 +0000
committerbors <bors@rust-lang.org>2024-01-04 14:10:57 +0000
commita2aab001a7300afec56d7682a244d7cc5e0bbca2 (patch)
tree6e9b16a02fa5f8c50f8619cee8381ec03b2e2cb1
parent7f75815ca2a61fd9afb6f77d71984f649349dc67 (diff)
parentf0f74486bf89194827017b9df3887b7b84982ab3 (diff)
downloadrust-a2aab001a7300afec56d7682a244d7cc5e0bbca2.tar.gz
rust-a2aab001a7300afec56d7682a244d7cc5e0bbca2.zip
Auto merge of #16241 - Nilstrieb:sysrooting, r=Veykril
Give a userful error when rustc cannot be found in explicit sysroot

Somehow r-a believed that my sysroot was something weird with no rustc. Probably a me issue, but it was impossible to diagnose since r-a just gave me a plain "No such file or directory". Adding this error makes it clear what happened and allows diagnosing the problem.
-rw-r--r--crates/project-model/src/sysroot.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/crates/project-model/src/sysroot.rs b/crates/project-model/src/sysroot.rs
index fe046dd1463..d52e448d747 100644
--- a/crates/project-model/src/sysroot.rs
+++ b/crates/project-model/src/sysroot.rs
@@ -6,7 +6,7 @@
 
 use std::{env, fs, iter, ops, path::PathBuf, process::Command};
 
-use anyhow::{format_err, Result};
+use anyhow::{format_err, Context, Result};
 use base_db::CrateName;
 use la_arena::{Arena, Idx};
 use paths::{AbsPath, AbsPathBuf};
@@ -119,12 +119,15 @@ impl Sysroot {
         get_rustc_src(&self.root)
     }
 
-    pub fn discover_rustc(&self) -> Result<AbsPathBuf, std::io::Error> {
+    pub fn discover_rustc(&self) -> anyhow::Result<AbsPathBuf> {
         let rustc = self.root.join("bin/rustc");
         tracing::debug!(?rustc, "checking for rustc binary at location");
         match fs::metadata(&rustc) {
             Ok(_) => Ok(rustc),
-            Err(e) => Err(e),
+            Err(e) => Err(e).context(format!(
+                "failed to discover rustc in sysroot: {:?}",
+                AsRef::<std::path::Path>::as_ref(&self.root)
+            )),
         }
     }