diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2024-06-04 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2024-06-04 22:50:35 +0200 |
| commit | 5d26f58423f72e300ef48df591c08e3d446b51aa (patch) | |
| tree | 56a1bf3faac058d9f319ca5da8c02f0d9b176581 | |
| parent | 44701e070c8453df10df1984944258018ac21610 (diff) | |
| download | rust-5d26f58423f72e300ef48df591c08e3d446b51aa.tar.gz rust-5d26f58423f72e300ef48df591c08e3d446b51aa.zip | |
Closures are recursively reachable
| -rw-r--r-- | compiler/rustc_passes/src/reachable.rs | 1 | ||||
| -rw-r--r-- | tests/ui/cross-crate/auxiliary/static_init_aux.rs | 6 | ||||
| -rw-r--r-- | tests/ui/cross-crate/static-init.rs | 2 |
3 files changed, 9 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index ab1dd248556..954a1ab6560 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -157,6 +157,7 @@ impl<'tcx> ReachableContext<'tcx> { } hir::ImplItemKind::Type(_) => false, }, + Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => true, _ => false, } } diff --git a/tests/ui/cross-crate/auxiliary/static_init_aux.rs b/tests/ui/cross-crate/auxiliary/static_init_aux.rs index dca708733b9..832cee8d4d4 100644 --- a/tests/ui/cross-crate/auxiliary/static_init_aux.rs +++ b/tests/ui/cross-crate/auxiliary/static_init_aux.rs @@ -3,6 +3,12 @@ pub static F: fn() = f; pub static G: fn() = G0; pub static H: &(dyn Fn() + Sync) = &h; pub static I: fn() = Helper(j).mk(); +pub static K: fn() -> fn() = { + #[inline(never)] + fn k() {} + #[inline(always)] + || -> fn() { k } +}; static X: u32 = 42; static G0: fn() = g; diff --git a/tests/ui/cross-crate/static-init.rs b/tests/ui/cross-crate/static-init.rs index c4697a1d010..f8003856c5c 100644 --- a/tests/ui/cross-crate/static-init.rs +++ b/tests/ui/cross-crate/static-init.rs @@ -8,6 +8,7 @@ static F: fn() = aux::F; static G: fn() = aux::G; static H: &(dyn Fn() + Sync) = aux::H; static I: fn() = aux::I; +static K: fn() -> fn() = aux::K; fn v() -> *const u32 { V @@ -19,4 +20,5 @@ fn main() { G(); H(); I(); + K()(); } |
