Partially outline code inside the panic! macro
This commit is contained in:
parent
a86e758228
commit
b5941a2fd5
4 changed files with 52 additions and 23 deletions
|
|
@ -227,16 +227,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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue