Only call span.rust_2021() when necessary.
This commit is contained in:
parent
8098ac1706
commit
a730970dff
1 changed files with 5 additions and 7 deletions
|
@ -12,25 +12,23 @@ use rustc_span::{Span, DUMMY_SP};
|
||||||
|
|
||||||
pub fn expand_assert<'cx>(
|
pub fn expand_assert<'cx>(
|
||||||
cx: &'cx mut ExtCtxt<'_>,
|
cx: &'cx mut ExtCtxt<'_>,
|
||||||
sp: Span,
|
span: Span,
|
||||||
tts: TokenStream,
|
tts: TokenStream,
|
||||||
) -> Box<dyn MacResult + 'cx> {
|
) -> 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,
|
Ok(assert) => assert,
|
||||||
Err(mut err) => {
|
Err(mut err) => {
|
||||||
err.emit();
|
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
|
// `core::panic` and `std::panic` are different macros, so we use call-site
|
||||||
// context to pick up whichever is currently in scope.
|
// 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 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!()`.
|
// On edition 2021, we always call `$crate::panic!()`.
|
||||||
Path {
|
Path {
|
||||||
span: sp,
|
span: sp,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue