mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 14:31:02 +02:00
Replace subtraction of Instants and Durations with saturating subtractions (#12549)
# Description Duration can not be negative, and an underflow causes a panic. This should fix #12539 as from what I can tell that bug was caused in `nu-explore:📟:events` from subtracting durations, but I figured this might be more widespread, and saturating to zero generally makes sense. I also added the relevant clippy lint to try to prevent this from happening in the future. I can't think of a reason we would ever want to subtract durations without checking first. cc @fdncred # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib`
This commit is contained in:
@ -47,7 +47,7 @@ impl UIEvents {
|
||||
}
|
||||
|
||||
let time_spent = now.elapsed();
|
||||
let rest = self.tick_rate - time_spent;
|
||||
let rest = self.tick_rate.saturating_sub(time_spent);
|
||||
|
||||
Self { tick_rate: rest }.next()
|
||||
}
|
||||
|
Reference in New Issue
Block a user