From 4a6e602c9419cc5ed464343b2373c7fe86fb89d6 Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 11 Feb 2021 17:34:56 +0100 Subject: Allow automatically detect the rustc-src directory (fixes #3517). If the configured rustcSource is set to "discover", try to automatically detect a source from the sysroot rustc directory. --- crates/project_model/src/workspace.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'crates/project_model/src/workspace.rs') diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs index c30861976..0220efdb4 100644 --- a/crates/project_model/src/workspace.rs +++ b/crates/project_model/src/workspace.rs @@ -114,6 +114,7 @@ impl ProjectWorkspace { cargo_version ) })?; + let sysroot = if config.no_sysroot { Sysroot::default() } else { @@ -125,7 +126,17 @@ impl ProjectWorkspace { })? }; - let rustc = if let Some(rustc_dir) = &config.rustc_source { + let rustc_dir = if let Some(rustc_source) = &config.rustc_source { + use cargo_workspace::RustcSource; + match rustc_source { + RustcSource::Path(path) => Some(path.clone()), + RustcSource::Discover => Sysroot::discover_rustc(&cargo_toml), + } + } else { + None + }; + + let rustc = if let Some(rustc_dir) = rustc_dir { Some( CargoWorkspace::from_cargo_metadata(&rustc_dir, config, progress) .with_context(|| { -- cgit v1.2.3