Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/generate_enum_projection_method.rs')
-rw-r--r--crates/ide-assists/src/handlers/generate_enum_projection_method.rs24
1 files changed, 9 insertions, 15 deletions
diff --git a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
index 732ee49f66..ad88a04ce8 100644
--- a/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
+++ b/crates/ide-assists/src/handlers/generate_enum_projection_method.rs
@@ -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);
},