Skip to content

Commit 298acef

Browse files
committed
Move if-block into closure to reduce duplicate code
1 parent d0ea440 commit 298acef

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

compiler/rustc_builtin_macros/src/format.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,19 @@ impl PositionalNamedArg {
8181
// For the message span, if there is formatting, we want to use the opening `{` and the
8282
// next character, which will the `:` indicating the start of formatting. If there is
8383
// not any formatting, we want to underline the entire span.
84-
if self.has_formatting {
85-
cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| {
84+
cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| {
85+
if self.has_formatting {
8686
(
8787
Some(arg_span.with_lo(arg_span.lo() + BytePos(1)).shrink_to_lo()),
8888
Some(arg_span.with_hi(arg_span.lo() + BytePos(2))),
8989
)
90-
})
91-
} else {
92-
cx.arg_spans.get(self.cur_piece).map_or((None, None), |arg_span| {
90+
} else {
9391
let replace_start = arg_span.lo() + BytePos(1);
9492
let replace_end = arg_span.hi() - BytePos(1);
9593
let to_replace = arg_span.with_lo(replace_start).with_hi(replace_end);
9694
(Some(to_replace), Some(*arg_span))
97-
})
98-
}
95+
}
96+
})
9997
} else {
10098
(None, None)
10199
}

0 commit comments

Comments
 (0)