Commit 027aabf497
Changed files (6)
lib
src
test
cases
compile_errors
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 {
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;
}
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(
\\
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) {
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
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