refactor: remove repetitive string interpolation and doc changes

This commit is contained in:
feniljain 2022-10-24 21:06:32 +05:30
parent c4bdb8e516
commit 4bf9b9b003
4 changed files with 12 additions and 18 deletions

View File

@ -161,27 +161,21 @@ fn generate_enum_projection_method(
let field_type_syntax = field_type.syntax();
let method = if ctx.config.assist_emit_must_use
{
format!(
" #[must_use]
{vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
if let Self::{variant_name}{pattern_suffix} = self {{
{happy_case}({bound_name})
}} else {{
{sad_case}
}}
}}")
let must_use = if ctx.config.assist_emit_must_use {
"#[must_use]\n"
} else {
format!(
" {vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
""
};
let method = format!(
" {must_use}{vis}fn {fn_name}({self_param}) -> {return_prefix}{field_type_syntax}{return_suffix} {{
if let Self::{variant_name}{pattern_suffix} = self {{
{happy_case}({bound_name})
}} else {{
{sad_case}
}}
}}")
};
}}"
);
add_method_to_adt(builder, &parent_enum, impl_def, &method);
},

View File

@ -56,7 +56,7 @@
// parsing the old name.
config_data! {
struct ConfigData {
/// Whether to insert must_use derive macro while generating `as_` methods
/// Whether to insert #[must_use] when generating `as_` methods
/// for enum variants.
assist_emitMustUse: bool = "false",
/// Placeholder expression to use for missing expressions in assists.

View File

@ -1,7 +1,7 @@
[[rust-analyzer.assist.emitMustUse]]rust-analyzer.assist.emitMustUse (default: `false`)::
+
--
Whether to insert must_use derive macro while generating `as_` methods
Whether to insert #[must_use] when generating `as_` methods
for enum variants.
--
[[rust-analyzer.assist.expressionFillDefault]]rust-analyzer.assist.expressionFillDefault (default: `"todo"`)::

View File

@ -398,7 +398,7 @@
},
"$generated-start": {},
"rust-analyzer.assist.emitMustUse": {
"markdownDescription": "Whether to insert must_use derive macro while generating `as_` methods\nfor enum variants.",
"markdownDescription": "Whether to insert #[must_use] when generating `as_` methods\nfor enum variants.",
"default": false,
"type": "boolean"
},