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