mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-16 15:04:05 +00:00
Stop using num_traits in builtin return
This can be simplified using the builtin abs() function.
This commit is contained in:
parent
66ebd88c44
commit
1a42bdf182
1 changed files with 2 additions and 3 deletions
|
@ -1,7 +1,5 @@
|
||||||
// Implementation of the return builtin.
|
// Implementation of the return builtin.
|
||||||
|
|
||||||
use num_traits::abs;
|
|
||||||
|
|
||||||
use super::prelude::*;
|
use super::prelude::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default)]
|
#[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
|
// 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
|
// 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().
|
// left shift a negative value in W_EXITCODE().
|
||||||
|
// Note in Rust, dividend % divisor has the same sign as the dividend.
|
||||||
if retval < 0 {
|
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).
|
// If we're not in a function, exit the current script (but not an interactive shell).
|
||||||
|
|
Loading…
Reference in a new issue