]> git.proxmox.com Git - rustc.git/blobdiff - src/libsyntax_ext/deriving/generic/mod.rs
New upstream version 1.38.0+dfsg1
[rustc.git] / src / libsyntax_ext / deriving / generic / mod.rs
index 22643db501693f270e61980320e724c58f615ae2..7e6d9126c87400bca5bfc1193afff2821d8f04e1 100644 (file)
 //!                 (<ident of C1>, <span of C1>, Named(vec![(<ident of x>, <span of x>)]))])
 //! ```
 
-pub use self::StaticFields::*;
-pub use self::SubstructureFields::*;
+pub use StaticFields::*;
+pub use SubstructureFields::*;
 
 use std::cell::RefCell;
 use std::iter;
@@ -186,18 +186,17 @@ use rustc_target::spec::abi::Abi;
 use syntax::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
 use syntax::ast::{VariantData, GenericParamKind, GenericArg};
 use syntax::attr;
-use syntax::ext::base::{Annotatable, ExtCtxt};
-use syntax::ext::build::AstBuilder;
+use syntax::ext::base::{Annotatable, ExtCtxt, SpecialDerives};
 use syntax::source_map::{self, respan};
-use syntax::util::move_map::MoveMap;
+use syntax::util::map_in_place::MapInPlace;
 use syntax::ptr::P;
-use syntax::symbol::{Symbol, keywords};
+use syntax::symbol::{Symbol, kw, sym};
 use syntax::parse::ParseSess;
 use syntax_pos::{DUMMY_SP, Span};
 
-use self::ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
+use ty::{LifetimeBounds, Path, Ptr, PtrTy, Self_, Ty};
 
-use deriving;
+use crate::deriving;
 
 pub mod ty;
 
@@ -243,7 +242,7 @@ pub struct MethodDef<'a> {
     /// Arguments other than the self argument
     pub args: Vec<(Ty<'a>, &'a str)>,
 
-    /// Return type
+    /// Returns type
     pub ret_ty: Ty<'a>,
 
     pub attributes: Vec<ast::Attribute>,
@@ -303,7 +302,7 @@ pub enum SubstructureFields<'a> {
     EnumMatching(usize, usize, &'a ast::Variant, Vec<FieldInfo<'a>>),
 
     /// Non-matching variants of the enum, but with all state hidden from
-    /// the consequent code.  The first component holds `Ident`s for all of
+    /// the consequent code. The first component holds `Ident`s for all of
     /// the `Self` arguments; the second component is a slice of all of the
     /// variants for the enum itself, and the third component is a list of
     /// `Ident`s bound to the variant index values for each of the actual
@@ -321,32 +320,33 @@ pub enum SubstructureFields<'a> {
 /// Combine the values of all the fields together. The last argument is
 /// all the fields of all the structures.
 pub type CombineSubstructureFunc<'a> =
-    Box<dyn FnMut(&mut ExtCtxt, Span, &Substructure) -> P<Expr> + 'a>;
+    Box<dyn FnMut(&mut ExtCtxt<'_>, Span, &Substructure<'_>) -> P<Expr> + 'a>;
 
-/// Deal with non-matching enum variants.  The tuple is a list of
+/// Deal with non-matching enum variants. The tuple is a list of
 /// identifiers (one for each `Self` argument, which could be any of the
 /// variants since they have been collapsed together) and the identifiers
-/// holding the variant index value for each of the `Self` arguments.  The
+/// holding the variant index value for each of the `Self` arguments. The
 /// last argument is all the non-`Self` args of the method being derived.
 pub type EnumNonMatchCollapsedFunc<'a> =
-    Box<dyn FnMut(&mut ExtCtxt, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
+    Box<dyn FnMut(&mut ExtCtxt<'_>, Span, (&[Ident], &[Ident]), &[P<Expr>]) -> P<Expr> + 'a>;
 
-pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>)
-                                -> RefCell<CombineSubstructureFunc<'a>> {
+pub fn combine_substructure(f: CombineSubstructureFunc<'_>)
+                            -> RefCell<CombineSubstructureFunc<'_>> {
     RefCell::new(f)
 }
 
 /// This method helps to extract all the type parameters referenced from a
 /// type. For a type parameter `<T>`, it looks for either a `TyPath` that
 /// is not global and starts with `T`, or a `TyQPath`.
-fn find_type_parameters(ty: &ast::Ty,
-                        ty_param_names: &[ast::Name],
-                        span: Span,
-                        cx: &ExtCtxt)
-                        -> Vec<P<ast::Ty>> {
+fn find_type_parameters(
+    ty: &ast::Ty,
+    ty_param_names: &[ast::Name],
+    span: Span,
+    cx: &ExtCtxt<'_>,
+) -> Vec<P<ast::Ty>> {
     use syntax::visit;
 
-    struct Visitor<'a, 'b: 'a> {
+    struct Visitor<'a, 'b> {
         cx: &'a ExtCtxt<'b>,
         span: Span,
         ty_param_names: &'a [ast::Name],
@@ -386,7 +386,7 @@ fn find_type_parameters(ty: &ast::Ty,
 
 impl<'a> TraitDef<'a> {
     pub fn expand(self,
-                  cx: &mut ExtCtxt,
+                  cx: &mut ExtCtxt<'_>,
                   mitem: &ast::MetaItem,
                   item: &'a Annotatable,
                   push: &mut dyn FnMut(Annotatable)) {
@@ -394,7 +394,7 @@ impl<'a> TraitDef<'a> {
     }
 
     pub fn expand_ext(self,
-                      cx: &mut ExtCtxt,
+                      cx: &mut ExtCtxt<'_>,
                       mitem: &ast::MetaItem,
                       item: &'a Annotatable,
                       push: &mut dyn FnMut(Annotatable),
@@ -425,8 +425,9 @@ impl<'a> TraitDef<'a> {
                         return;
                     }
                 };
+                let container_id = cx.current_expansion.id.parent();
                 let is_always_copy =
-                    attr::contains_name(&item.attrs, "rustc_copy_clone_marker") &&
+                    cx.resolver.has_derives(container_id, SpecialDerives::COPY) &&
                     has_no_type_params;
                 let use_temporaries = is_packed && is_always_copy;
 
@@ -464,10 +465,8 @@ impl<'a> TraitDef<'a> {
                 attrs.extend(item.attrs
                     .iter()
                     .filter(|a| {
-                        match &*a.name().as_str() {
-                            "allow" | "warn" | "deny" | "forbid" | "stable" | "unstable" => true,
-                            _ => false,
-                        }
+                        [sym::allow, sym::warn, sym::deny, sym::forbid, sym::stable, sym::unstable]
+                            .contains(&a.name_or_empty())
                     })
                     .cloned());
                 push(Annotatable::Item(P(ast::Item { attrs: attrs, ..(*newitem).clone() })))
@@ -497,7 +496,7 @@ impl<'a> TraitDef<'a> {
     /// create an impl like:
     ///
     /// ```ignore (only-for-syntax-highlight)
-    /// impl<'a, ..., 'z, A, B: DeclaredTrait, C, ...  Z> where
+    /// impl<'a, ..., 'z, A, B: DeclaredTrait, C, ... Z> where
     ///     C:                       WhereTrait,
     ///     A: DerivedTrait + B1 + ... + BN,
     ///     B: DerivedTrait + B1 + ... + BN,
@@ -513,7 +512,7 @@ impl<'a> TraitDef<'a> {
     /// where B1, ..., BN are the bounds given by `bounds_paths`.'. Z is a phantom type, and
     /// therefore does not get bound by the derived trait.
     fn create_derived_impl(&self,
-                           cx: &mut ExtCtxt,
+                           cx: &mut ExtCtxt<'_>,
                            type_ident: Ident,
                            generics: &Generics,
                            field_tys: Vec<P<ast::Ty>>,
@@ -531,7 +530,8 @@ impl<'a> TraitDef<'a> {
                 defaultness: ast::Defaultness::Final,
                 attrs: Vec::new(),
                 generics: Generics::default(),
-                node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, type_ident, generics)),
+                node: ast::ImplItemKind::TyAlias(
+                    type_def.to_ty(cx, self.span, type_ident, generics)),
                 tokens: None,
             }
         });
@@ -560,6 +560,7 @@ impl<'a> TraitDef<'a> {
 
                 cx.typaram(self.span, param.ident, vec![], bounds, None)
             }
+            GenericParamKind::Const { .. } => param.clone(),
         }));
 
         // and similarly for where clauses
@@ -657,21 +658,22 @@ impl<'a> TraitDef<'a> {
             GenericParamKind::Type { .. } => {
                 GenericArg::Type(cx.ty_ident(self.span, param.ident))
             }
+            GenericParamKind::Const { .. } => {
+                GenericArg::Const(cx.const_ident(self.span, param.ident))
+            }
         }).collect();
 
         // Create the type of `self`.
         let path = cx.path_all(self.span, false, vec![type_ident], self_params, vec![]);
         let self_type = cx.ty_path(path);
 
-        let attr = cx.attribute(self.span,
-                                cx.meta_word(self.span,
-                                             Symbol::intern("automatically_derived")));
+        let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
         // Just mark it now since we know that it'll end up used downstream
         attr::mark_used(&attr);
         let opt_trait_ref = Some(trait_ref);
         let unused_qual = {
             let word = cx.meta_list_item_word(self.span, Symbol::intern("unused_qualifications"));
-            cx.attribute(self.span, cx.meta_list(self.span, Symbol::intern("allow"), vec![word]))
+            cx.attribute(cx.meta_list(self.span, sym::allow, vec![word]))
         };
 
         let mut a = vec![attr, unused_qual];
@@ -684,7 +686,7 @@ impl<'a> TraitDef<'a> {
         };
 
         cx.item(self.span,
-                keywords::Invalid.ident(),
+                Ident::invalid(),
                 a,
                 ast::ItemKind::Impl(unsafety,
                                     ast::ImplPolarity::Positive,
@@ -696,7 +698,7 @@ impl<'a> TraitDef<'a> {
     }
 
     fn expand_struct_def(&self,
-                         cx: &mut ExtCtxt,
+                         cx: &mut ExtCtxt<'_>,
                          struct_def: &'a VariantData,
                          type_ident: Ident,
                          generics: &Generics,
@@ -746,7 +748,7 @@ impl<'a> TraitDef<'a> {
     }
 
     fn expand_enum_def(&self,
-                       cx: &mut ExtCtxt,
+                       cx: &mut ExtCtxt<'_>,
                        enum_def: &'a EnumDef,
                        type_attrs: &[ast::Attribute],
                        type_ident: Ident,
@@ -832,12 +834,12 @@ fn find_repr_type_name(sess: &ParseSess, type_attrs: &[ast::Attribute]) -> &'sta
 
 impl<'a> MethodDef<'a> {
     fn call_substructure_method(&self,
-                                cx: &mut ExtCtxt,
-                                trait_: &TraitDef,
+                                cx: &mut ExtCtxt<'_>,
+                                trait_: &TraitDef<'_>,
                                 type_ident: Ident,
                                 self_args: &[P<Expr>],
                                 nonself_args: &[P<Expr>],
-                                fields: &SubstructureFields)
+                                fields: &SubstructureFields<'_>)
                                 -> P<Expr> {
         let substructure = Substructure {
             type_ident,
@@ -847,13 +849,13 @@ impl<'a> MethodDef<'a> {
             fields,
         };
         let mut f = self.combine_substructure.borrow_mut();
-        let f: &mut CombineSubstructureFunc = &mut *f;
+        let f: &mut CombineSubstructureFunc<'_> = &mut *f;
         f(cx, trait_.span, &substructure)
     }
 
     fn get_ret_ty(&self,
-                  cx: &mut ExtCtxt,
-                  trait_: &TraitDef,
+                  cx: &mut ExtCtxt<'_>,
+                  trait_: &TraitDef<'_>,
                   generics: &Generics,
                   type_ident: Ident)
                   -> P<ast::Ty> {
@@ -866,8 +868,8 @@ impl<'a> MethodDef<'a> {
 
     fn split_self_nonself_args
         (&self,
-         cx: &mut ExtCtxt,
-         trait_: &TraitDef,
+         cx: &mut ExtCtxt<'_>,
+         trait_: &TraitDef<'_>,
          type_ident: Ident,
          generics: &Generics)
          -> (Option<ast::ExplicitSelf>, Vec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) {
@@ -912,8 +914,8 @@ impl<'a> MethodDef<'a> {
     }
 
     fn create_method(&self,
-                     cx: &mut ExtCtxt,
-                     trait_: &TraitDef,
+                     cx: &mut ExtCtxt<'_>,
+                     trait_: &TraitDef<'_>,
                      type_ident: Ident,
                      generics: &Generics,
                      abi: Abi,
@@ -921,14 +923,13 @@ impl<'a> MethodDef<'a> {
                      arg_types: Vec<(Ident, P<ast::Ty>)>,
                      body: P<Expr>)
                      -> ast::ImplItem {
-
-        // create the generics that aren't for Self
+        // Create the generics that aren't for `Self`.
         let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics);
 
         let args = {
             let self_args = explicit_self.map(|explicit_self| {
-                ast::Arg::from_self(explicit_self,
-                                    keywords::SelfLower.ident().with_span_pos(trait_.span))
+                let ident = Ident::with_empty_ctxt(kw::SelfLower).with_span_pos(trait_.span);
+                ast::Arg::from_self(ThinVec::default(), explicit_self, ident)
             });
             let nonself_args = arg_types.into_iter()
                 .map(|(name, ty)| cx.arg(trait_.span, name, ty));
@@ -1005,7 +1006,7 @@ impl<'a> MethodDef<'a> {
     /// }
     /// ```
     fn expand_struct_method_body<'b>(&self,
-                                     cx: &mut ExtCtxt,
+                                     cx: &mut ExtCtxt<'_>,
                                      trait_: &TraitDef<'b>,
                                      struct_def: &'b VariantData,
                                      type_ident: Ident,
@@ -1077,8 +1078,8 @@ impl<'a> MethodDef<'a> {
     }
 
     fn expand_static_struct_method_body(&self,
-                                        cx: &mut ExtCtxt,
-                                        trait_: &TraitDef,
+                                        cx: &mut ExtCtxt<'_>,
+                                        trait_: &TraitDef<'_>,
                                         struct_def: &VariantData,
                                         type_ident: Ident,
                                         self_args: &[P<Expr>],
@@ -1122,10 +1123,10 @@ impl<'a> MethodDef<'a> {
     ///
     /// (Of course `__self_vi` and `__arg_1_vi` are unused for
     /// `PartialEq`, and those subcomputations will hopefully be removed
-    /// as their results are unused.  The point of `__self_vi` and
+    /// as their results are unused. The point of `__self_vi` and
     /// `__arg_1_vi` is for `PartialOrd`; see #15503.)
     fn expand_enum_method_body<'b>(&self,
-                                   cx: &mut ExtCtxt,
+                                   cx: &mut ExtCtxt<'_>,
                                    trait_: &TraitDef<'b>,
                                    enum_def: &'b EnumDef,
                                    type_attrs: &[ast::Attribute],
@@ -1179,12 +1180,12 @@ impl<'a> MethodDef<'a> {
     /// }
     /// ```
     fn build_enum_match_tuple<'b>(&self,
-                                  cx: &mut ExtCtxt,
+                                  cx: &mut ExtCtxt<'_>,
                                   trait_: &TraitDef<'b>,
                                   enum_def: &'b EnumDef,
                                   type_attrs: &[ast::Attribute],
                                   type_ident: Ident,
-                                  self_args: Vec<P<Expr>>,
+                                  mut self_args: Vec<P<Expr>>,
                                   nonself_args: &[P<Expr>])
                                   -> P<Expr> {
         let sp = trait_.span;
@@ -1230,7 +1231,7 @@ impl<'a> MethodDef<'a> {
             .enumerate()
             .filter(|&(_, v)| !(self.unify_fieldless_variants && v.node.data.fields().is_empty()))
             .map(|(index, variant)| {
-                let mk_self_pat = |cx: &mut ExtCtxt, self_arg_name: &str| {
+                let mk_self_pat = |cx: &mut ExtCtxt<'_>, self_arg_name: &str| {
                     let (p, idents) = trait_.create_enum_variant_pattern(cx,
                                                      type_ident,
                                                      variant,
@@ -1296,7 +1297,7 @@ impl<'a> MethodDef<'a> {
                                     other: others,
                                     attrs,
                         }
-                    }).collect::<Vec<FieldInfo>>();
+                    }).collect::<Vec<FieldInfo<'_>>>();
 
                 // Now, for some given VariantK, we have built up
                 // expressions for referencing every field of every
@@ -1417,8 +1418,8 @@ impl<'a> MethodDef<'a> {
             // them when they are fed as r-values into a tuple
             // expression; here add a layer of borrowing, turning
             // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
-            let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
-            let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
+            self_args.map_in_place(|self_arg| cx.expr_addr_of(sp, self_arg));
+            let match_arg = cx.expr(sp, ast::ExprKind::Tup(self_args));
 
             // Lastly we create an expression which branches on all discriminants being equal
             //  if discriminant_test {
@@ -1494,15 +1495,15 @@ impl<'a> MethodDef<'a> {
             // them when they are fed as r-values into a tuple
             // expression; here add a layer of borrowing, turning
             // `(*self, *__arg_0, ...)` into `(&*self, &*__arg_0, ...)`.
-            let borrowed_self_args = self_args.move_map(|self_arg| cx.expr_addr_of(sp, self_arg));
-            let match_arg = cx.expr(sp, ast::ExprKind::Tup(borrowed_self_args));
+            self_args.map_in_place(|self_arg| cx.expr_addr_of(sp, self_arg));
+            let match_arg = cx.expr(sp, ast::ExprKind::Tup(self_args));
             cx.expr_match(sp, match_arg, match_arms)
         }
     }
 
     fn expand_static_enum_method_body(&self,
-                                      cx: &mut ExtCtxt,
-                                      trait_: &TraitDef,
+                                      cx: &mut ExtCtxt<'_>,
+                                      trait_: &TraitDef<'_>,
                                       enum_def: &EnumDef,
                                       type_ident: Ident,
                                       self_args: &[P<Expr>],
@@ -1527,7 +1528,7 @@ impl<'a> MethodDef<'a> {
 
 // general helper methods.
 impl<'a> TraitDef<'a> {
-    fn summarise_struct(&self, cx: &mut ExtCtxt, struct_def: &VariantData) -> StaticFields {
+    fn summarise_struct(&self, cx: &mut ExtCtxt<'_>, struct_def: &VariantData) -> StaticFields {
         let mut named_idents = Vec::new();
         let mut just_spans = Vec::new();
         for field in struct_def.fields() {
@@ -1538,6 +1539,7 @@ impl<'a> TraitDef<'a> {
             }
         }
 
+        let is_tuple = if let ast::VariantData::Tuple(..) = struct_def { true } else { false };
         match (just_spans.is_empty(), named_idents.is_empty()) {
             (false, false) => {
                 cx.span_bug(self.span,
@@ -1546,14 +1548,15 @@ impl<'a> TraitDef<'a> {
             }
             // named fields
             (_, false) => Named(named_idents),
-            // empty structs
-            _ if struct_def.is_struct() => Named(named_idents),
-            _ => Unnamed(just_spans, struct_def.is_tuple()),
+            // unnamed fields
+            (false, _) => Unnamed(just_spans, is_tuple),
+            // empty
+            _ => Named(Vec::new()),
         }
     }
 
     fn create_subpatterns(&self,
-                          cx: &mut ExtCtxt,
+                          cx: &mut ExtCtxt<'_>,
                           field_paths: Vec<ast::Ident>,
                           mutbl: ast::Mutability,
                           use_temporaries: bool)
@@ -1573,7 +1576,7 @@ impl<'a> TraitDef<'a> {
 
     fn create_struct_pattern
         (&self,
-         cx: &mut ExtCtxt,
+         cx: &mut ExtCtxt<'_>,
          struct_path: ast::Path,
          struct_def: &'a VariantData,
          prefix: &str,
@@ -1633,7 +1636,7 @@ impl<'a> TraitDef<'a> {
 
     fn create_enum_variant_pattern
         (&self,
-         cx: &mut ExtCtxt,
+         cx: &mut ExtCtxt<'_>,
          enum_ident: ast::Ident,
          variant: &'a ast::Variant,
          prefix: &str,
@@ -1652,10 +1655,10 @@ impl<'a> TraitDef<'a> {
 pub fn cs_fold_fields<'a, F>(use_foldl: bool,
                              mut f: F,
                              base: P<Expr>,
-                             cx: &mut ExtCtxt,
+                             cx: &mut ExtCtxt<'_>,
                              all_fields: &[FieldInfo<'a>])
                              -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
 {
     if use_foldl {
         all_fields.iter().fold(base, |old, field| {
@@ -1668,10 +1671,10 @@ pub fn cs_fold_fields<'a, F>(use_foldl: bool,
     }
 }
 
-pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                            cx: &mut ExtCtxt,
+pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                            cx: &mut ExtCtxt<'_>,
                             trait_span: Span,
-                            substructure: &Substructure)
+                            substructure: &Substructure<'_>)
                             -> P<Expr>
 {
     match *substructure.fields {
@@ -1685,7 +1688,7 @@ pub fn cs_fold_enumnonmatch(mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
     }
 }
 
-pub fn cs_fold_static(cx: &mut ExtCtxt,
+pub fn cs_fold_static(cx: &mut ExtCtxt<'_>,
                       trait_span: Span)
                       -> P<Expr>
 {
@@ -1697,12 +1700,12 @@ pub fn cs_fold_static(cx: &mut ExtCtxt,
 pub fn cs_fold<F>(use_foldl: bool,
                   f: F,
                   base: P<Expr>,
-                  enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                  cx: &mut ExtCtxt,
+                  enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                  cx: &mut ExtCtxt<'_>,
                   trait_span: Span,
-                  substructure: &Substructure)
+                  substructure: &Substructure<'_>)
                   -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>
 {
     match *substructure.fields {
         EnumMatching(.., ref all_fields) |
@@ -1720,7 +1723,7 @@ pub fn cs_fold<F>(use_foldl: bool,
 
 /// Function to fold over fields, with three cases, to generate more efficient and concise code.
 /// When the `substructure` has grouped fields, there are two cases:
-/// Zero fields: call the base case function with None (like the usual base case of `cs_fold`).
+/// Zero fields: call the base case function with `None` (like the usual base case of `cs_fold`).
 /// One or more fields: call the base case function on the first value (which depends on
 /// `use_fold`), and use that as the base case. Then perform `cs_fold` on the remainder of the
 /// fields.
@@ -1730,13 +1733,13 @@ pub fn cs_fold<F>(use_foldl: bool,
 pub fn cs_fold1<F, B>(use_foldl: bool,
                       f: F,
                       mut b: B,
-                      enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                      cx: &mut ExtCtxt,
+                      enum_nonmatch_f: EnumNonMatchCollapsedFunc<'_>,
+                      cx: &mut ExtCtxt<'_>,
                       trait_span: Span,
-                      substructure: &Substructure)
+                      substructure: &Substructure<'_>)
                       -> P<Expr>
-    where F: FnMut(&mut ExtCtxt, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>,
-          B: FnMut(&mut ExtCtxt, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr>
+    where F: FnMut(&mut ExtCtxt<'_>, Span, P<Expr>, P<Expr>, &[P<Expr>]) -> P<Expr>,
+          B: FnMut(&mut ExtCtxt<'_>, Option<(Span, P<Expr>, &[P<Expr>])>) -> P<Expr>
 {
     match *substructure.fields {
         EnumMatching(.., ref all_fields) |
@@ -1767,51 +1770,7 @@ pub fn cs_fold1<F, B>(use_foldl: bool,
     }
 }
 
-/// Call the method that is being derived on all the fields, and then
-/// process the collected results. i.e.
-///
-/// ```ignore (only-for-syntax-highlight)
-/// f(cx, span, vec![self_1.method(__arg_1_1, __arg_2_1),
-///                  self_2.method(__arg_1_2, __arg_2_2)])
-/// ```
-#[inline]
-pub fn cs_same_method<F>(f: F,
-                         mut enum_nonmatch_f: EnumNonMatchCollapsedFunc,
-                         cx: &mut ExtCtxt,
-                         trait_span: Span,
-                         substructure: &Substructure)
-                         -> P<Expr>
-    where F: FnOnce(&mut ExtCtxt, Span, Vec<P<Expr>>) -> P<Expr>
-{
-    match *substructure.fields {
-        EnumMatching(.., ref all_fields) |
-        Struct(_, ref all_fields) => {
-            // call self_n.method(other_1_n, other_2_n, ...)
-            let called = all_fields.iter()
-                .map(|field| {
-                    cx.expr_method_call(field.span,
-                                        field.self_.clone(),
-                                        substructure.method_ident,
-                                        field.other
-                                            .iter()
-                                            .map(|e| cx.expr_addr_of(field.span, e.clone()))
-                                            .collect())
-                })
-                .collect();
-
-            f(cx, trait_span, called)
-        }
-        EnumNonMatchingCollapsed(ref all_self_args, _, tuple) => {
-            enum_nonmatch_f(cx,
-                            trait_span,
-                            (&all_self_args[..], tuple),
-                            substructure.nonself_args)
-        }
-        StaticEnum(..) | StaticStruct(..) => cx.span_bug(trait_span, "static function in `derive`"),
-    }
-}
-
-/// Return true if the type has no value fields
+/// Returns `true` if the type has no value fields
 /// (for an enum, no variant has any fields)
 pub fn is_type_without_fields(item: &Annotatable) -> bool {
     if let Annotatable::Item(ref item) = *item {