Skip to content

Commit db5d479

Browse files
committed
New proposed changes
1 parent 37b48dc commit db5d479

33 files changed

+87
-87
lines changed

doc/docgen.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ const Tokenizer = struct {
216216
}
217217
};
218218

219-
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: ...) error {
219+
fn parseError(tokenizer: *Tokenizer, token: Token, comptime fmt: []const u8, args: ...) anyerror {
220220
const loc = tokenizer.getTokenLocation(token);
221221
warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
222222
if (loc.line_start <= loc.line_end) {

src-self-hosted/main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const usage =
4545

4646
const Command = struct {
4747
name: []const u8,
48-
exec: fn (*Allocator, []const []const u8) error!void,
48+
exec: fn (*Allocator, []const []const u8) anyerror!void,
4949
};
5050

5151
pub fn main() !void {

src-self-hosted/test.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub const TestContext = struct {
2828
zig_compiler: ZigCompiler,
2929
zig_lib_dir: []u8,
3030
file_index: std.atomic.Int(usize),
31-
group: std.event.Group(error!void),
32-
any_err: error!void,
31+
group: std.event.Group(anyerror!void),
32+
any_err: anyerror!void,
3333

3434
const tmp_dir_name = "stage2_test_tmp";
3535

@@ -49,7 +49,7 @@ pub const TestContext = struct {
4949
self.zig_compiler = try ZigCompiler.init(&self.loop);
5050
errdefer self.zig_compiler.deinit();
5151

52-
self.group = std.event.Group(error!void).init(&self.loop);
52+
self.group = std.event.Group(anyerror!void).init(&self.loop);
5353
errdefer self.group.deinit();
5454

5555
self.zig_lib_dir = try introspect.resolveZigLibDir(allocator);

std/base64.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn testDecodeIgnoreSpace(expected_decoded: []const u8, encoded: []const u8) !voi
432432
assert(mem.eql(u8, decoded[0..written], expected_decoded));
433433
}
434434

435-
fn testError(encoded: []const u8, expected_err: error) !void {
435+
fn testError(encoded: []const u8, expected_err: anyerror) !void {
436436
const standard_decoder_ignore_space = Base64DecoderWithIgnore.init(standard_alphabet_chars, standard_pad_char, " ");
437437
var buffer: [0x100]u8 = undefined;
438438
if (standard_decoder.calcSize(encoded)) |decoded_size| {

std/build.zig

+6-6
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ pub const Builder = struct {
269269
return &self.uninstall_tls.step;
270270
}
271271

272-
fn makeUninstall(uninstall_step: *Step) error!void {
272+
fn makeUninstall(uninstall_step: *Step) anyerror!void {
273273
const uninstall_tls = @fieldParentPtr(TopLevelStep, "step", uninstall_step);
274274
const self = @fieldParentPtr(Builder, "uninstall_tls", uninstall_tls);
275275

@@ -283,7 +283,7 @@ pub const Builder = struct {
283283
// TODO remove empty directories
284284
}
285285

286-
fn makeOneStep(self: *Builder, s: *Step) error!void {
286+
fn makeOneStep(self: *Builder, s: *Step) anyerror!void {
287287
if (s.loop_flag) {
288288
warn("Dependency loop detected:\n {}\n", s.name);
289289
return error.DependencyLoopDetected;
@@ -1998,7 +1998,7 @@ pub const LogStep = struct {
19981998
};
19991999
}
20002000

2001-
fn make(step: *Step) error!void {
2001+
fn make(step: *Step) anyerror!void {
20022002
const self = @fieldParentPtr(LogStep, "step", step);
20032003
warn("{}", self.data);
20042004
}
@@ -2030,12 +2030,12 @@ pub const RemoveDirStep = struct {
20302030

20312031
pub const Step = struct {
20322032
name: []const u8,
2033-
makeFn: fn (self: *Step) error!void,
2033+
makeFn: fn (self: *Step) anyerror!void,
20342034
dependencies: ArrayList(*Step),
20352035
loop_flag: bool,
20362036
done_flag: bool,
20372037

2038-
pub fn init(name: []const u8, allocator: *Allocator, makeFn: fn (*Step) error!void) Step {
2038+
pub fn init(name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
20392039
return Step{
20402040
.name = name,
20412041
.makeFn = makeFn,
@@ -2059,7 +2059,7 @@ pub const Step = struct {
20592059
self.dependencies.append(other) catch unreachable;
20602060
}
20612061

2062-
fn makeNoOp(self: *Step) error!void {}
2062+
fn makeNoOp(self: *Step) anyerror!void {}
20632063
};
20642064

20652065
fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {

std/debug/index.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub fn assert(ok: bool) void {
124124

125125
/// TODO: add `==` operator for `error_union == error_set`, and then
126126
/// remove this function
127-
pub fn assertError(value: var, expected_error: error) void {
127+
pub fn assertError(value: var, expected_error: anyerror) void {
128128
if (value) {
129129
@panic("expected error");
130130
} else |actual_error| {

std/dynamic_library.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ test "dynamic_library" {
203203
const libname = switch (builtin.os) {
204204
Os.linux => "invalid_so.so",
205205
Os.windows => "invalid_dll.dll",
206-
else => return;,
206+
else => return,
207207
};
208208

209209
const dynlib = DynLib.open(std.debug.global_allocator, libname) catch |err| {

std/event/fs.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -1310,15 +1310,15 @@ test "write a file, watch it, write it again" {
13101310
try loop.initMultiThreaded(allocator);
13111311
defer loop.deinit();
13121312

1313-
var result: error!void = error.ResultNeverWritten;
1313+
var result: anyerror!void = error.ResultNeverWritten;
13141314
const handle = try async<allocator> testFsWatchCantFail(&loop, &result);
13151315
defer cancel handle;
13161316

13171317
loop.run();
13181318
return result;
13191319
}
13201320

1321-
async fn testFsWatchCantFail(loop: *Loop, result: *(error!void)) void {
1321+
async fn testFsWatchCantFail(loop: *Loop, result: *(anyerror!void)) void {
13221322
result.* = await async testFsWatch(loop) catch unreachable;
13231323
}
13241324

std/event/group.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ async fn testGroup(loop: *Loop) void {
144144
await (async group.wait() catch @panic("memory"));
145145
assert(count == 11);
146146

147-
var another = Group(error!void).init(loop);
147+
var another = Group(anyerror!void).init(loop);
148148
another.add(async somethingElse() catch @panic("memory")) catch @panic("memory");
149149
another.call(doSomethingThatFails) catch @panic("memory");
150150
std.debug.assertError(await (async another.wait() catch @panic("memory")), error.ItBroke);
@@ -162,7 +162,7 @@ async fn increaseByTen(count: *usize) void {
162162
}
163163
}
164164

165-
async fn doSomethingThatFails() error!void {}
166-
async fn somethingElse() error!void {
165+
async fn doSomethingThatFails() anyerror!void {}
166+
async fn somethingElse() anyerror!void {
167167
return error.ItBroke;
168168
}

std/fmt/index.zig

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub fn formatType(
111111
output: fn (@typeOf(context), []const u8) Errors!void,
112112
) Errors!void {
113113
const T = @typeOf(value);
114-
if (T == error) {
114+
if (T == anyerror) {
115115
try output(context, "error.");
116116
return output(context, @errorName(value));
117117
}
@@ -913,11 +913,11 @@ test "fmt.format" {
913913
try testFmt("optional: null\n", "optional: {}\n", value);
914914
}
915915
{
916-
const value: error!i32 = 1234;
916+
const value: anyerror!i32 = 1234;
917917
try testFmt("error union: 1234\n", "error union: {}\n", value);
918918
}
919919
{
920-
const value: error!i32 = error.InvalidChar;
920+
const value: anyerror!i32 = error.InvalidChar;
921921
try testFmt("error union: error.InvalidChar\n", "error union: {}\n", value);
922922
}
923923
{
@@ -1236,7 +1236,7 @@ test "fmt.format" {
12361236
{
12371237
const S = struct {
12381238
a: u32,
1239-
b: error,
1239+
b: anyerror,
12401240
};
12411241

12421242
const inst = S{

std/meta/trait.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test "std.meta.trait.is" {
165165
debug.assert(!is(builtin.TypeId.Int)(f32));
166166
debug.assert(is(builtin.TypeId.Pointer)(*u8));
167167
debug.assert(is(builtin.TypeId.Void)(void));
168-
debug.assert(!is(builtin.TypeId.Optional)(error));
168+
debug.assert(!is(builtin.TypeId.Optional)(anyerror));
169169
}
170170

171171
///

std/net.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ test "std.net.parseIp4" {
198198
testParseIp4Fail("100..0.1", error.InvalidCharacter);
199199
}
200200

201-
fn testParseIp4Fail(buf: []const u8, expected_err: error) void {
201+
fn testParseIp4Fail(buf: []const u8, expected_err: anyerror) void {
202202
if (parseIp4(buf)) |_| {
203203
@panic("expected error");
204204
} else |e| {

std/os/child_process.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
789789
posix.exit(1);
790790
}
791791

792-
const ErrInt = @IntType(false, @sizeOf(error) * 8);
792+
const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);
793793

794794
fn writeIntFd(fd: i32, value: ErrInt) !void {
795795
const stream = &os.File.openHandle(fd).outStream().stream;

std/special/build_runner.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub fn main() !void {
132132
};
133133
}
134134

135-
fn runBuild(builder: *Builder) error!void {
135+
fn runBuild(builder: *Builder) anyerror!void {
136136
switch (@typeId(@typeOf(root.build).ReturnType)) {
137137
builtin.TypeId.Void => root.build(builder),
138138
builtin.TypeId.ErrorUnion => try root.build(builder),
@@ -198,7 +198,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
198198
);
199199
}
200200

201-
fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) error {
201+
fn usageAndErr(builder: *Builder, already_ran_build: bool, out_stream: var) anyerror {
202202
usage(builder, already_ran_build, out_stream) catch {};
203203
return error.InvalidArgs;
204204
}

std/special/init-exe/src/main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const std = @import("std");
22

3-
pub fn main() error!void {
3+
pub fn main() anyerror!void {
44
std.debug.warn("All your base are belong to us.\n");
55
}

std/unicode.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn testUtf8Encode() !void {
286286
debug.assert(array[0] == 0b11000010);
287287
debug.assert(array[1] == 0b10100010);
288288

289-
debug.assert((try utf8Encode(try utf8Decode("𐍈"), array[0..])) == 4);
289+
debug.assert((try utf8Encode(try utf8Decode("𝝈"), array[0..])) == 4);
290290
debug.assert(array[0] == 0b11110000);
291291
debug.assert(array[1] == 0b10010000);
292292
debug.assert(array[2] == 0b10001101);
@@ -305,7 +305,7 @@ fn testUtf8EncodeError() void {
305305
testErrorEncode(0xffffffff, array[0..], error.CodepointTooLarge);
306306
}
307307

308-
fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: error) void {
308+
fn testErrorEncode(codePoint: u32, array: []u8, expectedErr: anyerror) void {
309309
if (utf8Encode(codePoint, array)) |_| {
310310
unreachable;
311311
} else |err| {
@@ -458,7 +458,7 @@ fn testMiscInvalidUtf8() void {
458458
testValid("\xee\x80\x80", 0xe000);
459459
}
460460

461-
fn testError(bytes: []const u8, expected_err: error) void {
461+
fn testError(bytes: []const u8, expected_err: anyerror) void {
462462
if (testDecode(bytes)) |_| {
463463
unreachable;
464464
} else |err| {

test/cases/bugs/1442.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ const Union = union(enum) {
66
};
77

88
test "const error union field alignment" {
9-
var union_or_err: error!Union = Union{ .Color = 1234 };
9+
var union_or_err: anyerror!Union = Union{ .Color = 1234 };
1010
std.debug.assertOrPanic((union_or_err catch unreachable).Color == 1234);
1111
}

test/cases/cast.zig

+15-15
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test "explicit cast from integer to error type" {
5353
testCastIntToErr(error.ItBroke);
5454
comptime testCastIntToErr(error.ItBroke);
5555
}
56-
fn testCastIntToErr(err: error) void {
56+
fn testCastIntToErr(err: anyerror) void {
5757
const x = @errorToInt(err);
5858
const y = @intToError(x);
5959
assert(error.ItBroke == y);
@@ -80,7 +80,7 @@ fn testPeerResolveArrayConstSlice(b: bool) void {
8080
assert(mem.eql(u8, value2, "zz"));
8181
}
8282

83-
test "implicitly cast from T to error!?T" {
83+
test "implicitly cast from T to anyerror!?T" {
8484
castToOptionalTypeError(1);
8585
comptime castToOptionalTypeError(1);
8686
}
@@ -89,36 +89,36 @@ const A = struct {
8989
};
9090
fn castToOptionalTypeError(z: i32) void {
9191
const x = i32(1);
92-
const y: error!?i32 = x;
92+
const y: anyerror!?i32 = x;
9393
assert((try y).? == 1);
9494

9595
const f = z;
96-
const g: error!?i32 = f;
96+
const g: anyerror!?i32 = f;
9797

9898
const a = A{ .a = z };
99-
const b: error!?A = a;
99+
const b: anyerror!?A = a;
100100
assert((b catch unreachable).?.a == 1);
101101
}
102102

103-
test "implicitly cast from int to error!?T" {
103+
test "implicitly cast from int to anyerror!?T" {
104104
implicitIntLitToOptional();
105105
comptime implicitIntLitToOptional();
106106
}
107107
fn implicitIntLitToOptional() void {
108108
const f: ?i32 = 1;
109-
const g: error!?i32 = 1;
109+
const g: anyerror!?i32 = 1;
110110
}
111111

112-
test "return null from fn() error!?&T" {
112+
test "return null from fn() anyerror!?&T" {
113113
const a = returnNullFromOptionalTypeErrorRef();
114114
const b = returnNullLitFromOptionalTypeErrorRef();
115115
assert((try a) == null and (try b) == null);
116116
}
117-
fn returnNullFromOptionalTypeErrorRef() error!?*A {
117+
fn returnNullFromOptionalTypeErrorRef() anyerror!?*A {
118118
const a: ?*A = null;
119119
return a;
120120
}
121-
fn returnNullLitFromOptionalTypeErrorRef() error!?*A {
121+
fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A {
122122
return null;
123123
}
124124

@@ -163,7 +163,7 @@ fn castToOptionalSlice() ?[]const u8 {
163163
return "hi";
164164
}
165165

166-
test "implicitly cast from [0]T to error![]T" {
166+
test "implicitly cast from [0]T to anyerror![]T" {
167167
testCastZeroArrayToErrSliceMut();
168168
comptime testCastZeroArrayToErrSliceMut();
169169
}
@@ -172,11 +172,11 @@ fn testCastZeroArrayToErrSliceMut() void {
172172
assert((gimmeErrOrSlice() catch unreachable).len == 0);
173173
}
174174

175-
fn gimmeErrOrSlice() error![]u8 {
175+
fn gimmeErrOrSlice() anyerror![]u8 {
176176
return []u8{};
177177
}
178178

179-
test "peer type resolution: [0]u8, []const u8, and error![]u8" {
179+
test "peer type resolution: [0]u8, []const u8, and anyerror![]u8" {
180180
{
181181
var data = "hi";
182182
const slice = data[0..];
@@ -190,7 +190,7 @@ test "peer type resolution: [0]u8, []const u8, and error![]u8" {
190190
assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1);
191191
}
192192
}
193-
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) error![]u8 {
193+
fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 {
194194
if (a) {
195195
return []u8{};
196196
}
@@ -236,7 +236,7 @@ test "peer type resolution: error and [N]T" {
236236
// else => error.BadValue,
237237
// };
238238
//}
239-
fn testPeerErrorAndArray2(x: u8) error![]const u8 {
239+
fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {
240240
return switch (x) {
241241
0x00 => "OK",
242242
0x01 => "OKK",

test/cases/coroutines.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,14 @@ test "error return trace across suspend points - async return" {
221221
}
222222

223223
// TODO https://github.com/ziglang/zig/issues/760
224-
fn nonFailing() (promise->error!void) {
224+
fn nonFailing() (promise->anyerror!void) {
225225
return async<std.debug.global_allocator> suspendThenFail() catch unreachable;
226226
}
227-
async fn suspendThenFail() error!void {
227+
async fn suspendThenFail() anyerror!void {
228228
suspend;
229229
return error.Fail;
230230
}
231-
async fn printTrace(p: promise->error!void) void {
231+
async fn printTrace(p: promise->anyerror!void) void {
232232
(await p) catch |e| {
233233
std.debug.assert(e == error.Fail);
234234
if (@errorReturnTrace()) |trace| {

0 commit comments

Comments
 (0)