| author | |
| committer | |
| log | 5029e5364caccac07f2296c1f30f2f238f13864d |
| tree | 053498ffe1bdc9c1b2a378cbe2b7607038e52060 |
| parent | 293d6bdc73c5fe01b07ebe3d09c9a78613fed093 |
The intent here is to revert this commit after Zig 0.10.0 is released.4 files changed, 44 insertions(+), 1 deletions(-)
lib/std/zig/Ast.zig+12| ... | ... | @@ -2525,6 +2525,18 @@ pub const full = struct { |
| 2525 | 2525 | then_expr: Node.Index, |
| 2526 | 2526 | else_expr: Node.Index, |
| 2527 | 2527 | }; |
| 2528 | ||
| 2529 | /// TODO: remove this after zig 0.11.0 is tagged. | |
| 2530 | pub fn isOldSyntax(f: For, token_tags: []const Token.Tag) bool { | |
| 2531 | if (f.ast.inputs.len != 1) return false; | |
| 2532 | if (token_tags[f.payload_token + 1] == .comma) return true; | |
| 2533 | if (token_tags[f.payload_token] == .asterisk and | |
| 2534 | token_tags[f.payload_token + 2] == .comma) | |
| 2535 | { | |
| 2536 | return true; | |
| 2537 | } | |
| 2538 | return false; | |
| 2539 | } | |
| 2528 | 2540 | }; |
| 2529 | 2541 | |
| 2530 | 2542 | pub const ContainerField = struct { |
lib/std/zig/Parse.zig+4-1| ... | ... | @@ -2143,7 +2143,10 @@ fn forPrefix(p: *Parse) Error!usize { |
| 2143 | 2143 | _ = p.eatToken(.asterisk); |
| 2144 | 2144 | const identifier = try p.expectToken(.identifier); |
| 2145 | 2145 | captures += 1; |
| 2146 | if (captures > inputs and !warned_excess) { | |
| 2146 | if (!warned_excess and inputs == 1 and captures == 2) { | |
| 2147 | // TODO remove the above condition after 0.11.0 release. this silences | |
| 2148 | // the error so that zig fmt can fix it. | |
| 2149 | } else if (captures > inputs and !warned_excess) { | |
| 2147 | 2150 | try p.warnMsg(.{ .tag = .extra_for_capture, .token = identifier }); |
| 2148 | 2151 | warned_excess = true; |
| 2149 | 2152 | } |
lib/std/zig/render.zig+11| ... | ... | @@ -1211,6 +1211,17 @@ fn renderFor(gpa: Allocator, ais: *Ais, tree: Ast, for_node: Ast.full.For, space |
| 1211 | 1211 | const lparen = for_node.ast.for_token + 1; |
| 1212 | 1212 | try renderParamList(gpa, ais, tree, lparen, for_node.ast.inputs, .space); |
| 1213 | 1213 | |
| 1214 | // TODO remove this after zig 0.11.0 | |
| 1215 | if (for_node.isOldSyntax(token_tags)) { | |
| 1216 | // old: for (a) |b, c| {} | |
| 1217 | // new: for (a, 0..) |b, c| {} | |
| 1218 | const array_list = ais.underlying_writer.context; // abstractions? who needs 'em! | |
| 1219 | if (mem.endsWith(u8, array_list.items, ") ")) { | |
| 1220 | array_list.items.len -= 2; | |
| 1221 | try array_list.appendSlice(", 0..) "); | |
| 1222 | } | |
| 1223 | } | |
| 1224 | ||
| 1214 | 1225 | var cur = for_node.payload_token; |
| 1215 | 1226 | const pipe = std.mem.indexOfScalarPos(std.zig.Token.Tag, token_tags, cur, .pipe).?; |
| 1216 | 1227 | if (token_tags[pipe - 1] == .comma) { |
src/AstGen.zig+17| ... | ... | @@ -6302,6 +6302,23 @@ fn forExpr( |
| 6302 | 6302 | const node_data = tree.nodes.items(.data); |
| 6303 | 6303 | const gpa = astgen.gpa; |
| 6304 | 6304 | |
| 6305 | // TODO this can be deleted after zig 0.11.0 is released because it | |
| 6306 | // will be caught in the parser. | |
| 6307 | if (for_full.isOldSyntax(token_tags)) { | |
| 6308 | return astgen.failTokNotes( | |
| 6309 | for_full.payload_token + 2, | |
| 6310 | "extra capture in for loop", | |
| 6311 | .{}, | |
| 6312 | &[_]u32{ | |
| 6313 | try astgen.errNoteTok( | |
| 6314 | for_full.payload_token + 2, | |
| 6315 | "run 'zig fmt' to upgrade your code automatically", | |
| 6316 | .{}, | |
| 6317 | ), | |
| 6318 | }, | |
| 6319 | ); | |
| 6320 | } | |
| 6321 | ||
| 6305 | 6322 | // For counters, this is the start value; for indexables, this is the base |
| 6306 | 6323 | // pointer that can be used with elem_ptr and similar instructions. |
| 6307 | 6324 | // Special value `none` means that this is a counter and its start value is |