diff options
| author | Preston From <prestonfrom@gmail.com> | 2022-08-02 00:20:12 -0600 |
|---|---|---|
| committer | Preston From <prestonfrom@gmail.com> | 2022-08-02 00:20:44 -0600 |
| commit | 298acef30730ee676fdbc9e731370cd7ccedd431 (patch) | |
| tree | 1f743fd466b364ae223c8a45019d82a9891a1873 | |
| parent | d0ea440dfe8659debd01246b5f2b8448abfb1e8b (diff) | |
| download | rust-298acef30730ee676fdbc9e731370cd7ccedd431.tar.gz rust-298acef30730ee676fdbc9e731370cd7ccedd431.zip | |
Move if-block into closure to reduce duplicate code
| -rw-r--r-- | compiler/rustc_builtin_macros/src/format.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index e6d514e76d2..4f3cda16f03 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) } |
