Skip to content

Bad suggestion for refutable let without equals #123844

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

Closed
CAD97 opened this issue Apr 12, 2024 · 1 comment · Fixed by #123847
Closed

Bad suggestion for refutable let without equals #123844

CAD97 opened this issue Apr 12, 2024 · 1 comment · Fixed by #123847
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Apr 12, 2024

Code

fn main() {
    let Some(x);
    x = 1;
}

Current output

error[E0005]: refutable pattern in local binding
 --> src/main.rs:2:9
  |
2 |     let Some(x);
  |         ^^^^^^^ pattern `None` not covered
  |
  = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
  = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
  = note: the matched value is of type `Option<i32>`
help: you might want to use `let else` to handle the variant that isn't matched
  |
2 |     let Some(x); else { todo!() }
  |                  ++++++++++++++++

Desired output

error[E0005]: refutable pattern in local binding
 --> src/main.rs:2:9
  |
2 |     let Some(x);
  |         ^^^^^^^ pattern `None` not covered
  |
  = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
  = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
  = note: the matched value is of type `Option<i32>`

Rationale and extra context

Just drop the help suggestion, as let-else can't be used with deferred initialization let.

Other cases

No response

Rust Version

1.79.0-nightly
(2024-04-11 a07f3eb43acc5df851e1)

Anything else?

@rustbot label +D-invalid-suggestion

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Apr 12, 2024
@jieyouxu jieyouxu 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. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Apr 12, 2024
@eggyal
Copy link
Contributor

eggyal commented Apr 12, 2024

@rustbot claim

@bors bors closed this as completed in e4c8672 Apr 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 12, 2024
Rollup merge of rust-lang#123847 - eggyal:issue-123844, r=fmease

Suppress `let else` suggestion for uninitialized refutable `let`s

Fixes rust-lang#123844

r? `@CAD97`
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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.

4 participants