From 0e6285c8fc31ff866df96847fe34e660da38b4a9 Mon Sep 17 00:00:00 2001 From: Ali Chraghi Date: Sun, 22 May 2022 19:36:59 +0430 Subject: math: make `cast` return optional instead of an error --- src/Sema.zig | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/Sema.zig') 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, -- cgit v1.2.3