|
11 | 11 | use deriving::generic::*; |
12 | 12 | use deriving::generic::ty::*; |
13 | 13 |
|
14 | | -use syntax::ast::{MetaItem, Expr, Mutability}; |
| 14 | +use syntax::ast::{self, MetaItem, Expr, Mutability}; |
15 | 15 | use syntax::codemap::Span; |
16 | 16 | use syntax::ext::base::{ExtCtxt, Annotatable}; |
17 | 17 | use syntax::ext::build::AstBuilder; |
@@ -77,15 +77,18 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) |
77 | 77 |
|
78 | 78 | let fields = match *substr.fields { |
79 | 79 | Struct(_, ref fs) => fs, |
80 | | - EnumMatching(index, variant, ref fs) => { |
81 | | - // Determine the discriminant. We will feed this value to the byte |
82 | | - // iteration function. |
83 | | - let discriminant = match variant.node.disr_expr { |
84 | | - Some(ref d) => d.clone(), |
85 | | - None => cx.expr_usize(trait_span, index) |
86 | | - }; |
| 80 | + EnumMatching(_, _, ref fs) => { |
| 81 | + let path = cx.std_path(&["intrinsics", "discriminant_value"]); |
| 82 | + let call = cx.expr_call_global( |
| 83 | + trait_span, path, vec![cx.expr_self(trait_span)]); |
| 84 | + let variant_value = cx.expr_block(P(ast::Block { |
| 85 | + stmts: vec![], |
| 86 | + expr: Some(call), |
| 87 | + id: ast::DUMMY_NODE_ID, |
| 88 | + rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), |
| 89 | + span: trait_span })); |
87 | 90 |
|
88 | | - stmts.push(call_hash(trait_span, discriminant)); |
| 91 | + stmts.push(call_hash(trait_span, variant_value)); |
89 | 92 |
|
90 | 93 | fs |
91 | 94 | } |
|
0 commit comments