about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-07-04 15:08:28 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-07-04 18:37:29 +1000
commit2c911dc16f2ac3237fca7c7626982e6f6a4d0e33 (patch)
treea0ebfd913ceff8b7b49795bdcd32724b160c87a6 /compiler
parenta7b1d31a9f358747221e8eb9986bb8303d5d6586 (diff)
downloadrust-2c911dc16f2ac3237fca7c7626982e6f6a4d0e33.tar.gz
rust-2c911dc16f2ac3237fca7c7626982e6f6a4d0e33.zip
Avoid unnecessary 1-tuples in derived code.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/mod.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index e2d82b181a1..f3e1176cab3 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -1239,7 +1239,11 @@ impl<'a> MethodDef<'a> {
                 }
 
                 // Here is the pat = `(&VariantK, &VariantK, ...)`
-                let single_pat = cx.pat_tuple(span, subpats);
+                let single_pat = if subpats.len() == 1 {
+                    subpats.pop().unwrap()
+                } else {
+                    cx.pat_tuple(span, subpats)
+                };
 
                 // For the BodyK, we need to delegate to our caller,
                 // passing it an EnumMatching to indicate which case
@@ -1471,7 +1475,11 @@ impl<'a> MethodDef<'a> {
             // expression; here add a layer of borrowing, turning
             // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
             self_args.map_in_place(|self_arg| cx.expr_addr_of(span, self_arg));
-            let match_arg = cx.expr(span, ast::ExprKind::Tup(self_args));
+            let match_arg = if self_args.len() == 1 {
+                self_args.pop().unwrap()
+            } else {
+                cx.expr(span, ast::ExprKind::Tup(self_args))
+            };
             BlockOrExpr(vec![], Some(cx.expr_match(span, match_arg, match_arms)))
         }
     }