From 4ca127789d167f5d82c0e76e57649e35216afffc Mon Sep 17 00:00:00 2001 From: Falco Hirschenberger Date: Thu, 24 Jul 2014 23:49:30 +0200 Subject: [PATCH] Fix display of `-NaN%` in borrock stats caused by div by zero --- src/librustc/middle/borrowck/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs index 5604d33496d..c9cdcc5bc0d 100644 --- a/src/librustc/middle/borrowck/mod.rs +++ b/src/librustc/middle/borrowck/mod.rs @@ -98,9 +98,9 @@ pub fn check_crate(tcx: &ty::ctxt, } fn make_stat(bccx: &BorrowckCtxt, stat: uint) -> String { - let stat_f = stat as f64; let total = bccx.stats.guaranteed_paths.get() as f64; - format!("{} ({:.0f}%)", stat , stat_f * 100.0 / total) + let perc = if total == 0.0 { 0.0 } else { stat as f64 * 100.0 / total }; + format!("{} ({:.0f}%)", stat, perc) } }