Skip to content
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

rustc should suggest a cast from anonymous function type to function pointer #91258

Open
tobx opened this issue Nov 26, 2021 · 1 comment
Open
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-diagnostics Area: Messages for errors, warnings, and lints D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tobx
Copy link

tobx commented Nov 26, 2021

I have been told in Discord that:

"rustc should be able to see that one is an anonymous fn type and the other a fn pointer with the same call signature"

and that I should open an issue.

Given the following code:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=b35796ef8b42be226dbba7c213fbd348

The current output is:

error[E0308]: mismatched types
  --> src/lib.rs:21:16
   |
21 |         Self { entries }
   |                ^^^^^^^ expected fn pointer, found fn item
   |
   = note: expected struct `Filter<_, for<'r> fn(&'r Result<walkdir::DirEntry, walkdir::Error>) -> _>`
              found struct `Filter<_, for<'r> fn(&'r Result<walkdir::DirEntry, walkdir::Error>) -> _ {note_filter}>`

Ideally the output should add a note, something like:

Try to cast: `note_filter as MyFilter`
@tobx tobx added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 26, 2021
@tobx tobx changed the title rustc is not able to see that an anonymous fn type and a fn pointer have the same call signature rustc should suggest a cast from anonymous function type to function pointer Nov 26, 2021
@camelid
Copy link
Member

camelid commented Nov 26, 2021

Hmm, it kind of feels like rustc should be performing this cast automatically, though I guess that'd be a larger (and potentially difficult) language change.

@fmease fmease added A-coercions Area: implicit and explicit `expr as Type` coercions D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. labels Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coercions Area: implicit and explicit `expr as Type` coercions A-diagnostics Area: Messages for errors, warnings, and lints D-lack-of-suggestion Diagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants