Skip to content

break loop help ignores nested closures #112020

@SparkyPotato

Description

@SparkyPotato
Contributor

Code

fn test() {
    loop {
        let closure = || {
            if true {
                Err(1)
            }
            
            Ok(())
        };
    }
}

Current output

error[E0308]: mismatched types
 --> src/lib.rs:5:17
  |
4 | /             if true {
5 | |                 Err(1)
  | |                 ^^^^^^ expected `()`, found `Result<_, {integer}>`
6 | |             }
  | |_____________- expected this to be `()`
  |
  = note: expected unit type `()`
                  found enum `Result<_, {integer}>`
help: you might have meant to break the loop with this value
  |
5 |                 break Err(1);
  |                 +++++       +

Desired output

error[E0308]: mismatched types
 --> src/lib.rs:4:13
  |
4 | /         if true {
5 | |             Err(1)
  | |             ^^^^^^ expected `()`, found `Result<_, {integer}>`
6 | |         }
  | |_________- expected this to be `()`
  |
  = note: expected unit type `()`
                  found enum `Result<_, {integer}>`

Rationale and extra context

No response

Other cases

No response

Anything else?

No response

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 27, 2023
added a commit that references this issue on Jun 1, 2023
02c4b4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

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

    Participants

    @compiler-errors@SparkyPotato

    Issue actions

      break loop help ignores nested closures · Issue #112020 · rust-lang/rust