From 507a8096d2f9624bafaf963c3e189a477ef6b7bf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 22 Apr 2021 18:07:46 -0700 Subject: [PATCH] std: fix compile errors caught by stage2 AstGen * `comptime const` is redundant * don't use `extern enum`; specify a tag type. `extern enum` is only when you need tags to alias. But aliasing tags is a smell. I will be making a proposal shortly to remove `extern enum` from the language. * there is no such thing as `packed enum`. * instead of `catch |_|`, omit the capture entirely. * unused function definition with missing parameter name * using `try` outside of a function or test --- BRANCH_TODO | 2 ++ lib/std/array_hash_map.zig | 2 +- lib/std/crypto/25519/edwards25519.zig | 6 +++--- lib/std/crypto/utils.zig | 12 ++++++------ lib/std/elf.zig | 4 ++-- lib/std/fmt.zig | 28 +++++++++++++-------------- lib/std/json.zig | 4 ++-- lib/std/macho.zig | 10 +++++----- lib/std/mem.zig | 2 +- lib/std/meta.zig | 4 ---- lib/std/os/bits/darwin.zig | 8 ++++---- lib/std/os/bits/dragonfly.zig | 6 +++--- lib/std/os/bits/freebsd.zig | 6 +++--- lib/std/os/bits/haiku.zig | 8 ++++---- lib/std/os/bits/linux.zig | 16 +++++++-------- lib/std/os/bits/linux/arm-eabi.zig | 2 +- lib/std/os/bits/linux/arm64.zig | 2 +- lib/std/os/bits/linux/i386.zig | 2 +- lib/std/os/bits/linux/mips.zig | 2 +- lib/std/os/bits/linux/netlink.zig | 9 +++++---- lib/std/os/bits/linux/powerpc.zig | 2 +- lib/std/os/bits/linux/powerpc64.zig | 4 ++-- lib/std/os/bits/linux/prctl.zig | 2 +- lib/std/os/bits/linux/riscv64.zig | 2 +- lib/std/os/bits/linux/sparc64.zig | 2 +- lib/std/os/bits/linux/x86_64.zig | 3 +-- lib/std/os/bits/netbsd.zig | 8 ++++---- lib/std/os/bits/openbsd.zig | 6 +++--- lib/std/os/linux.zig | 2 -- lib/std/os/uefi/status.zig | 2 +- lib/std/os/windows/bits.zig | 6 +++--- lib/std/os/windows/ntstatus.zig | 2 +- lib/std/os/windows/win32error.zig | 2 +- lib/std/os/windows/ws2_32.zig | 2 +- lib/std/pdb.zig | 4 ++-- lib/std/valgrind.zig | 8 ++++---- lib/std/valgrind/callgrind.zig | 2 +- lib/std/valgrind/memcheck.zig | 4 ++-- src/AstGen.zig | 4 +++- src/Compilation.zig | 2 +- 40 files changed, 101 insertions(+), 103 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index 8a0bfd1b5f..334b75fe75 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -32,6 +32,8 @@ compile error for a local shadowing a decl with Sema looking up the decl name. - this means LocalVal and LocalPtr should use the string table + * sort compile errors before presenting them to eliminate nondeterministic error reporting + const container_name_hash: Scope.NameHash = if (found_pkg) |pkg| pkg.namespace_hash else diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig index 9b0c53b18a..1dc4110c75 100644 --- a/lib/std/array_hash_map.zig +++ b/lib/std/array_hash_map.zig @@ -1310,7 +1310,7 @@ test "reIndex" { } test "fromOwnedArrayList" { - comptime const array_hash_map_type = AutoArrayHashMap(i32, i32); + const array_hash_map_type = AutoArrayHashMap(i32, i32); var al = std.ArrayListUnmanaged(array_hash_map_type.Entry){}; const hash = getAutoHashFn(i32); diff --git a/lib/std/crypto/25519/edwards25519.zig b/lib/std/crypto/25519/edwards25519.zig index 89b7b9b9f3..a7f385c365 100644 --- a/lib/std/crypto/25519/edwards25519.zig +++ b/lib/std/crypto/25519/edwards25519.zig @@ -238,7 +238,7 @@ pub const Edwards25519 = struct { pub fn mul(p: Edwards25519, s: [32]u8) Error!Edwards25519 { const pc = if (p.is_base) basePointPc else pc: { const xpc = precompute(p, 15); - xpc[4].rejectIdentity() catch |_| return error.WeakPublicKey; + xpc[4].rejectIdentity() catch return error.WeakPublicKey; break :pc xpc; }; return pcMul16(pc, s, false); @@ -251,7 +251,7 @@ pub const Edwards25519 = struct { return pcMul16(basePointPc, s, true); } else { const pc = precompute(p, 8); - pc[4].rejectIdentity() catch |_| return error.WeakPublicKey; + pc[4].rejectIdentity() catch return error.WeakPublicKey; return pcMul(pc, s, true); } } @@ -266,7 +266,7 @@ pub const Edwards25519 = struct { pcs[i] = comptime precompute(Edwards25519.basePoint, 8); } else { pcs[i] = precompute(p, 8); - pcs[i][4].rejectIdentity() catch |_| return error.WeakPublicKey; + pcs[i][4].rejectIdentity() catch return error.WeakPublicKey; } } var es: [count][2 * 32]i8 = undefined; diff --git a/lib/std/crypto/utils.zig b/lib/std/crypto/utils.zig index 08271ac9f4..4e02092ed8 100644 --- a/lib/std/crypto/utils.zig +++ b/lib/std/crypto/utils.zig @@ -16,9 +16,9 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool { for (a) |x, i| { acc |= x ^ b[i]; } - comptime const s = @typeInfo(C).Int.bits; - comptime const Cu = std.meta.Int(.unsigned, s); - comptime const Cext = std.meta.Int(.unsigned, s + 1); + const s = @typeInfo(C).Int.bits; + const Cu = std.meta.Int(.unsigned, s); + const Cext = std.meta.Int(.unsigned, s + 1); return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s)); }, .Vector => |info| { @@ -27,9 +27,9 @@ pub fn timingSafeEql(comptime T: type, a: T, b: T) bool { @compileError("Elements to be compared must be integers"); } const acc = @reduce(.Or, a ^ b); - comptime const s = @typeInfo(C).Int.bits; - comptime const Cu = std.meta.Int(.unsigned, s); - comptime const Cext = std.meta.Int(.unsigned, s + 1); + const s = @typeInfo(C).Int.bits; + const Cu = std.meta.Int(.unsigned, s); + const Cext = std.meta.Int(.unsigned, s + 1); return @bitCast(bool, @truncate(u1, (@as(Cext, @bitCast(Cu, acc)) -% 1) >> s)); }, else => { diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 36382ecc42..c37cc74223 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -311,7 +311,7 @@ pub const VER_FLG_BASE = 0x1; pub const VER_FLG_WEAK = 0x2; /// File types -pub const ET = extern enum(u16) { +pub const ET = enum(u16) { /// No file type NONE = 0, @@ -991,7 +991,7 @@ pub const Half = switch (@sizeOf(usize)) { /// See current registered ELF machine architectures at: /// http://www.uxsglobal.com/developers/gabi/latest/ch4.eheader.html /// The underscore prefix is because many of these start with numbers. -pub const EM = extern enum(u16) { +pub const EM = enum(u16) { /// No machine _NONE = 0, diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index 354a259df4..ee4ca1bf89 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -187,7 +187,7 @@ pub fn format( comptime var i = 0; inline while (i < fmt.len) { - comptime const start_index = i; + const start_index = i; inline while (i < fmt.len) : (i += 1) { switch (fmt[i]) { @@ -226,10 +226,10 @@ pub fn format( comptime assert(fmt[i] == '{'); i += 1; - comptime const fmt_begin = i; + const fmt_begin = i; // Find the closing brace inline while (i < fmt.len and fmt[i] != '}') : (i += 1) {} - comptime const fmt_end = i; + const fmt_end = i; if (i >= fmt.len) { @compileError("Missing closing }"); @@ -246,23 +246,23 @@ pub fn format( parser.pos = 0; // Parse the positional argument number - comptime const opt_pos_arg = init: { - if (comptime parser.maybe('[')) { - comptime const arg_name = parser.until(']'); + const opt_pos_arg = comptime init: { + if (parser.maybe('[')) { + const arg_name = parser.until(']'); - if (!comptime parser.maybe(']')) { + if (!parser.maybe(']')) { @compileError("Expected closing ]"); } - break :init comptime meta.fieldIndex(ArgsType, arg_name) orelse + break :init meta.fieldIndex(ArgsType, arg_name) orelse @compileError("No argument with name '" ++ arg_name ++ "'"); } else { - break :init comptime parser.number(); + break :init parser.number(); } }; // Parse the format specifier - comptime const specifier_arg = comptime parser.until(':'); + const specifier_arg = comptime parser.until(':'); // Skip the colon, if present if (comptime parser.char()) |ch| { @@ -302,13 +302,13 @@ pub fn format( // Parse the width parameter options.width = init: { if (comptime parser.maybe('[')) { - comptime const arg_name = parser.until(']'); + const arg_name = parser.until(']'); if (!comptime parser.maybe(']')) { @compileError("Expected closing ]"); } - comptime const index = meta.fieldIndex(ArgsType, arg_name) orelse + const index = meta.fieldIndex(ArgsType, arg_name) orelse @compileError("No argument with name '" ++ arg_name ++ "'"); const arg_index = comptime arg_state.nextArg(index); @@ -328,13 +328,13 @@ pub fn format( // Parse the precision parameter options.precision = init: { if (comptime parser.maybe('[')) { - comptime const arg_name = parser.until(']'); + const arg_name = parser.until(']'); if (!comptime parser.maybe(']')) { @compileError("Expected closing ]"); } - comptime const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse + const arg_i = meta.fieldIndex(ArgsType, arg_name) orelse @compileError("No argument with name '" ++ arg_name ++ "'"); const arg_to_use = comptime arg_state.nextArg(arg_i); diff --git a/lib/std/json.zig b/lib/std/json.zig index 7596631ea2..e0e7965622 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -195,7 +195,7 @@ pub const StreamingParser = struct { p.number_is_integer = undefined; } - pub const State = enum { + pub const State = enum(u8) { // These must be first with these explicit values as we rely on them for indexing the // bit-stack directly and avoiding a branch. ObjectSeparator = 0, @@ -1765,7 +1765,7 @@ test "parse" { } test "parse into enum" { - const T = extern enum { + const T = enum(u32) { Foo = 42, Bar, @"with\\escape", diff --git a/lib/std/macho.zig b/lib/std/macho.zig index f66626bafe..8336b04c70 100644 --- a/lib/std/macho.zig +++ b/lib/std/macho.zig @@ -1314,13 +1314,13 @@ pub const BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: u8 = 0x40; pub const BIND_OPCODE_SET_TYPE_IMM: u8 = 0x50; pub const BIND_OPCODE_SET_ADDEND_SLEB: u8 = 0x60; pub const BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: u8 = 0x70; -pub const BIND_OPCODE_ADD_ADDR_ULEB: 0x80; +pub const BIND_OPCODE_ADD_ADDR_ULEB: u8 = 0x80; pub const BIND_OPCODE_DO_BIND: u8 = 0x90; pub const BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: u8 = 0xa0; pub const BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: u8 = 0xb0; -pub const BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: u8 = xc0; +pub const BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: u8 = 0xc0; -pub const reloc_type_x86_64 = packed enum(u4) { +pub const reloc_type_x86_64 = enum(u4) { /// for absolute addresses X86_64_RELOC_UNSIGNED = 0, @@ -1352,9 +1352,9 @@ pub const reloc_type_x86_64 = packed enum(u4) { X86_64_RELOC_TLV, }; -pub const reloc_type_arm64 = packed enum(u4) { +pub const reloc_type_arm64 = enum(u4) { /// For pointers. - ARM64_RELOC_UNSIGNED = 0, + ARM64_RELOC_UNSIGNED, /// Must be followed by a ARM64_RELOC_UNSIGNED. ARM64_RELOC_SUBTRACTOR, diff --git a/lib/std/mem.zig b/lib/std/mem.zig index aea68e1362..fc01599864 100644 --- a/lib/std/mem.zig +++ b/lib/std/mem.zig @@ -356,7 +356,7 @@ test "mem.zeroes" { /// If the field is present in the provided initial values, it will have that value instead. /// Structs are initialized recursively. pub fn zeroInit(comptime T: type, init: anytype) T { - comptime const Init = @TypeOf(init); + const Init = @TypeOf(init); switch (@typeInfo(T)) { .Struct => |struct_info| { diff --git a/lib/std/meta.zig b/lib/std/meta.zig index ff2e6fb226..a67e04431a 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -335,9 +335,6 @@ test "std.meta.containerLayout" { const E1 = enum { A, }; - const E2 = packed enum { - A, - }; const E3 = extern enum { A, }; @@ -355,7 +352,6 @@ test "std.meta.containerLayout" { }; testing.expect(containerLayout(E1) == .Auto); - testing.expect(containerLayout(E2) == .Packed); testing.expect(containerLayout(E3) == .Extern); testing.expect(containerLayout(S1) == .Auto); testing.expect(containerLayout(S2) == .Packed); diff --git a/lib/std/os/bits/darwin.zig b/lib/std/os/bits/darwin.zig index aca24b1c0c..c24b42b891 100644 --- a/lib/std/os/bits/darwin.zig +++ b/lib/std/os/bits/darwin.zig @@ -1521,19 +1521,19 @@ pub const rusage = extern struct { nivcsw: isize, }; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU = 0, FSIZE = 1, DATA = 2, STACK = 3, CORE = 4, - AS = 5, RSS = 5, MEMLOCK = 6, NPROC = 7, NOFILE = 8, - _, + + pub const AS: rlimit_resource = .RSS; }; pub const rlim_t = u64; @@ -1669,7 +1669,7 @@ pub const TCSANOW = 0; // make change immediate pub const TCSADRAIN = 1; // drain output, then change pub const TCSAFLUSH = 2; // drain output, flush input pub const TCSASOFT = 0x10; // flag - don't alter h.w. state -pub const TCSA = extern enum(c_uint) { +pub const TCSA = enum(c_uint) { NOW, DRAIN, FLUSH, diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index 3df6eb43de..e42b6fbd1d 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -734,7 +734,7 @@ pub const Flock = extern struct { l_whence: c_short, }; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU = 0, FSIZE = 1, DATA = 2, @@ -745,11 +745,11 @@ pub const rlimit_resource = extern enum(c_int) { NPROC = 7, NOFILE = 8, SBSIZE = 9, - AS = 10, VMEM = 10, POSIXLOCKS = 11, - _, + + pub const AS: rlimit_resource = .VMEM; }; pub const rlim_t = i64; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index 8529c5e3db..9703ccca04 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -1459,7 +1459,7 @@ pub const IPPROTO_RESERVED_253 = 253; /// Reserved pub const IPPROTO_RESERVED_254 = 254; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU = 0, FSIZE = 1, DATA = 2, @@ -1471,13 +1471,13 @@ pub const rlimit_resource = extern enum(c_int) { NOFILE = 8, SBSIZE = 9, VMEM = 10, - AS = 10, NPTS = 11, SWAP = 12, KQUEUES = 13, UMTXP = 14, - _, + + pub const AS: rlimit_resource = .VMEM; }; pub const rlim_t = i64; diff --git a/lib/std/os/bits/haiku.zig b/lib/std/os/bits/haiku.zig index 32093570d7..1b6e7a3378 100644 --- a/lib/std/os/bits/haiku.zig +++ b/lib/std/os/bits/haiku.zig @@ -1401,7 +1401,7 @@ pub const IPPROTO_RESERVED_253 = 253; /// Reserved pub const IPPROTO_RESERVED_254 = 254; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU = 0, FSIZE = 1, DATA = 2, @@ -1413,13 +1413,13 @@ pub const rlimit_resource = extern enum(c_int) { NOFILE = 8, SBSIZE = 9, VMEM = 10, - AS = 10, NPTS = 11, SWAP = 12, KQUEUES = 13, UMTXP = 14, - _, + + pub const AS: rlimit_resource = .VMEM; }; pub const rlim_t = i64; @@ -1442,7 +1442,7 @@ pub const SHUT_WR = 1; pub const SHUT_RDWR = 2; // TODO fill out if needed -pub const directory_which = extern enum(c_int) { +pub const directory_which = enum(c_int) { B_USER_SETTINGS_DIRECTORY = 0xbbe, _, diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 1c8414ceb5..7663066ac0 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -1487,7 +1487,7 @@ pub const io_uring_sqe = extern struct { __pad2: [2]u64, }; -pub const IOSQE_BIT = extern enum(u8) { +pub const IOSQE_BIT = enum(u8) { FIXED_FILE, IO_DRAIN, IO_LINK, @@ -1518,7 +1518,7 @@ pub const IOSQE_ASYNC = 1 << @enumToInt(IOSQE_BIT.ASYNC); /// select buffer from buf_group pub const IOSQE_BUFFER_SELECT = 1 << @enumToInt(IOSQE_BIT.BUFFER_SELECT); -pub const IORING_OP = extern enum(u8) { +pub const IORING_OP = enum(u8) { NOP, READV, WRITEV, @@ -1587,7 +1587,7 @@ pub const IORING_ENTER_GETEVENTS = 1 << 0; pub const IORING_ENTER_SQ_WAKEUP = 1 << 1; // io_uring_register opcodes and arguments -pub const IORING_REGISTER = extern enum(u8) { +pub const IORING_REGISTER = enum(u8) { REGISTER_BUFFERS, UNREGISTER_BUFFERS, REGISTER_FILES, @@ -1654,7 +1654,7 @@ pub const io_uring_restriction = extern struct { }; /// io_uring_restriction->opcode values -pub const IORING_RESTRICTION = extern enum(u8) { +pub const IORING_RESTRICTION = enum(u8) { /// Allow an io_uring_register(2) opcode REGISTER_OP = 0, @@ -1909,7 +1909,7 @@ pub const tcp_repair_window = extern struct { rcv_wup: u32, }; -pub const TcpRepairOption = extern enum { +pub const TcpRepairOption = enum { TCP_NO_QUEUE, TCP_RECV_QUEUE, TCP_SEND_QUEUE, @@ -1917,7 +1917,7 @@ pub const TcpRepairOption = extern enum { }; /// why fastopen failed from client perspective -pub const tcp_fastopen_client_fail = extern enum { +pub const tcp_fastopen_client_fail = enum { /// catch-all TFO_STATUS_UNSPEC, /// if not in TFO_CLIENT_NO_COOKIE mode @@ -2184,7 +2184,7 @@ pub const NOFLSH = 128; pub const TOSTOP = 256; pub const IEXTEN = 32768; -pub const TCSA = extern enum(c_uint) { +pub const TCSA = enum(c_uint) { NOW, DRAIN, FLUSH, @@ -2235,7 +2235,7 @@ pub const ifreq = extern struct { }; // doc comments copied from musl -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { /// Per-process CPU limit, in seconds. CPU, diff --git a/lib/std/os/bits/linux/arm-eabi.zig b/lib/std/os/bits/linux/arm-eabi.zig index 5673cb952b..f325050689 100644 --- a/lib/std/os/bits/linux/arm-eabi.zig +++ b/lib/std/os/bits/linux/arm-eabi.zig @@ -15,7 +15,7 @@ const uid_t = linux.uid_t; const gid_t = linux.gid_t; const pid_t = linux.pid_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { restart_syscall = 0, exit = 1, fork = 2, diff --git a/lib/std/os/bits/linux/arm64.zig b/lib/std/os/bits/linux/arm64.zig index e373d978e1..cec87954d3 100644 --- a/lib/std/os/bits/linux/arm64.zig +++ b/lib/std/os/bits/linux/arm64.zig @@ -16,7 +16,7 @@ const gid_t = linux.gid_t; const pid_t = linux.pid_t; const stack_t = linux.stack_t; const sigset_t = linux.sigset_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { io_setup = 0, io_destroy = 1, io_submit = 2, diff --git a/lib/std/os/bits/linux/i386.zig b/lib/std/os/bits/linux/i386.zig index 7ef34eb96b..f8dadb8a60 100644 --- a/lib/std/os/bits/linux/i386.zig +++ b/lib/std/os/bits/linux/i386.zig @@ -17,7 +17,7 @@ const pid_t = linux.pid_t; const stack_t = linux.stack_t; const sigset_t = linux.sigset_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { restart_syscall = 0, exit = 1, fork = 2, diff --git a/lib/std/os/bits/linux/mips.zig b/lib/std/os/bits/linux/mips.zig index 412a1f48be..e158755889 100644 --- a/lib/std/os/bits/linux/mips.zig +++ b/lib/std/os/bits/linux/mips.zig @@ -12,7 +12,7 @@ const uid_t = linux.uid_t; const gid_t = linux.gid_t; const pid_t = linux.pid_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { pub const Linux = 4000; syscall = Linux + 0, diff --git a/lib/std/os/bits/linux/netlink.zig b/lib/std/os/bits/linux/netlink.zig index 72596cb1ab..4f9f41bb80 100644 --- a/lib/std/os/bits/linux/netlink.zig +++ b/lib/std/os/bits/linux/netlink.zig @@ -126,7 +126,7 @@ pub const NLM_F_CAPPED = 0x100; /// extended ACK TVLs were included pub const NLM_F_ACK_TLVS = 0x200; -pub const NetlinkMessageType = extern enum(u16) { +pub const NetlinkMessageType = enum(u16) { /// < 0x10: reserved control messages pub const MIN_TYPE = 0x10; @@ -287,7 +287,7 @@ pub const rtattr = extern struct { pub const ALIGNTO = 4; }; -pub const IFLA = extern enum(c_ushort) { +pub const IFLA = enum(c_ushort) { UNSPEC, ADDRESS, BROADCAST, @@ -351,8 +351,7 @@ pub const IFLA = extern enum(c_ushort) { EVENT, NEW_NETNSID, - IF_NETNSID = 46, - TARGET_NETNSID = 46, // new alias + IF_NETNSID, CARRIER_UP_COUNT, CARRIER_DOWN_COUNT, @@ -361,6 +360,8 @@ pub const IFLA = extern enum(c_ushort) { MAX_MTU, _, + + pub const TARGET_NETNSID: IFLA = .IF_NETNSID; }; pub const rtnl_link_ifmap = extern struct { diff --git a/lib/std/os/bits/linux/powerpc.zig b/lib/std/os/bits/linux/powerpc.zig index baa6a57bcf..67be4146c4 100644 --- a/lib/std/os/bits/linux/powerpc.zig +++ b/lib/std/os/bits/linux/powerpc.zig @@ -14,7 +14,7 @@ const gid_t = linux.gid_t; const pid_t = linux.pid_t; const stack_t = linux.stack_t; const sigset_t = linux.sigset_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { restart_syscall = 0, exit = 1, fork = 2, diff --git a/lib/std/os/bits/linux/powerpc64.zig b/lib/std/os/bits/linux/powerpc64.zig index e0e9347aa1..0c219cfcf1 100644 --- a/lib/std/os/bits/linux/powerpc64.zig +++ b/lib/std/os/bits/linux/powerpc64.zig @@ -14,7 +14,7 @@ const gid_t = linux.gid_t; const pid_t = linux.pid_t; const stack_t = linux.stack_t; const sigset_t = linux.sigset_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { restart_syscall = 0, exit = 1, fork = 2, @@ -295,7 +295,7 @@ pub const SYS = extern enum(usize) { mknodat = 288, fchownat = 289, futimesat = 290, - newfstatat = 291, + fstatat = 291, unlinkat = 292, renameat = 293, linkat = 294, diff --git a/lib/std/os/bits/linux/prctl.zig b/lib/std/os/bits/linux/prctl.zig index 151acf4e71..249e60eca3 100644 --- a/lib/std/os/bits/linux/prctl.zig +++ b/lib/std/os/bits/linux/prctl.zig @@ -4,7 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -pub const PR = extern enum(i32) { +pub const PR = enum(i32) { SET_PDEATHSIG = 1, GET_PDEATHSIG = 2, diff --git a/lib/std/os/bits/linux/riscv64.zig b/lib/std/os/bits/linux/riscv64.zig index 0cbdea415c..eedb53da01 100644 --- a/lib/std/os/bits/linux/riscv64.zig +++ b/lib/std/os/bits/linux/riscv64.zig @@ -9,7 +9,7 @@ const uid_t = std.os.linux.uid_t; const gid_t = std.os.linux.gid_t; const pid_t = std.os.linux.pid_t; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { pub const arch_specific_syscall = 244; io_setup = 0, diff --git a/lib/std/os/bits/linux/sparc64.zig b/lib/std/os/bits/linux/sparc64.zig index 5644256a95..5c67b745f0 100644 --- a/lib/std/os/bits/linux/sparc64.zig +++ b/lib/std/os/bits/linux/sparc64.zig @@ -12,7 +12,7 @@ const socklen_t = linux.socklen_t; const iovec = linux.iovec; const iovec_const = linux.iovec_const; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { restart_syscall = 0, exit = 1, fork = 2, diff --git a/lib/std/os/bits/linux/x86_64.zig b/lib/std/os/bits/linux/x86_64.zig index 88d277a0c5..30e5af384f 100644 --- a/lib/std/os/bits/linux/x86_64.zig +++ b/lib/std/os/bits/linux/x86_64.zig @@ -21,7 +21,7 @@ const iovec_const = linux.iovec_const; pub const mode_t = usize; pub const time_t = isize; -pub const SYS = extern enum(usize) { +pub const SYS = enum(usize) { read = 0, write = 1, open = 2, @@ -284,7 +284,6 @@ pub const SYS = extern enum(usize) { mknodat = 259, fchownat = 260, futimesat = 261, - newfstatat = 262, fstatat = 262, unlinkat = 263, renameat = 264, diff --git a/lib/std/os/bits/netbsd.zig b/lib/std/os/bits/netbsd.zig index dfb6c3bdf9..1fd0eabc20 100644 --- a/lib/std/os/bits/netbsd.zig +++ b/lib/std/os/bits/netbsd.zig @@ -60,7 +60,7 @@ pub const addrinfo = extern struct { next: ?*addrinfo, }; -pub const EAI = extern enum(c_int) { +pub const EAI = enum(c_int) { /// address family for hostname not supported ADDRFAMILY = 1, @@ -1179,7 +1179,7 @@ pub const IPPROTO_PFSYNC = 240; /// raw IP packet pub const IPPROTO_RAW = 255; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU = 0, FSIZE = 1, DATA = 2, @@ -1190,11 +1190,11 @@ pub const rlimit_resource = extern enum(c_int) { NPROC = 7, NOFILE = 8, SBSIZE = 9, - AS = 10, VMEM = 10, NTHR = 11, - _, + + pub const AS: rlimit_resource = .VMEM; }; pub const rlim_t = u64; diff --git a/lib/std/os/bits/openbsd.zig b/lib/std/os/bits/openbsd.zig index 8d1e74ec20..6810ab9a33 100644 --- a/lib/std/os/bits/openbsd.zig +++ b/lib/std/os/bits/openbsd.zig @@ -76,7 +76,7 @@ pub const addrinfo = extern struct { next: ?*addrinfo, }; -pub const EAI = extern enum(c_int) { +pub const EAI = enum(c_int) { /// address family for hostname not supported ADDRFAMILY = -9, @@ -805,7 +805,7 @@ comptime { if (@sizeOf(usize) == 4) std.debug.assert(@sizeOf(siginfo_t) == 128) else - // Take into account the padding between errno and data fields. + // Take into account the padding between errno and data fields. std.debug.assert(@sizeOf(siginfo_t) == 136); } @@ -1177,7 +1177,7 @@ pub const IPPROTO_PFSYNC = 240; /// raw IP packet pub const IPPROTO_RAW = 255; -pub const rlimit_resource = extern enum(c_int) { +pub const rlimit_resource = enum(c_int) { CPU, FSIZE, DATA, diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index ad73d87bae..555a67cd55 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1143,8 +1143,6 @@ pub fn lstat(pathname: [*:0]const u8, statbuf: *kernel_stat) usize { pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *kernel_stat, flags: u32) usize { if (@hasField(SYS, "fstatat64")) { return syscall4(.fstatat64, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); - } else if (@hasField(SYS, "newfstatat")) { - return syscall4(.newfstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); } else { return syscall4(.fstatat, @bitCast(usize, @as(isize, dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags); } diff --git a/lib/std/os/uefi/status.zig b/lib/std/os/uefi/status.zig index ccf50d8515..48b8008b91 100644 --- a/lib/std/os/uefi/status.zig +++ b/lib/std/os/uefi/status.zig @@ -5,7 +5,7 @@ // and substantial portions of the software. const high_bit = 1 << @typeInfo(usize).Int.bits - 1; -pub const Status = extern enum(usize) { +pub const Status = enum(usize) { /// The operation completed successfully. Success = 0, diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig index efe981c93c..5b9294f921 100644 --- a/lib/std/os/windows/bits.zig +++ b/lib/std/os/windows/bits.zig @@ -281,7 +281,7 @@ pub const IO_STATUS_BLOCK = extern struct { Information: ULONG_PTR, }; -pub const FILE_INFORMATION_CLASS = extern enum { +pub const FILE_INFORMATION_CLASS = enum(c_int) { FileDirectoryInformation = 1, FileFullDirectoryInformation, FileBothDirectoryInformation, @@ -901,7 +901,7 @@ pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED; pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED; pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE; pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY; -pub const COINIT = extern enum { +pub const COINIT = enum(c_int) { COINIT_APARTMENTTHREADED = 2, COINIT_MULTITHREADED = 0, COINIT_DISABLE_OLE1DDE = 4, @@ -1623,7 +1623,7 @@ pub const SD_RECEIVE = 0; pub const SD_SEND = 1; pub const SD_BOTH = 2; -pub const OBJECT_INFORMATION_CLASS = extern enum { +pub const OBJECT_INFORMATION_CLASS = enum(c_int) { ObjectBasicInformation = 0, ObjectNameInformation = 1, ObjectTypeInformation = 2, diff --git a/lib/std/os/windows/ntstatus.zig b/lib/std/os/windows/ntstatus.zig index b86cd1186b..1657f70a5e 100644 --- a/lib/std/os/windows/ntstatus.zig +++ b/lib/std/os/windows/ntstatus.zig @@ -4,7 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. // NTSTATUS codes from https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/596a1078-e883-4972-9bbc-49e60bebca55? -pub const NTSTATUS = extern enum(u32) { +pub const NTSTATUS = enum(u32) { /// The operation completed successfully. SUCCESS = 0x00000000, diff --git a/lib/std/os/windows/win32error.zig b/lib/std/os/windows/win32error.zig index 61bbcac8bb..b66d1734cb 100644 --- a/lib/std/os/windows/win32error.zig +++ b/lib/std/os/windows/win32error.zig @@ -4,7 +4,7 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. // Codes are from https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/18d8fbe8-a967-4f1c-ae50-99ca8e491d2d -pub const Win32Error = extern enum(u16) { +pub const Win32Error = enum(u16) { /// The operation completed successfully. SUCCESS = 0, diff --git a/lib/std/os/windows/ws2_32.zig b/lib/std/os/windows/ws2_32.zig index 1dd2ce738b..90c75abd9e 100644 --- a/lib/std/os/windows/ws2_32.zig +++ b/lib/std/os/windows/ws2_32.zig @@ -256,7 +256,7 @@ pub const POLLHUP = 0x0002; pub const POLLNVAL = 0x0004; // https://docs.microsoft.com/en-au/windows/win32/winsock/windows-sockets-error-codes-2 -pub const WinsockError = extern enum(u16) { +pub const WinsockError = enum(u16) { /// Specified event object handle is invalid. /// An application attempts to use an event object, but the specified handle is not valid. WSA_INVALID_HANDLE = 6, diff --git a/lib/std/pdb.zig b/lib/std/pdb.zig index de0b8f3ec0..2b953aa5ac 100644 --- a/lib/std/pdb.zig +++ b/lib/std/pdb.zig @@ -115,7 +115,7 @@ pub const StreamType = enum(u16) { /// Duplicate copy of SymbolRecordKind, but using the official CV names. Useful /// for reference purposes and when dealing with unknown record types. -pub const SymbolKind = packed enum(u16) { +pub const SymbolKind = enum(u16) { S_COMPILE = 1, S_REGISTER_16t = 2, S_CONSTANT_16t = 3, @@ -426,7 +426,7 @@ pub const FileChecksumEntryHeader = packed struct { ChecksumKind: u8, }; -pub const DebugSubsectionKind = packed enum(u32) { +pub const DebugSubsectionKind = enum(u32) { None = 0, Symbols = 0xf1, Lines = 0xf2, diff --git a/lib/std/valgrind.zig b/lib/std/valgrind.zig index 0e5d2072ac..1b4365aab2 100644 --- a/lib/std/valgrind.zig +++ b/lib/std/valgrind.zig @@ -48,7 +48,7 @@ pub fn doClientRequest(default: usize, request: usize, a1: usize, a2: usize, a3: } } -pub const ClientRequest = extern enum { +pub const ClientRequest = enum(u32) { RunningOnValgrind = 4097, DiscardTranslations = 4098, ClientCall0 = 4353, @@ -156,9 +156,9 @@ pub fn freeLikeBlock(addr: [*]u8, rzB: usize) void { } /// Create a memory pool. -pub const MempoolFlags = extern enum { - AutoFree = 1, - MetaPool = 2, +pub const MempoolFlags = struct { + pub const AutoFree = 1; + pub const MetaPool = 2; }; pub fn createMempool(pool: [*]u8, rzB: usize, is_zeroed: bool, flags: usize) void { doClientRequestStmt(.CreateMempool, @ptrToInt(pool), rzB, @boolToInt(is_zeroed), flags, 0); diff --git a/lib/std/valgrind/callgrind.zig b/lib/std/valgrind/callgrind.zig index 3962ad3e3a..d29e1903fb 100644 --- a/lib/std/valgrind/callgrind.zig +++ b/lib/std/valgrind/callgrind.zig @@ -6,7 +6,7 @@ const std = @import("../std.zig"); const valgrind = std.valgrind; -pub const CallgrindClientRequest = extern enum { +pub const CallgrindClientRequest = enum(usize) { DumpStats = valgrind.ToolBase("CT"), ZeroStats, ToggleCollect, diff --git a/lib/std/valgrind/memcheck.zig b/lib/std/valgrind/memcheck.zig index 3226beec53..2de5d8a674 100644 --- a/lib/std/valgrind/memcheck.zig +++ b/lib/std/valgrind/memcheck.zig @@ -7,7 +7,7 @@ const std = @import("../std.zig"); const testing = std.testing; const valgrind = std.valgrind; -pub const MemCheckClientRequest = extern enum { +pub const MemCheckClientRequest = enum(usize) { MakeMemNoAccess = valgrind.ToolBase("MC".*), MakeMemUndefined, MakeMemDefined, @@ -76,7 +76,7 @@ pub fn createBlock(qzz: []u8, desc: [*]u8) usize { /// Discard a block-description-handle. Returns 1 for an /// invalid handle, 0 for a valid handle. -pub fn discard(blkindex) bool { +pub fn discard(blkindex: usize) bool { return doMemCheckClientRequestExpr(0, // default return .Discard, 0, blkindex, 0, 0, 0) != 0; } diff --git a/src/AstGen.zig b/src/AstGen.zig index 1080506192..2d34a938a7 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -2658,7 +2658,9 @@ fn fnDecl( var i: usize = 0; var it = fn_proto.iterate(tree.*); while (it.next()) |param| : (i += 1) { - const name_token = param.name_token.?; + const name_token = param.name_token orelse { + return astgen.failNode(param.type_expr, "missing parameter name", .{}); + }; const param_name = try astgen.identifierTokenString(name_token); const sub_scope = try astgen.arena.create(Scope.LocalVal); sub_scope.* = .{ diff --git a/src/Compilation.zig b/src/Compilation.zig index 7a496ccc45..cab4ba5e15 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -3220,7 +3220,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: *Allocator) Alloc \\const std = @import("std"); \\/// Zig version. When writing code that supports multiple versions of Zig, prefer \\/// feature detection (i.e. with `@hasDecl` or `@hasField`) over version checks. - \\pub const zig_version = try std.SemanticVersion.parse("{s}"); + \\pub const zig_version = std.SemanticVersion.parse("{s}") catch unreachable; \\/// Temporary until self-hosted is feature complete. \\pub const zig_is_stage2 = {}; \\/// Temporary until self-hosted supports the `cpu.arch` value.