Skip to content

Commit 0485a85

Browse files
committed
Set debug_assertions and miri cfgs as config defaults, allowing them to be overwritten
1 parent 8989dcf commit 0485a85

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

crates/project-model/src/env.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Cargo-like environment variables injection.
12
use base_db::Env;
23
use rustc_hash::FxHashMap;
34
use toolchain::Tool;

crates/project-model/src/rustc_cfg.rs

-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ pub(crate) fn get(
3232
}
3333
}
3434

35-
// Add miri cfg, which is useful for mir eval in stdlib
36-
res.push(CfgFlag::Atom("miri".into()));
37-
3835
let rustc_cfgs = get_rust_cfgs(target, extra_env, config);
3936

4037
let rustc_cfgs = match rustc_cfgs {

crates/project-model/src/workspace.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,14 @@ fn sysroot_to_crate_graph(
14541454
None,
14551455
rustc_cfg,
14561456
&CfgOverrides {
1457-
global: CfgDiff::new(vec![CfgAtom::Flag("debug_assertions".into())], vec![])
1458-
.unwrap(),
1457+
global: CfgDiff::new(
1458+
vec![
1459+
CfgAtom::Flag("debug_assertions".into()),
1460+
CfgAtom::Flag("miri".into()),
1461+
],
1462+
vec![],
1463+
)
1464+
.unwrap(),
14591465
..Default::default()
14601466
},
14611467
&WorkspaceBuildScripts::default(),
@@ -1519,6 +1525,7 @@ fn sysroot_to_crate_graph(
15191525
let mut cfg_options = CfgOptions::default();
15201526
cfg_options.extend(rustc_cfg);
15211527
cfg_options.insert_atom("debug_assertions".into());
1528+
cfg_options.insert_atom("miri".into());
15221529
cfg_options
15231530
});
15241531
let sysroot_crates: FxHashMap<SysrootCrate, CrateId> = stitched

crates/rust-analyzer/src/config.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,12 @@ config_data! {
124124
/// avoid checking unnecessary things.
125125
cargo_buildScripts_useRustcWrapper: bool = true,
126126
/// List of cfg options to enable with the given values.
127-
cargo_cfgs: FxHashMap<String, String> = FxHashMap::default(),
127+
cargo_cfgs: FxHashMap<String, Option<String>> = {
128+
let mut m = FxHashMap::default();
129+
m.insert("debug_assertions".to_owned(), None);
130+
m.insert("miri".to_owned(), None);
131+
m
132+
},
128133
/// Extra arguments that are passed to every cargo invocation.
129134
cargo_extraArgs: Vec<String> = vec![],
130135
/// Extra environment variables that will be set when running cargo, rustc
@@ -1591,12 +1596,9 @@ impl Config {
15911596
global: CfgDiff::new(
15921597
self.cargo_cfgs()
15931598
.iter()
1594-
.map(|(key, val)| {
1595-
if val.is_empty() {
1596-
CfgAtom::Flag(key.into())
1597-
} else {
1598-
CfgAtom::KeyValue { key: key.into(), value: val.into() }
1599-
}
1599+
.map(|(key, val)| match val {
1600+
Some(val) => CfgAtom::KeyValue { key: key.into(), value: val.into() },
1601+
None => CfgAtom::Flag(key.into()),
16001602
})
16011603
.collect(),
16021604
vec![],
@@ -2667,6 +2669,9 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
26672669
"FxHashMap<Box<str>, usize>" => set! {
26682670
"type": "object",
26692671
},
2672+
"FxHashMap<String, Option<String>>" => set! {
2673+
"type": "object",
2674+
},
26702675
"Option<usize>" => set! {
26712676
"type": ["null", "integer"],
26722677
"minimum": 0,

docs/user/generated_config.adoc

+9-1
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,18 @@ or build-script sources change and are saved.
8888
Use `RUSTC_WRAPPER=rust-analyzer` when running build scripts to
8989
avoid checking unnecessary things.
9090
--
91-
[[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs (default: `{}`)::
91+
[[rust-analyzer.cargo.cfgs]]rust-analyzer.cargo.cfgs::
9292
+
9393
--
94+
Default:
95+
----
96+
{
97+
"debug_assertions": null,
98+
"miri": null
99+
}
100+
----
94101
List of cfg options to enable with the given values.
102+
95103
--
96104
[[rust-analyzer.cargo.extraArgs]]rust-analyzer.cargo.extraArgs (default: `[]`)::
97105
+

editors/code/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,10 @@
610610
},
611611
"rust-analyzer.cargo.cfgs": {
612612
"markdownDescription": "List of cfg options to enable with the given values.",
613-
"default": {},
613+
"default": {
614+
"debug_assertions": null,
615+
"miri": null
616+
},
614617
"type": "object"
615618
},
616619
"rust-analyzer.cargo.extraArgs": {

0 commit comments

Comments
 (0)