Closed
Description
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=46a86936d28608b95d4e28854b854d80
unsafe fn foo(f: *mut dyn FnOnce()) {
(f as &dyn FnOnce())();
}
The current output is:
error[E0605]: non-primitive cast: `*mut (dyn FnOnce() + 'static)` as `&dyn FnOnce()`
--> src/lib.rs:2:5
|
2 | (f as &dyn FnOnce())();
| ^^^^^^^^^^^^^^^^^^^^ invalid cast
|
help: borrow the value for the cast to be valid
|
2 | (&f as &dyn FnOnce())();
| ^
However, this does not make a valid cast. The valid cast would use &*f
as far as I can tell (it still can't be called but regardless).