Skip to content

Commit

Permalink
Rollup merge of #125996 - tmiasko:closure-recursively-reachable, r=ol…
Browse files Browse the repository at this point in the history
…i-obk

Closures are recursively reachable

Fixes #126012.
  • Loading branch information
workingjubilee authored Jun 5, 2024
2 parents 6b6b698 + 5d26f58 commit eb2819e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl<'tcx> ReachableContext<'tcx> {
}
hir::ImplItemKind::Type(_) => false,
},
Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(..), .. }) => true,
_ => false,
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/cross-crate/auxiliary/static_init_aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/cross-crate/static-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,4 +20,5 @@ fn main() {
G();
H();
I();
K()();
}

0 comments on commit eb2819e

Please sign in to comment.