From 298acef30730ee676fdbc9e731370cd7ccedd431 Mon Sep 17 00:00:00 2001 From: Preston From Date: Tue, 2 Aug 2022 00:20:12 -0600 Subject: [PATCH] Move if-block into closure to reduce duplicate code --- compiler/rustc_builtin_macros/src/format.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index e6d514e76d2e..4f3cda16f037 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -81,21 +81,19 @@ impl PositionalNamedArg { // For the message span, if there is formatting, we want to use the opening `{` and the // next character, which will the `:` indicating the start of formatting. If there is // not any formatting, we want to underline the entire span. - if self.has_formatting { - cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| { + cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| { + if self.has_formatting { ( Some(arg_span.with_lo(arg_span.lo() + BytePos(1)).shrink_to_lo()), Some(arg_span.with_hi(arg_span.lo() + BytePos(2))), ) - }) - } else { - cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| { + } else { let replace_start = arg_span.lo() + BytePos(1); let replace_end = arg_span.hi() - BytePos(1); let to_replace = arg_span.with_lo(replace_start).with_hi(replace_end); (Some(to_replace), Some(*arg_span)) - }) - } + } + }) } else { (None, None) }