Skip to content

Commit fddef42

Browse files
committed
Only set rust-analyzer cfg for workspace members
1 parent e9e2c1a commit fddef42

5 files changed

+5
-18
lines changed

crates/project-model/src/workspace.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,9 @@ fn cargo_to_crate_graph(
867867
if cargo[pkg].is_local {
868868
cfg_options.insert_atom("test".into());
869869
}
870+
if cargo[pkg].is_member {
871+
cfg_options.insert_atom("rust_analyzer".into());
872+
}
870873

871874
if !override_cfg.global.is_empty() {
872875
cfg_options.apply_diff(override_cfg.global.clone());
@@ -1030,7 +1033,8 @@ fn detached_files_to_crate_graph(
10301033
None => (SysrootPublicDeps::default(), None),
10311034
};
10321035

1033-
let cfg_options = create_cfg_options(rustc_cfg);
1036+
let mut cfg_options = create_cfg_options(rustc_cfg);
1037+
cfg_options.insert_atom("rust_analyzer".into());
10341038

10351039
for detached_file in detached_files {
10361040
let file_id = match load(detached_file) {
@@ -1479,6 +1483,5 @@ fn create_cfg_options(rustc_cfg: Vec<CfgFlag>) -> CfgOptions {
14791483
let mut cfg_options = CfgOptions::default();
14801484
cfg_options.extend(rustc_cfg);
14811485
cfg_options.insert_atom("debug_assertions".into());
1482-
cfg_options.insert_atom("rust_analyzer".into());
14831486
cfg_options
14841487
}

crates/project-model/test_data/output/cargo_hello_world_project_model.txt

-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@
297297
"debug_assertions",
298298
"feature=default",
299299
"feature=std",
300-
"rust_analyzer",
301300
],
302301
),
303302
potential_cfg_options: Some(
@@ -311,7 +310,6 @@
311310
"feature=rustc-dep-of-std",
312311
"feature=std",
313312
"feature=use_std",
314-
"rust_analyzer",
315313
],
316314
),
317315
),

crates/project-model/test_data/output/cargo_hello_world_project_model_with_selective_overrides.txt

-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@
297297
"debug_assertions",
298298
"feature=default",
299299
"feature=std",
300-
"rust_analyzer",
301300
],
302301
),
303302
potential_cfg_options: Some(
@@ -311,7 +310,6 @@
311310
"feature=rustc-dep-of-std",
312311
"feature=std",
313312
"feature=use_std",
314-
"rust_analyzer",
315313
],
316314
),
317315
),

crates/project-model/test_data/output/cargo_hello_world_project_model_with_wildcard_overrides.txt

-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@
293293
"debug_assertions",
294294
"feature=default",
295295
"feature=std",
296-
"rust_analyzer",
297296
],
298297
),
299298
potential_cfg_options: Some(
@@ -307,7 +306,6 @@
307306
"feature=rustc-dep-of-std",
308307
"feature=std",
309308
"feature=use_std",
310-
"rust_analyzer",
311309
],
312310
),
313311
),

crates/project-model/test_data/output/rust_project_hello_world_project_model.txt

-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
cfg_options: CfgOptions(
1717
[
1818
"debug_assertions",
19-
"rust_analyzer",
2019
],
2120
),
2221
potential_cfg_options: None,
@@ -58,7 +57,6 @@
5857
cfg_options: CfgOptions(
5958
[
6059
"debug_assertions",
61-
"rust_analyzer",
6260
],
6361
),
6462
potential_cfg_options: None,
@@ -92,7 +90,6 @@
9290
cfg_options: CfgOptions(
9391
[
9492
"debug_assertions",
95-
"rust_analyzer",
9693
],
9794
),
9895
potential_cfg_options: None,
@@ -126,7 +123,6 @@
126123
cfg_options: CfgOptions(
127124
[
128125
"debug_assertions",
129-
"rust_analyzer",
130126
],
131127
),
132128
potential_cfg_options: None,
@@ -160,7 +156,6 @@
160156
cfg_options: CfgOptions(
161157
[
162158
"debug_assertions",
163-
"rust_analyzer",
164159
],
165160
),
166161
potential_cfg_options: None,
@@ -209,7 +204,6 @@
209204
cfg_options: CfgOptions(
210205
[
211206
"debug_assertions",
212-
"rust_analyzer",
213207
],
214208
),
215209
potential_cfg_options: None,
@@ -243,7 +237,6 @@
243237
cfg_options: CfgOptions(
244238
[
245239
"debug_assertions",
246-
"rust_analyzer",
247240
],
248241
),
249242
potential_cfg_options: None,
@@ -334,7 +327,6 @@
334327
cfg_options: CfgOptions(
335328
[
336329
"debug_assertions",
337-
"rust_analyzer",
338330
],
339331
),
340332
potential_cfg_options: None,
@@ -368,7 +360,6 @@
368360
cfg_options: CfgOptions(
369361
[
370362
"debug_assertions",
371-
"rust_analyzer",
372363
],
373364
),
374365
potential_cfg_options: None,
@@ -402,7 +393,6 @@
402393
cfg_options: CfgOptions(
403394
[
404395
"debug_assertions",
405-
"rust_analyzer",
406396
],
407397
),
408398
potential_cfg_options: None,

0 commit comments

Comments
 (0)