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

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

Open
ndmitchell opened this issue Oct 18, 2024 · 0 comments · May be fixed by #131899
Open
Labels
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.

Comments

@ndmitchell
Copy link

ndmitchell commented Oct 18, 2024

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?

@ndmitchell ndmitchell 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. labels Oct 18, 2024
@ndmitchell ndmitchell changed the title Diagnostic Diagnostic for E0533 (expected value, found struct variant) has hint with incorrect applicability Oct 18, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 18, 2024
Mark unexpected variant res suggestion as having placeholders

Fixes rust-lang#131878
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 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.

1 participant