Replace the String in ParseResult::Failure with Token.

This lets us delay creation of failure messages until they are needed,
which avoids ~1.6M allocations in html5ever.
This commit is contained in:
Nicholas Nethercote 2016-10-21 12:01:06 +11:00
parent e382267cfb
commit b817cf8b57
3 changed files with 31 additions and 15 deletions

View file

@ -25,6 +25,7 @@ use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder;
use syntax::ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
use syntax::ext::tt::macro_parser::{Success, Failure, Error};
use syntax::ext::tt::macro_parser::parse_failure_msg;
use syntax::ptr::P;
use syntax_pos::Span;
use rustc_plugin::Registry;
@ -58,8 +59,11 @@ fn expand_mbe_matches(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
_ => unreachable!()
}
}
Failure(_, s) | Error(_, s) => {
panic!("expected Success, but got Error/Failure: {}", s);
Failure(_, tok) => {
panic!("expected Success, but got Failure: {}", parse_failure_msg(tok));
}
Error(_, s) => {
panic!("expected Success, but got Error: {}", s);
}
};