Skip to content

Commit 638cc3e

Browse files
bors[bot]ucrhh
and
ucrhh
authored
Merge #11054
11054: fix #11049 by removing double trimming r=Veykril a=Heinenen The `unwrap_trivial_block()` removes the braces around trivial blocks (as the name suggests). This violates the precondition of `update_expr_string()` which removes the first and the last non-whitespace character and thus expects braces to still exist around all blocks. Co-authored-by: ucrhh <[email protected]>
2 parents b65d9c3 + b289f13 commit 638cc3e

File tree

1 file changed

+44
-3
lines changed

1 file changed

+44
-3
lines changed

crates/ide_assists/src/handlers/unwrap_block.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syntax::{
66
AstNode, SyntaxKind, TextRange, T,
77
};
88

9-
use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, Assists};
9+
use crate::{AssistContext, AssistId, AssistKind, Assists};
1010

1111
// Assist: unwrap_block
1212
//
@@ -88,9 +88,8 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
8888
_ => return None,
8989
};
9090

91-
let unwrapped = unwrap_trivial_block(block);
9291
acc.add(assist_id, assist_label, target, |builder| {
93-
builder.replace(parent.syntax().text_range(), update_expr_string(unwrapped.to_string()));
92+
builder.replace(parent.syntax().text_range(), update_expr_string(block.to_string()));
9493
})
9594
}
9695

@@ -672,6 +671,48 @@ fn main() {
672671
fn main() {
673672
/* foo */ foo()
674673
}
674+
"#,
675+
);
676+
}
677+
678+
#[test]
679+
fn if_single_statement() {
680+
check_assist(
681+
unwrap_block,
682+
r#"
683+
fn main() {
684+
if true {$0
685+
return 3;
686+
}
687+
}
688+
"#,
689+
r#"
690+
fn main() {
691+
return 3;
692+
}
693+
"#,
694+
);
695+
}
696+
697+
#[test]
698+
fn multiple_statements() {
699+
check_assist(
700+
unwrap_block,
701+
r#"
702+
fn main() -> i32 {
703+
if 2 > 1 {$0
704+
let a = 5;
705+
return 3;
706+
}
707+
5
708+
}
709+
"#,
710+
r#"
711+
fn main() -> i32 {
712+
let a = 5;
713+
return 3;
714+
5
715+
}
675716
"#,
676717
);
677718
}

0 commit comments

Comments
 (0)