Skip to content

Commit e9f6087

Browse files
committed
Auto merge of rust-lang#13661 - iredelmeier:fix-null-checkonsave-target, r=jonas-schievink
Fix: Handle empty `checkOnSave/target` values This fixes a regression introduced by rust-lang#13290, in which failing to set `checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid config. [Fixes rust-lang#13660]
2 parents 63a676e + b116fe9 commit e9f6087

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

crates/rust-analyzer/src/config.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ config_data! {
182182
/// `["aarch64-apple-darwin", "x86_64-apple-darwin"]`.
183183
///
184184
/// Aliased as `"checkOnSave.targets"`.
185-
checkOnSave_target | checkOnSave_targets: CheckOnSaveTargets = "[]",
185+
checkOnSave_target | checkOnSave_targets: Option<CheckOnSaveTargets> = "null",
186186

187187
/// Toggles the additional completions that automatically add imports when completed.
188188
/// Note that your client must specify the `additionalTextEdits` LSP client capability to truly have this feature enabled.
@@ -1153,10 +1153,15 @@ impl Config {
11531153
}
11541154
Some(_) | None => FlycheckConfig::CargoCommand {
11551155
command: self.data.checkOnSave_command.clone(),
1156-
target_triples: match &self.data.checkOnSave_target.0[..] {
1157-
[] => self.data.cargo_target.clone().into_iter().collect(),
1158-
targets => targets.into(),
1159-
},
1156+
target_triples: self
1157+
.data
1158+
.checkOnSave_target
1159+
.clone()
1160+
.and_then(|targets| match &targets.0[..] {
1161+
[] => None,
1162+
targets => Some(targets.into()),
1163+
})
1164+
.unwrap_or_else(|| self.data.cargo_target.clone().into_iter().collect()),
11601165
all_targets: self.data.checkOnSave_allTargets,
11611166
no_default_features: self
11621167
.data
@@ -2126,8 +2131,11 @@ fn field_props(field: &str, ty: &str, doc: &[&str], default: &str) -> serde_json
21262131
"The command will be executed in the project root."
21272132
],
21282133
},
2129-
"CheckOnSaveTargets" => set! {
2134+
"Option<CheckOnSaveTargets>" => set! {
21302135
"anyOf": [
2136+
{
2137+
"type": "null"
2138+
},
21312139
{
21322140
"type": "string",
21332141
},

docs/user/generated_config.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ cargo check --workspace --message-format=json --all-targets
190190
```
191191
.
192192
--
193-
[[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `[]`)::
193+
[[rust-analyzer.checkOnSave.target]]rust-analyzer.checkOnSave.target (default: `null`)::
194194
+
195195
--
196196
Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.

editors/code/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,11 @@
640640
},
641641
"rust-analyzer.checkOnSave.target": {
642642
"markdownDescription": "Check for specific targets. Defaults to `#rust-analyzer.cargo.target#` if empty.\n\nCan be a single target, e.g. `\"x86_64-unknown-linux-gnu\"` or a list of targets, e.g.\n`[\"aarch64-apple-darwin\", \"x86_64-apple-darwin\"]`.\n\nAliased as `\"checkOnSave.targets\"`.",
643-
"default": [],
643+
"default": null,
644644
"anyOf": [
645+
{
646+
"type": "null"
647+
},
645648
{
646649
"type": "string"
647650
},

0 commit comments

Comments
 (0)