Only check force_collect
in collect_tokens_trailing_token
.
There are three places where we currently check `force_collect` and call `collect_tokens_no_attrs` for `ForceCollect::Yes` and a vanilla parsing function for `ForceCollect::No`. But we can instead just pass in `force_collect` and let `collect_tokens_trailing_token` do the appropriate thing.
This commit is contained in:
parent
9d908a2877
commit
4158a1c48f
2 changed files with 21 additions and 24 deletions
|
@ -99,17 +99,17 @@ impl<'a> Parser<'a> {
|
|||
// or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
|
||||
// that starts like a path (1 token), but it fact not a path.
|
||||
// Also, we avoid stealing syntax from `parse_item_`.
|
||||
match force_collect {
|
||||
ForceCollect::Yes => {
|
||||
self.collect_tokens_no_attrs(|this| this.parse_stmt_path_start(lo, attrs))?
|
||||
let stmt = self.collect_tokens_trailing_token(
|
||||
AttrWrapper::empty(),
|
||||
force_collect,
|
||||
|this, _empty_attrs| Ok((this.parse_stmt_path_start(lo, attrs)?, false)),
|
||||
);
|
||||
match stmt {
|
||||
Ok(stmt) => stmt,
|
||||
Err(mut err) => {
|
||||
self.suggest_add_missing_let_for_stmt(&mut err);
|
||||
return Err(err);
|
||||
}
|
||||
ForceCollect::No => match self.parse_stmt_path_start(lo, attrs) {
|
||||
Ok(stmt) => stmt,
|
||||
Err(mut err) => {
|
||||
self.suggest_add_missing_let_for_stmt(&mut err);
|
||||
return Err(err);
|
||||
}
|
||||
},
|
||||
}
|
||||
} else if let Some(item) = self.parse_item_common(
|
||||
attrs.clone(),
|
||||
|
@ -126,12 +126,13 @@ impl<'a> Parser<'a> {
|
|||
self.mk_stmt(lo, StmtKind::Empty)
|
||||
} else if self.token != token::CloseDelim(Delimiter::Brace) {
|
||||
// Remainder are line-expr stmts.
|
||||
let e = match force_collect {
|
||||
ForceCollect::Yes => self.collect_tokens_no_attrs(|this| {
|
||||
this.parse_expr_res(Restrictions::STMT_EXPR, attrs)
|
||||
})?,
|
||||
ForceCollect::No => self.parse_expr_res(Restrictions::STMT_EXPR, attrs)?,
|
||||
};
|
||||
let e = self.collect_tokens_trailing_token(
|
||||
AttrWrapper::empty(),
|
||||
force_collect,
|
||||
|this, _empty_attrs| {
|
||||
Ok((this.parse_expr_res(Restrictions::STMT_EXPR, attrs)?, false))
|
||||
},
|
||||
)?;
|
||||
if matches!(e.kind, ExprKind::Assign(..)) && self.eat_keyword(kw::Else) {
|
||||
let bl = self.parse_block()?;
|
||||
// Destructuring assignment ... else.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue