Can't the compiler copy a static reference?

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

surdeus

Warning

This post was published 49 days ago. The information described in this article may have changed.
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