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

Tweak suggestions when using incorrect type of enum literal #127891

Merged
merged 3 commits into from
Jul 19, 2024

Commits on Jul 18, 2024

  1. Configuration menu
    Copy the full SHA
    2259db6 View commit details
    Browse the repository at this point in the history
  2. More accurate suggestions when writing wrong style of enum variant li…

    …teral
    
    ```
    error[E0533]: expected value, found struct variant `E::Empty3`
      --> $DIR/empty-struct-braces-expr.rs:18:14
       |
    LL |     let e3 = E::Empty3;
       |              ^^^^^^^^^ not a value
       |
    help: you might have meant to create a new value of the struct
       |
    LL |     let e3 = E::Empty3 {};
       |                        ++
    ```
    ```
    error[E0533]: expected value, found struct variant `E::V`
      --> $DIR/struct-literal-variant-in-if.rs:10:13
       |
    LL |     if x == E::V { field } {}
       |             ^^^^ not a value
       |
    help: you might have meant to create a new value of the struct
       |
    LL |     if x == (E::V { field }) {}
       |             +              +
    ```
    ```
    error[E0618]: expected function, found enum variant `Enum::Unit`
      --> $DIR/suggestion-highlights.rs:15:5
       |
    LL |     Unit,
       |     ---- enum variant `Enum::Unit` defined here
    ...
    LL |     Enum::Unit();
       |     ^^^^^^^^^^--
       |     |
       |     call expression requires function
       |
    help: `Enum::Unit` is a unit enum variant, and does not take parentheses to be constructed
       |
    LL -     Enum::Unit();
    LL +     Enum::Unit;
       |
    ```
    ```
    error[E0599]: no variant or associated item named `tuple` found for enum `Enum` in the current scope
      --> $DIR/suggestion-highlights.rs:36:11
       |
    LL | enum Enum {
       | --------- variant or associated item `tuple` not found for this enum
    ...
    LL |     Enum::tuple;
       |           ^^^^^ variant or associated item not found in `Enum`
       |
    help: there is a variant with a similar name
       |
    LL |     Enum::Tuple(/* i32 */);
       |           ~~~~~~~~~~~~~~~~;
       |
    ```
    estebank committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    ec7a188 View commit details
    Browse the repository at this point in the history
  3. Tweak "field not found" suggestion when giving struct literal for tup…

    …le struct type
    
    ```
    error[E0560]: struct `S` has no field named `x`
      --> $DIR/nested-non-tuple-tuple-struct.rs:8:19
       |
    LL | pub struct S(f32, f32);
       |            - `S` defined here
    ...
    LL |     let _x = (S { x: 1.0, y: 2.0 }, S { x: 3.0, y: 4.0 });
       |                   ^ field does not exist
       |
    help: `S` is a tuple struct, use the appropriate syntax
       |
    LL |     let _x = (S(/* f32 */, /* f32 */), S { x: 3.0, y: 4.0 });
       |               ~~~~~~~~~~~~~~~~~~~~~~~
    ```
    estebank committed Jul 18, 2024
    Configuration menu
    Copy the full SHA
    33bd4bd View commit details
    Browse the repository at this point in the history