Skip to content

Assigning the wrong fn type to a variable mentions 'pointer' vs 'item'  #127263

Description

@TheNeikos

Code

fn bar() {}

fn main() {
    let b: fn() -> u32 = bar;
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:4:26
  |
4 |     let b: fn() -> u32 = bar;
  |            -----------   ^^^ expected fn pointer, found fn item
  |            |
  |            expected due to this
  |
  = note: expected fn pointer `fn() -> u32`
                found fn item `fn() {bar}`

Desired output

error[E0308]: mismatched types
 --> src/main.rs:4:26
  |
4 |     let b: fn() -> u32 = bar;
  |            -----------   ^^^ `fn` return types do not match, expected `fn() -> u32`, found `fn() -> ()`
  |            |
  |            expected due to this

Rationale and extra context

The current version is not wrong, but it is a bit confusing when one does not know the way rustc handles fn stuff.

I think that leading with what is not matching up would make it easier to see one's error. Especially in context for example of RA, where in-line errors only show the 'main' message.

Other cases

No response

Rust Version

Playground, Stable 1.79.0

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions