-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Unwrap block assist deletes entire match #18537
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
Comments
What result would you have expected? |
fn foo() {
match (name, mode) {
(name, mode) => panic!()
}
} |
You're looking for an assist to remove the braces from a match expression (which I am coincidentally working on right now and should have PR for soon). Unwrap block is intended to turn an expression wrapping a block ( |
Maybe something like "Replace |
In my head I parse the |
"Unwrap block" remove code in other cases too, e.g. |
The intention with "Unwrap block" is not to pull out the tail expression of blocks with no statements (this is what if should_foo {
foo();
} Next, you restructure your program such that foo(); This is the intended behavior of "Unwrap block". And what you see when this behavior is applied to match expressions is intentional as well. It is actually checked in one of the tests written for the assist. I am in total agreement that this is not a particularly descriptive name, and as a whole this functionality is dubiously useful for match statements. Matching variants can bring values into scope that don't exist outside of the match arm. I would not be opposed to not offering this assist for match expressions. As for the functionality you intended, I opened PR #18539 which introduces an assist for it. |
Do I understand it correctly that if I inline a function outside of a match arm I did have to keep using unwrap block to remove the curly braces that the inlining assist introduces, but if I inline a function inside of a match arm I did have to use your new assist? |
Yes, that is correct. And, to be fair, these are two different behaviors, as the assist for match statements is only offered when the block contains only one statement, and handles adding a comma if required. I don't disagree that having separate assists here is weird UX, if that's what you're hinting at. I would not be opposed to consolidating much of this functionality. Plenty of assists as it stand have different behaviors depending on the context they're applied in. To be honest, I am more and more skeptical of the use of this existing unwrap block assist for control statements as time goes on. Outside of simple I have marked my PR #18539 as a draft and I will be updating it to be a full-fledged consolidation of block wrapping and unwrapping assists. |
I've always hated that unwrap block didn't do what one would expect, just like this issue is raising. We should absolutely change the name of this (as well as add a new assist that does what one would expect here). |
rust-analyzer version: rust-analyzer version: 0.3.2188-standalone [/home/bjorn/.vscode/extensions/rust-lang.rust-analyzer-0.3.2188-linux-x64/server/rust-analyzer]
rustc version: N/A
editor or extension: VSCode
relevant settings: None
repository link (if public, optional): None
code snippet to reproduce:
turns into
The text was updated successfully, but these errors were encountered: