Skip to content

Commit 64957ac

Browse files
committed
Fix incorrect scoping in while expressions
1 parent 62a4677 commit 64957ac

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

crates/hir_def/src/body/scope.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
188188
compute_expr_scopes(*body_expr, body, scopes, scope);
189189
}
190190
Expr::While { condition, body: body_expr, label } => {
191-
compute_expr_scopes(*condition, body, scopes, scope);
192191
let scope = scopes.new_labeled_scope(scope, make_label(label));
192+
compute_expr_scopes(*condition, body, scopes, scope);
193193
compute_expr_scopes(*body_expr, body, scopes, scope);
194194
}
195195
Expr::Loop { body: body_expr, label } => {

crates/ide_completion/src/completions/lifetime.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,33 @@ fn foo() {
253253
"#]],
254254
);
255255
}
256+
257+
#[test]
258+
fn complete_label_in_while_cond() {
259+
check(
260+
r#"
261+
fn foo() {
262+
'outer: while { 'inner: loop { break '$0 } } {}
263+
}
264+
"#,
265+
expect![[r#"
266+
lb 'inner
267+
lb 'outer
268+
"#]],
269+
);
270+
}
271+
272+
#[test]
273+
fn complete_label_in_for_iterable() {
274+
check(
275+
r#"
276+
fn foo() {
277+
'outer: for _ in [{ 'inner: loop { break '$0 } }] {}
278+
}
279+
"#,
280+
expect![[r#"
281+
lb 'inner
282+
"#]],
283+
);
284+
}
256285
}

crates/ide_completion/src/context.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -475,19 +475,17 @@ impl<'a> CompletionContext<'a> {
475475
return;
476476
}
477477

478-
if parent.kind() != syntax::SyntaxKind::LABEL {
479-
match_ast! {
480-
match parent {
481-
ast::LifetimeParam(_it) => {
482-
self.lifetime_allowed = true;
483-
self.lifetime_param_syntax =
484-
self.sema.find_node_at_offset_with_macros(original_file, offset);
485-
},
486-
ast::BreakExpr(_it) => self.is_label_ref = true,
487-
ast::ContinueExpr(_it) => self.is_label_ref = true,
488-
ast::Label(_it) => (),
489-
_ => self.lifetime_allowed = true,
490-
}
478+
match_ast! {
479+
match parent {
480+
ast::LifetimeParam(_it) => {
481+
self.lifetime_allowed = true;
482+
self.lifetime_param_syntax =
483+
self.sema.find_node_at_offset_with_macros(original_file, offset);
484+
},
485+
ast::BreakExpr(_it) => self.is_label_ref = true,
486+
ast::ContinueExpr(_it) => self.is_label_ref = true,
487+
ast::Label(_it) => (),
488+
_ => self.lifetime_allowed = true,
491489
}
492490
}
493491
}

0 commit comments

Comments
 (0)