removed double matching

This commit is contained in:
Jeroen Vannevel 2022-01-05 21:16:24 +00:00
parent 771c87f890
commit 035a373a6a
No known key found for this signature in database
GPG Key ID: 78EF5F52F38C49BD

View File

@ -52,10 +52,10 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
} }
} }
let ref_kind = match get_receiver_type(&ctx, &to_extract) { let reference_modifier = match get_receiver_type(&ctx, &to_extract) {
Some(receiver_type) if receiver_type.is_mutable_reference() => RefKind::MutRef, Some(receiver_type) if receiver_type.is_mutable_reference() => "&mut ",
Some(receiver_type) if receiver_type.is_reference() => RefKind::Ref, Some(receiver_type) if receiver_type.is_reference() => "&",
_ => RefKind::None, _ => "",
}; };
let anchor = Anchor::from(&to_extract)?; let anchor = Anchor::from(&to_extract)?;
@ -83,12 +83,6 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option
None => to_extract.syntax().text_range(), None => to_extract.syntax().text_range(),
}; };
let reference_modifier = match ref_kind {
RefKind::MutRef => "&mut ",
RefKind::Ref => "&",
RefKind::None => "",
};
match anchor { match anchor {
Anchor::Before(_) | Anchor::Replace(_) => { Anchor::Before(_) | Anchor::Replace(_) => {
format_to!(buf, "let {} = {}", var_name, reference_modifier) format_to!(buf, "let {} = {}", var_name, reference_modifier)
@ -176,13 +170,6 @@ fn get_receiver(expression: ast::Expr) -> Option<ast::Expr> {
} }
} }
#[derive(Debug)]
enum RefKind {
Ref,
MutRef,
None,
}
#[derive(Debug)] #[derive(Debug)]
enum Anchor { enum Anchor {
Before(SyntaxNode), Before(SyntaxNode),