mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 20:28:33 +00:00
extract is_certainly_not_a_block
This commit is contained in:
parent
66b8ae4bce
commit
f6e2bdc341
@ -1721,14 +1721,7 @@ impl<'a> Parser<'a> {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_parse_struct_expr(
|
fn is_certainly_not_a_block(&self) -> bool {
|
||||||
&mut self,
|
|
||||||
lo: Span,
|
|
||||||
path: &ast::Path,
|
|
||||||
attrs: &AttrVec,
|
|
||||||
) -> Option<PResult<'a, P<Expr>>> {
|
|
||||||
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
|
|
||||||
let certainly_not_a_block = || {
|
|
||||||
self.look_ahead(1, |t| t.is_ident())
|
self.look_ahead(1, |t| t.is_ident())
|
||||||
&& (
|
&& (
|
||||||
// `{ ident, ` cannot start a block.
|
// `{ ident, ` cannot start a block.
|
||||||
@ -1741,9 +1734,16 @@ impl<'a> Parser<'a> {
|
|||||||
self.look_ahead(3, |t| !t.can_begin_type())
|
self.look_ahead(3, |t| !t.can_begin_type())
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
};
|
}
|
||||||
|
|
||||||
if struct_allowed || certainly_not_a_block() {
|
fn maybe_parse_struct_expr(
|
||||||
|
&mut self,
|
||||||
|
lo: Span,
|
||||||
|
path: &ast::Path,
|
||||||
|
attrs: &AttrVec,
|
||||||
|
) -> Option<PResult<'a, P<Expr>>> {
|
||||||
|
let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL);
|
||||||
|
if struct_allowed || self.is_certainly_not_a_block() {
|
||||||
// This is a struct literal, but we don't can't accept them here.
|
// This is a struct literal, but we don't can't accept them here.
|
||||||
let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
|
let expr = self.parse_struct_expr(lo, path.clone(), attrs.clone());
|
||||||
if let (Ok(expr), false) = (&expr, struct_allowed) {
|
if let (Ok(expr), false) = (&expr, struct_allowed) {
|
||||||
|
Loading…
Reference in New Issue
Block a user