]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_builtin_macros/src/alloc_error_handler.rs
Rollup merge of #102406 - mejrs:missing_copy, r=wesleywiser
[rust.git] / compiler / rustc_builtin_macros / src / alloc_error_handler.rs
index 460175ed2ac84bb35abb7d29181ac418ecb5cd61..95e38e4b053f496604f25079b22722e2fbf3dc4b 100644 (file)
@@ -17,32 +17,23 @@ pub fn expand(
     check_builtin_macro_attribute(ecx, meta_item, sym::alloc_error_handler);
 
     let orig_item = item.clone();
-    let not_function = || {
-        ecx.sess
-            .parse_sess
-            .span_diagnostic
-            .span_err(item.span(), "alloc_error_handler must be a function");
-        vec![orig_item.clone()]
-    };
 
     // Allow using `#[alloc_error_handler]` on an item statement
     // FIXME - if we get deref patterns, use them to reduce duplication here
-    let (item, is_stmt, sig_span) = match &item {
-        Annotatable::Item(item) => match item.kind {
-            ItemKind::Fn(ref fn_kind) => (item, false, ecx.with_def_site_ctxt(fn_kind.sig.span)),
-            _ => return not_function(),
-        },
-        Annotatable::Stmt(stmt) => match &stmt.kind {
-            StmtKind::Item(item_) => match item_.kind {
-                ItemKind::Fn(ref fn_kind) => {
-                    (item_, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
-                }
-                _ => return not_function(),
-            },
-            _ => return not_function(),
-        },
-        _ => return not_function(),
-    };
+    let (item, is_stmt, sig_span) =
+        if let Annotatable::Item(item) = &item
+            && let ItemKind::Fn(fn_kind) = &item.kind
+        {
+            (item, false, ecx.with_def_site_ctxt(fn_kind.sig.span))
+        } else if let Annotatable::Stmt(stmt) = &item
+            && let StmtKind::Item(item) = &stmt.kind
+            && let ItemKind::Fn(fn_kind) = &item.kind
+        {
+            (item, true, ecx.with_def_site_ctxt(fn_kind.sig.span))
+        } else {
+            ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "alloc_error_handler must be a function");
+            return vec![orig_item.clone()];
+        };
 
     // Generate a bunch of new items using the AllocFnFactory
     let span = ecx.with_def_site_ctxt(item.span);