Skip to content

Commit ae7befe

Browse files
committed
Add support for async closures
Also re-jiggered the arguments of the `Closure` constructor to match that of the Rust AST.
1 parent a178a62 commit ae7befe

File tree

7 files changed

+87
-46
lines changed

7 files changed

+87
-46
lines changed

src/Language/Rust/Parser/Internal.y

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -958,14 +958,22 @@ gen_expression(lhs,rhs,rhs2) :: { Expr Span }
958958
| break label { Break [] (Just $2) Nothing ($1 # $2) }
959959
| break label rhs %prec break { Break [] (Just $2) (Just $3) ($1 # $3) }
960960
-- lambda expressions
961-
| static move lambda_args rhs %prec LAMBDA
962-
{ Closure [] Immovable Value (FnDecl (unspan $3) Nothing False (spanOf $3)) $> ($1 # $>) }
963-
| move lambda_args rhs %prec LAMBDA
964-
{ Closure [] Movable Value (FnDecl (unspan $2) Nothing False (spanOf $2)) $> ($1 # $>) }
965-
| static lambda_args rhs %prec LAMBDA
966-
{ Closure [] Immovable Ref (FnDecl (unspan $2) Nothing False (spanOf $2)) $> ($1 # $>) }
967-
| lambda_args rhs %prec LAMBDA
968-
{ Closure [] Movable Ref (FnDecl (unspan $1) Nothing False (spanOf $1)) $> ($1 # $>) }
961+
| static async move lambda_args rhs %prec LAMBDA
962+
{ Closure [] Value IsAsync Immovable (FnDecl (unspan $4) Nothing False (spanOf $4)) $> ($1 # $>) }
963+
| async move lambda_args rhs %prec LAMBDA
964+
{ Closure [] Value IsAsync Movable (FnDecl (unspan $3) Nothing False (spanOf $3)) $> ($1 # $>) }
965+
| static move lambda_args rhs %prec LAMBDA
966+
{ Closure [] Value NotAsync Immovable (FnDecl (unspan $3) Nothing False (spanOf $3)) $> ($1 # $>) }
967+
| move lambda_args rhs %prec LAMBDA
968+
{ Closure [] Value NotAsync Movable (FnDecl (unspan $2) Nothing False (spanOf $2)) $> ($1 # $>) }
969+
| static async lambda_args rhs %prec LAMBDA
970+
{ Closure [] Ref IsAsync Immovable (FnDecl (unspan $3) Nothing False (spanOf $3)) $> ($1 # $>) }
971+
| async lambda_args rhs %prec LAMBDA
972+
{ Closure [] Ref IsAsync Movable (FnDecl (unspan $2) Nothing False (spanOf $2)) $> ($1 # $>) }
973+
| static lambda_args rhs %prec LAMBDA
974+
{ Closure [] Ref NotAsync Immovable (FnDecl (unspan $2) Nothing False (spanOf $2)) $> ($1 # $>) }
975+
| lambda_args rhs %prec LAMBDA
976+
{ Closure [] Ref NotAsync Movable (FnDecl (unspan $1) Nothing False (spanOf $1)) $> ($1 # $>) }
969977

970978
-- Variant of 'gen_expression' which only constructs expressions starting with another expression.
971979
left_gen_expression(lhs,rhs,rhs2) :: { Expr Span }
@@ -1213,14 +1221,22 @@ paren_expr :: { Expr Span }
12131221

12141222
-- Closure ending in blocks
12151223
lambda_expr_block :: { Expr Span }
1216-
: static move lambda_args '->' ty_no_plus block
1217-
{ Closure [] Immovable Value (FnDecl (unspan $3) (Just $5) False (spanOf $3)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1218-
| move lambda_args '->' ty_no_plus block
1219-
{ Closure [] Movable Value (FnDecl (unspan $2) (Just $4) False (spanOf $2)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1220-
| static lambda_args '->' ty_no_plus block
1221-
{ Closure [] Immovable Ref (FnDecl (unspan $2) (Just $4) False (spanOf $2)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1222-
| lambda_args '->' ty_no_plus block
1223-
{ Closure [] Movable Ref (FnDecl (unspan $1) (Just $3) False (spanOf $1)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1224+
: static async move lambda_args '->' ty_no_plus block
1225+
{ Closure [] Value IsAsync Immovable (FnDecl (unspan $4) (Just $6) False (spanOf $4)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1226+
| async move lambda_args '->' ty_no_plus block
1227+
{ Closure [] Value IsAsync Movable (FnDecl (unspan $3) (Just $5) False (spanOf $3)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1228+
| static move lambda_args '->' ty_no_plus block
1229+
{ Closure [] Value NotAsync Immovable (FnDecl (unspan $3) (Just $5) False (spanOf $3)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1230+
| move lambda_args '->' ty_no_plus block
1231+
{ Closure [] Value NotAsync Movable (FnDecl (unspan $2) (Just $4) False (spanOf $2)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1232+
| static async lambda_args '->' ty_no_plus block
1233+
{ Closure [] Ref IsAsync Immovable (FnDecl (unspan $3) (Just $5) False (spanOf $3)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1234+
| async lambda_args '->' ty_no_plus block
1235+
{ Closure [] Ref IsAsync Movable (FnDecl (unspan $2) (Just $4) False (spanOf $2)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1236+
| static lambda_args '->' ty_no_plus block
1237+
{ Closure [] Ref NotAsync Immovable (FnDecl (unspan $2) (Just $4) False (spanOf $2)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
1238+
| lambda_args '->' ty_no_plus block
1239+
{ Closure [] Ref NotAsync Movable (FnDecl (unspan $1) (Just $3) False (spanOf $1)) (BlockExpr [] $> (spanOf $>)) ($1 # $>) }
12241240

12251241
-- Lambda expression arguments block
12261242
lambda_args :: { Spanned [Arg Span] }
@@ -1879,7 +1895,7 @@ addAttrs as (WhileLet as' p e b l s) = WhileLet (as ++ as') p e b l s
18791895
addAttrs as (ForLoop as' p e b l s) = ForLoop (as ++ as') p e b l s
18801896
addAttrs as (Loop as' b l s) = Loop (as ++ as') b l s
18811897
addAttrs as (Match as' e a s) = Match (as ++ as') e a s
1882-
addAttrs as (Closure as' m c f e s) = Closure (as ++ as') m c f e s
1898+
addAttrs as (Closure as' c a m f e s) = Closure (as ++ as') c a m f e s
18831899
addAttrs as (BlockExpr as' b s) = BlockExpr (as ++ as') b s
18841900
addAttrs as (TryBlock as' b s) = TryBlock (as ++ as') b s
18851901
addAttrs as (Async as' c b s) = Async (as ++ as') c b s

src/Language/Rust/Pretty/Internal.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,9 @@ printExprOuterAttrStyle expr isInline = glue (printEitherAttrs (expressionAttrs
381381
ForLoop as pat e blk lbl x -> annotate x (hsep [ printLbl lbl, "for", printPat pat, "in", printExpr e, printBlockWithAttrs True blk as ])
382382
Loop as blk lbl x -> annotate x (hsep [ printLbl lbl, "loop", printBlockWithAttrs True blk as ])
383383
Match as e arms x -> annotate x (hsep [ "match", printExpr e, block Brace False "," (printInnerAttrs as) (printArm `map` arms) ])
384-
Closure _ s cap decl body x -> annotate x (hsep [ when (s == Immovable) "static"
385-
, when (cap == Value) "move"
384+
Closure _ c a s decl body x -> annotate x (hsep [ when (s == Immovable) "static"
385+
, when (a == IsAsync) "async"
386+
, when (c == Value) "move"
386387
, printFnBlockArgs decl <+> printExpr body])
387388
BlockExpr attrs blk x -> annotate x (printBlockWithAttrs True blk attrs)
388389
TryBlock attrs blk x -> annotate x ("try" <+> printBlockWithAttrs True blk attrs)
@@ -470,7 +471,7 @@ expressionAttrs (WhileLet as _ _ _ _ _) = as
470471
expressionAttrs (ForLoop as _ _ _ _ _) = as
471472
expressionAttrs (Loop as _ _ _) = as
472473
expressionAttrs (Match as _ _ _) = as
473-
expressionAttrs (Closure as _ _ _ _ _) = as
474+
expressionAttrs (Closure as _ _ _ _ _ _) = as
474475
expressionAttrs (BlockExpr as _ _) = as
475476
expressionAttrs (TryBlock as _ _) = as
476477
expressionAttrs (Async as _ _ _) = as

src/Language/Rust/Pretty/Resolve.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,15 @@ resolveExprP p _ c@(Continue as ml x) = scope c $ parenE (p > 0) $ do
769769
ml' <- traverse resolveLbl ml
770770
pure (Continue as' ml' x)
771771
-- Closures
772-
resolveExprP _ _ c@(Closure _ _ _ (FnDecl _ _ True _) _ _) = scope c (err c "closures can never be variadic")
773-
resolveExprP p c e@(Closure as m cb fn@(FnDecl _ ret _ _) b x) = scope c $
772+
resolveExprP _ _ c@(Closure _ _ _ _ (FnDecl _ _ True _) _ _) = scope c (err c "closures can never be variadic")
773+
resolveExprP p c e@(Closure as cb a m fn@(FnDecl _ ret _ _) b x) = scope c $
774774
case (c, ret, b) of
775775
(NoStructExpr, Just _, BlockExpr{}) -> parenthesize e
776776
(NoStructBlockExpr, Just _, BlockExpr{}) -> parenthesize e
777-
(NoStructExpr, Just _, _ ) -> parenthesize (Closure as m cb fn (asBlock b) x)
778-
(NoStructBlockExpr, Just _, _ ) -> parenthesize (Closure as m cb fn (asBlock b) x)
777+
(NoStructExpr, Just _, _ ) -> parenthesize (Closure as cb a m fn (asBlock b) x)
778+
(NoStructBlockExpr, Just _, _ ) -> parenthesize (Closure as cb a m fn (asBlock b) x)
779779
(_, Just _, BlockExpr{}) -> resolved AnyExpr
780-
(_, Just _, _ ) -> parenthesize (Closure as m cb fn (asBlock b) x)
780+
(_, Just _, _ ) -> parenthesize (Closure as cb a m fn (asBlock b) x)
781781
_ -> resolved (rhs c)
782782
where
783783
asBlock ex = BlockExpr [] (Block [NoSemi ex mempty] Normal mempty) mempty
@@ -786,7 +786,7 @@ resolveExprP p c e@(Closure as m cb fn@(FnDecl _ ret _ _) b x) = scope c $
786786
as' <- traverse (resolveAttr OuterAttr) as
787787
fn' <- resolveFnDecl NoSelf NamedArg fn
788788
b' <- resolveExprP 0 c' b
789-
pure (Closure as' m cb fn' b' x)
789+
pure (Closure as' cb a m fn' b' x)
790790
-- Assignment/in-place expressions
791791
resolveExprP p c a@(Assign as l r x) = scope a $ parenE (p > 1) $ do
792792
as' <- traverse (resolveAttr OuterAttr) as

src/Language/Rust/Syntax/AST.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module Language.Rust.Syntax.AST (
4444
Expr(..),
4545
Abi(..),
4646
Arm(..),
47+
IsAsync(..),
4748
UnOp(..),
4849
BinOp(..),
4950
Label(..),
@@ -327,7 +328,7 @@ data Expr a
327328
-- | match block
328329
| Match [Attribute a] (Expr a) [Arm a] a
329330
-- | closure (example: @move |a, b, c| { a + b + c }@)
330-
| Closure [Attribute a] Movability CaptureBy (FnDecl a) (Expr a) a
331+
| Closure [Attribute a] CaptureBy IsAsync Movability (FnDecl a) (Expr a) a
331332
-- | (possibly unsafe) block (example: @unsafe { 1 }@)
332333
| BlockExpr [Attribute a] (Block a) a
333334
-- | a try block (example: @try { 1 }@)
@@ -389,7 +390,7 @@ instance Located a => Located (Expr a) where
389390
spanOf (ForLoop _ _ _ _ _ s) = spanOf s
390391
spanOf (Loop _ _ _ s) = spanOf s
391392
spanOf (Match _ _ _ s) = spanOf s
392-
spanOf (Closure _ _ _ _ _ s) = spanOf s
393+
spanOf (Closure _ _ _ _ _ _ s) = spanOf s
393394
spanOf (BlockExpr _ _ s) = spanOf s
394395
spanOf (TryBlock _ _ s) = spanOf s
395396
spanOf (Async _ _ _ s) = spanOf s
@@ -543,7 +544,14 @@ instance Located a => Located (ImplItem a) where
543544
-- traits](https://github.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md)
544545
--
545546
-- Example: @!@ as in @impl !Trait for Foo { }@
546-
data ImplPolarity = Positive | Negative deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData)
547+
data ImplPolarity = Positive | Negative
548+
deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData)
549+
550+
-- | Distinguishes async from not async elements, eg. closures.
551+
--
552+
-- Example: @async@ in @async |x: i32| { ... }@
553+
data IsAsync = IsAsync | NotAsync
554+
deriving (Eq, Ord, Enum, Bounded, Show, Typeable, Data, Generic, NFData)
547555

548556
-- | A top-level item, possibly in a 'Mod' or a 'ItemStmt' (@syntax::ast::Item@ with
549557
-- @syntax::ast::ItemKind@ inlined).

test/rustc-tests/Diff.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ instance Show a => Diffable (Expr a) where
856856
l === (n ! "fields" ! 0)
857857
h === (n ! "fields" ! 1)
858858
rl === (n ! "fields" ! 2)
859-
("Closure", Closure as m c decl e _) -> do
859+
("Closure", Closure as c a m decl e _) -> do
860+
error "TODO async closure"
860861
NullList as === (val ! "attrs" ! "_field0")
861862
m === (n ! "fields" ! 1)
862863
c === (n ! "fields" ! 0)

test/unit-tests/ParserTest.hs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,18 +498,21 @@ parserExpressions = testGroup "parsing expressions"
498498
, testP "()" (TupExpr [] [] ())
499499
, testP "(1,)" (TupExpr [] [Lit [] (Int Dec 1 Unsuffixed ()) ()] ())
500500
, testP "(1,2)" (TupExpr [] [Lit [] (Int Dec 1 Unsuffixed ()) (), Lit [] (Int Dec 2 Unsuffixed ()) ()] ())
501-
, testP "|| 1" (Closure [] Movable Ref (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
502-
, testP "|_: ()| 1" (Closure [] Movable Ref (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
503-
, testP "|_| 1" (Closure [] Movable Ref (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
504-
, testP "static |_| 1" (Closure [] Immovable Ref (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
505-
, testP "|_: ()| -> () { (); }" (Closure [] Movable Ref (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [Semi (TupExpr [] [] ()) ()] Normal ()) ()) ())
506-
, testP "move || 1" (Closure [] Movable Value (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
507-
, testP "static move || 1" (Closure [] Immovable Value (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
508-
, testP "move |_: ()| 1" (Closure [] Movable Value (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
509-
, testP "move |_| 1" (Closure [] Movable Value (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
510-
, testP "move |_: ()| -> () { (); }" (Closure [] Movable Value (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [Semi (TupExpr [] [] ()) ()] Normal ()) ()) ())
511-
, testP "|_: ()| -> () { () }" (Closure [] Movable Ref (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [NoSemi (TupExpr [] [] ()) ()] Normal ()) ()) ())
512-
, testP "move |_: ()| -> () { () }" (Closure [] Movable Value (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [NoSemi (TupExpr [] [] ()) ()] Normal ()) ()) ())
501+
, testP "|| 1" (Closure [] Ref NotAsync Movable (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
502+
, testP "async || 1" (Closure [] Ref IsAsync Movable (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
503+
, testP "|_: ()| 1" (Closure [] Ref NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
504+
, testP "|_| 1" (Closure [] Ref NotAsync Movable (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
505+
, testP "static |_| 1" (Closure [] Ref NotAsync Immovable (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
506+
, testP "static async |_| 1" (Closure [] Ref IsAsync Immovable (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
507+
, testP "|_: ()| -> () { (); }" (Closure [] Ref NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [Semi (TupExpr [] [] ()) ()] Normal ()) ()) ())
508+
, testP "move || 1" (Closure [] Value NotAsync Movable (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
509+
, testP "static move || 1" (Closure [] Value NotAsync Immovable (FnDecl [] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
510+
, testP "move |_: ()| 1" (Closure [] Value NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
511+
, testP "move |_| 1" (Closure [] Value NotAsync Movable (FnDecl [Arg (Just (WildP ())) (Infer ()) ()] Nothing False ()) (Lit [] (Int Dec 1 Unsuffixed ()) ()) ())
512+
, testP "move |_: ()| -> () { (); }" (Closure [] Value NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [Semi (TupExpr [] [] ()) ()] Normal ()) ()) ())
513+
, testP "|_: ()| -> () { () }" (Closure [] Ref NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [NoSemi (TupExpr [] [] ()) ()] Normal ()) ()) ())
514+
, testP "move |_: ()| -> () { () }" (Closure [] Value NotAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [NoSemi (TupExpr [] [] ()) ()] Normal ()) ()) ())
515+
, testP "async move |_: ()| -> () { () }" (Closure [] Value IsAsync Movable (FnDecl [Arg (Just (WildP ())) (TupTy [] ()) ()] (Just (TupTy [] ())) False ()) (BlockExpr [] (Block [NoSemi (TupExpr [] [] ()) ()] Normal ()) ()) ())
513516
, testP "[(); 512]" (Repeat [] (TupExpr [] [] ()) (Lit [] (Int Dec 512 Unsuffixed ()) ()) ())
514517
, testP "[]" (Vec [] [] ())
515518
, testP "[1]" (Vec [] [Lit [] (Int Dec 1 Unsuffixed ()) ()] ())

test/unit-tests/PrettyTest.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,28 @@ prettyExpressions = testGroup "printing expressions"
302302
, testFlatten "match foo { _ => { return 1; } }" (printExpr (Match [] foo [Arm [] [WildP ()] Nothing (BlockExpr [] retBlk ()) ()] ()))
303303
, testFlatten "match foo { _ => { return 1; }, _ | _ if foo => 1 }" (printExpr (Match [] foo [Arm [] [WildP ()] Nothing (BlockExpr [] retBlk ()) (), Arm [] [WildP (), WildP ()] (Just foo) _1 ()] ()))
304304
, testFlatten "move |x: i32| { return 1; }"
305-
(printExpr (Closure [] Movable Value (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
305+
(printExpr (Closure [] Value NotAsync Movable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
306306
(BlockExpr [] retBlk ()) ()))
307307
, testFlatten "static move |x: i32| { return 1; }"
308-
(printExpr (Closure [] Immovable Value (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
308+
(printExpr (Closure [] Value NotAsync Immovable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
309309
(BlockExpr [] retBlk ()) ()))
310310
, testFlatten "|x: i32| -> i32 { return 1; }"
311-
(printExpr (Closure [] Movable Ref (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
311+
(printExpr (Closure [] Ref NotAsync Movable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
312312
(BlockExpr [] retBlk ()) ()))
313313
, testFlatten "static |x: i32| -> i32 { return 1; }"
314-
(printExpr (Closure [] Immovable Ref (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
314+
(printExpr (Closure [] Ref NotAsync Immovable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
315+
(BlockExpr [] retBlk ()) ()))
316+
, testFlatten "async move |x: i32| { return 1; }"
317+
(printExpr (Closure [] Value IsAsync Movable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
318+
(BlockExpr [] retBlk ()) ()))
319+
, testFlatten "static async move |x: i32| { return 1; }"
320+
(printExpr (Closure [] Value IsAsync Immovable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] Nothing False ())
321+
(BlockExpr [] retBlk ()) ()))
322+
, testFlatten "async |x: i32| -> i32 { return 1; }"
323+
(printExpr (Closure [] Ref IsAsync Movable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
324+
(BlockExpr [] retBlk ()) ()))
325+
, testFlatten "static async |x: i32| -> i32 { return 1; }"
326+
(printExpr (Closure [] Ref IsAsync Immovable (FnDecl [Arg (Just (IdentP (ByValue Immutable) (mkIdent "x") Nothing ())) i32 ()] (Just i32) False ())
315327
(BlockExpr [] retBlk ()) ()))
316328
, testFlatten "#[cfgo] { #![cfgi] return 1; }" (printExpr (BlockExpr [cfgI,cfgO] retBlk ()))
317329
, testFlatten "{ return 1; }" (printExpr (BlockExpr [] retBlk ()))

0 commit comments

Comments
 (0)