diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-28 10:34:44 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2016-08-28 10:34:50 +0000 |
| commit | 413ecdee30d76eeed574bc9af547b539bc511863 (patch) | |
| tree | a1931941954b1e2702eeb5f9a0ed70526c22fdf0 /src/libsyntax_ext/deriving/generic | |
| parent | bd38e890ee5c9e35bbc8874edf8547515bf57b37 (diff) | |
| parent | f6e06a8a365b118937079e3f9c4dfa8f221e7db5 (diff) | |
| download | rust-413ecdee30d76eeed574bc9af547b539bc511863.tar.gz rust-413ecdee30d76eeed574bc9af547b539bc511863.zip | |
Rollup merge of #35728 - petrochenkov:empderive, r=manishearth
Fix #[derive] for empty tuple structs/variants This was missing from https://github.com/rust-lang/rust/pull/35138
Diffstat (limited to 'src/libsyntax_ext/deriving/generic')
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 5960e4546b1..03282653d36 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -294,8 +294,8 @@ pub struct FieldInfo<'a> { /// Fields for a static method pub enum StaticFields { - /// Tuple structs/enum variants like this. - Unnamed(Vec<Span>), + /// Tuple and unit structs/enum variants like this. + Unnamed(Vec<Span>, bool /*is tuple*/), /// Normal structs/struct variants. Named(Vec<(Ident, Span)>), } @@ -1472,7 +1472,7 @@ impl<'a> TraitDef<'a> { (_, false) => Named(named_idents), // empty structs _ if struct_def.is_struct() => Named(named_idents), - _ => Unnamed(just_spans), + _ => Unnamed(just_spans, struct_def.is_tuple()), } } @@ -1512,26 +1512,32 @@ impl<'a> TraitDef<'a> { } let subpats = self.create_subpatterns(cx, paths, mutbl); - let pattern = if struct_def.is_struct() { - let field_pats = subpats.into_iter() - .zip(&ident_exprs) - .map(|(pat, &(sp, ident, _, _))| { - if ident.is_none() { - cx.span_bug(sp, "a braced struct with unnamed fields in `derive`"); - } - codemap::Spanned { - span: pat.span, - node: ast::FieldPat { - ident: ident.unwrap(), - pat: pat, - is_shorthand: false, - }, - } - }) - .collect(); - cx.pat_struct(self.span, struct_path, field_pats) - } else { - cx.pat_enum(self.span, struct_path, subpats) + let pattern = match *struct_def { + VariantData::Struct(..) => { + let field_pats = subpats.into_iter() + .zip(&ident_exprs) + .map(|(pat, &(sp, ident, _, _))| { + if ident.is_none() { + cx.span_bug(sp, "a braced struct with unnamed fields in `derive`"); + } + codemap::Spanned { + span: pat.span, + node: ast::FieldPat { + ident: ident.unwrap(), + pat: pat, + is_shorthand: false, + }, + } + }) + .collect(); + cx.pat_struct(self.span, struct_path, field_pats) + } + VariantData::Tuple(..) => { + cx.pat_tuple_struct(self.span, struct_path, subpats) + } + VariantData::Unit(..) => { + cx.pat_path(self.span, struct_path) + } }; (pattern, ident_exprs) |
