Skip to content

Commit 001e90d

Browse files
authored
Rollup merge of rust-lang#100933 - a1phyr:cheap_assert_match_failed, r=JoshTriplett
Reduce code size of `assert_matches_failed` Using `write_str` instead of `<str as Display>::fmt` avoids the `pad` function which is very expensive to have in size-constrained code.
2 parents 6da589b + 289d7cc commit 001e90d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

library/core/src/panicking.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ pub fn assert_matches_failed<T: fmt::Debug + ?Sized>(
190190
right: &str,
191191
args: Option<fmt::Arguments<'_>>,
192192
) -> ! {
193-
// Use the Display implementation to display the pattern.
193+
// The pattern is a string so it can be displayed directly.
194194
struct Pattern<'a>(&'a str);
195195
impl fmt::Debug for Pattern<'_> {
196196
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
197-
fmt::Display::fmt(self.0, f)
197+
f.write_str(self.0)
198198
}
199199
}
200200
assert_failed_inner(AssertKind::Match, &left, &Pattern(right), args);

0 commit comments

Comments
 (0)