Skip to content

Commit 58d5c69

Browse files
committed
Fix Expr::MacroStmts using wrong scopes
1 parent 9165e3b commit 58d5c69

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

crates/hir-def/src/body/scope.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -145,27 +145,28 @@ fn compute_block_scopes(
145145
tail: Option<ExprId>,
146146
body: &Body,
147147
scopes: &mut ExprScopes,
148-
mut scope: ScopeId,
148+
scope: &mut ScopeId,
149149
) {
150150
for stmt in statements {
151151
match stmt {
152152
Statement::Let { pat, initializer, else_branch, .. } => {
153153
if let Some(expr) = initializer {
154-
compute_expr_scopes(*expr, body, scopes, &mut scope);
154+
compute_expr_scopes(*expr, body, scopes, scope);
155155
}
156156
if let Some(expr) = else_branch {
157-
compute_expr_scopes(*expr, body, scopes, &mut scope);
157+
compute_expr_scopes(*expr, body, scopes, scope);
158158
}
159-
scope = scopes.new_scope(scope);
160-
scopes.add_bindings(body, scope, *pat);
159+
160+
*scope = scopes.new_scope(*scope);
161+
scopes.add_bindings(body, *scope, *pat);
161162
}
162163
Statement::Expr { expr, .. } => {
163-
compute_expr_scopes(*expr, body, scopes, &mut scope);
164+
compute_expr_scopes(*expr, body, scopes, scope);
164165
}
165166
}
166167
}
167168
if let Some(expr) = tail {
168-
compute_expr_scopes(expr, body, scopes, &mut scope);
169+
compute_expr_scopes(expr, body, scopes, scope);
169170
}
170171
}
171172

@@ -176,14 +177,14 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope
176177
scopes.set_scope(expr, *scope);
177178
match &body[expr] {
178179
Expr::MacroStmts { statements, tail } => {
179-
compute_block_scopes(statements, *tail, body, scopes, *scope);
180+
compute_block_scopes(statements, *tail, body, scopes, scope);
180181
}
181182
Expr::Block { statements, tail, id, label } => {
182-
let scope = scopes.new_block_scope(*scope, *id, make_label(label));
183+
let mut scope = scopes.new_block_scope(*scope, *id, make_label(label));
183184
// Overwrite the old scope for the block expr, so that every block scope can be found
184185
// via the block itself (important for blocks that only contain items, no expressions).
185186
scopes.set_scope(expr, scope);
186-
compute_block_scopes(statements, *tail, body, scopes, scope);
187+
compute_block_scopes(statements, *tail, body, scopes, &mut scope);
187188
}
188189
Expr::For { iterable, pat, body: body_expr, label } => {
189190
compute_expr_scopes(*iterable, body, scopes, scope);

crates/hir-ty/src/tests/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ fn recurisve_macro_expanded_in_stmts() {
346346
!3..4 'a': i32
347347
!5..6 '3': i32
348348
196..237 '{ ...= a; }': ()
349-
229..230 'b': {unknown}
350-
233..234 'a': {unknown}
349+
229..230 'b': i32
350+
233..234 'a': i32
351351
"#]],
352352
);
353353
}

0 commit comments

Comments
 (0)