Skip to content

Autofix for wrapping in fields loses the existing value #18302

Closed as not planned
@ndmitchell

Description

@ndmitchell

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 };

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions