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

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

Closed
TheNeikos opened this issue Jul 3, 2024 · 0 comments · Fixed by #127417
Closed

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

TheNeikos opened this issue Jul 3, 2024 · 0 comments · Fixed by #127417
Assignees
Labels
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.

Comments

@TheNeikos
Copy link
Contributor

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

@TheNeikos TheNeikos 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 Jul 3, 2024
@chenyukang chenyukang self-assigned this Jul 6, 2024
@bors bors closed this as completed in 413345c Jul 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 6, 2024
Rollup merge of rust-lang#127417 - chenyukang:yukang-method-output-diff, r=oli-obk

Show fnsig's unit output  explicitly when there is output diff in diagnostics

Fixes rust-lang#127263
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 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.

2 participants