Auto merge of #14556 - Veykril:sysroot-no-core-warn, r=Veykril
internal: Warn when loading sysroot fails to find the core library Should help a bit more with user experience, before we only logged this now we show it in the status Closes https://github.com/rust-lang/rust-analyzer/issues/11606
This commit is contained in:
commit
b093423d12
@ -74,6 +74,23 @@ impl Sysroot {
|
|||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.crates.is_empty()
|
self.crates.is_empty()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn loading_warning(&self) -> Option<String> {
|
||||||
|
if self.by_name("core").is_none() {
|
||||||
|
let var_note = if env::var_os("RUST_SRC_PATH").is_some() {
|
||||||
|
" (`RUST_SRC_PATH` might be incorrect, try unsetting it)"
|
||||||
|
} else {
|
||||||
|
" try running `rustup component add rust-src` to possible fix this"
|
||||||
|
};
|
||||||
|
Some(format!(
|
||||||
|
"could not find libcore in loaded sysroot at `{}`{}",
|
||||||
|
self.src_root.as_path().display(),
|
||||||
|
var_note,
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Expose a builder api as loading the sysroot got way too modular and complicated.
|
// FIXME: Expose a builder api as loading the sysroot got way too modular and complicated.
|
||||||
@ -103,7 +120,7 @@ impl Sysroot {
|
|||||||
|
|
||||||
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
|
pub fn with_sysroot_dir(sysroot_dir: AbsPathBuf) -> Result<Sysroot> {
|
||||||
let sysroot_src_dir = discover_sysroot_src_dir(&sysroot_dir).ok_or_else(|| {
|
let sysroot_src_dir = discover_sysroot_src_dir(&sysroot_dir).ok_or_else(|| {
|
||||||
format_err!("can't load standard library from sysroot {}", sysroot_dir.display())
|
format_err!("can't load standard library from sysroot path {}", sysroot_dir.display())
|
||||||
})?;
|
})?;
|
||||||
Ok(Sysroot::load(sysroot_dir, sysroot_src_dir))
|
Ok(Sysroot::load(sysroot_dir, sysroot_src_dir))
|
||||||
}
|
}
|
||||||
@ -153,19 +170,6 @@ impl Sysroot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sysroot.by_name("core").is_none() {
|
|
||||||
let var_note = if env::var_os("RUST_SRC_PATH").is_some() {
|
|
||||||
" (`RUST_SRC_PATH` might be incorrect, try unsetting it)"
|
|
||||||
} else {
|
|
||||||
""
|
|
||||||
};
|
|
||||||
tracing::error!(
|
|
||||||
"could not find libcore in sysroot path `{}`{}",
|
|
||||||
sysroot.src_root.as_path().display(),
|
|
||||||
var_note,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
sysroot
|
sysroot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,10 +138,20 @@ impl GlobalState {
|
|||||||
let (ProjectWorkspace::Cargo { sysroot, .. }
|
let (ProjectWorkspace::Cargo { sysroot, .. }
|
||||||
| ProjectWorkspace::Json { sysroot, .. }
|
| ProjectWorkspace::Json { sysroot, .. }
|
||||||
| ProjectWorkspace::DetachedFiles { sysroot, .. }) = ws;
|
| ProjectWorkspace::DetachedFiles { sysroot, .. }) = ws;
|
||||||
if let Err(Some(e)) = sysroot {
|
match sysroot {
|
||||||
status.health = lsp_ext::Health::Warning;
|
Err(None) => (),
|
||||||
message.push_str(e);
|
Err(Some(e)) => {
|
||||||
message.push_str("\n\n");
|
status.health = lsp_ext::Health::Warning;
|
||||||
|
message.push_str(e);
|
||||||
|
message.push_str("\n\n");
|
||||||
|
}
|
||||||
|
Ok(s) => {
|
||||||
|
if let Some(e) = s.loading_warning() {
|
||||||
|
status.health = lsp_ext::Health::Warning;
|
||||||
|
message.push_str(&e);
|
||||||
|
message.push_str("\n\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let ProjectWorkspace::Cargo { rustc: Err(Some(e)), .. } = ws {
|
if let ProjectWorkspace::Cargo { rustc: Err(Some(e)), .. } = ws {
|
||||||
status.health = lsp_ext::Health::Warning;
|
status.health = lsp_ext::Health::Warning;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user