Fix block inner item defined in macro

This commit is contained in:
Edwin Cheng 2021-04-01 03:45:21 +08:00
parent 75011bbccb
commit 6a3f2ce76c
2 changed files with 32 additions and 0 deletions

View file

@ -174,6 +174,12 @@ impl Ctx {
let forced_vis = self.forced_visibility.take();
let mut block_stack = Vec::new();
// if container itself is block, add it to the stack
if let Some(block) = ast::BlockExpr::cast(container.clone()) {
block_stack.push(self.source_ast_id_map.ast_id(&block));
}
for event in container.preorder().skip(1) {
match event {
WalkEvent::Enter(node) => {

View file

@ -372,6 +372,32 @@ fn recursive_inner_item_macro_rules() {
);
}
#[test]
fn infer_macro_defining_block_with_items() {
check_infer(
r#"
macro_rules! foo {
() => {{
fn bar() -> usize { 0 }
bar()
}};
}
fn main() {
let _a = foo!();
}
"#,
expect![[r#"
!15..18 '{0}': usize
!16..17 '0': usize
!0..24 '{fnbar...bar()}': usize
!18..21 'bar': fn bar() -> usize
!18..23 'bar()': usize
98..122 '{ ...!(); }': ()
108..110 '_a': usize
"#]],
);
}
#[test]
fn infer_type_value_macro_having_same_name() {
check_infer(