aboutsummaryrefslogtreecommitdiff
path: root/crates/project_model
diff options
context:
space:
mode:
authorJade <[email protected]>2021-06-12 13:16:22 +0100
committerJade <[email protected]>2021-06-19 09:09:19 +0100
commit1f6abb7fbae35dbd036032a6ea2a9e04307f1f55 (patch)
treec49a07d81e3cc3a6ea6ca3c57fd364492475c49b /crates/project_model
parent0d3bad85e60d011b35da0a8e5dd6611934f6816d (diff)
Fix libcore not being included in rust-lang/rust module tree
If you are opening libcore from rust-lang/rust as opposed to e.g. goto definition from some other crate which would use the sysroot instance of libcore, a `#![cfg(not(test))]` would previously have made all the code excluded from the module tree, breaking the editor experience. This puts in a slight hack that checks for the crate name "core" and turns off `#[cfg(test)]`.
Diffstat (limited to 'crates/project_model')
-rw-r--r--crates/project_model/src/workspace.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/crates/project_model/src/workspace.rs b/crates/project_model/src/workspace.rs
index ef0f3c9e4..c2edb3327 100644
--- a/crates/project_model/src/workspace.rs
+++ b/crates/project_model/src/workspace.rs
@@ -7,7 +7,7 @@ use std::{collections::VecDeque, fmt, fs, path::Path, process::Command};
7use anyhow::{format_err, Context, Result}; 7use anyhow::{format_err, Context, Result};
8use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro}; 8use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro};
9use cargo_workspace::DepKind; 9use cargo_workspace::DepKind;
10use cfg::CfgOptions; 10use cfg::{CfgAtom, CfgDiff, CfgOptions};
11use paths::{AbsPath, AbsPathBuf}; 11use paths::{AbsPath, AbsPathBuf};
12use proc_macro_api::ProcMacroClient; 12use proc_macro_api::ProcMacroClient;
13use rustc_hash::{FxHashMap, FxHashSet}; 13use rustc_hash::{FxHashMap, FxHashSet};
@@ -425,6 +425,20 @@ fn cargo_to_crate_graph(
425 let mut has_private = false; 425 let mut has_private = false;
426 // Next, create crates for each package, target pair 426 // Next, create crates for each package, target pair
427 for pkg in cargo.packages() { 427 for pkg in cargo.packages() {
428 let mut cfg_options = &cfg_options;
429 let mut replaced_cfg_options;
430 if cargo[pkg].name == "core" {
431 // FIXME: in the specific case of libcore in rust-lang/rust (i.e. it is not coming from
432 // a sysroot), there's a `#![cfg(not(test))]` at the top of it that makes its contents
433 // get ignored by r-a. We should implement a more general solution for this
434
435 replaced_cfg_options = cfg_options.clone();
436 replaced_cfg_options.apply_diff(
437 CfgDiff::new(Default::default(), vec![CfgAtom::Flag("test".into())]).unwrap(),
438 );
439 cfg_options = &replaced_cfg_options;
440 };
441
428 has_private |= cargo[pkg].metadata.rustc_private; 442 has_private |= cargo[pkg].metadata.rustc_private;
429 let mut lib_tgt = None; 443 let mut lib_tgt = None;
430 for &tgt in cargo[pkg].targets.iter() { 444 for &tgt in cargo[pkg].targets.iter() {