From c01937b402b23400a20725fb083d5a988096c5a3 Mon Sep 17 00:00:00 2001 From: Sidney Cammeresi Date: Mon, 7 Oct 2024 08:50:32 -0700 Subject: [PATCH] Clamp width settings to max_width before warning about exceeding it Within a macro scope, max_width is reduced, which can trigger warnings if it is reduced below some other width setting (e.g. struct_lit_width.) Width settings were already being clamped to max_width, but only after the warning fired. The order is now reversed. --- src/config/config_type.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 14217caba0a..7671144c9b6 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -431,18 +431,24 @@ macro_rules! create_config { heuristic_value: usize, config_key: &str, | -> usize { - if !was_set { - return heuristic_value; - } - if override_value > max_width { + let value = if !was_set { + heuristic_value + } else { + override_value + }; + + let value = value.min(max_width); + + if value > max_width { eprintln!( "`{0}` cannot have a value that exceeds `max_width`. \ `{0}` will be set to the same value as `max_width`", config_key, ); - return max_width; + max_width + } else { + value } - override_value }; let fn_call_width = get_width_value(