]> git.lizzy.rs Git - rust.git/commitdiff
Fix display of `-NaN%` in borrock stats caused by div by zero
authorFalco Hirschenberger <falco.hirschenberger@gmail.com>
Thu, 24 Jul 2014 21:49:30 +0000 (23:49 +0200)
committerFalco Hirschenberger <falco.hirschenberger@gmail.com>
Thu, 24 Jul 2014 21:49:30 +0000 (23:49 +0200)
src/librustc/middle/borrowck/mod.rs

index 5604d33496d9dfc0e6f37d9831abc8b4eaa732b5..c9cdcc5bc0dc01c3f4ea9321659f0d1fb847b1e2 100644 (file)
@@ -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)
     }
 }