Skip to content

Commit

Permalink
Rollup merge of rust-lang#125996 - tmiasko:closure-recursively-reacha…
Browse files Browse the repository at this point in the history
…ble, r=oli-obk

Closures are recursively reachable
  • Loading branch information
fmease authored Jun 4, 2024
2 parents b6117c6 + 5d26f58 commit a82d14b
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 a82d14b

Please sign in to comment.