Skip to content

Unhelpful message when not using value from a loop break #115905

Closed
@not-holar

Description

@not-holar

Code

loop {
    break Some(1);
}

Current output

error[E0308]: mismatched types
  --> src\main.rs:24:15
   |
24 |         break Some(1);
   |               ^^^^^^^ expected `()`, found `Option<{integer}>`
   |
   = note: expected unit type `()`
                   found enum `Option<{integer}>`

error: aborting due to previous error

Desired output

loop value is never used so
break expected unit type `()`
              found enum `Option<{integer}>`

Rationale and extra context

It might not be too hard to figure what the issue is in such a simple example as the above, but when you have multiple levels of nesting with complex layered types, this can quickly become a source of frustration as it sends you on a wild chase of misdirection.

Other cases

No response

Anything else?

No response

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