@@ -739,9 +739,10 @@ impl<'a> Parser<'a> {
739
739
fn check_const_closure ( & self ) -> bool {
740
740
self . is_keyword_ahead ( 0 , & [ kw:: Const ] )
741
741
&& self . look_ahead ( 1 , |t| match & t. kind {
742
- token:: Ident ( kw:: Move | kw:: Static | kw:: Async , _)
743
- | token:: OrOr
744
- | token:: BinOp ( token:: Or ) => true ,
742
+ // async closures do not work with const closures, so we do not parse that here.
743
+ token:: Ident ( kw:: Move | kw:: Static , _) | token:: OrOr | token:: BinOp ( token:: Or ) => {
744
+ true
745
+ }
745
746
_ => false ,
746
747
} )
747
748
}
@@ -1203,8 +1204,18 @@ impl<'a> Parser<'a> {
1203
1204
1204
1205
/// Parses constness: `const` or nothing.
1205
1206
fn parse_constness ( & mut self , case : Case ) -> Const {
1206
- // Avoid const blocks to be parsed as const items
1207
- if self . look_ahead ( 1 , |t| t != & token:: OpenDelim ( Delimiter :: Brace ) )
1207
+ self . parse_constness_ ( case, false )
1208
+ }
1209
+
1210
+ /// Parses constness for closures
1211
+ fn parse_closure_constness ( & mut self , case : Case ) -> Const {
1212
+ self . parse_constness_ ( case, true )
1213
+ }
1214
+
1215
+ fn parse_constness_ ( & mut self , case : Case , is_closure : bool ) -> Const {
1216
+ // Avoid const blocks and const closures to be parsed as const items
1217
+ if ( self . check_const_closure ( ) == is_closure)
1218
+ && self . look_ahead ( 1 , |t| t != & token:: OpenDelim ( Delimiter :: Brace ) )
1208
1219
&& self . eat_keyword_case ( kw:: Const , case)
1209
1220
{
1210
1221
Const :: Yes ( self . prev_token . uninterpolated_span ( ) )
0 commit comments