diff options
Diffstat (limited to 'crates/ra_project_model/src/sysroot.rs')
-rw-r--r-- | crates/ra_project_model/src/sysroot.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs index 24c3f47a2..10ca391b6 100644 --- a/crates/ra_project_model/src/sysroot.rs +++ b/crates/ra_project_model/src/sysroot.rs | |||
@@ -8,7 +8,7 @@ use std::{ | |||
8 | 8 | ||
9 | use ra_arena::{impl_arena_id, Arena, RawId}; | 9 | use ra_arena::{impl_arena_id, Arena, RawId}; |
10 | 10 | ||
11 | use crate::WorkspaceError; | 11 | use crate::Result; |
12 | 12 | ||
13 | #[derive(Default, Debug, Clone)] | 13 | #[derive(Default, Debug, Clone)] |
14 | pub struct Sysroot { | 14 | pub struct Sysroot { |
@@ -47,11 +47,16 @@ impl Sysroot { | |||
47 | self.crates.iter().map(|(id, _data)| id) | 47 | self.crates.iter().map(|(id, _data)| id) |
48 | } | 48 | } |
49 | 49 | ||
50 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot, WorkspaceError> { | 50 | pub fn discover(cargo_toml: &Path) -> Result<Sysroot> { |
51 | let src = try_find_src_path(cargo_toml)?; | 51 | let src = try_find_src_path(cargo_toml)?; |
52 | 52 | ||
53 | if !src.exists() { | 53 | if !src.exists() { |
54 | return Err(WorkspaceError::NoStdLib(src)); | 54 | Err(format!( |
55 | "can't load standard library from sysroot\n\ | ||
56 | {:?}\n\ | ||
57 | try running `rustup component add rust-src` or set `RUST_SRC_PATH`", | ||
58 | src, | ||
59 | ))?; | ||
55 | } | 60 | } |
56 | 61 | ||
57 | let mut sysroot = Sysroot { crates: Arena::default() }; | 62 | let mut sysroot = Sysroot { crates: Arena::default() }; |
@@ -85,7 +90,7 @@ impl Sysroot { | |||
85 | } | 90 | } |
86 | } | 91 | } |
87 | 92 | ||
88 | fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf, WorkspaceError> { | 93 | fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf> { |
89 | if let Ok(path) = env::var("RUST_SRC_PATH") { | 94 | if let Ok(path) = env::var("RUST_SRC_PATH") { |
90 | return Ok(path.into()); | 95 | return Ok(path.into()); |
91 | } | 96 | } |
@@ -93,13 +98,11 @@ fn try_find_src_path(cargo_toml: &Path) -> Result<PathBuf, WorkspaceError> { | |||
93 | let rustc_output = Command::new("rustc") | 98 | let rustc_output = Command::new("rustc") |
94 | .current_dir(cargo_toml.parent().unwrap()) | 99 | .current_dir(cargo_toml.parent().unwrap()) |
95 | .args(&["--print", "sysroot"]) | 100 | .args(&["--print", "sysroot"]) |
96 | .output() | 101 | .output()?; |
97 | .map_err(|err| WorkspaceError::RustcError(err))?; | ||
98 | if !rustc_output.status.success() { | 102 | if !rustc_output.status.success() { |
99 | Err(WorkspaceError::SysrootNotFound)?; | 103 | Err("failed to locate sysroot")?; |
100 | } | 104 | } |
101 | let stdout = String::from_utf8(rustc_output.stdout) | 105 | let stdout = String::from_utf8(rustc_output.stdout)?; |
102 | .map_err(|err| WorkspaceError::RustcOutputError(err))?; | ||
103 | let sysroot_path = Path::new(stdout.trim()); | 106 | let sysroot_path = Path::new(stdout.trim()); |
104 | Ok(sysroot_path.join("lib/rustlib/src/rust/src")) | 107 | Ok(sysroot_path.join("lib/rustlib/src/rust/src")) |
105 | } | 108 | } |