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

Renaming a struct field should rename variables that destructure the field #6547

Open
jyn514 opened this issue Nov 14, 2020 · 2 comments
Open
Labels
C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now

Comments

@jyn514
Copy link
Member

jyn514 commented Nov 14, 2020

The title is not as clear as it could be - here's an example:

        let Item { attrs, name, source, visibility, def_id, inner, stability, deprecation } = item;

When I rename inner to kind, I expect this to be changed to

        let Item { attrs, name, source, visibility, def_id, kind, stability, deprecation } = item;

and all usages of inner in this scope updated. Instead, rust-analyzer changes it to

        let Item { attrs, name, source, visibility, def_id, kind: inner, stability, deprecation } = item;

which is not super helpful and messes up rustfmt.

@bjorn3
Copy link
Member

bjorn3 commented Nov 14, 2020

This may not be the best idea in the general case. For example:

enum Foo {
    A { bar: u8 },
    B { bar: u8 },
}

let a: Foo = todo!();
match a {
    Foo::A { bar } | Foo::B { bar } => {
        std::mem::drop(bar);
    }
}

If you were to rename the bar in Foo::A { bar } then this would cause the result to be:

enum Foo {
    A { baz: u8 },
    B { bar: u8 },
}

let a: Foo = todo!();
match a {
    Foo::A { baz } | Foo::B { bar: baz } => {
        std::mem::drop(baz);
    }
}

@jyn514
Copy link
Member Author

jyn514 commented Nov 14, 2020

Sure - maybe 'rename variables that destructure the field when all types/variants in the match are the same'? I think the common case is useful though.

@flodiebold flodiebold added S-unactionable Issue requires feedback, design decisions or is blocked on other work S-actionable Someone could pick this issue up and work on it right now and removed S-unactionable Issue requires feedback, design decisions or is blocked on other work labels Dec 21, 2020
@Veykril Veykril self-assigned this Feb 13, 2021
@Veykril Veykril removed their assignment Sep 3, 2021
@Veykril Veykril added the C-feature Category: feature request label Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

4 participants