Can't the compiler copy a static reference?

⚓ Rust    📅 2026-03-01    👤 surdeus    👁️ 1      

surdeus

fn f(a: &'static ()) -> impl Fn() {
    || g(a)
}

fn g(_: &'static ()) {}

The compiler requires me to write move here.
It's simple, but a little weird. Why can't the compiler copy a static reference?

It's even stranger when you realize that || g(&*a) also works

2 posts - 2 participants

Read full topic

🏷️ Rust_feed