This is in preparation for https://github.com/rust-lang/rust/pull/124636, where we're making set_var unsafe. On old (pre-2024) editions, the unsafety error is downgraded to a warning so old code largely keeps working -- except when set_var is coerced to a function pointer, as is done by this crate (and by no other crate it seems); then the true type of set_var being an unsafe fn shines through and the build fails.
So to keep this crate building with future versions of rustc, wrap set_var in a closure such that the closure gets coerced to a function pointer, and set_var just gets called the normal way.
This is in preparation for https://github.com/rust-lang/rust/pull/124636, where we're making
set_var
unsafe. On old (pre-2024) editions, the unsafety error is downgraded to a warning so old code largely keeps working -- except whenset_var
is coerced to a function pointer, as is done by this crate (and by no other crate it seems); then the true type ofset_var
being anunsafe fn
shines through and the build fails.So to keep this crate building with future versions of rustc, wrap
set_var
in a closure such that the closure gets coerced to a function pointer, andset_var
just gets called the normal way.