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.
This commit is contained in:
@@ -12,7 +12,7 @@ use deriving;
|
|||||||
use deriving::generic::*;
|
use deriving::generic::*;
|
||||||
use deriving::generic::ty::*;
|
use deriving::generic::ty::*;
|
||||||
|
|
||||||
use syntax::ast::{MetaItem, Expr, Mutability};
|
use syntax::ast::{self, MetaItem, Expr, Mutability};
|
||||||
use syntax::codemap::Span;
|
use syntax::codemap::Span;
|
||||||
use syntax::ext::base::{ExtCtxt, Annotatable};
|
use syntax::ext::base::{ExtCtxt, Annotatable};
|
||||||
use syntax::ext::build::AstBuilder;
|
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 {
|
let fields = match *substr.fields {
|
||||||
Struct(_, ref fs) => fs,
|
Struct(_, ref fs) => fs,
|
||||||
EnumMatching(index, variant, ref fs) => {
|
EnumMatching(_, _, ref fs) => {
|
||||||
// Determine the discriminant. We will feed this value to the byte
|
let path = cx.std_path(&["intrinsics", "discriminant_value"]);
|
||||||
// iteration function.
|
let call = cx.expr_call_global(
|
||||||
let discriminant = match variant.node.disr_expr {
|
trait_span, path, vec![cx.expr_self(trait_span)]);
|
||||||
Some(ref d) => d.clone(),
|
let variant_value = cx.expr_block(P(ast::Block {
|
||||||
None => cx.expr_usize(trait_span, index)
|
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
|
fs
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user