aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_project_model
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_project_model')
-rw-r--r--crates/ra_project_model/src/lib.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index ef443fc09..4ef2e6f85 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -250,7 +250,7 @@ impl ProjectWorkspace {
250 250
251 pub fn to_crate_graph( 251 pub fn to_crate_graph(
252 &self, 252 &self,
253 default_cfg_options: &CfgOptions, 253 target: Option<&String>,
254 extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>, 254 extern_source_roots: &FxHashMap<PathBuf, ExternSourceId>,
255 proc_macro_client: &ProcMacroClient, 255 proc_macro_client: &ProcMacroClient,
256 load: &mut dyn FnMut(&Path) -> Option<FileId>, 256 load: &mut dyn FnMut(&Path) -> Option<FileId>,
@@ -269,7 +269,7 @@ impl ProjectWorkspace {
269 json_project::Edition::Edition2018 => Edition::Edition2018, 269 json_project::Edition::Edition2018 => Edition::Edition2018,
270 }; 270 };
271 let cfg_options = { 271 let cfg_options = {
272 let mut opts = default_cfg_options.clone(); 272 let mut opts = CfgOptions::default();
273 for cfg in &krate.cfg { 273 for cfg in &krate.cfg {
274 match cfg.find('=') { 274 match cfg.find('=') {
275 None => opts.insert_atom(cfg.into()), 275 None => opts.insert_atom(cfg.into()),
@@ -343,14 +343,13 @@ impl ProjectWorkspace {
343 } 343 }
344 } 344 }
345 ProjectWorkspace::Cargo { cargo, sysroot } => { 345 ProjectWorkspace::Cargo { cargo, sysroot } => {
346 let mut cfg_options = get_rustc_cfg_options(target);
347
346 let sysroot_crates: FxHashMap<_, _> = sysroot 348 let sysroot_crates: FxHashMap<_, _> = sysroot
347 .crates() 349 .crates()
348 .filter_map(|krate| { 350 .filter_map(|krate| {
349 let file_id = load(&sysroot[krate].root)?; 351 let file_id = load(&sysroot[krate].root)?;
350 352
351 // Crates from sysroot have `cfg(test)` disabled
352 let cfg_options = default_cfg_options.clone();
353
354 let env = Env::default(); 353 let env = Env::default();
355 let extern_source = ExternSource::default(); 354 let extern_source = ExternSource::default();
356 let proc_macro = vec![]; 355 let proc_macro = vec![];
@@ -361,7 +360,7 @@ impl ProjectWorkspace {
361 file_id, 360 file_id,
362 Edition::Edition2018, 361 Edition::Edition2018,
363 Some(crate_name), 362 Some(crate_name),
364 cfg_options, 363 cfg_options.clone(),
365 env, 364 env,
366 extern_source, 365 extern_source,
367 proc_macro, 366 proc_macro,
@@ -392,6 +391,10 @@ impl ProjectWorkspace {
392 391
393 let mut pkg_to_lib_crate = FxHashMap::default(); 392 let mut pkg_to_lib_crate = FxHashMap::default();
394 let mut pkg_crates = FxHashMap::default(); 393 let mut pkg_crates = FxHashMap::default();
394
395 // Add test cfg for non-sysroot crates
396 cfg_options.insert_atom("test".into());
397
395 // Next, create crates for each package, target pair 398 // Next, create crates for each package, target pair
396 for pkg in cargo.packages() { 399 for pkg in cargo.packages() {
397 let mut lib_tgt = None; 400 let mut lib_tgt = None;
@@ -400,12 +403,7 @@ impl ProjectWorkspace {
400 if let Some(file_id) = load(root) { 403 if let Some(file_id) = load(root) {
401 let edition = cargo[pkg].edition; 404 let edition = cargo[pkg].edition;
402 let cfg_options = { 405 let cfg_options = {
403 let mut opts = { 406 let mut opts = cfg_options.clone();
404 let mut opts = default_cfg_options.clone();
405 opts.insert_atom("test".into());
406 opts
407 };
408
409 for feature in cargo[pkg].features.iter() { 407 for feature in cargo[pkg].features.iter() {
410 opts.insert_key_value("feature".into(), feature.into()); 408 opts.insert_key_value("feature".into(), feature.into());
411 } 409 }
@@ -562,7 +560,7 @@ impl ProjectWorkspace {
562 } 560 }
563} 561}
564 562
565pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions { 563fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
566 let mut cfg_options = CfgOptions::default(); 564 let mut cfg_options = CfgOptions::default();
567 565
568 // Some nightly-only cfgs, which are required for stdlib 566 // Some nightly-only cfgs, which are required for stdlib
@@ -602,6 +600,8 @@ pub fn get_rustc_cfg_options(target: Option<&String>) -> CfgOptions {
602 Err(e) => log::error!("failed to get rustc cfgs: {:#}", e), 600 Err(e) => log::error!("failed to get rustc cfgs: {:#}", e),
603 } 601 }
604 602
603 cfg_options.insert_atom("debug_assertion".into());
604
605 cfg_options 605 cfg_options
606} 606}
607 607