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
@ -251,13 +251,12 @@ pub(super) fn error_on_forbidden_inner_attr(&self, attr_sp: Span, policy: InnerA
|
|||||||
pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, ast::AttrItem> {
|
pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, ast::AttrItem> {
|
||||||
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
|
maybe_whole!(self, NtMeta, |attr| attr.into_inner());
|
||||||
|
|
||||||
let do_parse = |this: &mut Self| {
|
let do_parse = |this: &mut Self, _empty_attrs| {
|
||||||
let is_unsafe = this.eat_keyword(kw::Unsafe);
|
let is_unsafe = this.eat_keyword(kw::Unsafe);
|
||||||
let unsafety = if is_unsafe {
|
let unsafety = if is_unsafe {
|
||||||
let unsafe_span = this.prev_token.span;
|
let unsafe_span = this.prev_token.span;
|
||||||
this.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
|
this.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
|
||||||
this.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
|
this.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
|
||||||
|
|
||||||
ast::Safety::Unsafe(unsafe_span)
|
ast::Safety::Unsafe(unsafe_span)
|
||||||
} else {
|
} else {
|
||||||
ast::Safety::Default
|
ast::Safety::Default
|
||||||
@ -268,13 +267,10 @@ pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, as
|
|||||||
if is_unsafe {
|
if is_unsafe {
|
||||||
this.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
|
this.expect(&token::CloseDelim(Delimiter::Parenthesis))?;
|
||||||
}
|
}
|
||||||
Ok(ast::AttrItem { unsafety, path, args, tokens: None })
|
Ok((ast::AttrItem { unsafety, path, args, tokens: None }, false))
|
||||||
};
|
};
|
||||||
// Attr items don't have attributes
|
// Attr items don't have attributes.
|
||||||
match force_collect {
|
self.collect_tokens_trailing_token(AttrWrapper::empty(), force_collect, do_parse)
|
||||||
ForceCollect::Yes => self.collect_tokens_no_attrs(do_parse),
|
|
||||||
ForceCollect::No => do_parse(self),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses attributes that appear after the opening of an item. These should
|
/// Parses attributes that appear after the opening of an item. These should
|
||||||
|
@ -99,17 +99,17 @@ pub fn parse_stmt_without_recovery(
|
|||||||
// or `auto trait` items. We aim to parse an arbitrary path `a::b` but not something
|
// 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.
|
// that starts like a path (1 token), but it fact not a path.
|
||||||
// Also, we avoid stealing syntax from `parse_item_`.
|
// Also, we avoid stealing syntax from `parse_item_`.
|
||||||
match force_collect {
|
let stmt = self.collect_tokens_trailing_token(
|
||||||
ForceCollect::Yes => {
|
AttrWrapper::empty(),
|
||||||
self.collect_tokens_no_attrs(|this| this.parse_stmt_path_start(lo, attrs))?
|
force_collect,
|
||||||
}
|
|this, _empty_attrs| Ok((this.parse_stmt_path_start(lo, attrs)?, false)),
|
||||||
ForceCollect::No => match self.parse_stmt_path_start(lo, attrs) {
|
);
|
||||||
|
match stmt {
|
||||||
Ok(stmt) => stmt,
|
Ok(stmt) => stmt,
|
||||||
Err(mut err) => {
|
Err(mut err) => {
|
||||||
self.suggest_add_missing_let_for_stmt(&mut err);
|
self.suggest_add_missing_let_for_stmt(&mut err);
|
||||||
return Err(err);
|
return Err(err);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
}
|
}
|
||||||
} else if let Some(item) = self.parse_item_common(
|
} else if let Some(item) = self.parse_item_common(
|
||||||
attrs.clone(),
|
attrs.clone(),
|
||||||
@ -126,12 +126,13 @@ pub fn parse_stmt_without_recovery(
|
|||||||
self.mk_stmt(lo, StmtKind::Empty)
|
self.mk_stmt(lo, StmtKind::Empty)
|
||||||
} else if self.token != token::CloseDelim(Delimiter::Brace) {
|
} else if self.token != token::CloseDelim(Delimiter::Brace) {
|
||||||
// Remainder are line-expr stmts.
|
// Remainder are line-expr stmts.
|
||||||
let e = match force_collect {
|
let e = self.collect_tokens_trailing_token(
|
||||||
ForceCollect::Yes => self.collect_tokens_no_attrs(|this| {
|
AttrWrapper::empty(),
|
||||||
this.parse_expr_res(Restrictions::STMT_EXPR, attrs)
|
force_collect,
|
||||||
})?,
|
|this, _empty_attrs| {
|
||||||
ForceCollect::No => self.parse_expr_res(Restrictions::STMT_EXPR, attrs)?,
|
Ok((this.parse_expr_res(Restrictions::STMT_EXPR, attrs)?, false))
|
||||||
};
|
},
|
||||||
|
)?;
|
||||||
if matches!(e.kind, ExprKind::Assign(..)) && self.eat_keyword(kw::Else) {
|
if matches!(e.kind, ExprKind::Assign(..)) && self.eat_keyword(kw::Else) {
|
||||||
let bl = self.parse_block()?;
|
let bl = self.parse_block()?;
|
||||||
// Destructuring assignment ... else.
|
// Destructuring assignment ... else.
|
||||||
|
Loading…
Reference in New Issue
Block a user