From 1a42bdf182eb4e671c44279888b9e4e720abe390 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 21 Jan 2024 16:16:37 -0800 Subject: [PATCH] Stop using num_traits in builtin return This can be simplified using the builtin abs() function. --- src/builtins/return.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/builtins/return.rs b/src/builtins/return.rs index 77d46232e..0be3680d6 100644 --- a/src/builtins/return.rs +++ b/src/builtins/return.rs @@ -1,7 +1,5 @@ // Implementation of the return builtin. -use num_traits::abs; - use super::prelude::*; #[derive(Debug, Clone, Copy, Default)] @@ -59,8 +57,9 @@ pub fn r#return(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> // Map negative values to (256 - their absolute value). This prevents `return -1` from // evaluating to a `$status` of 0 and keeps us from running into undefined behavior by trying to // left shift a negative value in W_EXITCODE(). + // Note in Rust, dividend % divisor has the same sign as the dividend. if retval < 0 { - retval = 256 - (abs(retval) % 256); + retval = 256 - (retval % 256).abs(); } // If we're not in a function, exit the current script (but not an interactive shell).