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

Closure signature not mentioned on mismatch with fn ptr #119266

Closed
Noratrieb opened this issue Dec 23, 2023 · 1 comment · Fixed by #123379
Closed

Closure signature not mentioned on mismatch with fn ptr #119266

Noratrieb opened this issue Dec 23, 2023 · 1 comment · Fixed by #123379
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Noratrieb
Copy link
Member

Noratrieb commented Dec 23, 2023

Code

fn main() {
    let x = |a: u8| {};
    
    let x: fn(i32) = x;
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:4:22
  |
2 |     let x = |a: u8| {};
  |             ------- the found closure
3 |     
4 |     let x: fn(i32) = x;
  |            -------   ^ expected fn pointer, found closure
  |            |
  |            expected due to this
  |
  = note: expected fn pointer `fn(i32)`
                found closure `{closure@src/main.rs:2:13: 2:20}`

Desired output

error[E0308]: mismatched types
 --> src/main.rs:4:22
  |
2 |     let x = |a: u8| {};
  |             ------- the found closure
3 |     
4 |     let x: fn(i32) = x;
  |            -------   ^ expected fn pointer, found closure
  |            |
  |            expected due to this
  |
  = note: expected fn pointer `fn(i32)`
  |             found closure `{closure@src/main.rs:2:13: 2:20}`
  = note: closure has signature `fn(u8)`

Rationale and extra context

Here it's obvious, but when the error says that it is mismatched with for<'tcx> fn(context::TyCtxt<'tcx>, rustc_span::def_id::LocalDefId) -> &'tcx rustc_data_structures::unord::UnordSet<rustc_span::Symbol> and that "types differ in mutability" then I have zero chance of figuring what's going on.

Other cases

No response

Anything else?

No response

@Noratrieb Noratrieb 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 Dec 23, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 23, 2023
@Noratrieb Noratrieb added D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 23, 2023
@wutchzone
Copy link
Contributor

wutchzone commented Mar 26, 2024

@rustbot claim

Sounds like a feature I would like to use as well.

jieyouxu added a commit to jieyouxu/rust that referenced this issue Apr 20, 2024
Print note with closure signature on type mismatch

Fixes rust-lang#119266

r? Nilstrieb
@bors bors closed this as completed in e9e936c Apr 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 21, 2024
Rollup merge of rust-lang#123379 - wutchzone:119266, r=compiler-errors

Print note with closure signature on type mismatch

Fixes rust-lang#119266

r? Nilstrieb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants