| author | |
| committer | |
| log | 027aabf4977d0362e908d9ef732aaa929605d563 |
| tree | 4ad870f35d24ba01f6b417ba6a273941ca279a95 |
| parent | 69dc1a6bb28dc47a57902d421c538f2f82edea8a |
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 { | ... | @@ -432,7 +432,7 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 432 | return stream.writeAll("use 'var' or 'const' to declare variable"); | 432 | return stream.writeAll("use 'var' or 'const' to declare variable"); |
| 433 | }, | 433 | }, |
| 434 | .extra_for_capture => { | 434 | .extra_for_capture => { |
| 435 | return stream.writeAll("excess for captures"); | 435 | return stream.writeAll("extra capture in for loop"); |
| 436 | }, | 436 | }, |
| 437 | .for_input_not_captured => { | 437 | .for_input_not_captured => { |
| 438 | return stream.writeAll("for input is not captured"); | 438 | return stream.writeAll("for input is not captured"); |
| ... | @@ -2541,18 +2541,6 @@ pub const full = struct { | ... | @@ -2541,18 +2541,6 @@ pub const full = struct { |
| 2541 | then_expr: Node.Index, | 2541 | then_expr: Node.Index, |
| 2542 | else_expr: Node.Index, | 2542 | else_expr: Node.Index, |
| 2543 | }; | 2543 | }; |
| 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 | } | ||
| 2556 | }; | 2544 | }; |
| 2557 | 2545 | ||
| 2558 | pub const ContainerField = struct { | 2546 | pub const ContainerField = struct { |
lib/std/zig/Parse.zig+1-4| ... | @@ -2345,10 +2345,7 @@ fn forPrefix(p: *Parse) Error!usize { | ... | @@ -2345,10 +2345,7 @@ fn forPrefix(p: *Parse) Error!usize { |
| 2345 | _ = p.eatToken(.asterisk); | 2345 | _ = p.eatToken(.asterisk); |
| 2346 | const identifier = try p.expectToken(.identifier); | 2346 | const identifier = try p.expectToken(.identifier); |
| 2347 | captures += 1; | 2347 | captures += 1; |
| 2348 | if (!warned_excess and inputs == 1 and captures == 2) { | 2348 | if (captures > inputs and !warned_excess) { |
| 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) { | ||
| 2352 | try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier }); | 2349 | try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier }); |
| 2353 | warned_excess = true; | 2350 | warned_excess = true; |
| 2354 | } | 2351 | } |
lib/std/zig/parser_test.zig-20| ... | @@ -1,23 +1,3 @@ | ... | @@ -1,23 +1,3 @@ |
| 1 | // TODO: remove this after zig 0.11.0 is released | ||
| 2 | test "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 | |||
| 21 | test "zig fmt: remove extra whitespace at start and end of file with comment between" { | 1 | test "zig fmt: remove extra whitespace at start and end of file with comment between" { |
| 22 | try testTransform( | 2 | try testTransform( |
| 23 | \\ | 3 | \\ |
lib/std/zig/render.zig-11| ... | @@ -1262,17 +1262,6 @@ fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space | ... | @@ -1262,17 +1262,6 @@ fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space |
| 1262 | const lparen = for_node.ast.for_token + 1; | 1262 | const lparen = for_node.ast.for_token + 1; |
| 1263 | try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space); | 1263 | try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space); |
| 1264 | 1264 | ||
| 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 | |||
| 1276 | var cur = for_node.payload_token; | 1265 | var cur = for_node.payload_token; |
| 1277 | const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?; | 1266 | const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?; |
| 1278 | if (token_tags[pipe - 1] == .comma) { | 1267 | if (token_tags[pipe - 1] == .comma) { |
src/AstGen.zig-17| ... | @@ -6456,23 +6456,6 @@ fn forExpr( | ... | @@ -6456,23 +6456,6 @@ fn forExpr( |
| 6456 | const node_data = tree.nodes.items(.data); | 6456 | const node_data = tree.nodes.items(.data); |
| 6457 | const gpa = astgen.gpa; | 6457 | const gpa = astgen.gpa; |
| 6458 | 6458 | ||
| 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 | |||
| 6476 | // For counters, this is the start value; for indexables, this is the base | 6459 | // For counters, this is the start value; for indexables, this is the base |
| 6477 | // pointer that can be used with elem_ptr and similar instructions. | 6460 | // pointer that can be used with elem_ptr and similar instructions. |
| 6478 | // Special value `none` means that this is a counter and its start value is | 6461 | // 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 { | ... | @@ -12,4 +12,3 @@ export fn b() void { |
| 12 | // target=native | 12 | // target=native |
| 13 | // | 13 | // |
| 14 | // :3:21: error: extra capture in for loop | 14 | // :3:21: error: extra capture in for loop |
| 15 | // :3:21: note: run 'zig fmt' to upgrade your code automatically |