From c5214df981a88d30226e9b3ac1b88da32395806a Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 27 Feb 2026 16:24:14 -0700 Subject: [PATCH] Don't panic in duration underflow In debug mode we check for tokens being dropped out of order, but in a release build this can fail. --- cranelift/codegen/src/timing.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cranelift/codegen/src/timing.rs b/cranelift/codegen/src/timing.rs index a06c6001ef41..8eb4630ba0ec 100644 --- a/cranelift/codegen/src/timing.rs +++ b/cranelift/codegen/src/timing.rs @@ -171,7 +171,10 @@ mod enabled { /// Returns the total amount of time taken by all the passes measured. pub fn total(&self) -> Duration { - self.pass.iter().map(|p| p.total - p.child).sum() + self.pass + .iter() + .map(|p| p.total.saturating_sub(p.child)) + .sum() } }