2 use rustc_ast::tokenstream::{DelimSpan, TokenStream};
4 use rustc_expand::base::*;
5 use rustc_span::symbol::sym;
8 // This expands to either
9 // - `$crate::panic::panic_2015!(...)` or
10 // - `$crate::panic::panic_2021!(...)`
11 // depending on the edition.
13 // This is used for both std::panic!() and core::panic!().
15 // `$crate` will refer to either the `std` or `core` crate depending on which
16 // one we're expanding from.
17 pub fn expand_panic<'cx>(
18 cx: &'cx mut ExtCtxt<'_>,
21 ) -> Box<dyn MacResult + 'cx> {
22 let panic = if sp.rust_2021() { sym::panic_2021 } else { sym::panic_2015 };
24 let sp = cx.with_call_site_ctxt(sp);
29 ExprKind::MacCall(MacCall {
33 .std_path(&[sym::panic, panic])
35 .map(|ident| PathSegment::from_ident(ident))
39 args: P(MacArgs::Delimited(
40 DelimSpan::from_single(sp),
41 MacDelimiter::Parenthesis,
44 prior_type_ascription: None,