Skip to content

libsyntax: remove dead code from parser.rs #28286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 13, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 31 additions & 38 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4726,9 +4726,13 @@ impl<'a> Parser<'a> {
let fields = try!(self.parse_record_struct_body(&class_name));
(fields, None)
// Tuple-style struct definition with optional where-clause.
} else {
} else if self.token == token::OpenDelim(token::Paren) {
let fields = try!(self.parse_tuple_struct_body(&class_name, &mut generics));
(fields, Some(ast::DUMMY_NODE_ID))
} else {
let token_str = self.this_token_to_string();
return Err(self.fatal(&format!("expected `where`, `{{`, `(`, or `;` after struct \
name, found `{}`", token_str)))
};

Ok((class_name,
Expand Down Expand Up @@ -4756,8 +4760,8 @@ impl<'a> Parser<'a> {
try!(self.bump());
} else {
let token_str = self.this_token_to_string();
return Err(self.fatal(&format!("expected `where`, or `{}` after struct \
name, found `{}`", "{",
return Err(self.fatal(&format!("expected `where`, or `{{` after struct \
name, found `{}`",
token_str)));
}

Expand All @@ -4769,43 +4773,32 @@ impl<'a> Parser<'a> {
generics: &mut ast::Generics)
-> PResult<Vec<StructField>> {
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
if self.check(&token::OpenDelim(token::Paren)) {
let fields = try!(self.parse_unspanned_seq(
&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p| {
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
let struct_field_ = ast::StructField_ {
kind: UnnamedField(try!(p.parse_visibility())),
id: ast::DUMMY_NODE_ID,
ty: try!(p.parse_ty_sum()),
attrs: attrs,
};
Ok(spanned(lo, p.span.hi, struct_field_))
}));

if fields.is_empty() {
return Err(self.fatal(&format!("unit-like struct definition should be \
written as `struct {};`",
class_name)));
}
// Unit like structs are handled in parse_item_struct function
let fields = try!(self.parse_unspanned_seq(
&token::OpenDelim(token::Paren),
&token::CloseDelim(token::Paren),
seq_sep_trailing_allowed(token::Comma),
|p| {
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
let struct_field_ = ast::StructField_ {
kind: UnnamedField(try!(p.parse_visibility())),
id: ast::DUMMY_NODE_ID,
ty: try!(p.parse_ty_sum()),
attrs: attrs,
};
Ok(spanned(lo, p.span.hi, struct_field_))
}));

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)))
if fields.is_empty() {
return Err(self.fatal(&format!("unit-like struct definition should be \
written as `struct {};`",
class_name)));
}

generics.where_clause = try!(self.parse_where_clause());
try!(self.expect(&token::Semi));
Ok(fields)
}

/// Parse a structure field declaration
Expand Down