diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-12-06 13:22:36 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-12-06 14:45:58 +0000 |
| commit | 700c095306ce89b0b18e2487aae9c0721e60a5e3 (patch) | |
| tree | 50e8a78e271c55895f1875234640d0bce83591f3 /compiler/rustc_builtin_macros/src/global_allocator.rs | |
| parent | 244990a6e91843289e094b384d67294756891fe9 (diff) | |
| download | rust-700c095306ce89b0b18e2487aae9c0721e60a5e3.tar.gz rust-700c095306ce89b0b18e2487aae9c0721e60a5e3.zip | |
`rustc_builtin_macros`: remove `ref` patterns
... and other pattern matching improvements
Diffstat (limited to 'compiler/rustc_builtin_macros/src/global_allocator.rs')
| -rw-r--r-- | compiler/rustc_builtin_macros/src/global_allocator.rs | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 0817aed037e..41531580c19 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -20,27 +20,23 @@ pub fn expand( check_builtin_macro_attribute(ecx, meta_item, sym::global_allocator); let orig_item = item.clone(); - let not_static = || { - ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "allocators must be statics"); - vec![orig_item.clone()] - }; // Allow using `#[global_allocator]` on an item statement // FIXME - if we get deref patterns, use them to reduce duplication here - let (item, is_stmt, ty_span) = match &item { - Annotatable::Item(item) => match item.kind { - ItemKind::Static(ref ty, ..) => (item, false, ecx.with_def_site_ctxt(ty.span)), - _ => return not_static(), - }, - Annotatable::Stmt(stmt) => match &stmt.kind { - StmtKind::Item(item_) => match item_.kind { - ItemKind::Static(ref ty, ..) => (item_, true, ecx.with_def_site_ctxt(ty.span)), - _ => return not_static(), - }, - _ => return not_static(), - }, - _ => return not_static(), - }; + let (item, is_stmt, ty_span) = + if let Annotatable::Item(item) = &item + && let ItemKind::Static(ty, ..) = &item.kind + { + (item, false, ecx.with_def_site_ctxt(ty.span)) + } else if let Annotatable::Stmt(stmt) = &item + && let StmtKind::Item(item) = &stmt.kind + && let ItemKind::Static(ty, ..) = &item.kind + { + (item, true, ecx.with_def_site_ctxt(ty.span)) + } else { + ecx.sess.parse_sess.span_diagnostic.span_err(item.span(), "allocators must be statics"); + return vec![orig_item.clone()] + }; // Generate a bunch of new items using the AllocFnFactory let span = ecx.with_def_site_ctxt(item.span); |
