diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs index 409193b269..e188d80eb8 100644 --- a/crates/hir-def/src/body/lower.rs +++ b/crates/hir-def/src/body/lower.rs @@ -631,7 +631,6 @@ impl ExprCollector<'_> { let mac_call = mac.macro_call()?; let syntax_ptr = AstPtr::new(expr); let macro_ptr = AstPtr::new(&mac_call); - // let prev_stmt = self.statements_in_scope.len(); let stmt = self.collect_macro_call( mac_call, macro_ptr, diff --git a/crates/hir-def/src/body/scope.rs b/crates/hir-def/src/body/scope.rs index c9ab19e59b..019c10712b 100644 --- a/crates/hir-def/src/body/scope.rs +++ b/crates/hir-def/src/body/scope.rs @@ -175,6 +175,9 @@ fn compute_expr_scopes(expr: ExprId, body: &Body, scopes: &mut ExprScopes, scope scopes.set_scope(expr, *scope); match &body[expr] { + Expr::MacroStmts { statements, tail } => { + compute_block_scopes(statements, *tail, body, scopes, *scope); + } Expr::Block { statements, tail, id, label } => { let scope = scopes.new_block_scope(*scope, *id, make_label(label)); // Overwrite the old scope for the block expr, so that every block scope can be found diff --git a/crates/hir-ty/src/tests/macros.rs b/crates/hir-ty/src/tests/macros.rs index a61175f273..5a3cde028d 100644 --- a/crates/hir-ty/src/tests/macros.rs +++ b/crates/hir-ty/src/tests/macros.rs @@ -191,6 +191,8 @@ fn expr_macro_def_expanded_in_various_places() { !0..6 '1isize': isize !0..6 '1isize': isize !0..6 '1isize': isize + !0..6 '1isize': isize + !0..6 '1isize': isize 39..442 '{ ...!(); }': () 73..94 'spam!(...am!())': {unknown} 100..119 'for _ ...!() {}': () @@ -272,6 +274,8 @@ fn expr_macro_rules_expanded_in_various_places() { !0..6 '1isize': isize !0..6 '1isize': isize !0..6 '1isize': isize + !0..6 '1isize': isize + !0..6 '1isize': isize 53..456 '{ ...!(); }': () 87..108 'spam!(...am!())': {unknown} 114..133 'for _ ...!() {}': () @@ -306,7 +310,6 @@ fn expr_macro_expanded_in_stmts() { } "#, expect![[r#" - !0..8 'leta=();': () !0..8 'leta=();': () !3..4 'a': () !5..7 '()': () @@ -335,16 +338,16 @@ fn recurisve_macro_expanded_in_stmts() { } "#, expect![[r#" - !0..7 'leta=3;': {unknown} - !0..7 'leta=3;': {unknown} - !0..13 'ng!{[leta=3]}': {unknown} - !0..13 'ng!{[leta=]3}': {unknown} - !0..13 'ng!{[leta]=3}': {unknown} + !0..7 'leta=3;': () + !0..13 'ng!{[leta=3]}': () + !0..13 'ng!{[leta=]3}': () + !0..13 'ng!{[leta]=3}': () + !0..13 'ng!{[let]a=3}': () !3..4 'a': i32 !5..6 '3': i32 196..237 '{ ...= a; }': () - 229..230 'b': i32 - 233..234 'a': i32 + 229..230 'b': {unknown} + 233..234 'a': {unknown} "#]], ); } @@ -364,8 +367,8 @@ fn recursive_inner_item_macro_rules() { "#, expect![[r#" !0..1 '1': i32 - !0..26 'macro_...>{1};}': {unknown} - !0..26 'macro_...>{1};}': {unknown} + !0..7 'mac!($)': () + !0..26 'macro_...>{1};}': () 107..143 '{ ...!(); }': () 129..130 'a': i32 "#]], diff --git a/crates/hir-ty/src/tests/regression.rs b/crates/hir-ty/src/tests/regression.rs index 93f765f703..d41470d29f 100644 --- a/crates/hir-ty/src/tests/regression.rs +++ b/crates/hir-ty/src/tests/regression.rs @@ -573,6 +573,7 @@ fn issue_6811() { } "#, expect![[r#" + !0..16 'let_a=...t_b=1;': () !3..5 '_a': i32 !6..7 '1': i32 !11..13 '_b': i32 @@ -1012,17 +1013,17 @@ fn cfg_tail() { "#, expect![[r#" 14..53 '{ ...)] 9 }': () - 20..31 '{ "first" }': () + 20..31 '{ "first" }': &str 22..29 '"first"': &str 72..190 '{ ...] 13 }': () 78..88 '{ "fake" }': &str 80..86 '"fake"': &str 93..103 '{ "fake" }': &str 95..101 '"fake"': &str - 108..120 '{ "second" }': () + 108..120 '{ "second" }': &str 110..118 '"second"': &str 210..273 '{ ... 15; }': () - 216..227 '{ "third" }': () + 216..227 '{ "third" }': &str 218..225 '"third"': &str 293..357 '{ ...] 15 }': () 299..311 '{ "fourth" }': &str