Skip to content

Diagnostic for E0533 (expected value, found struct variant) has hint with incorrect applicability #131878

Closed
@ndmitchell

Description

@ndmitchell

Code

// https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=59feacaf2986a2fd0b2510b2c225ae41

enum Magic {
    Value { count: usize },
}

fn create() {
    Magic::Value(42);
}

Current output

   Compiling playground v0.0.1 (/playground)
error[E0533]: expected value, found struct variant `Magic::Value`
 --> src/lib.rs:6:5
  |
6 |     Magic::Value(42);
  |     ^^^^^^^^^^^^ not a value
  |
help: you might have meant to create a new value of the struct
  |
6 |     Magic::Value { count: /* value */ };
  |                  ~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0533`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

Either of:

Magic::Value { count: 42 };

Or:

Fix the applicability of the diagnostic to indicate it contains placeholder text.

Rationale and extra context

The diagnostic is taken by Rust Analyzer and applied, as it is marked applicable. It should either not be marked applicable, OR (preferably) fixed so that it doesn't contain the placeholder /* value */.

Originally reported at rust-lang/rust-analyzer#18302, since it causes incorrect replacements in the IDE

Other cases

No response

Rust Version

I'm running on the nightly in the playground (https://play.rust-lang.org/), since I'm at a company that internally has a patched rustc. The playground reports:

Build using the Nightly version: 1.84.0-nightly (2024-10-17 3ed6e3cc69857129c1d3)

Anything else?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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