authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-11 19:26:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-13 03:43:54-07:00
log027aabf4977d0362e908d9ef732aaa929605d563
tree4ad870f35d24ba01f6b417ba6a273941ca279a95
parent69dc1a6bb28dc47a57902d421c538f2f82edea8a

drop for loop syntax upgrade mechanisms


6 files changed, 2 insertions(+), 66 deletions(-)

lib/std/zig/Ast.zig+1-13
......@@ -432,7 +432,7 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void {
432432 return stream.writeAll("use 'var' or 'const' to declare variable");
433433 },
434434 .extra_for_capture => {
435 return stream.writeAll("excess for captures");
435 return stream.writeAll("extra capture in for loop");
436436 },
437437 .for_input_not_captured => {
438438 return stream.writeAll("for input is not captured");
......@@ -2541,18 +2541,6 @@ pub const full = struct {
25412541 then_expr: Node.Index,
25422542 else_expr: Node.Index,
25432543 };
2544
2545 /// TODO: remove this after zig 0.11.0 is tagged.
2546 pub fn isOldSyntax(f: For, token_tags: []const Token.Tag) bool {
2547 if (f.ast.inputs.len != 1) return false;
2548 if (token_tags[f.payload_token + 1] == .comma) return true;
2549 if (token_tags[f.payload_token] == .asterisk and
2550 token_tags[f.payload_token + 2] == .comma)
2551 {
2552 return true;
2553 }
2554 return false;
2555 }
25562544 };
25572545
25582546 pub const ContainerField = struct {
lib/std/zig/Parse.zig+1-4
......@@ -2345,10 +2345,7 @@ fn forPrefix(p: *Parse) Error!usize {
23452345 _ = p.eatToken(.asterisk);
23462346 const identifier = try p.expectToken(.identifier);
23472347 captures += 1;
2348 if (!warned_excess and inputs == 1 and captures == 2) {
2349 // TODO remove the above condition after 0.11.0 release. this silences
2350 // the error so that zig fmt can fix it.
2351 } else if (captures > inputs and !warned_excess) {
2348 if (captures > inputs and !warned_excess) {
23522349 try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier });
23532350 warned_excess = true;
23542351 }
lib/std/zig/parser_test.zig-20
......@@ -1,23 +1,3 @@
1// TODO: remove this after zig 0.11.0 is released
2test "zig fmt: transform old for loop syntax to new" {
3 try testTransform(
4 \\fn foo() void {
5 \\ for (a) |b, i| {
6 \\ _ = b; _ = i;
7 \\ }
8 \\}
9 \\
10 ,
11 \\fn foo() void {
12 \\ for (a, 0..) |b, i| {
13 \\ _ = b;
14 \\ _ = i;
15 \\ }
16 \\}
17 \\
18 );
19}
20
211test "zig fmt: remove extra whitespace at start and end of file with comment between" {
222 try testTransform(
233 \\
lib/std/zig/render.zig-11
......@@ -1262,17 +1262,6 @@ fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space
12621262 const lparen = for_node.ast.for_token + 1;
12631263 try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space);
12641264
1265 // TODO remove this after zig 0.11.0
1266 if (for_node.isOldSyntax(token_tags)) {
1267 // old: for (a) |b, c| {}
1268 // new: for (a, 0..) |b, c| {}
1269 const array_list = ais.underlying_writer.context; // abstractions? who needs 'em!
1270 if (mem.endsWith(u8, array_list.items, ") ")) {
1271 array_list.items.len -= 2;
1272 try array_list.appendSlice(", 0..) ");
1273 }
1274 }
1275
12761265 var cur = for_node.payload_token;
12771266 const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?;
12781267 if (token_tags[pipe - 1] == .comma) {
src/AstGen.zig-17
......@@ -6456,23 +6456,6 @@ fn forExpr(
64566456 const node_data = tree.nodes.items(.data);
64576457 const gpa = astgen.gpa;
64586458
6459 // TODO this can be deleted after zig 0.11.0 is released because it
6460 // will be caught in the parser.
6461 if (for_full.isOldSyntax(token_tags)) {
6462 return astgen.failTokNotes(
6463 for_full.payload_token + 2,
6464 "extra capture in for loop",
6465 .{},
6466 &[_]u32{
6467 try astgen.errNoteTok(
6468 for_full.payload_token + 2,
6469 "run 'zig fmt' to upgrade your code automatically",
6470 .{},
6471 ),
6472 },
6473 );
6474 }
6475
64766459 // For counters, this is the start value; for indexables, this is the base
64776460 // pointer that can be used with elem_ptr and similar instructions.
64786461 // Special value `none` means that this is a counter and its start value is
test/cases/compile_errors/for_extra_capture.zig-1
......@@ -12,4 +12,3 @@ export fn b() void {
1212// target=native
1313//
1414// :3:21: error: extra capture in for loop
15// :3:21: note: run 'zig fmt' to upgrade your code automatically