Skip to content

Commit a2aab00

Browse files
committed
Auto merge of rust-lang#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.
2 parents 7f75815 + f0f7448 commit a2aab00

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

crates/project-model/src/sysroot.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::{env, fs, iter, ops, path::PathBuf, process::Command};
88

9-
use anyhow::{format_err, Result};
9+
use anyhow::{format_err, Context, Result};
1010
use base_db::CrateName;
1111
use la_arena::{Arena, Idx};
1212
use paths::{AbsPath, AbsPathBuf};
@@ -119,12 +119,15 @@ impl Sysroot {
119119
get_rustc_src(&self.root)
120120
}
121121

122-
pub fn discover_rustc(&self) -> Result<AbsPathBuf, std::io::Error> {
122+
pub fn discover_rustc(&self) -> anyhow::Result<AbsPathBuf> {
123123
let rustc = self.root.join("bin/rustc");
124124
tracing::debug!(?rustc, "checking for rustc binary at location");
125125
match fs::metadata(&rustc) {
126126
Ok(_) => Ok(rustc),
127-
Err(e) => Err(e),
127+
Err(e) => Err(e).context(format!(
128+
"failed to discover rustc in sysroot: {:?}",
129+
AsRef::<std::path::Path>::as_ref(&self.root)
130+
)),
128131
}
129132
}
130133

0 commit comments

Comments
 (0)