This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
ide-diagnostics/src/handlers Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -744,7 +744,27 @@ impl ExprCollector<'_> {
744744 fn collect_while_loop ( & mut self , syntax_ptr : AstPtr < ast:: Expr > , e : ast:: WhileExpr ) -> ExprId {
745745 let label = e. label ( ) . map ( |label| self . collect_label ( label) ) ;
746746 let body = self . collect_labelled_block_opt ( label, e. loop_body ( ) ) ;
747- let condition = self . collect_expr_opt ( e. condition ( ) ) ;
747+
748+ // Labels can also be used in the condition expression, like this:
749+ // ```
750+ // fn main() {
751+ // let mut optional = Some(0);
752+ // 'my_label: while let Some(a) = match optional {
753+ // None => break 'my_label,
754+ // Some(val) => Some(val),
755+ // } {
756+ // println!("{}", a);
757+ // optional = None;
758+ // }
759+ // }
760+ // ```
761+ let condition = match label {
762+ Some ( label) => {
763+ self . with_labeled_rib ( label, |this| this. collect_expr_opt ( e. condition ( ) ) )
764+ }
765+ None => self . collect_expr_opt ( e. condition ( ) ) ,
766+ } ;
767+
748768 let break_expr =
749769 self . alloc_expr ( Expr :: Break { expr : None , label : None } , syntax_ptr. clone ( ) ) ;
750770 let if_expr = self . alloc_expr (
Original file line number Diff line number Diff line change @@ -34,6 +34,25 @@ fn foo() {
3434 ) ;
3535 }
3636
37+ #[ test]
38+ fn while_let_loop_with_label_in_condition ( ) {
39+ check_diagnostics (
40+ r#"
41+ fn foo() {
42+ let mut optional = Some(0);
43+
44+ 'my_label: while let Some(a) = match optional {
45+ None => break 'my_label,
46+ Some(val) => Some(val),
47+ } {
48+ optional = None;
49+ continue 'my_label;
50+ }
51+ }
52+ "# ,
53+ ) ;
54+ }
55+
3756 #[ test]
3857 fn for_loop ( ) {
3958 check_diagnostics (
You can’t perform that action at this time.
0 commit comments