mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
refactor: remove repetitive string interpolation and doc changes
This commit is contained in:
parent
c4bdb8e516
commit
4bf9b9b003
4 changed files with 12 additions and 18 deletions
|
@ -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);
|
||||
},
|
||||
|
|
|
@ -56,7 +56,7 @@ mod patch_old_style;
|
|||
// 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.
|
||||
|
|
|
@ -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"`)::
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue