Add ide-assists: merge let statements
Close rust-lang/rust-analyzer#10651
Assist: merge_let_stmts
Merge multiple lets into a let tuple pattern, allowing for the use of multiple identical let-else.
fn main() {
$0let a = 2;
let b = 3;$0
}
->
fn main() {
let (a, b) = (2, 3);
}
:warning: Warning :warning:
- There are issue links (such as
#123) in the commit messages of the following commits. Please remove them as they will spam the issue with references to the commit.- 794320f6ec38b2b0c23d4a967f01aa6e040d1b6e
Thinking about this a bit more, I really don't see the usefulness in this. I am not quite sure why you'd want to turn multiple let statements into a single one that just does destructuring on the left, and merging via a tuple expression on the right. That seems like a net readability downgrade to me.
For related simple assignments, in single let statement may be more readable
Such as let (x, y) = (10, 5);
r? @rust-lang/rust-analyzer, as per my comment above https://github.com/rust-lang/rust-analyzer/pull/19777#issuecomment-2930224427 I am inclined to close this, thoughts?
I don't know. This could be a useful step in a larger refactoring. But I'm not sure if it's worth having for that.
Random thought, I could imagine our "Join lines" function doing this if the lines are two let statements :thinking:
I think this is useful (it's a transformation I've made a number of times), but I can't remember all the assists we have, so I'm not sure I'd use it.
I personally agree with closing this.
Random thought, I could imagine our "Join lines" function doing this if the lines are two let statements 🤔
Implementing it in "Join lines" seems quite complex, And it seems that using "Join lines" requires inputting commands, which is not as simplify as using assist