Skip to content

Erroneous suggestion to add .field when matching arrays #91058

Closed

Description

Given this code:

struct S(());

fn main() {
    let array = [S(())];
    
    match array {
        [()] => {}
        _ => {}
    }
}

The current output is:

error[E0308]: mismatched types
 --> src/main.rs:7:10
  |
6 |     match array {
  |           ----- this expression has type `[S; 1]`
7 |         [()] => {}
  |          ^^ expected struct `S`, found `()`
  |
help: you might have meant to use field `0` whose type is `()`
  |
6 |     match array.0 {
  |           ~~~~~~~

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` due to previous error

We should suppress the help: suggestion in this case, since it's not possible to apply that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-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