diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-08-15 21:28:17 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2016-08-18 01:33:18 +0300 |
| commit | f6e06a8a365b118937079e3f9c4dfa8f221e7db5 (patch) | |
| tree | b96e5026f26ba96edb9eafbdf9a25dab18164914 /src/libsyntax_ext | |
| parent | 28ed8b159237a2704f2308a404b3bd81b676ce17 (diff) | |
| download | rust-f6e06a8a365b118937079e3f9c4dfa8f221e7db5.tar.gz rust-f6e06a8a365b118937079e3f9c4dfa8f221e7db5.zip | |
Split `AstBuilder::pat_enum` into `pat_tuple_struct` and `pat_path`
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/ord.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/cmp/partial_ord.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 46 |
3 files changed, 28 insertions, 22 deletions
diff --git a/src/libsyntax_ext/deriving/cmp/ord.rs b/src/libsyntax_ext/deriving/cmp/ord.rs index 8ae77e79310..31194b04fa6 100644 --- a/src/libsyntax_ext/deriving/cmp/ord.rs +++ b/src/libsyntax_ext/deriving/cmp/ord.rs @@ -104,7 +104,7 @@ pub fn cs_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P<Expr> { }; let eq_arm = cx.arm(span, - vec![cx.pat_enum(span, equals_path.clone(), vec![])], + vec![cx.pat_path(span, equals_path.clone())], old); let neq_arm = cx.arm(span, vec![cx.pat_ident(span, test_id)], diff --git a/src/libsyntax_ext/deriving/cmp/partial_ord.rs b/src/libsyntax_ext/deriving/cmp/partial_ord.rs index 10a9738742e..9e9b2f02062 100644 --- a/src/libsyntax_ext/deriving/cmp/partial_ord.rs +++ b/src/libsyntax_ext/deriving/cmp/partial_ord.rs @@ -165,7 +165,7 @@ pub fn cs_partial_cmp(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> P< }; let eq_arm = cx.arm(span, - vec![cx.pat_some(span, cx.pat_enum(span, ordering.clone(), vec![]))], + vec![cx.pat_some(span, cx.pat_path(span, ordering.clone()))], old); let neq_arm = cx.arm(span, vec![cx.pat_ident(span, test_id)], diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 22e98fb213f..b2b887c7ef2 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -1510,26 +1510,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) |
