Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-assists/src/handlers/generate_trait_from_impl.rs')
-rw-r--r--crates/ide-assists/src/handlers/generate_trait_from_impl.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
index 315b6487b5..a8817436ba 100644
--- a/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
+++ b/crates/ide-assists/src/handlers/generate_trait_from_impl.rs
@@ -85,10 +85,7 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
let assoc_items = impl_ast.assoc_item_list()?;
let first_element = assoc_items.assoc_items().next();
- if first_element.is_none() {
- // No reason for an assist.
- return None;
- }
+ first_element.as_ref()?;
let impl_name = impl_ast.self_ty()?;
@@ -184,21 +181,18 @@ fn remove_items_visibility(item: &ast::AssocItem) {
}
fn strip_body(item: &ast::AssocItem) {
- match item {
- ast::AssocItem::Fn(f) => {
- if let Some(body) = f.body() {
- // In constrast to function bodies, we want to see no ws before a semicolon.
- // So let's remove them if we see any.
- if let Some(prev) = body.syntax().prev_sibling_or_token() {
- if prev.kind() == SyntaxKind::WHITESPACE {
- ted::remove(prev);
- }
+ if let ast::AssocItem::Fn(f) = item {
+ if let Some(body) = f.body() {
+ // In constrast to function bodies, we want to see no ws before a semicolon.
+ // So let's remove them if we see any.
+ if let Some(prev) = body.syntax().prev_sibling_or_token() {
+ if prev.kind() == SyntaxKind::WHITESPACE {
+ ted::remove(prev);
}
-
- ted::replace(body.syntax(), make::tokens::semicolon());
}
+
+ ted::replace(body.syntax(), make::tokens::semicolon());
}
- _ => (),
};
}