Only call span.rust_2021() when necessary.

This commit is contained in:
Mara Bos 2021-01-24 14:15:15 +01:00
parent 8098ac1706
commit a730970dff
1 changed files with 5 additions and 7 deletions

View File

@ -12,25 +12,23 @@ use rustc_span::{Span, DUMMY_SP};
pub fn expand_assert<'cx>(
cx: &'cx mut ExtCtxt<'_>,
sp: Span,
span: Span,
tts: TokenStream,
) -> Box<dyn MacResult + 'cx> {
let Assert { cond_expr, custom_message } = match parse_assert(cx, sp, tts) {
let Assert { cond_expr, custom_message } = match parse_assert(cx, span, tts) {
Ok(assert) => assert,
Err(mut err) => {
err.emit();
return DummyResult::any(sp);
return DummyResult::any(span);
}
};
let is_2021 = sp.rust_2021();
// `core::panic` and `std::panic` are different macros, so we use call-site
// context to pick up whichever is currently in scope.
let sp = cx.with_call_site_ctxt(sp);
let sp = cx.with_call_site_ctxt(span);
let panic_call = if let Some(tokens) = custom_message {
let path = if is_2021 {
let path = if span.rust_2021() {
// On edition 2021, we always call `$crate::panic!()`.
Path {
span: sp,