Skip to content

Commit 3dbd8b5

Browse files
Merge #8276
8276: Fix block inner item defined in macro r=jonas-schievink a=edwin0cheng Fixes #8229 r? @jonas-schievink Co-authored-by: Edwin Cheng <[email protected]>
2 parents 75011bb + 6a3f2ce commit 3dbd8b5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

crates/hir_def/src/item_tree/lower.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ impl Ctx {
174174
let forced_vis = self.forced_visibility.take();
175175

176176
let mut block_stack = Vec::new();
177+
178+
// if container itself is block, add it to the stack
179+
if let Some(block) = ast::BlockExpr::cast(container.clone()) {
180+
block_stack.push(self.source_ast_id_map.ast_id(&block));
181+
}
182+
177183
for event in container.preorder().skip(1) {
178184
match event {
179185
WalkEvent::Enter(node) => {

crates/hir_ty/src/tests/macros.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,32 @@ fn recursive_inner_item_macro_rules() {
372372
);
373373
}
374374

375+
#[test]
376+
fn infer_macro_defining_block_with_items() {
377+
check_infer(
378+
r#"
379+
macro_rules! foo {
380+
() => {{
381+
fn bar() -> usize { 0 }
382+
bar()
383+
}};
384+
}
385+
fn main() {
386+
let _a = foo!();
387+
}
388+
"#,
389+
expect![[r#"
390+
!15..18 '{0}': usize
391+
!16..17 '0': usize
392+
!0..24 '{fnbar...bar()}': usize
393+
!18..21 'bar': fn bar() -> usize
394+
!18..23 'bar()': usize
395+
98..122 '{ ...!(); }': ()
396+
108..110 '_a': usize
397+
"#]],
398+
);
399+
}
400+
375401
#[test]
376402
fn infer_type_value_macro_having_same_name() {
377403
check_infer(

0 commit comments

Comments
 (0)