parser: early return for item stmt

This commit is contained in:
Mazdak Farrokhzad 2019-12-03 05:50:05 +01:00
parent 690815b70e
commit c54c9ef863

View File

@ -84,9 +84,10 @@ impl<'a> Parser<'a> {
let item = self.parse_item_(attrs.clone(), false, true)?;
self.directory.ownership = old_directory_ownership;
match item {
Some(i) => self.mk_stmt(lo.to(i.span), StmtKind::Item(i)),
None => {
if let Some(item) = item {
return Ok(Some(self.mk_stmt(lo.to(item.span), StmtKind::Item(item))));
}
let unused_attrs = |attrs: &[Attribute], s: &mut Self| {
if !attrs.is_empty() {
if s.prev_token_kind == PrevTokenKind::DocComment {
@ -127,8 +128,6 @@ impl<'a> Parser<'a> {
// Remainder are line-expr stmts.
let e = self.parse_expr_res( Restrictions::STMT_EXPR, Some(attrs.into()))?;
self.mk_stmt(lo.to(e.span), StmtKind::Expr(e))
}
}
}))
}