-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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).
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.