]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/ext/deriving/hash.rs
Associated types support for deriving::generic::TraitDef
[rust.git] / src / libsyntax / ext / deriving / hash.rs
index 889a212a2872911931f1b40e965577e27e289527..e7f546b2691f2c7bb9d94c597f0649d43df536c6 100644 (file)
@@ -54,7 +54,8 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
                     hash_substructure(a, b, c)
                 })
             }
-        )
+        ),
+        associated_types: Vec::new(),
     };
 
     hash_trait_def.expand(cx, mitem, item, push);
@@ -63,7 +64,7 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
 fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) -> P<Expr> {
     let state_expr = match substr.nonself_args {
         [ref state_expr] => state_expr,
-        _ => cx.span_bug(trait_span, "incorrect number of arguments in `deriving(Hash)`")
+        _ => cx.span_bug(trait_span, "incorrect number of arguments in `derive(Hash)`")
     };
     let call_hash = |&: span, thing_expr| {
         let hash_path = {
@@ -89,23 +90,19 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
             // iteration function.
             let discriminant = match variant.node.disr_expr {
                 Some(ref d) => d.clone(),
-                None => cx.expr_uint(trait_span, index)
+                None => cx.expr_usize(trait_span, index)
             };
 
             stmts.push(call_hash(trait_span, discriminant));
 
             fs
         }
-        _ => cx.span_bug(trait_span, "impossible substructure in `deriving(Hash)`")
+        _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`")
     };
 
     for &FieldInfo { ref self_, span, .. } in fields.iter() {
         stmts.push(call_hash(span, self_.clone()));
     }
 
-    if stmts.len() == 0 {
-        cx.span_bug(trait_span, "#[derive(Hash)] needs at least one field");
-    }
-
     cx.expr_block(cx.block(trait_span, stmts, None))
 }