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

break loop help ignores nested closures #112020

Closed
SparkyPotato opened this issue May 27, 2023 · 0 comments · Fixed by #112024
Closed

break loop help ignores nested closures #112020

SparkyPotato opened this issue May 27, 2023 · 0 comments · Fixed by #112024
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

@SparkyPotato
Copy link
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

@SparkyPotato SparkyPotato 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 May 27, 2023
@compiler-errors compiler-errors self-assigned this May 27, 2023
@bors bors closed this as completed in 02c4b4b Jun 1, 2023
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