diff options
| author | Ali Chraghi <chraghiali1@gmail.com> | 2022-05-22 19:36:59 +0430 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-05-27 16:43:33 -0400 |
| commit | 0e6285c8fc31ff866df96847fe34e660da38b4a9 (patch) | |
| tree | 5d5830d5b3ce6c13041aacb7e073763551cb4852 /src/Sema.zig | |
| parent | ddd5b57045d38b7d1f7d5a4120302797433233cd (diff) | |
| download | zig-0e6285c8fc31ff866df96847fe34e660da38b4a9.tar.gz zig-0e6285c8fc31ff866df96847fe34e660da38b4a9.zip | |
math: make `cast` return optional instead of an error
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 269a9c7587..e0310e5ad7 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -21786,9 +21786,7 @@ fn cmpNumeric( const dest_ty = if (dest_float_type) |ft| ft else blk: { const max_bits = std.math.max(lhs_bits, rhs_bits); - const casted_bits = std.math.cast(u16, max_bits) catch |err| switch (err) { - error.Overflow => return sema.fail(block, src, "{d} exceeds maximum integer bit count", .{max_bits}), - }; + const casted_bits = std.math.cast(u16, max_bits) orelse return sema.fail(block, src, "{d} exceeds maximum integer bit count", .{max_bits}); const signedness: std.builtin.Signedness = if (dest_int_is_signed) .signed else .unsigned; break :blk try Module.makeIntType(sema.arena, signedness, casted_bits); }; @@ -24073,9 +24071,7 @@ fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr /// is too big to fit. fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError!usize { if (@bitSizeOf(u64) <= @bitSizeOf(usize)) return int; - return std.math.cast(usize, int) catch |err| switch (err) { - error.Overflow => return sema.fail(block, src, "expression produces integer value {d} which is too big for this compiler implementation to handle", .{int}), - }; + return std.math.cast(usize, int) orelse return sema.fail(block, src, "expression produces integer value {d} which is too big for this compiler implementation to handle", .{int}); } /// For pointer-like optionals, it returns the pointer type. For pointers, |
