Skip to content

Compiler gives odd context in error that isn't relevant to the actual issue #51752

Closed
@repnop

Description

@repnop

Playground link: https://play.rust-lang.org/?gist=41596a413b9d567407a84423bd63174a&version=stable&mode=debug

Error:

error[E0308]: mismatched types
 --> src/main.rs:7:39
  |
1 | fn main() {
  |           - expected `()` because of default return type
...
7 |         thingy(if let Some(r) = opt { r } else { None });
  |                                       ^ expected enum `std::option::Option`, found mutable reference
  |
  = note: expected type `std::option::Option<&mut i32>`
             found type `&mut {integer}`

For some reason rustc appears to include the return type of main as if it was important here, even though the expression is passing the return value to the thingy function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions