libsyntax: remove dead code from parser.rs
Both `parse_tuple_struct_body` and `parse_item_struct` handled the case of unit like struct. The redundancy is removed, `parse_tuple_struct_body` now handles only real tuple structs.
This commit is contained in:
parent
0762f58c11
commit
c8da5697e0
1 changed files with 24 additions and 35 deletions
|
@ -4769,43 +4769,32 @@ impl<'a> Parser<'a> {
|
||||||
generics: &mut ast::Generics)
|
generics: &mut ast::Generics)
|
||||||
-> PResult<Vec<StructField>> {
|
-> PResult<Vec<StructField>> {
|
||||||
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
|
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
|
||||||
if self.check(&token::OpenDelim(token::Paren)) {
|
// Unit like structs are handled in parse_item_struct function
|
||||||
let fields = try!(self.parse_unspanned_seq(
|
let fields = try!(self.parse_unspanned_seq(
|
||||||
&token::OpenDelim(token::Paren),
|
&token::OpenDelim(token::Paren),
|
||||||
&token::CloseDelim(token::Paren),
|
&token::CloseDelim(token::Paren),
|
||||||
seq_sep_trailing_allowed(token::Comma),
|
seq_sep_trailing_allowed(token::Comma),
|
||||||
|p| {
|
|p| {
|
||||||
let attrs = p.parse_outer_attributes();
|
let attrs = p.parse_outer_attributes();
|
||||||
let lo = p.span.lo;
|
let lo = p.span.lo;
|
||||||
let struct_field_ = ast::StructField_ {
|
let struct_field_ = ast::StructField_ {
|
||||||
kind: UnnamedField(try!(p.parse_visibility())),
|
kind: UnnamedField(try!(p.parse_visibility())),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
ty: try!(p.parse_ty_sum()),
|
ty: try!(p.parse_ty_sum()),
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
};
|
};
|
||||||
Ok(spanned(lo, p.span.hi, struct_field_))
|
Ok(spanned(lo, p.span.hi, struct_field_))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
return Err(self.fatal(&format!("unit-like struct definition should be \
|
return Err(self.fatal(&format!("unit-like struct definition should be \
|
||||||
written as `struct {};`",
|
written as `struct {};`",
|
||||||
class_name)));
|
class_name)));
|
||||||
}
|
|
||||||
|
|
||||||
generics.where_clause = try!(self.parse_where_clause());
|
|
||||||
try!(self.expect(&token::Semi));
|
|
||||||
Ok(fields)
|
|
||||||
// This is the case where we just see struct Foo<T> where T: Copy;
|
|
||||||
} else if self.token.is_keyword(keywords::Where) {
|
|
||||||
generics.where_clause = try!(self.parse_where_clause());
|
|
||||||
try!(self.expect(&token::Semi));
|
|
||||||
Ok(Vec::new())
|
|
||||||
// This case is where we see: `struct Foo<T>;`
|
|
||||||
} else {
|
|
||||||
let token_str = self.this_token_to_string();
|
|
||||||
Err(self.fatal(&format!("expected `where`, `{}`, `(`, or `;` after struct \
|
|
||||||
name, found `{}`", "{", token_str)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generics.where_clause = try!(self.parse_where_clause());
|
||||||
|
try!(self.expect(&token::Semi));
|
||||||
|
Ok(fields)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a structure field declaration
|
/// Parse a structure field declaration
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue