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

Suggest replacing an inexisting field for an unmentioned field #87960

Commits on Sep 13, 2021

  1. Suggest replacing an inexisting field for an unmentioned field

    This PR adds a suggestion to replace an inexisting field for an
    unmentioned field. Given the following code:
    ```rust
    enum Foo {
        Bar { alpha: u8, bravo: u8, charlie: u8 },
    }
    
    fn foo(foo: Foo) {
        match foo {
            Foo::Bar {
                alpha,
                beta, // `bravo` miswritten as `beta` here.
                charlie,
            } => todo!(),
        }
    }
    ```
    the compiler now emits the error messages below.
    ```text
    error[E0026]: variant `Foo::Bar` does not have a field named `beta`
     --> src/lib.rs:9:13
      |
    9 |             beta, // `bravo` miswritten as `beta` here.
      |             ^^^^
      |             |
      |             variant `Foo::Bar` does not have this field
      |             help: `Foo::Bar` has a field named `bravo`: `bravo`
    ```
    
    Note that this suggestion is available iff the number of inexisting
    fields and unmentioned fields are both 1.
    hkmatsumoto committed Sep 13, 2021
    Configuration menu
    Copy the full SHA
    37196e3 View commit details
    Browse the repository at this point in the history