aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_project_model/src/sysroot.rs42
1 files changed, 34 insertions, 8 deletions
diff --git a/crates/ra_project_model/src/sysroot.rs b/crates/ra_project_model/src/sysroot.rs
index 8a92acea5..9e23b5805 100644
--- a/crates/ra_project_model/src/sysroot.rs
+++ b/crates/ra_project_model/src/sysroot.rs
@@ -54,6 +54,8 @@ impl Sysroot {
54 let src = get_or_install_rust_src(cargo_toml)?; 54 let src = get_or_install_rust_src(cargo_toml)?;
55 let mut sysroot = Sysroot { crates: Arena::default() }; 55 let mut sysroot = Sysroot { crates: Arena::default() };
56 for name in SYSROOT_CRATES.trim().lines() { 56 for name in SYSROOT_CRATES.trim().lines() {
57 // FIXME: remove this path when 1.47 comes out
58 // https://github.com/rust-lang/rust/pull/73265
57 let root = src.join(format!("lib{}", name)).join("lib.rs"); 59 let root = src.join(format!("lib{}", name)).join("lib.rs");
58 if root.exists() { 60 if root.exists() {
59 sysroot.crates.alloc(SysrootCrateData { 61 sysroot.crates.alloc(SysrootCrateData {
@@ -61,6 +63,15 @@ impl Sysroot {
61 root, 63 root,
62 deps: Vec::new(), 64 deps: Vec::new(),
63 }); 65 });
66 } else {
67 let root = src.join(name).join("src/lib.rs");
68 if root.exists() {
69 sysroot.crates.alloc(SysrootCrateData {
70 name: name.into(),
71 root,
72 deps: Vec::new(),
73 });
74 }
64 } 75 }
65 } 76 }
66 if let Some(std) = sysroot.std() { 77 if let Some(std) = sysroot.std() {
@@ -94,23 +105,38 @@ fn get_or_install_rust_src(cargo_toml: &AbsPath) -> Result<AbsPathBuf> {
94 rustc.current_dir(current_dir).args(&["--print", "sysroot"]); 105 rustc.current_dir(current_dir).args(&["--print", "sysroot"]);
95 let stdout = utf8_stdout(rustc)?; 106 let stdout = utf8_stdout(rustc)?;
96 let sysroot_path = AbsPath::assert(Path::new(stdout.trim())); 107 let sysroot_path = AbsPath::assert(Path::new(stdout.trim()));
97 let src_path = sysroot_path.join("lib/rustlib/src/rust/src"); 108 let mut src = get_rust_src(sysroot_path);
98 109 if src.is_none() {
99 if !src_path.exists() {
100 let mut rustup = Command::new(ra_toolchain::rustup()); 110 let mut rustup = Command::new(ra_toolchain::rustup());
101 rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]); 111 rustup.current_dir(current_dir).args(&["component", "add", "rust-src"]);
102 utf8_stdout(rustup)?; 112 utf8_stdout(rustup)?;
113 src = get_rust_src(sysroot_path);
103 } 114 }
104 if !src_path.exists() { 115 match src {
105 bail!( 116 Some(r) => Ok(r),
117 None => bail!(
106 "can't load standard library from sysroot\n\ 118 "can't load standard library from sysroot\n\
107 {}\n\ 119 {}\n\
108 (discovered via `rustc --print sysroot`)\n\ 120 (discovered via `rustc --print sysroot`)\n\
109 try running `rustup component add rust-src` or set `RUST_SRC_PATH`", 121 try running `rustup component add rust-src` or set `RUST_SRC_PATH`",
110 src_path.display(), 122 sysroot_path.display(),
111 ) 123 ),
124 }
125}
126
127fn get_rust_src(sysroot_path: &AbsPath) -> Option<AbsPathBuf> {
128 // try the new path first since the old one still exists
129 let mut src_path = sysroot_path.join("lib/rustlib/src/rust/library");
130 if !src_path.exists() {
131 // FIXME: remove this path when 1.47 comes out
132 // https://github.com/rust-lang/rust/pull/73265
133 src_path = sysroot_path.join("lib/rustlib/src/rust/src");
134 }
135 if src_path.exists() {
136 Some(src_path)
137 } else {
138 None
112 } 139 }
113 Ok(src_path)
114} 140}
115 141
116impl SysrootCrateData { 142impl SysrootCrateData {