@@ -1721,29 +1721,29 @@ impl<'a> Parser<'a> {
1721
1721
) )
1722
1722
}
1723
1723
1724
+ fn is_certainly_not_a_block ( & self ) -> bool {
1725
+ self . look_ahead ( 1 , |t| t. is_ident ( ) )
1726
+ && (
1727
+ // `{ ident, ` cannot start a block.
1728
+ self . look_ahead ( 2 , |t| t == & token:: Comma )
1729
+ || self . look_ahead ( 2 , |t| t == & token:: Colon )
1730
+ && (
1731
+ // `{ ident: token, ` cannot start a block.
1732
+ self . look_ahead ( 4 , |t| t == & token:: Comma ) ||
1733
+ // `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`.
1734
+ self . look_ahead ( 3 , |t| !t. can_begin_type ( ) )
1735
+ )
1736
+ )
1737
+ }
1738
+
1724
1739
fn maybe_parse_struct_expr (
1725
1740
& mut self ,
1726
1741
lo : Span ,
1727
1742
path : & ast:: Path ,
1728
1743
attrs : & AttrVec ,
1729
1744
) -> Option < PResult < ' a , P < Expr > > > {
1730
1745
let struct_allowed = !self . restrictions . contains ( Restrictions :: NO_STRUCT_LITERAL ) ;
1731
- let certainly_not_a_block = || {
1732
- self . look_ahead ( 1 , |t| t. is_ident ( ) )
1733
- && (
1734
- // `{ ident, ` cannot start a block.
1735
- self . look_ahead ( 2 , |t| t == & token:: Comma )
1736
- || self . look_ahead ( 2 , |t| t == & token:: Colon )
1737
- && (
1738
- // `{ ident: token, ` cannot start a block.
1739
- self . look_ahead ( 4 , |t| t == & token:: Comma ) ||
1740
- // `{ ident: ` cannot start a block unless it's a type ascription `ident: Type`.
1741
- self . look_ahead ( 3 , |t| !t. can_begin_type ( ) )
1742
- )
1743
- )
1744
- } ;
1745
-
1746
- if struct_allowed || certainly_not_a_block ( ) {
1746
+ if struct_allowed || self . is_certainly_not_a_block ( ) {
1747
1747
// This is a struct literal, but we don't can't accept them here.
1748
1748
let expr = self . parse_struct_expr ( lo, path. clone ( ) , attrs. clone ( ) ) ;
1749
1749
if let ( Ok ( expr) , false ) = ( & expr, struct_allowed) {
0 commit comments