diff options
| author | bors <bors@rust-lang.org> | 2017-06-28 06:32:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-28 06:32:10 +0000 |
| commit | 5bc89416388f0a852f6e48542bf2fc021682fcb5 (patch) | |
| tree | 39ae70eab21af001459e1eaf9759a2f9c1e32302 /src/libsyntax_ext | |
| parent | 88c3242ef26956266970d62571a1d7d079b5799a (diff) | |
| parent | f11e40a8119bac1ab28c1cbaf18078466d84d951 (diff) | |
| download | rust-5bc89416388f0a852f6e48542bf2fc021682fcb5.tar.gz rust-5bc89416388f0a852f6e48542bf2fc021682fcb5.zip | |
Auto merge of #42709 - stepancheg:discriminant-hash, r=jseyfried
deriv(Hash) for single-variant enum should not hash discriminant Fixes #39137
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/clone.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/debug.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/encodable.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/hash.rs | 2 |
5 files changed, 9 insertions, 8 deletions
diff --git a/src/libsyntax_ext/deriving/clone.rs b/src/libsyntax_ext/deriving/clone.rs index 1993d6ebe5b..35a2a2513f4 100644 --- a/src/libsyntax_ext/deriving/clone.rs +++ b/src/libsyntax_ext/deriving/clone.rs @@ -167,7 +167,7 @@ fn cs_clone(name: &str, all_fields = af; vdata = vdata_; } - EnumMatching(_, variant, ref af) => { + EnumMatching(.., variant, ref af) => { ctor_path = cx.path(trait_span, vec![substr.type_ident, variant.node.name]); all_fields = af; vdata = &variant.node.data; diff --git a/src/libsyntax_ext/deriving/debug.rs b/src/libsyntax_ext/deriving/debug.rs index ec4cb815960..38ed596098b 100644 --- a/src/libsyntax_ext/deriving/debug.rs +++ b/src/libsyntax_ext/deriving/debug.rs @@ -60,7 +60,7 @@ fn show_substructure(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<E // based on the "shape". let (ident, is_struct) = match *substr.fields { Struct(vdata, _) => (substr.type_ident, vdata.is_struct()), - EnumMatching(_, v, _) => (v.node.name, v.node.data.is_struct()), + EnumMatching(_, _, v, _) => (v.node.name, v.node.data.is_struct()), EnumNonMatchingCollapsed(..) | StaticStruct(..) | StaticEnum(..) => cx.span_bug(span, "nonsensical .fields in `#[derive(Debug)]`"), diff --git a/src/libsyntax_ext/deriving/encodable.rs b/src/libsyntax_ext/deriving/encodable.rs index 33f742282c1..1e19cd99419 100644 --- a/src/libsyntax_ext/deriving/encodable.rs +++ b/src/libsyntax_ext/deriving/encodable.rs @@ -237,7 +237,7 @@ fn encodable_substructure(cx: &mut ExtCtxt, blk]) } - EnumMatching(idx, variant, ref fields) => { + EnumMatching(idx, _, variant, ref fields) => { // We're not generating an AST that the borrow checker is expecting, // so we need to generate a unique local variable to take the // mutable loan out on, otherwise we get conflicts which don't diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 3a15b82d19f..4acd65bbf86 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -305,10 +305,10 @@ pub enum StaticFields { /// A summary of the possible sets of fields. pub enum SubstructureFields<'a> { Struct(&'a ast::VariantData, Vec<FieldInfo<'a>>), - /// Matching variants of the enum: variant index, ast::Variant, + /// Matching variants of the enum: variant index, variant count, ast::Variant, /// fields: the field name is only non-`None` in the case of a struct /// variant. - EnumMatching(usize, &'a ast::Variant, Vec<FieldInfo<'a>>), + EnumMatching(usize, usize, &'a ast::Variant, Vec<FieldInfo<'a>>), /// Non-matching variants of the enum, but with all state hidden from /// the consequent code. The first component holds `Ident`s for all of @@ -1252,7 +1252,7 @@ impl<'a> MethodDef<'a> { // expressions for referencing every field of every // Self arg, assuming all are instances of VariantK. // Build up code associated with such a case. - let substructure = EnumMatching(index, variant, field_tuples); + let substructure = EnumMatching(index, variants.len(), variant, field_tuples); let arm_expr = self.call_substructure_method(cx, trait_, type_ident, @@ -1269,12 +1269,13 @@ impl<'a> MethodDef<'a> { // We need a default case that handles the fieldless variants. // The index and actual variant aren't meaningful in this case, // so just use whatever + let substructure = EnumMatching(0, variants.len(), v, Vec::new()); Some(self.call_substructure_method(cx, trait_, type_ident, &self_args[..], nonself_args, - &EnumMatching(0, v, Vec::new()))) + &substructure)) } _ if variants.len() > 1 && self_args.len() > 1 => { // Since we know that all the arguments will match if we reach diff --git a/src/libsyntax_ext/deriving/hash.rs b/src/libsyntax_ext/deriving/hash.rs index 97d7f2ce800..a341c21d0a1 100644 --- a/src/libsyntax_ext/deriving/hash.rs +++ b/src/libsyntax_ext/deriving/hash.rs @@ -81,7 +81,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) let mut stmts = Vec::new(); let fields = match *substr.fields { - Struct(_, ref fs) => fs, + Struct(_, ref fs) | EnumMatching(_, 1, .., ref fs) => fs, EnumMatching(.., ref fs) => { let variant_value = deriving::call_intrinsic(cx, trait_span, |
