From 9b36156020f3c4eaad41268ae7f318954e4ccea1 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Wed, 2 May 2018 10:36:02 +0200 Subject: [PATCH] Do not scale WidthHeuristics when max_width less than 100 --- src/config/options.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/config/options.rs b/src/config/options.rs index 7bd3a51a9b49..c350aac8d960 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -242,8 +242,14 @@ impl WidthHeuristics { // scale the default WidthHeuristics according to max_width pub fn scaled(max_width: usize) -> WidthHeuristics { - let mut max_width_ratio: f32 = max_width as f32 / 100.0; // 100 is the default width -> default ratio is 1 - max_width_ratio = (max_width_ratio * 10.0).round() / 10.0; // round to the closest 0.1 + const DEFAULT_MAX_WIDTH: usize = 100; + let max_width_ratio = if max_width > DEFAULT_MAX_WIDTH { + let ratio = max_width as f32 / DEFAULT_MAX_WIDTH as f32; + // round to the closest 0.1 + (ratio * 10.0).round() / 10.0 + } else { + 1.0 + }; WidthHeuristics { fn_call_width: (60.0 * max_width_ratio).round() as usize, struct_lit_width: (18.0 * max_width_ratio).round() as usize,