summary refs log tree commit diff
path: root/src/libsyntax_ext
diff options
context:
space:
mode:
authorAlex Burka <aburka@seas.upenn.edu>2016-03-07 13:05:12 -0500
committerAlex Burka <aburka@seas.upenn.edu>2016-03-27 01:25:46 -0400
commitc480b6a75df08cef48190e3c18eab26e99bae58c (patch)
tree2735939396a33874f15e586382033c9a7ce0190f /src/libsyntax_ext
parent01c0723ef247fec4b85af203c7247b66e3817e1b (diff)
downloadrust-c480b6a75df08cef48190e3c18eab26e99bae58c.tar.gz
rust-c480b6a75df08cef48190e3c18eab26e99bae58c.zip
fix #21714 by using discriminant_value in #[derive(Hash)]
This is the same approach taken in #24270, except that this
should not be a breaking change because it only changes the output
of hash functions, which nobody should be relying on.
Diffstat (limited to 'src/libsyntax_ext')
-rw-r--r--src/libsyntax_ext/deriving/hash.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs
index ba38ebc8607..93686586489 100644
--- a/src/libsyntax_ext/deriving/hash.rs
+++ b/src/libsyntax_ext/deriving/hash.rs
@@ -12,7 +12,7 @@ use deriving;
 use deriving::generic::*;
 use deriving::generic::ty::*;
 
-use syntax::ast::{MetaItem, Expr, Mutability};
+use syntax::ast::{self, MetaItem, Expr, Mutability};
 use syntax::codemap::Span;
 use syntax::ext::base::{ExtCtxt, Annotatable};
 use syntax::ext::build::AstBuilder;
@@ -81,15 +81,18 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure)
 
     let fields = match *substr.fields {
         Struct(_, ref fs) => fs,
-        EnumMatching(index, variant, ref fs) => {
-            // Determine the discriminant. We will feed this value to the byte
-            // iteration function.
-            let discriminant = match variant.node.disr_expr {
-                Some(ref d) => d.clone(),
-                None => cx.expr_usize(trait_span, index)
-            };
+        EnumMatching(_, _, ref fs) => {
+            let path = cx.std_path(&["intrinsics", "discriminant_value"]);
+            let call = cx.expr_call_global(
+                trait_span, path, vec![cx.expr_self(trait_span)]);
+            let variant_value = cx.expr_block(P(ast::Block {
+                stmts: vec![],
+                expr: Some(call),
+                id: ast::DUMMY_NODE_ID,
+                rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated),
+                span: trait_span }));
 
-            stmts.push(call_hash(trait_span, discriminant));
+            stmts.push(call_hash(trait_span, variant_value));
 
             fs
         }