Skip to content

Commit 0c53b45

Browse files
authored
Rollup merge of rust-lang#57461 - nnethercote:ParseResult-Failure-static-str, r=simulacrum
Change `String` to `&'static str` in `ParseResult::Failure`. This avoids 770,000 allocations when compiling the `html5ever` benchmark, reducing instruction counts by up to 2%.
2 parents b7093e5 + 46fa818 commit 0c53b45

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub enum ParseResult<T> {
271271
Success(T),
272272
/// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected
273273
/// end of macro invocation. Otherwise, it indicates that no rules expected the given token.
274-
Failure(syntax_pos::Span, Token, String),
274+
Failure(syntax_pos::Span, Token, &'static str),
275275
/// Fatal error (malformed macro?). Abort compilation.
276276
Error(syntax_pos::Span, String),
277277
}
@@ -721,7 +721,7 @@ pub fn parse(
721721
sess.source_map().next_point(parser.span)
722722
},
723723
token::Eof,
724-
"missing tokens in macro arguments".to_string(),
724+
"missing tokens in macro arguments",
725725
);
726726
}
727727
}
@@ -760,7 +760,7 @@ pub fn parse(
760760
return Failure(
761761
parser.span,
762762
parser.token,
763-
"no rules expected this token in macro call".to_string(),
763+
"no rules expected this token in macro call",
764764
);
765765
}
766766
// Dump all possible `next_items` into `cur_items` for the next iteration.

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
202202
let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
203203
let span = best_fail_spot.substitute_dummy(sp);
204204
let mut err = cx.struct_span_err(span, &best_fail_msg);
205-
err.span_label(span, best_fail_text.unwrap_or(best_fail_msg));
205+
err.span_label(span, best_fail_text.unwrap_or(&best_fail_msg));
206206
if let Some(sp) = def_span {
207207
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
208208
err.span_label(cx.source_map().def_span(sp), "when calling this macro");

0 commit comments

Comments
 (0)