|
1 | | -use rustc_ast::token::{Delimiter, Lit, LitKind, TokenKind}; |
2 | | -use rustc_ast::tokenstream::{TokenStream, TokenTree}; |
| 1 | +use rustc_ast::token::Delimiter; |
| 2 | +use rustc_ast::tokenstream::TokenStream; |
3 | 3 | use rustc_ast::*; |
4 | 4 | use rustc_expand::base::*; |
5 | 5 | use rustc_span::edition::Edition; |
6 | | -use rustc_span::{Ident, Span, Symbol, sym}; |
| 6 | +use rustc_span::{Span, Symbol, sym}; |
7 | 7 |
|
8 | 8 | // Use an enum to ensure that no new macro calls are added without also updating the message in the |
9 | 9 | // optimized path below. |
@@ -67,55 +67,6 @@ fn expand<'cx>( |
67 | 67 | ) -> MacroExpanderResult<'cx> { |
68 | 68 | let sp = cx.with_call_site_ctxt(sp); |
69 | 69 |
|
70 | | - // If the call is of the form `panic!(<string literal>)` and there are no formatting arguments |
71 | | - // in the string literal, we can call `core::panicking::panic` to centralize the panic logic. |
72 | | - if tts.len() == 1 |
73 | | - && let Some(TokenTree::Token(token, _)) = tts.get(0) |
74 | | - && let TokenKind::Literal(lit) = &token.kind |
75 | | - && let Lit { kind: LitKind::Str | LitKind::StrRaw(_), symbol, .. } = lit |
76 | | - && let msg = symbol.as_str() |
77 | | - && !msg.contains(|c| c == '{' || c == '}') |
78 | | - { |
79 | | - let msg = match mac { |
80 | | - InnerCall::Panic2015 | InnerCall::Panic2021 => cx.expr(sp, ExprKind::Lit(*lit)), |
81 | | - InnerCall::Unreachable2015 | InnerCall::Unreachable2021 => { |
82 | | - let msg = if msg.contains('\\') { |
83 | | - let mut buf = String::with_capacity(msg.len()); |
84 | | - // Force-inlining here is aggressive but the closure is |
85 | | - // called on every char in the string, so it can be hot in |
86 | | - // programs with many long strings containing escapes. |
87 | | - rustc_literal_escaper::unescape_str( |
88 | | - msg, |
89 | | - #[inline(always)] |
90 | | - |_, res| match res { |
91 | | - Ok(c) => buf.push(c), |
92 | | - Err(err) => { |
93 | | - assert!(!err.is_fatal(), "failed to unescape string literal") |
94 | | - } |
95 | | - }, |
96 | | - ); |
97 | | - buf |
98 | | - } else { |
99 | | - msg.to_owned() |
100 | | - }; |
101 | | - |
102 | | - cx.expr_str( |
103 | | - sp, |
104 | | - Symbol::intern(&format!("internal error: entered unreachable code: {msg}")), |
105 | | - ) |
106 | | - } |
107 | | - }; |
108 | | - |
109 | | - return ExpandResult::Ready(MacEager::expr(cx.expr_call( |
110 | | - sp, |
111 | | - cx.expr_path(cx.path_global( |
112 | | - sp, |
113 | | - [sym::core, sym::panicking, sym::panic].map(|sym| Ident::new(sym, sp)).to_vec(), |
114 | | - )), |
115 | | - [msg].into(), |
116 | | - ))); |
117 | | - } |
118 | | - |
119 | 70 | ExpandResult::Ready(MacEager::expr( |
120 | 71 | cx.expr_macro_call( |
121 | 72 | sp, |
|
0 commit comments