From 027aabf4977d0362e908d9ef732aaa929605d563 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 11 Oct 2023 19:26:55 -0700 Subject: [PATCH] drop for loop syntax upgrade mechanisms --- lib/std/zig/Ast.zig | 14 +------------ lib/std/zig/Parse.zig | 5 +---- lib/std/zig/parser_test.zig | 20 ------------------- lib/std/zig/render.zig | 11 ---------- src/AstGen.zig | 17 ---------------- .../compile_errors/for_extra_capture.zig | 1 - 6 files changed, 2 insertions(+), 66 deletions(-) diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig index 85fa4b422c..b95391c119 100644 --- a/lib/std/zig/Ast.zig +++ b/lib/std/zig/Ast.zig @@ -432,7 +432,7 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { return stream.writeAll("use 'var' or 'const' to declare variable"); }, .extra_for_capture => { - return stream.writeAll("excess for captures"); + return stream.writeAll("extra capture in for loop"); }, .for_input_not_captured => { return stream.writeAll("for input is not captured"); @@ -2541,18 +2541,6 @@ pub const full = struct { then_expr: Node.Index, else_expr: Node.Index, }; - - /// TODO: remove this after zig 0.11.0 is tagged. - pub fn isOldSyntax(f: For, token_tags: []const Token.Tag) bool { - if (f.ast.inputs.len != 1) return false; - if (token_tags[f.payload_token + 1] == .comma) return true; - if (token_tags[f.payload_token] == .asterisk and - token_tags[f.payload_token + 2] == .comma) - { - return true; - } - return false; - } }; pub const ContainerField = struct { diff --git a/lib/std/zig/Parse.zig b/lib/std/zig/Parse.zig index b978077404..0187c09108 100644 --- a/lib/std/zig/Parse.zig +++ b/lib/std/zig/Parse.zig @@ -2345,10 +2345,7 @@ fn forPrefix(p: *Parse) Error!usize { _ = p.eatToken(.asterisk); const identifier = try p.expectToken(.identifier); captures += 1; - if (!warned_excess and inputs == 1 and captures == 2) { - // TODO remove the above condition after 0.11.0 release. this silences - // the error so that zig fmt can fix it. - } else if (captures > inputs and !warned_excess) { + if (captures > inputs and !warned_excess) { try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier }); warned_excess = true; } diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 4117bd6d4b..203976ec1a 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1,23 +1,3 @@ -// TODO: remove this after zig 0.11.0 is released -test "zig fmt: transform old for loop syntax to new" { - try testTransform( - \\fn foo() void { - \\ for (a) |b, i| { - \\ _ = b; _ = i; - \\ } - \\} - \\ - , - \\fn foo() void { - \\ for (a, 0..) |b, i| { - \\ _ = b; - \\ _ = i; - \\ } - \\} - \\ - ); -} - test "zig fmt: remove extra whitespace at start and end of file with comment between" { try testTransform( \\ diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index bb4d6a9e8e..6533c21f63 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1262,17 +1262,6 @@ fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space const lparen = for_node.ast.for_token + 1; try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space); - // TODO remove this after zig 0.11.0 - if (for_node.isOldSyntax(token_tags)) { - // old: for (a) |b, c| {} - // new: for (a, 0..) |b, c| {} - const array_list = ais.underlying_writer.context; // abstractions? who needs 'em! - if (mem.endsWith(u8, array_list.items, ") ")) { - array_list.items.len -= 2; - try array_list.appendSlice(", 0..) "); - } - } - var cur = for_node.payload_token; const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?; if (token_tags[pipe - 1] == .comma) { diff --git a/src/AstGen.zig b/src/AstGen.zig index 346177e5ac..de512e5bdb 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -6456,23 +6456,6 @@ fn forExpr( const node_data = tree.nodes.items(.data); const gpa = astgen.gpa; - // TODO this can be deleted after zig 0.11.0 is released because it - // will be caught in the parser. - if (for_full.isOldSyntax(token_tags)) { - return astgen.failTokNotes( - for_full.payload_token + 2, - "extra capture in for loop", - .{}, - &[_]u32{ - try astgen.errNoteTok( - for_full.payload_token + 2, - "run 'zig fmt' to upgrade your code automatically", - .{}, - ), - }, - ); - } - // For counters, this is the start value; for indexables, this is the base // pointer that can be used with elem_ptr and similar instructions. // Special value `none` means that this is a counter and its start value is diff --git a/test/cases/compile_errors/for_extra_capture.zig b/test/cases/compile_errors/for_extra_capture.zig index 0a4ed724ad..a1cdd58a33 100644 --- a/test/cases/compile_errors/for_extra_capture.zig +++ b/test/cases/compile_errors/for_extra_capture.zig @@ -12,4 +12,3 @@ export fn b() void { // target=native // // :3:21: error: extra capture in for loop -// :3:21: note: run 'zig fmt' to upgrade your code automatically