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

while let suggestion missing when E0308 happens in closure body #113354

Closed
e2-71828 opened this issue Jul 5, 2023 · 0 comments · Fixed by #113567
Closed

while let suggestion missing when E0308 happens in closure body #113354

e2-71828 opened this issue Jul 5, 2023 · 0 comments · Fixed by #113567
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

@e2-71828
Copy link

e2-71828 commented Jul 5, 2023

Code

fn main() {
    let _ = || { while Some(_) = None { } };
}

Current output

error[E0308]: mismatched types
 --> src/main.rs:2:24
  |
2 |     let _ = || { while Some(_) = None { } };
  |                        ^^^^^^^^^^^^^^ expected `bool`, found `()`

For more information about this error, try `rustc --explain E0308`.

Desired output

error[E0308]: mismatched types
 --> src/main.rs:2:24
  |
2 |     let _ = || { while Some(_) = None { } };
  |                        ^^^^^^^^^^^^^^ expected `bool`, found `()`
help: consider adding `let`
  |
2 |     let _ = || { while let Some(_) = None { } };
  |                           

For more information about this error, try `rustc --explain E0308`.

Rationale and extra context

When an assignment is used as the test in a while statement, the compiler will add a help message suggesting while let instead. This message fails to appear when the erroneous while statement is inside a closure body.

Other cases

No response

Anything else?

This problem was discovered while investigating #113352 .

@e2-71828 e2-71828 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 Jul 5, 2023
@chenyukang chenyukang self-assigned this Jul 6, 2023
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jul 12, 2023
…-let, r=cjgillot

While let suggestion will work for closure body

Fixes rust-lang#113354
@bors bors closed this as completed in f7a34f9 Jul 12, 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