Named functions do not implement traits implemented on fn() #121632
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
D-incorrect
Diagnostics: A diagnostic that is giving misleading or incorrect information.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
I tried this code:
playground link
I expected this code to compile, as
main
is a fn() pointer, which implements the traitFoo
However, rustc seems to need additiontal casting to convert a named fn() to a unnamed one:
On a side note, the solution suggested by rustc is missing parentheses. The correct way would be
&(main as fn())
. When following the suggestions given by rustc, the code goes&main
->&main as fn()
->&(&main as fn())
. The last code suggestion is an invalid cast, because you cannot cast&fn()
tofn()
.Meta
rustc --version --verbose
:(also happens on beta and nightly)
The text was updated successfully, but these errors were encountered: