Fix incorrect scoping in while expressions
This commit is contained in:
parent
62a4677dbc
commit
64957acb5f
@ -188,8 +188,8 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
|
||||
compute_expr_scopes(*body_expr, body, scopes, scope);
|
||||
}
|
||||
Expr::While { condition, body: body_expr, label } => {
|
||||
compute_expr_scopes(*condition, body, scopes, scope);
|
||||
let scope = scopes.new_labeled_scope(scope, make_label(label));
|
||||
compute_expr_scopes(*condition, body, scopes, scope);
|
||||
compute_expr_scopes(*body_expr, body, scopes, scope);
|
||||
}
|
||||
Expr::Loop { body: body_expr, label } => {
|
||||
|
@ -253,4 +253,33 @@ fn foo() {
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complete_label_in_while_cond() {
|
||||
check(
|
||||
r#"
|
||||
fn foo() {
|
||||
'outer: while { 'inner: loop { break '$0 } } {}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
lb 'inner
|
||||
lb 'outer
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complete_label_in_for_iterable() {
|
||||
check(
|
||||
r#"
|
||||
fn foo() {
|
||||
'outer: for _ in [{ 'inner: loop { break '$0 } }] {}
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
lb 'inner
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -475,19 +475,17 @@ impl<'a> CompletionContext<'a> {
|
||||
return;
|
||||
}
|
||||
|
||||
if parent.kind() != syntax::SyntaxKind::LABEL {
|
||||
match_ast! {
|
||||
match parent {
|
||||
ast::LifetimeParam(_it) => {
|
||||
self.lifetime_allowed = true;
|
||||
self.lifetime_param_syntax =
|
||||
self.sema.find_node_at_offset_with_macros(original_file, offset);
|
||||
},
|
||||
ast::BreakExpr(_it) => self.is_label_ref = true,
|
||||
ast::ContinueExpr(_it) => self.is_label_ref = true,
|
||||
ast::Label(_it) => (),
|
||||
_ => self.lifetime_allowed = true,
|
||||
}
|
||||
match_ast! {
|
||||
match parent {
|
||||
ast::LifetimeParam(_it) => {
|
||||
self.lifetime_allowed = true;
|
||||
self.lifetime_param_syntax =
|
||||
self.sema.find_node_at_offset_with_macros(original_file, offset);
|
||||
},
|
||||
ast::BreakExpr(_it) => self.is_label_ref = true,
|
||||
ast::ContinueExpr(_it) => self.is_label_ref = true,
|
||||
ast::Label(_it) => (),
|
||||
_ => self.lifetime_allowed = true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user