mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Use symbol in cfg
This commit is contained in:
parent
93024ad411
commit
c30bdfcc84
22 changed files with 147 additions and 92 deletions
|
@ -4,6 +4,7 @@
|
|||
use std::{fmt, str::FromStr};
|
||||
|
||||
use cfg::{CfgDiff, CfgOptions};
|
||||
use intern::Symbol;
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::Serialize;
|
||||
|
||||
|
@ -44,8 +45,10 @@ impl Extend<CfgFlag> for CfgOptions {
|
|||
fn extend<T: IntoIterator<Item = CfgFlag>>(&mut self, iter: T) {
|
||||
for cfg_flag in iter {
|
||||
match cfg_flag {
|
||||
CfgFlag::Atom(it) => self.insert_atom(it.into()),
|
||||
CfgFlag::KeyValue { key, value } => self.insert_key_value(key.into(), value.into()),
|
||||
CfgFlag::Atom(it) => self.insert_atom(Symbol::intern(&it)),
|
||||
CfgFlag::KeyValue { key, value } => {
|
||||
self.insert_key_value(Symbol::intern(&key), Symbol::intern(&value))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use base_db::{CrateGraph, FileId, ProcMacroPaths};
|
|||
use cargo_metadata::Metadata;
|
||||
use cfg::{CfgAtom, CfgDiff};
|
||||
use expect_test::{expect_file, ExpectFile};
|
||||
use intern::sym;
|
||||
use paths::{AbsPath, AbsPathBuf, Utf8Path, Utf8PathBuf};
|
||||
use rustc_hash::FxHashMap;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
@ -180,7 +181,7 @@ fn check_crate_graph(crate_graph: CrateGraph, expect: ExpectFile) {
|
|||
#[test]
|
||||
fn cargo_hello_world_project_model_with_wildcard_overrides() {
|
||||
let cfg_overrides = CfgOverrides {
|
||||
global: CfgDiff::new(Vec::new(), vec![CfgAtom::Flag("test".into())]).unwrap(),
|
||||
global: CfgDiff::new(Vec::new(), vec![CfgAtom::Flag(sym::test.clone())]).unwrap(),
|
||||
selective: Default::default(),
|
||||
};
|
||||
let (crate_graph, _proc_macros) =
|
||||
|
@ -199,7 +200,7 @@ fn cargo_hello_world_project_model_with_selective_overrides() {
|
|||
global: Default::default(),
|
||||
selective: std::iter::once((
|
||||
"libc".to_owned(),
|
||||
CfgDiff::new(Vec::new(), vec![CfgAtom::Flag("test".into())]).unwrap(),
|
||||
CfgDiff::new(Vec::new(), vec![CfgAtom::Flag(sym::test.clone())]).unwrap(),
|
||||
))
|
||||
.collect(),
|
||||
};
|
||||
|
|
|
@ -10,6 +10,7 @@ use base_db::{
|
|||
LangCrateOrigin, ProcMacroPaths, TargetLayoutLoadResult,
|
||||
};
|
||||
use cfg::{CfgAtom, CfgDiff, CfgOptions};
|
||||
use intern::{sym, Symbol};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use semver::Version;
|
||||
|
@ -977,8 +978,8 @@ fn cargo_to_crate_graph(
|
|||
|
||||
if cargo[pkg].is_local {
|
||||
// Add test cfg for local crates
|
||||
cfg_options.insert_atom("test".into());
|
||||
cfg_options.insert_atom("rust_analyzer".into());
|
||||
cfg_options.insert_atom(sym::test.clone());
|
||||
cfg_options.insert_atom(sym::rust_analyzer.clone());
|
||||
}
|
||||
|
||||
override_cfg.apply(&mut cfg_options, &cargo[pkg].name);
|
||||
|
@ -1144,8 +1145,8 @@ fn detached_file_to_crate_graph(
|
|||
sysroot_to_crate_graph(&mut crate_graph, sysroot, rustc_cfg.clone(), load);
|
||||
|
||||
let mut cfg_options = CfgOptions::from_iter(rustc_cfg);
|
||||
cfg_options.insert_atom("test".into());
|
||||
cfg_options.insert_atom("rust_analyzer".into());
|
||||
cfg_options.insert_atom(sym::test.clone());
|
||||
cfg_options.insert_atom(sym::rust_analyzer.clone());
|
||||
override_cfg.apply(&mut cfg_options, "");
|
||||
let cfg_options = Arc::new(cfg_options);
|
||||
|
||||
|
@ -1307,7 +1308,7 @@ fn add_target_crate_root(
|
|||
let cfg_options = {
|
||||
let mut opts = cfg_options;
|
||||
for feature in pkg.active_features.iter() {
|
||||
opts.insert_key_value("feature".into(), feature.into());
|
||||
opts.insert_key_value(sym::feature.clone(), Symbol::intern(feature));
|
||||
}
|
||||
if let Some(cfgs) = build_data.as_ref().map(|it| &it.cfgs) {
|
||||
opts.extend(cfgs.iter().cloned());
|
||||
|
@ -1381,8 +1382,8 @@ fn sysroot_to_crate_graph(
|
|||
&CfgOverrides {
|
||||
global: CfgDiff::new(
|
||||
vec![
|
||||
CfgAtom::Flag("debug_assertions".into()),
|
||||
CfgAtom::Flag("miri".into()),
|
||||
CfgAtom::Flag(sym::debug_assertions.clone()),
|
||||
CfgAtom::Flag(sym::miri.clone()),
|
||||
],
|
||||
vec![],
|
||||
)
|
||||
|
@ -1394,7 +1395,7 @@ fn sysroot_to_crate_graph(
|
|||
|
||||
let mut pub_deps = vec![];
|
||||
let mut libproc_macro = None;
|
||||
let diff = CfgDiff::new(vec![], vec![CfgAtom::Flag("test".into())]).unwrap();
|
||||
let diff = CfgDiff::new(vec![], vec![CfgAtom::Flag(sym::test.clone())]).unwrap();
|
||||
for (cid, c) in cg.iter_mut() {
|
||||
// uninject `test` flag so `core` keeps working.
|
||||
Arc::make_mut(&mut c.cfg_options).apply_diff(diff.clone());
|
||||
|
@ -1449,8 +1450,8 @@ fn sysroot_to_crate_graph(
|
|||
let cfg_options = Arc::new({
|
||||
let mut cfg_options = CfgOptions::default();
|
||||
cfg_options.extend(rustc_cfg);
|
||||
cfg_options.insert_atom("debug_assertions".into());
|
||||
cfg_options.insert_atom("miri".into());
|
||||
cfg_options.insert_atom(sym::debug_assertions.clone());
|
||||
cfg_options.insert_atom(sym::miri.clone());
|
||||
cfg_options
|
||||
});
|
||||
let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue