]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax_ext/deriving/hash.rs
Auto merge of #35856 - phimuemue:master, r=brson
[rust.git] / src / libsyntax_ext / deriving / hash.rs
index 0fad96c84ef3d2a859569768a4115995ebfc54b0..0941ebca868e3207e340ff03d6e6cb9ac7a80aa9 100644 (file)
@@ -12,8 +12,8 @@
 use deriving::generic::*;
 use deriving::generic::ty::*;
 
-use syntax::ast::{MetaItem, Expr, Mutability};
-use syntax::ext::base::{ExtCtxt, Annotatable};
+use syntax::ast::{Expr, MetaItem, Mutability};
+use syntax::ext::base::{Annotatable, ExtCtxt};
 use syntax::ext::build::AstBuilder;
 use syntax::ptr::P;
 use syntax_pos::Span;
@@ -22,11 +22,9 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
                             span: Span,
                             mitem: &MetaItem,
                             item: &Annotatable,
-                            push: &mut FnMut(Annotatable))
-{
+                            push: &mut FnMut(Annotatable)) {
 
-    let path = Path::new_(pathvec_std!(cx, core::hash::Hash), None,
-                          vec!(), true);
+    let path = Path::new_(pathvec_std!(cx, core::hash::Hash), None, vec![], true);
 
     let typaram = &*deriving::hygienic_type_parameter(item, "__H");
 
@@ -38,25 +36,24 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
         additional_bounds: Vec::new(),
         generics: LifetimeBounds::empty(),
         is_unsafe: false,
-        methods: vec!(
-            MethodDef {
-                name: "hash",
-                generics: LifetimeBounds {
-                    lifetimes: Vec::new(),
-                    bounds: vec![(typaram,
-                                  vec![path_std!(cx, core::hash::Hasher)])],
-                },
-                explicit_self: borrowed_explicit_self(),
-                args: vec!(Ptr(Box::new(Literal(arg)), Borrowed(None, Mutability::Mutable))),
-                ret_ty: nil_ty(),
-                attributes: vec![],
-                is_unsafe: false,
-                unify_fieldless_variants: true,
-                combine_substructure: combine_substructure(Box::new(|a, b, c| {
-                    hash_substructure(a, b, c)
-                }))
-            }
-        ),
+        supports_unions: false,
+        methods: vec![MethodDef {
+                          name: "hash",
+                          generics: LifetimeBounds {
+                              lifetimes: Vec::new(),
+                              bounds: vec![(typaram, vec![path_std!(cx, core::hash::Hasher)])],
+                          },
+                          explicit_self: borrowed_explicit_self(),
+                          args: vec![Ptr(Box::new(Literal(arg)),
+                                         Borrowed(None, Mutability::Mutable))],
+                          ret_ty: nil_ty(),
+                          attributes: vec![],
+                          is_unsafe: false,
+                          unify_fieldless_variants: true,
+                          combine_substructure: combine_substructure(Box::new(|a, b, c| {
+                              hash_substructure(a, b, c)
+                          })),
+                      }],
         associated_types: Vec::new(),
     };
 
@@ -66,7 +63,10 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
 fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
     let state_expr = match (substr.nonself_args.len(), substr.nonself_args.get(0)) {
         (1, Some(o_f)) => o_f,
-        _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`")
+        _ => {
+            cx.span_bug(trait_span,
+                        "incorrect number of arguments in `derive(Hash)`")
+        }
     };
     let call_hash = |span, thing_expr| {
         let hash_path = {
@@ -75,7 +75,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
             cx.expr_path(cx.path_global(span, strs))
         };
         let ref_thing = cx.expr_addr_of(span, thing_expr);
-        let expr = cx.expr_call(span, hash_path, vec!(ref_thing, state_expr.clone()));
+        let expr = cx.expr_call(span, hash_path, vec![ref_thing, state_expr.clone()]);
         cx.stmt_expr(expr)
     };
     let mut stmts = Vec::new();
@@ -92,7 +92,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
 
             fs
         }
-        _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`")
+        _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`"),
     };
 
     for &FieldInfo { ref self_, span, .. } in fields {