Skip to content

Conversation

@nathanwhit
Copy link
Contributor

This PR tweaks the fill struct fields assist to use the struct init shorthand when a local variable with a matching name and type is in scope.

For example:

struct Foo {
    a: usize,
    b: i32,
    c: char,
}

fn main() {
    let a = 1;
    let b = 2;
    let c = 3;
    let foo = Foo { <|> };
}

Before we would insert

Foo {
    a: (),
    b: (),
    c: (),
}

now we would insert

Foo {
    a,
    b,
    c: ()
}

Copy link
Contributor

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely 😍, I've been wanting this since forever!

@matklad
Copy link
Contributor

matklad commented Aug 30, 2021

bors d+

@bors
Copy link
Contributor

bors bot commented Aug 30, 2021

✌️ nathanwhit can now approve this pull request. To approve and merge a pull request, simply reply with bors r+. More detailed instructions are available here.

@nathanwhit
Copy link
Contributor Author

bors r=matklad

@bors
Copy link
Contributor

bors bot commented Aug 30, 2021

@bors bors bot merged commit 02a3d89 into rust-lang:master Aug 30, 2021
@lnicola lnicola changed the title Use struct init shorthand when applicable in fill struct fields assist fix: Use struct init shorthand when applicable in fill struct fields assist Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants