authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2020-03-10 20:02:22+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-10 15:27:11-04:00
log1ad831a0ef22f354d4e1dd5073456a0683249846
treeaade0aaeb2654992a24b92d66224cd1bd0065d93
parent90c232bbe8e53c09df14536def54b33d92ddd3c5

fix zig fmt on noasync block


2 files changed, 41 insertions(+), 26 deletions(-)

lib/std/zig/ast.zig+30-26
......@@ -500,68 +500,72 @@ pub const Node = struct {
500500 var n = base;
501501 while (true) {
502502 switch (n.id) {
503 Id.Root,
504 Id.ContainerField,
505 Id.ParamDecl,
506 Id.Block,
507 Id.Payload,
508 Id.PointerPayload,
509 Id.PointerIndexPayload,
510 Id.Switch,
511 Id.SwitchCase,
512 Id.SwitchElse,
513 Id.FieldInitializer,
514 Id.DocComment,
515 Id.TestDecl,
503 .Root,
504 .ContainerField,
505 .ParamDecl,
506 .Block,
507 .Payload,
508 .PointerPayload,
509 .PointerIndexPayload,
510 .Switch,
511 .SwitchCase,
512 .SwitchElse,
513 .FieldInitializer,
514 .DocComment,
515 .TestDecl,
516516 => return false,
517 Id.While => {
517 .While => {
518518 const while_node = @fieldParentPtr(While, "base", n);
519519 if (while_node.@"else") |@"else"| {
520520 n = &@"else".base;
521521 continue;
522522 }
523523
524 return while_node.body.id != Id.Block;
524 return while_node.body.id != .Block;
525525 },
526 Id.For => {
526 .For => {
527527 const for_node = @fieldParentPtr(For, "base", n);
528528 if (for_node.@"else") |@"else"| {
529529 n = &@"else".base;
530530 continue;
531531 }
532532
533 return for_node.body.id != Id.Block;
533 return for_node.body.id != .Block;
534534 },
535 Id.If => {
535 .If => {
536536 const if_node = @fieldParentPtr(If, "base", n);
537537 if (if_node.@"else") |@"else"| {
538538 n = &@"else".base;
539539 continue;
540540 }
541541
542 return if_node.body.id != Id.Block;
542 return if_node.body.id != .Block;
543543 },
544 Id.Else => {
544 .Else => {
545545 const else_node = @fieldParentPtr(Else, "base", n);
546546 n = else_node.body;
547547 continue;
548548 },
549 Id.Defer => {
549 .Defer => {
550550 const defer_node = @fieldParentPtr(Defer, "base", n);
551 return defer_node.expr.id != Id.Block;
551 return defer_node.expr.id != .Block;
552552 },
553 Id.Comptime => {
553 .Comptime => {
554554 const comptime_node = @fieldParentPtr(Comptime, "base", n);
555 return comptime_node.expr.id != Id.Block;
555 return comptime_node.expr.id != .Block;
556556 },
557 Id.Suspend => {
557 .Suspend => {
558558 const suspend_node = @fieldParentPtr(Suspend, "base", n);
559559 if (suspend_node.body) |body| {
560 return body.id != Id.Block;
560 return body.id != .Block;
561561 }
562562
563563 return true;
564564 },
565 .Noasync => {
566 const noasync_node = @fieldParentPtr(Noasync, "base", n);
567 return noasync_node.expr.id != .Block;
568 },
565569 else => return true,
566570 }
567571 }
lib/std/zig/parser_test.zig+11
......@@ -1,3 +1,14 @@
1test "zig fmt: noasync block" {
2 try testCanonical(
3 \\pub fn main() anyerror!void {
4 \\ noasync {
5 \\ var foo: Foo = .{ .bar = 42 };
6 \\ }
7 \\}
8 \\
9 );
10}
11
112test "zig fmt: noasync await" {
213 try testCanonical(
314 \\fn foo() void {