Skip to content

Commit 379f318

Browse files
committed
parse: simplify parse_fn_body
1 parent 055733f commit 379f318

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/librustc_parse/parser/item.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,23 +1411,13 @@ impl<'a> Parser<'a> {
14111411
/// This can either be `;` when there's no body,
14121412
/// or e.g. a block when the function is a provided one.
14131413
fn parse_fn_body(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, Option<P<Block>>> {
1414-
let (inner_attrs, body) = match self.token.kind {
1415-
token::Semi => {
1416-
self.bump();
1417-
(Vec::new(), None)
1418-
}
1419-
token::OpenDelim(token::Brace) => {
1420-
let (attrs, body) = self.parse_inner_attrs_and_block()?;
1421-
(attrs, Some(body))
1422-
}
1423-
token::Interpolated(ref nt) => match **nt {
1424-
token::NtBlock(..) => {
1425-
let (attrs, body) = self.parse_inner_attrs_and_block()?;
1426-
(attrs, Some(body))
1427-
}
1428-
_ => return self.expected_semi_or_open_brace(),
1429-
},
1430-
_ => return self.expected_semi_or_open_brace(),
1414+
let (inner_attrs, body) = if self.check(&token::Semi) {
1415+
self.bump();
1416+
(Vec::new(), None)
1417+
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
1418+
self.parse_inner_attrs_and_block().map(|(attrs, body)| (attrs, Some(body)))?
1419+
} else {
1420+
return self.expected_semi_or_open_brace();
14311421
};
14321422
attrs.extend(inner_attrs);
14331423
Ok(body)

0 commit comments

Comments
 (0)