Skip to content

break loop help ignores nested closures #112020

Closed
@SparkyPotato

Description

@SparkyPotato

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

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

No branches or pull requests

Issue actions