about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-07-08 07:57:34 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-07-09 10:04:09 +1000
commit0578697a63f3b531f6ffeb18a186eff372bf67f1 (patch)
treee2c2cb249b84504c4cfe0688844f61e546fbed4c
parent16a286b003477fe07c06c5030f0ae8298c3e78ec (diff)
downloadrust-0578697a63f3b531f6ffeb18a186eff372bf67f1.tar.gz
rust-0578697a63f3b531f6ffeb18a186eff372bf67f1.zip
Minor updates based on review comments.
-rw-r--r--compiler/rustc_builtin_macros/src/deriving/generic/mod.rs25
1 files changed, 10 insertions, 15 deletions
diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
index 5cad71467a1..74e18bffc2e 100644
--- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
+++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
@@ -245,7 +245,8 @@ pub struct MethodDef<'a> {
 pub struct Substructure<'a> {
     /// ident of self
     pub type_ident: Ident,
-    /// verbatim access to any non-selflike arguments
+    /// Verbatim access to any non-selflike arguments, i.e. arguments that
+    /// don't have type `&Self`.
     pub nonselflike_args: &'a [P<Expr>],
     pub fields: &'a SubstructureFields<'a>,
 }
@@ -934,10 +935,9 @@ impl<'a> MethodDef<'a> {
 
             let arg_expr = cx.expr_ident(span, ident);
 
-            match *ty {
-                // for static methods, just treat any Self
-                // arguments as a normal arg
-                Ref(ref ty, _) if matches!(**ty, Self_) && !self.is_static() => {
+            match ty {
+                // Selflike (`&Self`) arguments only occur in non-static methods.
+                Ref(box Self_, _) if !self.is_static() => {
                     selflike_args.push(cx.expr_deref(span, arg_expr))
                 }
                 Self_ => cx.span_bug(span, "`Self` in non-return position"),
@@ -1459,11 +1459,8 @@ impl<'a> TraitDef<'a> {
         prefixes
             .iter()
             .map(|prefix| {
-                let pieces: Vec<_> = struct_def
-                    .fields()
-                    .iter()
-                    .enumerate()
-                    .map(|(i, struct_field)| {
+                let pieces_iter =
+                    struct_def.fields().iter().enumerate().map(|(i, struct_field)| {
                         let sp = struct_field.span.with_ctxt(self.span.ctxt());
                         let binding_mode = if use_temporaries {
                             ast::BindingMode::ByValue(ast::Mutability::Not)
@@ -1477,14 +1474,12 @@ impl<'a> TraitDef<'a> {
                             struct_field.ident,
                             cx.pat(path.span, PatKind::Ident(binding_mode, path, None)),
                         )
-                    })
-                    .collect();
+                    });
 
                 let struct_path = struct_path.clone();
                 match *struct_def {
                     VariantData::Struct(..) => {
-                        let field_pats = pieces
-                            .into_iter()
+                        let field_pats = pieces_iter
                             .map(|(sp, ident, pat)| {
                                 if ident.is_none() {
                                     cx.span_bug(
@@ -1506,7 +1501,7 @@ impl<'a> TraitDef<'a> {
                         cx.pat_struct(self.span, struct_path, field_pats)
                     }
                     VariantData::Tuple(..) => {
-                        let subpats = pieces.into_iter().map(|(_, _, subpat)| subpat).collect();
+                        let subpats = pieces_iter.map(|(_, _, subpat)| subpat).collect();
                         cx.pat_tuple_struct(self.span, struct_path, subpats)
                     }
                     VariantData::Unit(..) => cx.pat_path(self.span, struct_path),