diff options
| author | bors <bors@rust-lang.org> | 2022-12-12 14:06:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-12 14:06:45 +0000 |
| commit | e7dff7491a675588a42089fe86009ddf93305e10 (patch) | |
| tree | 55ae1239b208162e59144f5d9243a933340caa27 | |
| parent | 3a7215b92ee23d8e4399ff713381416fb4886bcc (diff) | |
| parent | 4794572e364244dcfb60b6c67995ab53282ad4b1 (diff) | |
| download | rust-e7dff7491a675588a42089fe86009ddf93305e10.tar.gz rust-e7dff7491a675588a42089fe86009ddf93305e10.zip | |
Auto merge of #13726 - feniljain:fix_assists, r=jonas-schievink
feat: allow unwrap block in let initializers Possible fix for #13679 ### Points to help in review: - I just added a parent case for let statements and it seems everything else was in place already, so turned out to be a small fix
| -rw-r--r-- | crates/ide-assists/src/handlers/unwrap_block.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/unwrap_block.rs b/crates/ide-assists/src/handlers/unwrap_block.rs index 7969a491822..53cdac03a33 100644 --- a/crates/ide-assists/src/handlers/unwrap_block.rs +++ b/crates/ide-assists/src/handlers/unwrap_block.rs @@ -37,7 +37,8 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option parent = parent.ancestors().find(|it| ast::MatchExpr::can_cast(it.kind()))? } - if matches!(parent.kind(), SyntaxKind::STMT_LIST | SyntaxKind::EXPR_STMT) { + if matches!(parent.kind(), SyntaxKind::STMT_LIST | SyntaxKind::EXPR_STMT | SyntaxKind::LET_STMT) + { return acc.add(assist_id, assist_label, target, |builder| { builder.replace(block.syntax().text_range(), update_expr_string(block.to_string())); }); @@ -716,4 +717,48 @@ fn main() -> i32 { "#, ); } + + #[test] + fn unwrap_block_in_let_initializers() { + // https://github.com/rust-lang/rust-analyzer/issues/13679 + check_assist( + unwrap_block, + r#" +fn main() { + let x = {$0 + bar + }; +} +"#, + r#" +fn main() { + let x = bar; +} +"#, + ); + } + + #[test] + fn unwrap_if_in_let_initializers() { + // https://github.com/rust-lang/rust-analyzer/issues/13679 + check_assist( + unwrap_block, + r#" +fn main() { + let a = 1; + let x = if a - 1 == 0 {$0 + foo + } else { + bar + }; +} +"#, + r#" +fn main() { + let a = 1; + let x = foo; +} +"#, + ); + } } |
