Skip to content

Commit 9b36156

Browse files
committed
Do not scale WidthHeuristics when max_width less than 100
1 parent 36c49d7 commit 9b36156

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/config/options.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,14 @@ impl WidthHeuristics {
242242

243243
// scale the default WidthHeuristics according to max_width
244244
pub fn scaled(max_width: usize) -> WidthHeuristics {
245-
let mut max_width_ratio: f32 = max_width as f32 / 100.0; // 100 is the default width -> default ratio is 1
246-
max_width_ratio = (max_width_ratio * 10.0).round() / 10.0; // round to the closest 0.1
245+
const DEFAULT_MAX_WIDTH: usize = 100;
246+
let max_width_ratio = if max_width > DEFAULT_MAX_WIDTH {
247+
let ratio = max_width as f32 / DEFAULT_MAX_WIDTH as f32;
248+
// round to the closest 0.1
249+
(ratio * 10.0).round() / 10.0
250+
} else {
251+
1.0
252+
};
247253
WidthHeuristics {
248254
fn_call_width: (60.0 * max_width_ratio).round() as usize,
249255
struct_lit_width: (18.0 * max_width_ratio).round() as usize,

0 commit comments

Comments
 (0)