aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model/src/lib.rs')
-rw-r--r--crates/ra_project_model/src/lib.rs48
1 files changed, 42 insertions, 6 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 0e14f1b70..55ff4d6ef 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -13,7 +13,7 @@ use std::{
13}; 13};
14 14
15use ra_cfg::CfgOptions; 15use ra_cfg::CfgOptions;
16use ra_db::{CrateGraph, CrateId, Edition, FileId}; 16use ra_db::{CrateGraph, CrateId, Edition, Env, FileId};
17use rustc_hash::FxHashMap; 17use rustc_hash::FxHashMap;
18use serde_json::from_reader; 18use serde_json::from_reader;
19 19
@@ -146,7 +146,12 @@ impl ProjectWorkspace {
146 }; 146 };
147 crates.insert( 147 crates.insert(
148 crate_id, 148 crate_id,
149 crate_graph.add_crate_root(file_id, edition, cfg_options), 149 crate_graph.add_crate_root(
150 file_id,
151 edition,
152 cfg_options,
153 Env::default(),
154 ),
150 ); 155 );
151 } 156 }
152 } 157 }
@@ -180,8 +185,12 @@ impl ProjectWorkspace {
180 opts 185 opts
181 }; 186 };
182 187
183 let crate_id = 188 let crate_id = crate_graph.add_crate_root(
184 crate_graph.add_crate_root(file_id, Edition::Edition2018, cfg_options); 189 file_id,
190 Edition::Edition2018,
191 cfg_options,
192 Env::default(),
193 );
185 sysroot_crates.insert(krate, crate_id); 194 sysroot_crates.insert(krate, crate_id);
186 names.insert(crate_id, krate.name(&sysroot).to_string()); 195 names.insert(crate_id, krate.name(&sysroot).to_string());
187 } 196 }
@@ -200,7 +209,10 @@ impl ProjectWorkspace {
200 } 209 }
201 210
202 let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied()); 211 let libcore = sysroot.core().and_then(|it| sysroot_crates.get(&it).copied());
212 let liballoc = sysroot.alloc().and_then(|it| sysroot_crates.get(&it).copied());
203 let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied()); 213 let libstd = sysroot.std().and_then(|it| sysroot_crates.get(&it).copied());
214 let libproc_macro =
215 sysroot.proc_macro().and_then(|it| sysroot_crates.get(&it).copied());
204 216
205 let mut pkg_to_lib_crate = FxHashMap::default(); 217 let mut pkg_to_lib_crate = FxHashMap::default();
206 let mut pkg_crates = FxHashMap::default(); 218 let mut pkg_crates = FxHashMap::default();
@@ -216,13 +228,32 @@ impl ProjectWorkspace {
216 opts.insert_features(pkg.features(&cargo).iter().map(Into::into)); 228 opts.insert_features(pkg.features(&cargo).iter().map(Into::into));
217 opts 229 opts
218 }; 230 };
219 let crate_id = 231 let crate_id = crate_graph.add_crate_root(
220 crate_graph.add_crate_root(file_id, edition, cfg_options); 232 file_id,
233 edition,
234 cfg_options,
235 Env::default(),
236 );
221 names.insert(crate_id, pkg.name(&cargo).to_string()); 237 names.insert(crate_id, pkg.name(&cargo).to_string());
222 if tgt.kind(&cargo) == TargetKind::Lib { 238 if tgt.kind(&cargo) == TargetKind::Lib {
223 lib_tgt = Some(crate_id); 239 lib_tgt = Some(crate_id);
224 pkg_to_lib_crate.insert(pkg, crate_id); 240 pkg_to_lib_crate.insert(pkg, crate_id);
225 } 241 }
242 if tgt.is_proc_macro(&cargo) {
243 if let Some(proc_macro) = libproc_macro {
244 if let Err(_) = crate_graph.add_dep(
245 crate_id,
246 "proc_macro".into(),
247 proc_macro,
248 ) {
249 log::error!(
250 "cyclic dependency on proc_macro for {}",
251 pkg.name(&cargo)
252 )
253 }
254 }
255 }
256
226 pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id); 257 pkg_crates.entry(pkg).or_insert_with(Vec::new).push(crate_id);
227 } 258 }
228 } 259 }
@@ -248,6 +279,11 @@ impl ProjectWorkspace {
248 log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) 279 log::error!("cyclic dependency on core for {}", pkg.name(&cargo))
249 } 280 }
250 } 281 }
282 if let Some(alloc) = liballoc {
283 if let Err(_) = crate_graph.add_dep(from, "alloc".into(), alloc) {
284 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo))
285 }
286 }
251 if let Some(std) = libstd { 287 if let Some(std) = libstd {
252 if let Err(_) = crate_graph.add_dep(from, "std".into(), std) { 288 if let Err(_) = crate_graph.add_dep(from, "std".into(), std) {
253 log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) 289 log::error!("cyclic dependency on std for {}", pkg.name(&cargo))