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

Autofix for wrapping in fields loses the existing value #18302

Closed
ndmitchell opened this issue Oct 15, 2024 · 2 comments
Closed

Autofix for wrapping in fields loses the existing value #18302

ndmitchell opened this issue Oct 15, 2024 · 2 comments
Labels
C-bug Category: bug

Comments

@ndmitchell
Copy link

ndmitchell commented Oct 15, 2024

rust-analyzer version: [edited by @davidbarsky: it is a slightly patched rust-analyzer built from 28830ff]

rustc version: rustc 1.81.0 (eeb90cda1 2024-09-04).

editor or extension: VS Code v0.4.2007

relevant settings: None

code snippet to reproduce:

enum Magic {
    Value { count: usize },
}

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

That gives the error:

expected value, found struct variant `Magic::Value` not a value

And the autofix:

you might have meant to create a new value of the struct: ` { count: /* value */}`

Applying that fix results in the code:

    Magic::Value { count: /* value */ };

Namely it deletes the value 42, when I would much prefer the replacement:

    Magic::Value { count: 42 };
@ndmitchell ndmitchell added the C-bug Category: bug label Oct 15, 2024
@Veykril
Copy link
Member

Veykril commented Oct 15, 2024

Thats a rustc diagnostic, sounds like this is marked with an incorrect applicability given it contains placeholder text. Would be good to report that to https://github.com/rust-lang/rust

@ndmitchell
Copy link
Author

Reported upstream as rust-lang/rust#131878

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

3 participants