Skip to content

Commit 6f25fef

Browse files
committed
cargo fmt
1 parent e0f08fc commit 6f25fef

File tree

1 file changed

+20
-35
lines changed

1 file changed

+20
-35
lines changed

crates/ide_assists/src/handlers/generate_enum_match_method.rs

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ use stdx::to_lower_snake_case;
33
use syntax::ast::VisibilityOwner;
44
use syntax::ast::{self, AstNode, NameOwner};
55

6-
use crate::{AssistContext, AssistId, AssistKind, Assists, assist_context::AssistBuilder, utils::{find_impl_block_end, find_struct_impl, generate_impl_text}};
6+
use crate::{
7+
assist_context::AssistBuilder,
8+
utils::{find_impl_block_end, find_struct_impl, generate_impl_text},
9+
AssistContext, AssistId, AssistKind, Assists,
10+
};
711

812
// Assist: generate_enum_is_method
913
//
@@ -41,11 +45,7 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) ->
4145
let fn_name = format!("is_{}", &to_lower_snake_case(variant_name.text()));
4246

4347
// Return early if we've found an existing new fn
44-
let impl_def = find_struct_impl(
45-
&ctx,
46-
&parent_enum,
47-
&fn_name,
48-
)?;
48+
let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?;
4949

5050
let target = variant.syntax().text_range();
5151
acc.add(
@@ -108,11 +108,7 @@ pub(crate) fn generate_enum_into_method(acc: &mut Assists, ctx: &AssistContext)
108108
let fn_name = format!("into_{}", &to_lower_snake_case(variant_name.text()));
109109

110110
// Return early if we've found an existing new fn
111-
let impl_def = find_struct_impl(
112-
&ctx,
113-
&parent_enum,
114-
&fn_name,
115-
)?;
111+
let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?;
116112

117113
let field_type = variant_kind.single_field_type()?;
118114
let (pattern_suffix, bound_name) = variant_kind.binding_pattern()?;
@@ -181,11 +177,7 @@ pub(crate) fn generate_enum_as_method(acc: &mut Assists, ctx: &AssistContext) ->
181177
let fn_name = format!("as_{}", &to_lower_snake_case(variant_name.text()));
182178

183179
// Return early if we've found an existing new fn
184-
let impl_def = find_struct_impl(
185-
&ctx,
186-
&parent_enum,
187-
&fn_name,
188-
)?;
180+
let impl_def = find_struct_impl(&ctx, &parent_enum, &fn_name)?;
189181

190182
let field_type = variant_kind.single_field_type()?;
191183
let (pattern_suffix, bound_name) = variant_kind.binding_pattern()?;
@@ -243,7 +235,9 @@ fn add_method_to_adt(
243235
enum VariantKind {
244236
Unit,
245237
/// Tuple with a single field
246-
NewtypeTuple { ty: Option<ast::Type> },
238+
NewtypeTuple {
239+
ty: Option<ast::Type>,
240+
},
247241
/// Tuple with 0 or more than 2 fields
248242
Tuple,
249243
/// Record with a single field
@@ -259,36 +253,27 @@ impl VariantKind {
259253
fn pattern_suffix(&self) -> &'static str {
260254
match self {
261255
VariantKind::Unit => "",
262-
VariantKind::NewtypeTuple { .. } |
263-
VariantKind::Tuple => "(..)",
264-
VariantKind::NewtypeRecord { .. } |
265-
VariantKind::Record => " { .. }",
256+
VariantKind::NewtypeTuple { .. } | VariantKind::Tuple => "(..)",
257+
VariantKind::NewtypeRecord { .. } | VariantKind::Record => " { .. }",
266258
}
267259
}
268260

269261
fn binding_pattern(&self) -> Option<(String, String)> {
270262
match self {
271-
VariantKind::Unit |
272-
VariantKind::Tuple |
273-
VariantKind::Record |
274-
VariantKind::NewtypeRecord { field_name: None, .. } => None,
275-
VariantKind::NewtypeTuple { .. } => {
276-
Some(("(v)".to_owned(), "v".to_owned()))
277-
}
263+
VariantKind::Unit
264+
| VariantKind::Tuple
265+
| VariantKind::Record
266+
| VariantKind::NewtypeRecord { field_name: None, .. } => None,
267+
VariantKind::NewtypeTuple { .. } => Some(("(v)".to_owned(), "v".to_owned())),
278268
VariantKind::NewtypeRecord { field_name: Some(name), .. } => {
279-
Some((
280-
format!(" {{ {} }}", name.syntax()),
281-
name.syntax().to_string(),
282-
))
269+
Some((format!(" {{ {} }}", name.syntax()), name.syntax().to_string()))
283270
}
284271
}
285272
}
286273

287274
fn single_field_type(&self) -> Option<&ast::Type> {
288275
match self {
289-
VariantKind::Unit |
290-
VariantKind::Tuple |
291-
VariantKind::Record => None,
276+
VariantKind::Unit | VariantKind::Tuple | VariantKind::Record => None,
292277
VariantKind::NewtypeTuple { ty } => ty.as_ref(),
293278
VariantKind::NewtypeRecord { field_type, .. } => field_type.as_ref(),
294279
}

0 commit comments

Comments
 (0)