From 84cd28fddc89bfa75760e81f4fbc5aa21ce2742c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 23 Jun 2020 18:56:26 +0200 Subject: Cut problematic dependency --- crates/ra_db/src/fixture.rs | 6 +++++- crates/ra_ide/src/mock_analysis.rs | 7 ++++++- crates/test_utils/Cargo.toml | 3 +-- crates/test_utils/src/fixture.rs | 28 +++++++++++++++++++--------- crates/test_utils/src/lib.rs | 1 - 5 files changed, 31 insertions(+), 14 deletions(-) (limited to 'crates') diff --git a/crates/ra_db/src/fixture.rs b/crates/ra_db/src/fixture.rs index 6c13e62bb..ea52ec563 100644 --- a/crates/ra_db/src/fixture.rs +++ b/crates/ra_db/src/fixture.rs @@ -203,11 +203,15 @@ struct FileMeta { impl From<&Fixture> for ParsedMeta { fn from(f: &Fixture) -> Self { + let mut cfg = CfgOptions::default(); + f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); + f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); + Self::File(FileMeta { path: f.path.to_owned(), krate: f.crate_name.to_owned(), deps: f.deps.to_owned(), - cfg: f.cfg.to_owned(), + cfg, edition: f .edition .as_ref() diff --git a/crates/ra_ide/src/mock_analysis.rs b/crates/ra_ide/src/mock_analysis.rs index f15990158..981bdf924 100644 --- a/crates/ra_ide/src/mock_analysis.rs +++ b/crates/ra_ide/src/mock_analysis.rs @@ -38,7 +38,12 @@ impl MockFileData { fn cfg_options(&self) -> CfgOptions { match self { - MockFileData::Fixture(f) => f.cfg.clone(), + MockFileData::Fixture(f) => { + let mut cfg = CfgOptions::default(); + f.cfg_atoms.iter().for_each(|it| cfg.insert_atom(it.into())); + f.cfg_key_values.iter().for_each(|(k, v)| cfg.insert_key_value(k.into(), v.into())); + cfg + } _ => CfgOptions::default(), } } diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index afd2005f8..6821db1e8 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml @@ -8,10 +8,9 @@ authors = ["rust-analyzer developers"] doctest = false [dependencies] +# Avoid adding deps here, this crate is widely used in tests it should compile fast! difference = "2.0.0" text-size = "1.0.0" serde_json = "1.0.48" rustc-hash = "1.1.0" - -ra_cfg = { path = "../ra_cfg" } stdx = { path = "../stdx" } diff --git a/crates/test_utils/src/fixture.rs b/crates/test_utils/src/fixture.rs index 2a51bb559..44cf835b3 100644 --- a/crates/test_utils/src/fixture.rs +++ b/crates/test_utils/src/fixture.rs @@ -1,4 +1,3 @@ -use ra_cfg::CfgOptions; use rustc_hash::FxHashMap; use stdx::split1; @@ -8,7 +7,8 @@ pub struct Fixture { pub text: String, pub crate_name: Option, pub deps: Vec, - pub cfg: CfgOptions, + pub cfg_atoms: Vec, + pub cfg_key_values: Vec<(String, String)>, pub edition: Option, pub env: FxHashMap, } @@ -73,7 +73,8 @@ The offending line: {:?}"#, let mut krate = None; let mut deps = Vec::new(); let mut edition = None; - let mut cfg = CfgOptions::default(); + let mut cfg_atoms = Vec::new(); + let mut cfg_key_values = Vec::new(); let mut env = FxHashMap::default(); for component in components[1..].iter() { let (key, value) = split1(component, ':').unwrap(); @@ -82,10 +83,10 @@ The offending line: {:?}"#, "deps" => deps = value.split(',').map(|it| it.to_string()).collect(), "edition" => edition = Some(value.to_string()), "cfg" => { - for key in value.split(',') { - match split1(key, '=') { - None => cfg.insert_atom(key.into()), - Some((k, v)) => cfg.insert_key_value(k.into(), v.into()), + for entry in value.split(',') { + match split1(entry, '=') { + Some((k, v)) => cfg_key_values.push((k.to_string(), v.to_string())), + None => cfg_atoms.push(entry.to_string()), } } } @@ -100,7 +101,16 @@ The offending line: {:?}"#, } } - Fixture { path, text: String::new(), crate_name: krate, deps, edition, cfg, env } + Fixture { + path, + text: String::new(), + crate_name: krate, + deps, + cfg_atoms, + cfg_key_values, + edition, + env, + } } } @@ -152,7 +162,7 @@ fn indent_len(s: &str) -> usize { #[test] #[should_panic] fn parse_fixture_checks_further_indented_metadata() { - parse_fixture( + Fixture::parse( r" //- /lib.rs mod bar; diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 316f3d501..3fd8505ed 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs @@ -19,7 +19,6 @@ use serde_json::Value; use text_size::{TextRange, TextSize}; pub use difference::Changeset as __Changeset; -pub use ra_cfg::CfgOptions; pub use rustc_hash::FxHashMap; pub use crate::fixture::Fixture; -- cgit v1.2.3