Skip to content

Commit 4bf9b9b

Browse files
committed
refactor: remove repetitive string interpolation and doc changes
1 parent c4bdb8e commit 4bf9b9b

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

crates/ide-assists/src/handlers/generate_enum_projection_method.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -161,27 +161,21 @@ fn generate_enum_projection_method(
161161

162162
let field_type_syntax = field_type.syntax();
163163

164-
let method = if ctx.config.assist_emit_must_use
165-
{
166-
format!(
167-
" #[must_use]
168-
{vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
169-
if let Self::{variant_name}{pattern_suffix} = self {{
170-
{happy_case}({bound_name})
171-
}} else {{
172-
{sad_case}
173-
}}
174-
}}")
164+
let must_use = if ctx.config.assist_emit_must_use {
165+
"#[must_use]\n"
175166
} else {
176-
format!(
177-
" {vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
167+
""
168+
};
169+
170+
let method = format!(
171+
" {must_use}{vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
178172
if let Self::{variant_name}{pattern_suffix} = self {{
179173
{happy_case}({bound_name})
180174
}} else {{
181175
{sad_case}
182176
}}
183-
}}")
184-
};
177+
}}"
178+
);
185179

186180
add_method_to_adt(builder, &parent_enum, impl_def, &method);
187181
},

crates/rust-analyzer/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod patch_old_style;
5656
// parsing the old name.
5757
config_data! {
5858
struct ConfigData {
59-
/// Whether to insert must_use derive macro while generating `as_` methods
59+
/// Whether to insert #[must_use] when generating `as_` methods
6060
/// for enum variants.
6161
assist_emitMustUse: bool = "false",
6262
/// Placeholder expression to use for missing expressions in assists.

docs/user/generated_config.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[[rust-analyzer.assist.emitMustUse]]rust-analyzer.assist.emitMustUse (default: `false`)::
22
+
33
--
4-
Whether to insert must_use derive macro while generating `as_` methods
4+
Whether to insert #[must_use] when generating `as_` methods
55
for enum variants.
66
--
77
[[rust-analyzer.assist.expressionFillDefault]]rust-analyzer.assist.expressionFillDefault (default: `"todo"`)::

editors/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
},
399399
"$generated-start": {},
400400
"rust-analyzer.assist.emitMustUse": {
401-
"markdownDescription": "Whether to insert must_use derive macro while generating `as_` methods\nfor enum variants.",
401+
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
402402
"default": false,
403403
"type": "boolean"
404404
},

0 commit comments

Comments
 (0)