From 40aa09e4c9f4c3f0fa2b088895c8f5125325eaa4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 8 Oct 2015 23:45:46 +0300 Subject: Merge struct fields and struct kind --- src/libsyntax/parse/parser.rs | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f944c93073a..2431c8cbe88 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -45,7 +45,7 @@ use ast::{PatRegion, PatStruct, PatTup, PatVec, PatWild, PatWildMulti}; use ast::PatWildSingle; use ast::{PolyTraitRef, QSelf}; use ast::{Return, BiShl, BiShr, Stmt, StmtDecl}; -use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField, VariantKind}; +use ast::{StmtExpr, StmtSemi, StmtMac, VariantData, StructField, VariantData_}; use ast::{BiSub, StrStyle}; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; use ast::{Delimited, SequenceRepetition, TokenTree, TraitItem, TraitRef}; @@ -4640,26 +4640,24 @@ impl<'a> Parser<'a> { // Otherwise if we look ahead and see a paren we parse a tuple-style // struct. - let (fields, kind) = if self.token.is_keyword(keywords::Where) { + let data_ = if self.token.is_keyword(keywords::Where) { generics.where_clause = try!(self.parse_where_clause()); if try!(self.eat(&token::Semi)) { // If we see a: `struct Foo where T: Copy;` style decl. - (Vec::new(), VariantKind::Unit) + VariantData_::Unit } else { // If we see: `struct Foo where T: Copy { ... }` - (try!(self.parse_record_struct_body()), VariantKind::Struct) + VariantData_::Struct(try!(self.parse_record_struct_body())) } // No `where` so: `struct Foo;` } else if try!(self.eat(&token::Semi) ){ - (Vec::new(), VariantKind::Unit) + VariantData_::Unit // Record-style struct definition } else if self.token == token::OpenDelim(token::Brace) { - let fields = try!(self.parse_record_struct_body()); - (fields, VariantKind::Struct) + VariantData_::Struct(try!(self.parse_record_struct_body())) // Tuple-style struct definition with optional where-clause. } else if self.token == token::OpenDelim(token::Paren) { - let fields = try!(self.parse_tuple_struct_body(&mut generics)); - (fields, VariantKind::Tuple) + VariantData_::Tuple(try!(self.parse_tuple_struct_body(&mut generics))) } else { let token_str = self.this_token_to_string(); return Err(self.fatal(&format!("expected `where`, `{{`, `(`, or `;` after struct \ @@ -4668,9 +4666,8 @@ impl<'a> Parser<'a> { Ok((class_name, ItemStruct(P(ast::VariantData { - fields: fields, + data_: data_, id: ast::DUMMY_NODE_ID, - kind: kind, }), generics), None)) } @@ -5111,9 +5108,8 @@ impl<'a> Parser<'a> { try!(self.bump()); Ok(P(VariantData { - fields: fields, + data_: VariantData_::Struct(fields), id: ast::DUMMY_NODE_ID, - kind: VariantKind::Struct, })) } @@ -5150,19 +5146,16 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID, }}); } - struct_def = P(VariantData { fields: fields, - id: ast::DUMMY_NODE_ID, - kind: ast::VariantKind::Tuple }); + struct_def = P(VariantData { data_: ast::VariantData_::Tuple(fields), + id: ast::DUMMY_NODE_ID}); } else if try!(self.eat(&token::Eq) ){ disr_expr = Some(try!(self.parse_expr_nopanic())); any_disr = disr_expr.as_ref().map(|expr| expr.span); - struct_def = P(VariantData { fields: Vec::new(), - id: ast::DUMMY_NODE_ID, - kind: ast::VariantKind::Unit }); + struct_def = P(VariantData { data_: ast::VariantData_::Unit, + id: ast::DUMMY_NODE_ID}); } else { - struct_def = P(VariantData { fields: Vec::new(), - id: ast::DUMMY_NODE_ID, - kind: ast::VariantKind::Unit }); + struct_def = P(VariantData { data_: ast::VariantData_::Unit, + id: ast::DUMMY_NODE_ID}); } let vr = ast::Variant_ { -- cgit 1.4.1-3-g733a5