@@ -208,6 +208,8 @@ import qualified Data.List.NonEmpty as N
208
208
where { Spanned (IdentTok " where" ) _ }
209
209
while { Spanned (IdentTok " while" ) _ }
210
210
do { Spanned (IdentTok " do" ) _ }
211
+ yield { Spanned (IdentTok " yield" ) _ }
212
+ dyn { Spanned (IdentTok " dyn" ) _ }
211
213
212
214
-- Keywords reserved for future use
213
215
abstract { Spanned (IdentTok " abstract" ) _ }
@@ -224,7 +226,6 @@ import qualified Data.List.NonEmpty as N
224
226
typeof { Spanned (IdentTok " typeof" ) _ }
225
227
unsized { Spanned (IdentTok " unsized" ) _ }
226
228
virtual { Spanned (IdentTok " virtual" ) _ }
227
- yield { Spanned (IdentTok " yield" ) _ }
228
229
229
230
-- Weak keywords, have special meaning only in specific contexts.
230
231
default { Spanned (IdentTok " default" ) _ }
@@ -280,7 +281,11 @@ import qualified Data.List.NonEmpty as N
280
281
%nonassoc IDENT ntIdent default union catch self auto
281
282
282
283
-- These are all very low precedence unary operators
283
- %nonassoc box return break continue IMPLTRAIT LAMBDA
284
+ %nonassoc box return yield break continue IMPLTRAIT LAMBDA
285
+
286
+ -- 'static' needs to have higher precedenc than 'LAMBDA' so that statements starting in static get
287
+ -- considered as static items, and not a static lambda
288
+ %nonassoc static
284
289
285
290
-- These are the usual arithmetic precedences. 'UNARY' is introduced here for '*', '!', '-', '&'
286
291
%right '=' '>>=' '<<=' '-=' '+=' '*=' '/=' '^=' '|=' '&=' '%='
@@ -331,6 +336,7 @@ ident :: { Spanned Ident }
331
336
| default { toIdent $1 }
332
337
| catch { toIdent $1 }
333
338
| auto { toIdent $1 }
339
+ | dyn { toIdent $1 }
334
340
| IDENT { toIdent $1 }
335
341
336
342
-- This should precede any ' >' token which could be absorbed in a ' >>' , ' >=' , or ' >>=' token. Its
@@ -638,6 +644,7 @@ for_ty_no_plus :: { Ty Span }
638
644
639
645
impl_ty :: { Ty Span }
640
646
: impl sep_by1 (ty_param_bound_mod,' +' ) %prec IMPLTRAIT { ImplTrait (toNonEmpty $2 ) ($1 # $2 ) }
647
+ -- | dyn sep_by1 (ty_param_bound_mod,' +' ) %prec IMPLTRAIT { TraitObject (toNonEmpty $2 ) ($1 # $2 ) }
641
648
642
649
-- An optional lifetime followed by an optional mutability
643
650
lifetime_mut :: { (Maybe (Lifetime Span), Mutability) }
@@ -916,17 +923,23 @@ gen_expression(lhs,rhs,rhs2) :: { Expr Span }
916
923
-- low precedence prefix expressions
917
924
| return { Ret [] Nothing (spanOf $1 ) }
918
925
| return rhs { Ret [] (Just $2 ) ($1 # $2 ) }
926
+ | yield { Yield [] Nothing (spanOf $1 ) }
927
+ | yield rhs { Yield [] (Just $2 ) ($1 # $2 ) }
919
928
| continue { Continue [] Nothing (spanOf $1 ) }
920
- | continue lifetime { Continue [] (Just $2 ) ($1 # $2 ) }
929
+ | continue label { Continue [] (Just $2 ) ($1 # $2 ) }
921
930
| break { Break [] Nothing Nothing (spanOf $1 ) }
922
- | break rhs { Break [] Nothing (Just $2 ) ($1 # $2 ) }
923
- | break lifetime { Break [] (Just $2 ) Nothing ($1 # $2 ) }
924
- | break lifetime rhs %prec break { Break [] (Just $2 ) (Just $3 ) ($1 # $3 ) }
931
+ | break rhs { Break [] Nothing (Just $2 ) ($1 # $2 ) }
932
+ | break label { Break [] (Just $2 ) Nothing ($1 # $2 ) }
933
+ | break label rhs %prec break { Break [] (Just $2 ) (Just $3 ) ($1 # $3 ) }
925
934
-- lambda expressions
926
- | move lambda_args rhs %prec LAMBDA
927
- { Closure [] Value (FnDecl (unspan $2 ) Nothing False (spanOf $2 )) $> ($1 # $>) }
928
- | lambda_args rhs %prec LAMBDA
929
- { Closure [] Ref (FnDecl (unspan $1 ) Nothing False (spanOf $1 )) $> ($1 # $>) }
935
+ | static move lambda_args rhs %prec LAMBDA
936
+ { Closure [] Immovable Value (FnDecl (unspan $3 ) Nothing False (spanOf $3 )) $> ($1 # $>) }
937
+ | move lambda_args rhs %prec LAMBDA
938
+ { Closure [] Movable Value (FnDecl (unspan $2 ) Nothing False (spanOf $2 )) $> ($1 # $>) }
939
+ | static lambda_args rhs %prec LAMBDA
940
+ { Closure [] Immovable Ref (FnDecl (unspan $2 ) Nothing False (spanOf $2 )) $> ($1 # $>) }
941
+ | lambda_args rhs %prec LAMBDA
942
+ { Closure [] Movable Ref (FnDecl (unspan $1 ) Nothing False (spanOf $1 )) $> ($1 # $>) }
930
943
931
944
-- Variant of ' gen_expression' which only constructs expressions starting with another expression.
932
945
left_gen_expression (lhs,rhs,rhs2) :: { Expr Span }
@@ -1084,6 +1097,10 @@ blockpostfix_expr :: { Expr Span }
1084
1097
1085
1098
-- Finally, what remains is the more mundane definitions of particular types of expressions.
1086
1099
1100
+ -- labels on loops
1101
+ label :: { Label Span }
1102
+ : LIFETIME { let Spanned (LifetimeTok (Ident l _)) s = $1 in Label l s }
1103
+
1087
1104
-- Literal expressions (composed of just literals)
1088
1105
lit_expr :: { Expr Span }
1089
1106
: lit { Lit [] $1 (spanOf $1 ) }
@@ -1098,21 +1115,21 @@ block_expr :: { Expr Span }
1098
1115
1099
1116
-- Any expression ending in a ' { ... }' block except a block itself.
1100
1117
block_like_expr :: { Expr Span }
1101
- : if_expr { $1 }
1102
- | loop inner_attrs_block { let (as,b) = $> in Loop as b Nothing ($1 # b) }
1103
- | lifetime ' :' loop inner_attrs_block { let (as,b) = $> in Loop as b (Just $1 ) ($1 # b) }
1104
- | for pat in nostruct_expr inner_attrs_block { let (as,b) = $> in ForLoop as $2 $4 b Nothing ($1 # b) }
1105
- | lifetime ' :' for pat in nostruct_expr inner_attrs_block { let (as,b) = $> in ForLoop as $4 $6 b (Just $1 ) ($1 # b) }
1106
- | while nostruct_expr inner_attrs_block { let (as,b) = $> in While as $2 b Nothing ($1 # b) }
1107
- | lifetime ' :' while nostruct_expr inner_attrs_block { let (as,b) = $> in While as $4 b (Just $1 ) ($1 # b) }
1108
- | while let pat ' =' nostruct_expr inner_attrs_block { let (as,b) = $> in WhileLet as $3 $5 b Nothing ($1 # b) }
1109
- | lifetime ' :' while let pat ' =' nostruct_expr inner_attrs_block { let (as,b) = $> in WhileLet as $5 $7 b (Just $1 ) ($1 # b) }
1110
- | match nostruct_expr ' {' ' }' { Match [] $2 [] ($1 # $>) }
1111
- | match nostruct_expr ' {' inner_attrs ' }' { Match (toList $4 ) $2 [] ($1 # $>) }
1112
- | match nostruct_expr ' {' arms ' }' { Match [] $2 $4 ($1 # $>) }
1113
- | match nostruct_expr ' {' inner_attrs arms ' }' { Match (toList $4 ) $2 $5 ($1 # $>) }
1114
- | expr_path ' !' ' {' token_stream ' }' { MacExpr [] (Mac $1 $4 ($1 # $>)) ($1 # $>) }
1115
- | do catch inner_attrs_block { let (as,b) = $> in Catch as b ($1 # b) }
1118
+ : if_expr { $1 }
1119
+ | loop inner_attrs_block { let (as,b) = $> in Loop as b Nothing ($1 # b) }
1120
+ | label ' :' loop inner_attrs_block { let (as,b) = $> in Loop as b (Just $1 ) ($1 # b) }
1121
+ | for pat in nostruct_expr inner_attrs_block { let (as,b) = $> in ForLoop as $2 $4 b Nothing ($1 # b) }
1122
+ | label ' :' for pat in nostruct_expr inner_attrs_block { let (as,b) = $> in ForLoop as $4 $6 b (Just $1 ) ($1 # b) }
1123
+ | while nostruct_expr inner_attrs_block { let (as,b) = $> in While as $2 b Nothing ($1 # b) }
1124
+ | label ' :' while nostruct_expr inner_attrs_block { let (as,b) = $> in While as $4 b (Just $1 ) ($1 # b) }
1125
+ | while let pat ' =' nostruct_expr inner_attrs_block { let (as,b) = $> in WhileLet as $3 $5 b Nothing ($1 # b) }
1126
+ | label ' :' while let pat ' =' nostruct_expr inner_attrs_block { let (as,b) = $> in WhileLet as $5 $7 b (Just $1 ) ($1 # b) }
1127
+ | match nostruct_expr ' {' ' }' { Match [] $2 [] ($1 # $>) }
1128
+ | match nostruct_expr ' {' inner_attrs ' }' { Match (toList $4 ) $2 [] ($1 # $>) }
1129
+ | match nostruct_expr ' {' arms ' }' { Match [] $2 $4 ($1 # $>) }
1130
+ | match nostruct_expr ' {' inner_attrs arms ' }' { Match (toList $4 ) $2 $5 ($1 # $>) }
1131
+ | expr_path ' !' ' {' token_stream ' }' { MacExpr [] (Mac $1 $4 ($1 # $>)) ($1 # $>) }
1132
+ | do catch inner_attrs_block { let (as,b) = $> in Catch as b ($1 # b) }
1116
1133
1117
1134
-- ' if' expressions are a bit special since they can have an arbitrary number of ' else if' chains.
1118
1135
if_expr :: { Expr Span }
@@ -1168,10 +1185,14 @@ paren_expr :: { Expr Span }
1168
1185
1169
1186
-- Closure ending in blocks
1170
1187
lambda_expr_block :: { Expr Span }
1171
- : move lambda_args ' ->' ty_no_plus block
1172
- { Closure [] Value (FnDecl (unspan $2 ) (Just $4 ) False (spanOf $2 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1173
- | lambda_args ' ->' ty_no_plus block
1174
- { Closure [] Ref (FnDecl (unspan $1 ) (Just $3 ) False (spanOf $1 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1188
+ : static move lambda_args ' ->' ty_no_plus block
1189
+ { Closure [] Immovable Value (FnDecl (unspan $3 ) (Just $5 ) False (spanOf $3 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1190
+ | move lambda_args ' ->' ty_no_plus block
1191
+ { Closure [] Movable Value (FnDecl (unspan $2 ) (Just $4 ) False (spanOf $2 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1192
+ | static lambda_args ' ->' ty_no_plus block
1193
+ { Closure [] Immovable Ref (FnDecl (unspan $2 ) (Just $4 ) False (spanOf $2 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1194
+ | lambda_args ' ->' ty_no_plus block
1195
+ { Closure [] Movable Ref (FnDecl (unspan $1 ) (Just $3 ) False (spanOf $1 )) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1175
1196
1176
1197
-- Lambda expression arguments block
1177
1198
lambda_args :: { Spanned [Arg Span] }
@@ -1317,8 +1338,8 @@ gen_item(vis) :: { Item Span }
1317
1338
{ Trait $1 (unspan $2) (unspan $6) True (unspan $3) ($7 `withWhere` $10) (toList $9) $12 ($1 # $2 # $3 # $5 # $>) }
1318
1339
| many(outer_attribute) vis safety auto trait ident generics where_clause ' {' many(trait_item) ' }'
1319
1340
{ Trait $1 (unspan $2) (unspan $6) True (unspan $3) ($7 `withWhere` $8) [] $10 ($1 # $2 # $3 # $5 # $>) }
1320
- -- | many(outer_attribute) vis trait ident generics ' =' sep_by1T(ty_param_bound,' +' ) ' ;'
1321
- -- { TraitAlias $1 (unspan $2) (unspan $4 ) $5 (toNonEmpty $7 ) ($1 # $2 # $3 # $>) }
1341
+ | many(outer_attribute) vis safety trait ident generics ' =' sep_by1T(ty_param_bound,' +' ) ' ;'
1342
+ {% noSafety $3 ( TraitAlias $1 (unspan $2) (unspan $5 ) $6 (toNonEmpty $8 ) ($1 # $2 # $3 # $>) ) }
1322
1343
| many(outer_attribute) vis safety impl generics ty_prim where_clause ' {' impl_items ' }'
1323
1344
{ Impl ($1 ++ fst $9) (unspan $2) Final (unspan $3) Positive ($5 `withWhere` $7) Nothing $6 (snd $9) ($1 # $2 # $3 # $4 # $5 # $>) }
1324
1345
| many(outer_attribute) vis default safety impl generics ty_prim where_clause ' {' impl_items ' }'
@@ -1335,11 +1356,6 @@ gen_item(vis) :: { Item Span }
1335
1356
{ Impl ($1 ++ fst $11) (unspan $2) Final (unspan $3) Positive ($5 `withWhere` $9) (Just $6) $8 (snd $11) ($1 # $2 # $3 # $4 # $5 # $>) }
1336
1357
| many(outer_attribute) vis default safety impl generics trait_ref for ty where_clause ' {' impl_items ' }'
1337
1358
{ Impl ($1 ++ fst $12) (unspan $2) Default (unspan $4) Positive ($6 `withWhere` $10) (Just $7) $9 (snd $12) ($1 # $2 # $3 # $4 # $5 # $>) }
1338
- | many(outer_attribute) vis safety impl generics trait_ref for ' ..' ' {' ' }'
1339
- {% case $5 of
1340
- Generics [] [] _ _ -> pure $ AutoImpl $1 (unspan $2) (unspan $3) $6 ($1 # $2 # $3 # $4 # $>)
1341
- _ -> fail "non-empty generics are no allowed on default implementations"
1342
- }
1343
1359
1344
1360
-- Most general type of item
1345
1361
mod_item :: { Item Span }
@@ -1365,6 +1381,8 @@ foreign_item :: { ForeignItem Span }
1365
1381
{ ForeignStatic $1 (unspan $2) (unspan $5) $7 Mutable ($1 # $2 # $>) }
1366
1382
| many(outer_attribute) vis fn ident generics fn_decl(arg_named) where_clause ' ;'
1367
1383
{ ForeignFn $1 (unspan $2) (unspan $4) $6 ($5 `withWhere` $7) ($1 # $2 # $>) }
1384
+ | many(outer_attribute) vis type ident ' ;'
1385
+ { ForeignTy $1 (unspan $2) (unspan $4) ($1 # $2 # $>) }
1368
1386
1369
1387
-- parse_generics
1370
1388
-- Leaves the WhereClause empty
@@ -1599,6 +1617,7 @@ token :: { Spanned Token }
1599
1617
| pub { $1 }
1600
1618
| ref { $1 }
1601
1619
| return { $1 }
1620
+ | yield { $1 }
1602
1621
| Self { $1 }
1603
1622
| self { $1 }
1604
1623
| static { $1 }
@@ -1627,7 +1646,6 @@ token :: { Spanned Token }
1627
1646
| typeof { $1 }
1628
1647
| unsized { $1 }
1629
1648
| virtual { $1 }
1630
- | yield { $1 }
1631
1649
-- Weak keywords, have special meaning only in specific contexts.
1632
1650
| default { $1 }
1633
1651
| union { $1 }
@@ -1804,7 +1822,7 @@ addAttrs as (WhileLet as' p e b l s) = WhileLet (as ++ as') p e b l s
1804
1822
addAttrs as (ForLoop as' p e b l s) = ForLoop (as ++ as' ) p e b l s
1805
1823
addAttrs as (Loop as' b l s) = Loop (as ++ as' ) b l s
1806
1824
addAttrs as (Match as' e a s) = Match (as ++ as' ) e a s
1807
- addAttrs as (Closure as' c f e s) = Closure (as ++ as' ) c f e s
1825
+ addAttrs as (Closure as' m c f e s) = Closure (as ++ as' ) m c f e s
1808
1826
addAttrs as (BlockExpr as' b s) = BlockExpr (as ++ as' ) b s
1809
1827
addAttrs as (Catch as' b s) = Catch (as ++ as' ) b s
1810
1828
addAttrs as (Assign as' e1 e2 s) = Assign (as ++ as' ) e1 e2 s
@@ -1823,6 +1841,7 @@ addAttrs as (Struct as' p f e a) = Struct (as ++ as') p f e a
1823
1841
addAttrs as (Repeat as' e1 e2 s) = Repeat (as ++ as' ) e1 e2 s
1824
1842
addAttrs as (ParenExpr as' e s) = ParenExpr (as ++ as' ) e s
1825
1843
addAttrs as (Try as' e s) = Try (as ++ as' ) e s
1844
+ addAttrs as (Yield as' e s) = Yield (as ++ as' ) e s
1826
1845
1827
1846
1828
1847
-- | Given a ' LitTok' token that is expected to result in a valid literal, construct the associated
0 commit comments