From eecab99dec7a812199d2c403013d393dd1dec680 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Wed, 28 Dec 2022 20:46:45 +0000 Subject: [PATCH] Allow `break` and co to go through `try{}` blocks --- crates/hir-ty/src/infer/expr.rs | 2 +- .../src/handlers/break_outside_of_loop.rs | 40 +++++++++---------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index b1f4de8260..0d3f15c3d5 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -152,7 +152,7 @@ impl<'a> InferenceContext<'a> { .1 } Expr::TryBlock { body } => { - self.with_breakable_ctx(BreakableKind::Border, self.err_ty(), None, |this| { + self.with_breakable_ctx(BreakableKind::Block, self.err_ty(), None, |this| { let _inner = this.infer_expr(*body, expected); }); // FIXME should be std::result::Result<{inner}, _> diff --git a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs index 0c92e706b3..7a957e1c50 100644 --- a/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs +++ b/crates/ide-diagnostics/src/handlers/break_outside_of_loop.rs @@ -37,28 +37,6 @@ fn foo() { ); } - #[test] - fn try_blocks_are_borders() { - check_diagnostics( - r#" -fn foo() { - 'a: loop { - try { - break; - //^^^^^ error: break outside of loop - break 'a; - //^^^^^^^^ error: break outside of loop - continue; - //^^^^^^^^ error: continue outside of loop - continue 'a; - //^^^^^^^^^^^ error: continue outside of loop - }; - } -} -"#, - ); - } - #[test] fn async_blocks_are_borders() { check_diagnostics( @@ -121,6 +99,24 @@ fn foo() { ); } + #[test] + fn try_blocks_pass_through() { + check_diagnostics( + r#" +fn foo() { + 'a: loop { + try { + break; + break 'a; + continue; + continue 'a; + }; + } +} +"#, + ); + } + #[test] fn label_blocks() { check_diagnostics(