Skip to content

Commit f4ecc34

Browse files
authored
Merge pull request rust-lang#18885 from qjerome/refactor-cargo-cfgs
refactor: struct holding cargo cfgs settings
2 parents 85310c4 + 93d08b7 commit f4ecc34

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,11 +571,8 @@ 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
574+
cargo_cfgs: Vec<String> = {
575+
vec!["debug_assertion".into(), "miri".into()]
579576
},
580577
/// Extra arguments that are passed to every cargo invocation.
581578
cargo_extraArgs: Vec<String> = vec![],
@@ -1944,6 +1941,13 @@ impl Config {
19441941
global: CfgDiff::new(
19451942
self.cargo_cfgs(source_root)
19461943
.iter()
1944+
// parse any cfg setting formatted as key=value or just key (without value)
1945+
.filter_map(|s| {
1946+
let mut sp = s.splitn(2, "=");
1947+
let key = sp.next();
1948+
let val = sp.next();
1949+
key.map(|key| (key, val))
1950+
})
19471951
.map(|(key, val)| match val {
19481952
Some(val) => CfgAtom::KeyValue {
19491953
key: Symbol::intern(key),

src/tools/rust-analyzer/docs/user/generated_config.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ avoid checking unnecessary things.
9494
--
9595
Default:
9696
----
97-
{
98-
"miri": null,
99-
"debug_assertions": null
100-
}
97+
[
98+
"debug_assertion",
99+
"miri"
100+
]
101101
----
102102
List of cfg options to enable with the given values.
103103

src/tools/rust-analyzer/editors/code/package.json

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,14 @@
791791
"properties": {
792792
"rust-analyzer.cargo.cfgs": {
793793
"markdownDescription": "List of cfg options to enable with the given values.",
794-
"default": {
795-
"miri": null,
796-
"debug_assertions": null
797-
},
798-
"type": "object"
794+
"default": [
795+
"debug_assertion",
796+
"miri"
797+
],
798+
"type": "array",
799+
"items": {
800+
"type": "string"
801+
}
799802
}
800803
}
801804
},

0 commit comments

Comments
 (0)