-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Named functions do not implement traits implemented on fn() #121632
Comments
This is not true, and that's what the diagnostic is trying to explain.
The suggestion is incorrect though, it needs parentheses. An alternative is to do @rustbot label -needs-triage +A-diagnostics +D-papercut +D-incorrect |
@rustbot claim I'll work on fixing the suggestion at least, and possibly see about clarifying the diagnostic |
…arens-fn-pointer, r=compiler-errors diagnostics: wrap fn cast suggestions in parens when needed Fixes rust-lang#121632
Rollup merge of rust-lang#130911 - notriddle:notriddle/suggest-wrap-parens-fn-pointer, r=compiler-errors diagnostics: wrap fn cast suggestions in parens when needed Fixes rust-lang#121632
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: