mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
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)]`.
This commit is contained in:
parent
0d3bad85e6
commit
1f6abb7fba
2 changed files with 30 additions and 2 deletions
|
@ -7,7 +7,7 @@ use std::{collections::VecDeque, fmt, fs, path::Path, process::Command};
|
|||
use anyhow::{format_err, Context, Result};
|
||||
use base_db::{CrateDisplayName, CrateGraph, CrateId, CrateName, Edition, Env, FileId, ProcMacro};
|
||||
use cargo_workspace::DepKind;
|
||||
use cfg::CfgOptions;
|
||||
use cfg::{CfgAtom, CfgDiff, CfgOptions};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
use proc_macro_api::ProcMacroClient;
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
|
@ -425,6 +425,20 @@ fn cargo_to_crate_graph(
|
|||
let mut has_private = false;
|
||||
// Next, create crates for each package, target pair
|
||||
for pkg in cargo.packages() {
|
||||
let mut cfg_options = &cfg_options;
|
||||
let mut replaced_cfg_options;
|
||||
if cargo[pkg].name == "core" {
|
||||
// FIXME: in the specific case of libcore in rust-lang/rust (i.e. it is not coming from
|
||||
// a sysroot), there's a `#![cfg(not(test))]` at the top of it that makes its contents
|
||||
// get ignored by r-a. We should implement a more general solution for this
|
||||
|
||||
replaced_cfg_options = cfg_options.clone();
|
||||
replaced_cfg_options.apply_diff(
|
||||
CfgDiff::new(Default::default(), vec![CfgAtom::Flag("test".into())]).unwrap(),
|
||||
);
|
||||
cfg_options = &replaced_cfg_options;
|
||||
};
|
||||
|
||||
has_private |= cargo[pkg].metadata.rustc_private;
|
||||
let mut lib_tgt = None;
|
||||
for &tgt in cargo[pkg].targets.iter() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue