]> git.lizzy.rs Git - rust.git/commitdiff
improve codegen
authorYoshua Wuyts <yoshuawuyts@gmail.com>
Wed, 11 Aug 2021 18:33:13 +0000 (20:33 +0200)
committerYoshua Wuyts <yoshuawuyts@gmail.com>
Wed, 11 Aug 2021 18:33:13 +0000 (20:33 +0200)
crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs
crates/ide_assists/src/utils/gen_trait_fn_body.rs

index 30d291bff9b764c964ac4a86fddf54bef37b08d6..d29a312eba59e77f3b503801c46909c17bcfbcb0 100644 (file)
@@ -726,13 +726,9 @@ enum Foo {
 
 impl PartialEq for Foo {
     $0fn eq(&self, other: &Self) -> bool {
-        if core::mem::discriminant(self) == core::mem::discriminant(other) {
-            match (self, other) {
-                (Self::Bar(l0), Self::Bar(r0)) => l0 == r0,
-                _ => true,
-            }
-        } else {
-            false
+        match (self, other) {
+            (Self::Bar(l0), Self::Bar(r0)) => l0 == r0,
+            _ => core::mem::discriminant(self) == core::mem::discriminant(other),
         }
     }
 }
@@ -774,14 +770,10 @@ enum Foo {
 
 impl PartialEq for Foo {
     $0fn eq(&self, other: &Self) -> bool {
-        if core::mem::discriminant(self) == core::mem::discriminant(other) {
-            match (self, other) {
-                (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin == r_bin,
-                (Self::Baz { qux: l_qux, fez: l_fez }, Self::Baz { qux: r_qux, fez: r_fez }) => l_qux == r_qux && l_fez == r_fez,
-                _ => true,
-            }
-        } else {
-            false
+        match (self, other) {
+            (Self::Bar { bin: l_bin }, Self::Bar { bin: r_bin }) => l_bin == r_bin,
+            (Self::Baz { qux: l_qux, fez: l_fez }, Self::Baz { qux: r_qux, fez: r_fez }) => l_qux == r_qux && l_fez == r_fez,
+            _ => core::mem::discriminant(self) == core::mem::discriminant(other),
         }
     }
 }
index 701e763bcea065996c95e073a2b877657a38941c..65d39c370aefb3ba6f647739cd90ec575b9fafad 100644 (file)
@@ -449,27 +449,17 @@ fn gen_tuple_field(field_name: &String) -> ast::Pat {
                 }
             }
 
-            if !arms.is_empty() && case_count > arms.len() {
-                let lhs = make::wildcard_pat().into();
-                arms.push(make::match_arm(Some(lhs), None, make::expr_literal("true").into()));
-            }
-
             let expr = match arms.len() {
                 0 => eq_check,
                 _ => {
-                    let condition = make::condition(eq_check, None);
+                    if case_count > arms.len() {
+                        let lhs = make::wildcard_pat().into();
+                        arms.push(make::match_arm(Some(lhs), None, eq_check));
+                    }
 
                     let match_target = make::expr_tuple(vec![self_name, other_name]);
                     let list = make::match_arm_list(arms).indent(ast::edit::IndentLevel(1));
-                    let match_expr = Some(make::expr_match(match_target, list));
-                    let then_branch = make::block_expr(None, match_expr);
-                    let then_branch = then_branch.indent(ast::edit::IndentLevel(1));
-
-                    let else_branche = make::expr_literal("false");
-                    let else_branche = make::block_expr(None, Some(else_branche.into()))
-                        .indent(ast::edit::IndentLevel(1));
-
-                    make::expr_if(condition, then_branch, Some(else_branche.into()))
+                    make::expr_match(match_target, list)
                 }
             };