authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-17 20:23:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-18 19:17:21-07:00
logf0530385b57218ef323747bdb7438330a07d25cc
tree07d87e78355e518aa67ea48e3cdf1a242917a5d7
parent321ccbdc525ab0f5862e42378b962c10ec54e4a1

update existing behavior tests and std lib to new for loop semantics


19 files changed, 46 insertions(+), 46 deletions(-)

lib/std/crypto/blake3.zig+1-1
...@@ -211,7 +211,7 @@ fn first8Words(words: [16]u32) [8]u32 {...@@ -211,7 +211,7 @@ fn first8Words(words: [16]u32) [8]u32 {
211211
212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {212fn wordsFromLittleEndianBytes(comptime count: usize, bytes: [count * 4]u8) [count]u32 {
213 var words: [count]u32 = undefined;213 var words: [count]u32 = undefined;
214 for (words) |*word, i| {214 for (&words) |*word, i| {
215 word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]);215 word.* = mem.readIntSliceLittle(u32, bytes[4 * i ..]);
216 }216 }
217 return words;217 return words;
test/behavior/array.zig+1-1
...@@ -185,7 +185,7 @@ test "nested arrays of strings" {...@@ -185,7 +185,7 @@ test "nested arrays of strings" {
185 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO185 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
186186
187 const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" };187 const array_of_strings = [_][]const u8{ "hello", "this", "is", "my", "thing" };
188 for (array_of_strings) |s, i| {188 for (array_of_strings, 0..) |s, i| {
189 if (i == 0) try expect(mem.eql(u8, s, "hello"));189 if (i == 0) try expect(mem.eql(u8, s, "hello"));
190 if (i == 1) try expect(mem.eql(u8, s, "this"));190 if (i == 1) try expect(mem.eql(u8, s, "this"));
191 if (i == 2) try expect(mem.eql(u8, s, "is"));191 if (i == 2) try expect(mem.eql(u8, s, "is"));
test/behavior/bit_shifting.zig+2-2
...@@ -84,14 +84,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c...@@ -84,14 +84,14 @@ fn testShardedTable(comptime Key: type, comptime mask_bit_count: comptime_int, c
8484
85 var table = Table.create();85 var table = Table.create();
86 var node_buffer: [node_count]Table.Node = undefined;86 var node_buffer: [node_count]Table.Node = undefined;
87 for (node_buffer) |*node, i| {87 for (&node_buffer, 0..) |*node, i| {
88 const key = @intCast(Key, i);88 const key = @intCast(Key, i);
89 try expect(table.get(key) == null);89 try expect(table.get(key) == null);
90 node.init(key, {});90 node.init(key, {});
91 table.put(node);91 table.put(node);
92 }92 }
9393
94 for (node_buffer) |*node, i| {94 for (&node_buffer, 0..) |*node, i| {
95 try expect(table.get(@intCast(Key, i)) == node);95 try expect(table.get(@intCast(Key, i)) == node);
96 }96 }
97}97}
test/behavior/bugs/1607.zig+1-1
...@@ -5,7 +5,7 @@ const builtin = @import("builtin");...@@ -5,7 +5,7 @@ const builtin = @import("builtin");
5const a = [_]u8{ 1, 2, 3 };5const a = [_]u8{ 1, 2, 3 };
66
7fn checkAddress(s: []const u8) !void {7fn checkAddress(s: []const u8) !void {
8 for (s) |*i, j| {8 for (s, 0..) |*i, j| {
9 try testing.expect(i == &a[j]);9 try testing.expect(i == &a[j]);
10 }10 }
11}11}
test/behavior/bugs/920.zig+3-3
...@@ -23,13 +23,13 @@ fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, co...@@ -23,13 +23,13 @@ fn ZigTableGen(comptime is_symmetric: bool, comptime r: f64, comptime v: f64, co
23 tables.x[0] = v / f(r);23 tables.x[0] = v / f(r);
24 tables.x[1] = r;24 tables.x[1] = r;
2525
26 for (tables.x[2..256]) |*entry, i| {26 for (tables.x[2..256], 0..) |*entry, i| {
27 const last = tables.x[2 + i - 1];27 const last = tables.x[2 + i - 1];
28 entry.* = f_inv(v / last + f(last));28 entry.* = f_inv(v / last + f(last));
29 }29 }
30 tables.x[256] = 0;30 tables.x[256] = 0;
3131
32 for (tables.f[0..]) |*entry, i| {32 for (tables.f[0..], 0..) |*entry, i| {
33 entry.* = f(tables.x[i]);33 entry.* = f(tables.x[i]);
34 }34 }
3535
...@@ -67,7 +67,7 @@ test "bug 920 fixed" {...@@ -67,7 +67,7 @@ test "bug 920 fixed" {
67 break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case);67 break :blk ZigTableGen(true, norm_r, norm_v, norm_f, norm_f_inv, norm_zero_case);
68 };68 };
6969
70 for (NormalDist1.f) |_, i| {70 for (NormalDist1.f, 0..) |_, i| {
71 // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small71 // Here we use `expectApproxEqAbs` instead of `expectEqual` to account for the small
72 // differences in math functions of different libcs. For example, if the compiler72 // differences in math functions of different libcs. For example, if the compiler
73 // links against glibc, but the target is musl libc, then these values might be73 // links against glibc, but the target is musl libc, then these values might be
test/behavior/call.zig+1-1
...@@ -364,7 +364,7 @@ test "Enum constructed by @Type passed as generic argument" {...@@ -364,7 +364,7 @@ test "Enum constructed by @Type passed as generic argument" {
364 try expect(@enumToInt(a) == b);364 try expect(@enumToInt(a) == b);
365 }365 }
366 };366 };
367 inline for (@typeInfo(S.E).Enum.fields) |_, i| {367 inline for (@typeInfo(S.E).Enum.fields, 0..) |_, i| {
368 try S.foo(@intToEnum(S.E, i), i);368 try S.foo(@intToEnum(S.E, i), i);
369 }369 }
370}370}
test/behavior/const_slice_child.zig+2-2
...@@ -26,7 +26,7 @@ fn foo(args: [][]const u8) !void {...@@ -26,7 +26,7 @@ fn foo(args: [][]const u8) !void {
26fn bar(argc: usize) !void {26fn bar(argc: usize) !void {
27 var args_buffer: [10][]const u8 = undefined;27 var args_buffer: [10][]const u8 = undefined;
28 const args = args_buffer[0..argc];28 const args = args_buffer[0..argc];
29 for (args) |_, i| {29 for (args, 0..) |_, i| {
30 const ptr = argv[i];30 const ptr = argv[i];
31 args[i] = ptr[0..strlen(ptr)];31 args[i] = ptr[0..strlen(ptr)];
32 }32 }
...@@ -41,7 +41,7 @@ fn strlen(ptr: [*]const u8) usize {...@@ -41,7 +41,7 @@ fn strlen(ptr: [*]const u8) usize {
4141
42fn streql(a: []const u8, b: []const u8) bool {42fn streql(a: []const u8, b: []const u8) bool {
43 if (a.len != b.len) return false;43 if (a.len != b.len) return false;
44 for (a) |item, index| {44 for (a, 0..) |item, index| {
45 if (b[index] != item) return false;45 if (b[index] != item) return false;
46 }46 }
47 return true;47 return true;
test/behavior/eval.zig+3-3
...@@ -317,7 +317,7 @@ test "create global array with for loop" {...@@ -317,7 +317,7 @@ test "create global array with for loop" {
317317
318const global_array = x: {318const global_array = x: {
319 var result: [10]usize = undefined;319 var result: [10]usize = undefined;
320 for (result) |*item, index| {320 for (&result, 0..) |*item, index| {
321 item.* = index * index;321 item.* = index * index;
322 }322 }
323 break :x result;323 break :x result;
...@@ -447,7 +447,7 @@ test "binary math operator in partially inlined function" {...@@ -447,7 +447,7 @@ test "binary math operator in partially inlined function" {
447 var s: [4]u32 = undefined;447 var s: [4]u32 = undefined;
448 var b: [16]u8 = undefined;448 var b: [16]u8 = undefined;
449449
450 for (b) |*r, i|450 for (&b, 0..) |*r, i|
451 r.* = @intCast(u8, i + 1);451 r.* = @intCast(u8, i + 1);
452452
453 copyWithPartialInline(s[0..], b[0..]);453 copyWithPartialInline(s[0..], b[0..]);
...@@ -915,7 +915,7 @@ test "comptime pointer load through elem_ptr" {...@@ -915,7 +915,7 @@ test "comptime pointer load through elem_ptr" {
915915
916 comptime {916 comptime {
917 var array: [10]S = undefined;917 var array: [10]S = undefined;
918 for (array) |*elem, i| {918 for (&array, 0..) |*elem, i| {
919 elem.* = .{919 elem.* = .{
920 .x = i,920 .x = i,
921 };921 };
test/behavior/fn.zig+1-1
...@@ -311,7 +311,7 @@ test "function pointers" {...@@ -311,7 +311,7 @@ test "function pointers" {
311 &fn3,311 &fn3,
312 &fn4,312 &fn4,
313 };313 };
314 for (fns) |f, i| {314 for (fns, 0..) |f, i| {
315 try expect(f() == @intCast(u32, i) + 5);315 try expect(f() == @intCast(u32, i) + 5);
316 }316 }
317}317}
test/behavior/for.zig+10-10
...@@ -55,9 +55,9 @@ fn testContinueOuter() !void {...@@ -55,9 +55,9 @@ fn testContinueOuter() !void {
55}55}
5656
57test "ignore lval with underscore (for loop)" {57test "ignore lval with underscore (for loop)" {
58 for ([_]void{}) |_, i| {58 for ([_]void{}, 0..) |_, i| {
59 _ = i;59 _ = i;
60 for ([_]void{}) |_, j| {60 for ([_]void{}, 0..) |_, j| {
61 _ = j;61 _ = j;
62 break;62 break;
63 }63 }
...@@ -81,7 +81,7 @@ test "basic for loop" {...@@ -81,7 +81,7 @@ test "basic for loop" {
81 buffer[buf_index] = item;81 buffer[buf_index] = item;
82 buf_index += 1;82 buf_index += 1;
83 }83 }
84 for (array) |item, index| {84 for (array, 0..) |item, index| {
85 _ = item;85 _ = item;
86 buffer[buf_index] = @intCast(u8, index);86 buffer[buf_index] = @intCast(u8, index);
87 buf_index += 1;87 buf_index += 1;
...@@ -91,7 +91,7 @@ test "basic for loop" {...@@ -91,7 +91,7 @@ test "basic for loop" {
91 buffer[buf_index] = item;91 buffer[buf_index] = item;
92 buf_index += 1;92 buf_index += 1;
93 }93 }
94 for (array_ptr) |item, index| {94 for (array_ptr, 0..) |item, index| {
95 _ = item;95 _ = item;
96 buffer[buf_index] = @intCast(u8, index);96 buffer[buf_index] = @intCast(u8, index);
97 buf_index += 1;97 buf_index += 1;
...@@ -101,7 +101,7 @@ test "basic for loop" {...@@ -101,7 +101,7 @@ test "basic for loop" {
101 buffer[buf_index] = item;101 buffer[buf_index] = item;
102 buf_index += 1;102 buf_index += 1;
103 }103 }
104 for (unknown_size) |_, index| {104 for (unknown_size, 0..) |_, index| {
105 buffer[buf_index] = @intCast(u8, index);105 buffer[buf_index] = @intCast(u8, index);
106 buf_index += 1;106 buf_index += 1;
107 }107 }
...@@ -163,11 +163,11 @@ test "for loop with pointer elem var" {...@@ -163,11 +163,11 @@ test "for loop with pointer elem var" {
163 mangleString(target[0..]);163 mangleString(target[0..]);
164 try expect(mem.eql(u8, &target, "bcdefgh"));164 try expect(mem.eql(u8, &target, "bcdefgh"));
165165
166 for (source) |*c, i| {166 for (source, 0..) |*c, i| {
167 _ = i;167 _ = i;
168 try expect(@TypeOf(c) == *const u8);168 try expect(@TypeOf(c) == *const u8);
169 }169 }
170 for (target) |*c, i| {170 for (&target, 0..) |*c, i| {
171 _ = i;171 _ = i;
172 try expect(@TypeOf(c) == *u8);172 try expect(@TypeOf(c) == *u8);
173 }173 }
...@@ -186,7 +186,7 @@ test "for copies its payload" {...@@ -186,7 +186,7 @@ test "for copies its payload" {
186 const S = struct {186 const S = struct {
187 fn doTheTest() !void {187 fn doTheTest() !void {
188 var x = [_]usize{ 1, 2, 3 };188 var x = [_]usize{ 1, 2, 3 };
189 for (x) |value, i| {189 for (x, 0..) |value, i| {
190 // Modify the original array190 // Modify the original array
191 x[i] += 99;191 x[i] += 99;
192 try expect(value == i + 1);192 try expect(value == i + 1);
...@@ -206,8 +206,8 @@ test "for on slice with allowzero ptr" {...@@ -206,8 +206,8 @@ test "for on slice with allowzero ptr" {
206 const S = struct {206 const S = struct {
207 fn doTheTest(slice: []const u8) !void {207 fn doTheTest(slice: []const u8) !void {
208 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];208 var ptr = @ptrCast([*]allowzero const u8, slice.ptr)[0..slice.len];
209 for (ptr) |x, i| try expect(x == i + 1);209 for (ptr, 0..) |x, i| try expect(x == i + 1);
210 for (ptr) |*x, i| try expect(x.* == i + 1);210 for (ptr, 0..) |*x, i| try expect(x.* == i + 1);
211 }211 }
212 };212 };
213 try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });213 try S.doTheTest(&[_]u8{ 1, 2, 3, 4 });
test/behavior/generics.zig+1-1
...@@ -325,7 +325,7 @@ test "generic function instantiation non-duplicates" {...@@ -325,7 +325,7 @@ test "generic function instantiation non-duplicates" {
325 const S = struct {325 const S = struct {
326 fn copy(comptime T: type, dest: []T, source: []const T) void {326 fn copy(comptime T: type, dest: []T, source: []const T) void {
327 @export(foo, .{ .name = "test_generic_instantiation_non_dupe" });327 @export(foo, .{ .name = "test_generic_instantiation_non_dupe" });
328 for (source) |s, i| dest[i] = s;328 for (source, 0..) |s, i| dest[i] = s;
329 }329 }
330330
331 fn foo() callconv(.C) void {}331 fn foo() callconv(.C) void {}
test/behavior/lower_strlit_to_vector.zig+1-1
...@@ -12,7 +12,7 @@ test "strlit to vector" {...@@ -12,7 +12,7 @@ test "strlit to vector" {
12 const strlit = "0123456789abcdef0123456789ABCDEF";12 const strlit = "0123456789abcdef0123456789ABCDEF";
13 const vec_from_strlit: @Vector(32, u8) = strlit.*;13 const vec_from_strlit: @Vector(32, u8) = strlit.*;
14 const arr_from_vec = @as([32]u8, vec_from_strlit);14 const arr_from_vec = @as([32]u8, vec_from_strlit);
15 for (strlit) |c, i|15 for (strlit, 0..) |c, i|
16 try std.testing.expect(c == arr_from_vec[i]);16 try std.testing.expect(c == arr_from_vec[i]);
17 try std.testing.expectEqualSlices(u8, strlit, &arr_from_vec);17 try std.testing.expectEqualSlices(u8, strlit, &arr_from_vec);
18}18}
test/behavior/math.zig+1-1
...@@ -1221,7 +1221,7 @@ test "quad hex float literal parsing accurate" {...@@ -1221,7 +1221,7 @@ test "quad hex float literal parsing accurate" {
1221 0xb6a0000000000000,1221 0xb6a0000000000000,
1222 };1222 };
12231223
1224 for (exp2ft) |x, i| {1224 for (exp2ft, 0..) |x, i| {
1225 try expect(@bitCast(u64, x) == answers[i]);1225 try expect(@bitCast(u64, x) == answers[i]);
1226 }1226 }
1227 }1227 }
test/behavior/slice.zig+2-2
...@@ -99,7 +99,7 @@ test "comptime slice of slice preserves comptime var" {...@@ -99,7 +99,7 @@ test "comptime slice of slice preserves comptime var" {
99test "slice of type" {99test "slice of type" {
100 comptime {100 comptime {
101 var types_array = [_]type{ i32, f64, type };101 var types_array = [_]type{ i32, f64, type };
102 for (types_array) |T, i| {102 for (types_array, 0..) |T, i| {
103 switch (i) {103 switch (i) {
104 0 => try expect(T == i32),104 0 => try expect(T == i32),
105 1 => try expect(T == f64),105 1 => try expect(T == f64),
...@@ -107,7 +107,7 @@ test "slice of type" {...@@ -107,7 +107,7 @@ test "slice of type" {
107 else => unreachable,107 else => unreachable,
108 }108 }
109 }109 }
110 for (types_array[0..]) |T, i| {110 for (types_array[0..], 0..) |T, i| {
111 switch (i) {111 switch (i) {
112 0 => try expect(T == i32),112 0 => try expect(T == i32),
113 1 => try expect(T == f64),113 1 => try expect(T == f64),
test/behavior/tuple.zig+1-1
...@@ -40,7 +40,7 @@ test "tuple multiplication" {...@@ -40,7 +40,7 @@ test "tuple multiplication" {
40 {40 {
41 const t = .{ 1, 2, 3 } ** 4;41 const t = .{ 1, 2, 3 } ** 4;
42 try expect(@typeInfo(@TypeOf(t)).Struct.fields.len == 12);42 try expect(@typeInfo(@TypeOf(t)).Struct.fields.len == 12);
43 inline for (t) |x, i| try expect(x == 1 + i % 3);43 inline for (t, 0..) |x, i| try expect(x == 1 + i % 3);
44 }44 }
45 }45 }
46 };46 };
test/behavior/vector.zig+11-11
...@@ -456,20 +456,20 @@ test "vector division operators" {...@@ -456,20 +456,20 @@ test "vector division operators" {
456 fn doTheTestDiv(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void {456 fn doTheTestDiv(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void {
457 if (!comptime std.meta.trait.isSignedInt(T)) {457 if (!comptime std.meta.trait.isSignedInt(T)) {
458 const d0 = x / y;458 const d0 = x / y;
459 for (@as([4]T, d0)) |v, i| {459 for (@as([4]T, d0), 0..) |v, i| {
460 try expect(x[i] / y[i] == v);460 try expect(x[i] / y[i] == v);
461 }461 }
462 }462 }
463 const d1 = @divExact(x, y);463 const d1 = @divExact(x, y);
464 for (@as([4]T, d1)) |v, i| {464 for (@as([4]T, d1), 0..) |v, i| {
465 try expect(@divExact(x[i], y[i]) == v);465 try expect(@divExact(x[i], y[i]) == v);
466 }466 }
467 const d2 = @divFloor(x, y);467 const d2 = @divFloor(x, y);
468 for (@as([4]T, d2)) |v, i| {468 for (@as([4]T, d2), 0..) |v, i| {
469 try expect(@divFloor(x[i], y[i]) == v);469 try expect(@divFloor(x[i], y[i]) == v);
470 }470 }
471 const d3 = @divTrunc(x, y);471 const d3 = @divTrunc(x, y);
472 for (@as([4]T, d3)) |v, i| {472 for (@as([4]T, d3), 0..) |v, i| {
473 try expect(@divTrunc(x[i], y[i]) == v);473 try expect(@divTrunc(x[i], y[i]) == v);
474 }474 }
475 }475 }
...@@ -477,16 +477,16 @@ test "vector division operators" {...@@ -477,16 +477,16 @@ test "vector division operators" {
477 fn doTheTestMod(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void {477 fn doTheTestMod(comptime T: type, x: @Vector(4, T), y: @Vector(4, T)) !void {
478 if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {478 if ((!comptime std.meta.trait.isSignedInt(T)) and @typeInfo(T) != .Float) {
479 const r0 = x % y;479 const r0 = x % y;
480 for (@as([4]T, r0)) |v, i| {480 for (@as([4]T, r0), 0..) |v, i| {
481 try expect(x[i] % y[i] == v);481 try expect(x[i] % y[i] == v);
482 }482 }
483 }483 }
484 const r1 = @mod(x, y);484 const r1 = @mod(x, y);
485 for (@as([4]T, r1)) |v, i| {485 for (@as([4]T, r1), 0..) |v, i| {
486 try expect(@mod(x[i], y[i]) == v);486 try expect(@mod(x[i], y[i]) == v);
487 }487 }
488 const r2 = @rem(x, y);488 const r2 = @rem(x, y);
489 for (@as([4]T, r2)) |v, i| {489 for (@as([4]T, r2), 0..) |v, i| {
490 try expect(@rem(x[i], y[i]) == v);490 try expect(@rem(x[i], y[i]) == v);
491 }491 }
492 }492 }
...@@ -538,7 +538,7 @@ test "vector bitwise not operator" {...@@ -538,7 +538,7 @@ test "vector bitwise not operator" {
538 const S = struct {538 const S = struct {
539 fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void {539 fn doTheTestNot(comptime T: type, x: @Vector(4, T)) !void {
540 var y = ~x;540 var y = ~x;
541 for (@as([4]T, y)) |v, i| {541 for (@as([4]T, y), 0..) |v, i| {
542 try expect(~x[i] == v);542 try expect(~x[i] == v);
543 }543 }
544 }544 }
...@@ -577,11 +577,11 @@ test "vector shift operators" {...@@ -577,11 +577,11 @@ test "vector shift operators" {
577 var yv = @as(@Vector(N, TY), y);577 var yv = @as(@Vector(N, TY), y);
578578
579 var z0 = xv >> yv;579 var z0 = xv >> yv;
580 for (@as([N]TX, z0)) |v, i| {580 for (@as([N]TX, z0), 0..) |v, i| {
581 try expect(x[i] >> y[i] == v);581 try expect(x[i] >> y[i] == v);
582 }582 }
583 var z1 = xv << yv;583 var z1 = xv << yv;
584 for (@as([N]TX, z1)) |v, i| {584 for (@as([N]TX, z1), 0..) |v, i| {
585 try expect(x[i] << y[i] == v);585 try expect(x[i] << y[i] == v);
586 }586 }
587 }587 }
...@@ -594,7 +594,7 @@ test "vector shift operators" {...@@ -594,7 +594,7 @@ test "vector shift operators" {
594 var yv = @as(@Vector(N, TY), y);594 var yv = @as(@Vector(N, TY), y);
595595
596 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);596 var z = if (dir == .Left) @shlExact(xv, yv) else @shrExact(xv, yv);
597 for (@as([N]TX, z)) |v, i| {597 for (@as([N]TX, z), 0..) |v, i| {
598 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];598 const check = if (dir == .Left) x[i] << y[i] else x[i] >> y[i];
599 try expect(check == v);599 try expect(check == v);
600 }600 }
test/behavior/void.zig+1-1
...@@ -22,7 +22,7 @@ test "iterate over a void slice" {...@@ -22,7 +22,7 @@ test "iterate over a void slice" {
22 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO22 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
2323
24 var j: usize = 0;24 var j: usize = 0;
25 for (times(10)) |_, i| {25 for (times(10), 0..) |_, i| {
26 try expect(i == j);26 try expect(i == j);
27 j += 1;27 j += 1;
28 }28 }
test/standalone/brace_expansion/main.zig+2-2
...@@ -29,7 +29,7 @@ fn tokenize(input: []const u8) !ArrayList(Token) {...@@ -29,7 +29,7 @@ fn tokenize(input: []const u8) !ArrayList(Token) {
29 var tok_begin: usize = undefined;29 var tok_begin: usize = undefined;
30 var state = State.Start;30 var state = State.Start;
3131
32 for (input) |b, i| {32 for (input, 0..) |b, i| {
33 switch (state) {33 switch (state) {
34 .Start => switch (b) {34 .Start => switch (b) {
35 'a'...'z', 'A'...'Z' => {35 'a'...'z', 'A'...'Z' => {
...@@ -159,7 +159,7 @@ fn expandString(input: []const u8, output: *ArrayList(u8)) !void {...@@ -159,7 +159,7 @@ fn expandString(input: []const u8, output: *ArrayList(u8)) !void {
159 try expandNode(root, &result_list);159 try expandNode(root, &result_list);
160160
161 try output.resize(0);161 try output.resize(0);
162 for (result_list.items) |buf, i| {162 for (result_list.items, 0..) |buf, i| {
163 if (i != 0) {163 if (i != 0) {
164 try output.append(' ');164 try output.append(' ');
165 }165 }
test/tests.zig+1-1
...@@ -958,7 +958,7 @@ pub const StackTracesContext = struct {...@@ -958,7 +958,7 @@ pub const StackTracesContext = struct {
958 // locate delims/anchor958 // locate delims/anchor
959 const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" };959 const delims = [_][]const u8{ ":", ":", ":", " in ", "(", ")" };
960 var marks = [_]usize{0} ** delims.len;960 var marks = [_]usize{0} ** delims.len;
961 for (delims) |delim, i| {961 for (delims, 0..) |delim, i| {
962 marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {962 marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
963 // unexpected pattern: emit raw line and cont963 // unexpected pattern: emit raw line and cont
964 try buf.appendSlice(line);964 try buf.appendSlice(line);