Skip to content

Commit eecab99

Browse files
committed
Allow break and co to go through try{} blocks
1 parent 16264a3 commit eecab99

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

crates/hir-ty/src/infer/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ impl<'a> InferenceContext<'a> {
152152
.1
153153
}
154154
Expr::TryBlock { body } => {
155-
self.with_breakable_ctx(BreakableKind::Border, self.err_ty(), None, |this| {
155+
self.with_breakable_ctx(BreakableKind::Block, self.err_ty(), None, |this| {
156156
let _inner = this.infer_expr(*body, expected);
157157
});
158158
// FIXME should be std::result::Result<{inner}, _>

crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn foo() {
3838
}
3939

4040
#[test]
41-
fn try_blocks_are_borders() {
41+
fn async_blocks_are_borders() {
4242
check_diagnostics(
4343
r#"
4444
fn foo() {
@@ -60,7 +60,7 @@ fn foo() {
6060
}
6161

6262
#[test]
63-
fn async_blocks_are_borders() {
63+
fn closures_are_borders() {
6464
check_diagnostics(
6565
r#"
6666
fn foo() {
@@ -82,39 +82,35 @@ fn foo() {
8282
}
8383

8484
#[test]
85-
fn closures_are_borders() {
85+
fn blocks_pass_through() {
8686
check_diagnostics(
8787
r#"
8888
fn foo() {
8989
'a: loop {
90-
try {
91-
break;
92-
//^^^^^ error: break outside of loop
93-
break 'a;
94-
//^^^^^^^^ error: break outside of loop
95-
continue;
96-
//^^^^^^^^ error: continue outside of loop
97-
continue 'a;
98-
//^^^^^^^^^^^ error: continue outside of loop
99-
};
90+
{
91+
break;
92+
break 'a;
93+
continue;
94+
continue 'a;
95+
}
10096
}
10197
}
10298
"#,
10399
);
104100
}
105101

106102
#[test]
107-
fn blocks_pass_through() {
103+
fn try_blocks_pass_through() {
108104
check_diagnostics(
109105
r#"
110106
fn foo() {
111107
'a: loop {
112-
{
113-
break;
114-
break 'a;
115-
continue;
116-
continue 'a;
117-
}
108+
try {
109+
break;
110+
break 'a;
111+
continue;
112+
continue 'a;
113+
};
118114
}
119115
}
120116
"#,

0 commit comments

Comments
 (0)