Auto merge of #115670 - Zoxc:outline-panic-macro-1, r=Mark-Simulacrum
Partially outline code inside the panic! macro This outlines code inside the panic! macro in some cases. This is split out from https://github.com/rust-lang/rust/pull/115562 to exclude changes to rustc.
This commit is contained in:
@@ -228,16 +228,26 @@ pub enum PanicExpn<'a> {
|
||||
|
||||
impl<'a> PanicExpn<'a> {
|
||||
pub fn parse(expr: &'a Expr<'a>) -> Option<Self> {
|
||||
let ExprKind::Call(callee, [arg, rest @ ..]) = &expr.kind else {
|
||||
let ExprKind::Call(callee, args) = &expr.kind else {
|
||||
return None;
|
||||
};
|
||||
let ExprKind::Path(QPath::Resolved(_, path)) = &callee.kind else {
|
||||
return None;
|
||||
};
|
||||
let result = match path.segments.last().unwrap().ident.as_str() {
|
||||
let name = path.segments.last().unwrap().ident.as_str();
|
||||
|
||||
// This has no argument
|
||||
if name == "panic_cold_explicit" {
|
||||
return Some(Self::Empty);
|
||||
};
|
||||
|
||||
let [arg, rest @ ..] = args else {
|
||||
return None;
|
||||
};
|
||||
let result = match name {
|
||||
"panic" if arg.span.ctxt() == expr.span.ctxt() => Self::Empty,
|
||||
"panic" | "panic_str" => Self::Str(arg),
|
||||
"panic_display" => {
|
||||
"panic_display" | "panic_cold_display" => {
|
||||
let ExprKind::AddrOf(_, _, e) = &arg.kind else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user