Skip to content

Commit e7dff74

Browse files
committed
Auto merge of rust-lang#13726 - feniljain:fix_assists, r=jonas-schievink
feat: allow unwrap block in let initializers Possible fix for rust-lang#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
2 parents 3a7215b + 4794572 commit e7dff74

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

crates/ide-assists/src/handlers/unwrap_block.rs

+46-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
3737
parent = parent.ancestors().find(|it| ast::MatchExpr::can_cast(it.kind()))?
3838
}
3939

40-
if matches!(parent.kind(), SyntaxKind::STMT_LIST | SyntaxKind::EXPR_STMT) {
40+
if matches!(parent.kind(), SyntaxKind::STMT_LIST | SyntaxKind::EXPR_STMT | SyntaxKind::LET_STMT)
41+
{
4142
return acc.add(assist_id, assist_label, target, |builder| {
4243
builder.replace(block.syntax().text_range(), update_expr_string(block.to_string()));
4344
});
@@ -713,6 +714,50 @@ fn main() -> i32 {
713714
return 3;
714715
5
715716
}
717+
"#,
718+
);
719+
}
720+
721+
#[test]
722+
fn unwrap_block_in_let_initializers() {
723+
// https://github.com/rust-lang/rust-analyzer/issues/13679
724+
check_assist(
725+
unwrap_block,
726+
r#"
727+
fn main() {
728+
let x = {$0
729+
bar
730+
};
731+
}
732+
"#,
733+
r#"
734+
fn main() {
735+
let x = bar;
736+
}
737+
"#,
738+
);
739+
}
740+
741+
#[test]
742+
fn unwrap_if_in_let_initializers() {
743+
// https://github.com/rust-lang/rust-analyzer/issues/13679
744+
check_assist(
745+
unwrap_block,
746+
r#"
747+
fn main() {
748+
let a = 1;
749+
let x = if a - 1 == 0 {$0
750+
foo
751+
} else {
752+
bar
753+
};
754+
}
755+
"#,
756+
r#"
757+
fn main() {
758+
let a = 1;
759+
let x = foo;
760+
}
716761
"#,
717762
);
718763
}

0 commit comments

Comments
 (0)