Skip to content

Commit 2be4ce0

Browse files
committed
refactor: struct holding cargo cfgs settings
1 parent 16721e3 commit 2be4ce0

File tree

1 file changed

+15
-6
lines changed
  • src/tools/rust-analyzer/crates/rust-analyzer/src

1 file changed

+15
-6
lines changed

src/tools/rust-analyzer/crates/rust-analyzer/src/config.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -571,12 +571,10 @@ config_data! {
571571
/// avoid checking unnecessary things.
572572
cargo_buildScripts_useRustcWrapper: bool = true,
573573
/// List of cfg options to enable with the given values.
574-
cargo_cfgs: FxHashMap<String, Option<String>> = {
575-
let mut m = FxHashMap::default();
576-
m.insert("debug_assertions".to_owned(), None);
577-
m.insert("miri".to_owned(), None);
578-
m
579-
},
574+
cargo_cfgs: Vec<String> = {
575+
vec!["debug_assertion".into(), "miri".into()]
576+
}
577+
,
580578
/// Extra arguments that are passed to every cargo invocation.
581579
cargo_extraArgs: Vec<String> = vec![],
582580
/// Extra environment variables that will be set when running cargo, rustc
@@ -1944,6 +1942,17 @@ impl Config {
19441942
global: CfgDiff::new(
19451943
self.cargo_cfgs(source_root)
19461944
.iter()
1945+
// parse any cfg setting formatted as key=value
1946+
.map(|s| {
1947+
let mut sp = s.splitn(2, "=");
1948+
let key = sp.next();
1949+
let val = sp.next();
1950+
(key, val)
1951+
})
1952+
// we filter out anything with a None key
1953+
.filter(|(key, _)| key.is_some())
1954+
// unwrap cannot panic here as we are sure key is Some
1955+
.map(|(key, val)| (key.unwrap(), val))
19471956
.map(|(key, val)| match val {
19481957
Some(val) => CfgAtom::KeyValue {
19491958
key: Symbol::intern(key),

0 commit comments

Comments
 (0)