Merge struct fields and struct kind
This commit is contained in:
parent
30af54dede
commit
40aa09e4c9
36 changed files with 222 additions and 148 deletions
|
@ -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<T> where T: Copy;` style decl.
|
||||
(Vec::new(), VariantKind::Unit)
|
||||
VariantData_::Unit
|
||||
} else {
|
||||
// If we see: `struct Foo<T> where T: Copy { ... }`
|
||||
(try!(self.parse_record_struct_body()), VariantKind::Struct)
|
||||
VariantData_::Struct(try!(self.parse_record_struct_body()))
|
||||
}
|
||||
// No `where` so: `struct Foo<T>;`
|
||||
} 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_ {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue