From 8ce15b02dea7152953775904fd937cced2422bc6 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 26 Mar 2021 03:52:35 +0800 Subject: Fix recursive macro statement expansion --- crates/hir_ty/src/infer/expr.rs | 1 + crates/hir_ty/src/tests/macros.rs | 40 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 3f3187ea2..e6ede05ca 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs @@ -767,6 +767,7 @@ impl<'a> InferenceContext<'a> { None => self.table.new_float_var(), }, }, + Expr::MacroStmts { tail } => self.infer_expr(*tail, expected), }; // use a new type variable if we got unknown here let ty = self.insert_type_vars_shallow(ty); diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 7eda51866..01935ec99 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs @@ -226,11 +226,48 @@ fn expr_macro_expanded_in_stmts() { "#, expect![[r#" !0..8 'leta=();': () + !0..8 'leta=();': () + !3..4 'a': () + !5..7 '()': () 57..84 '{ ...); } }': () "#]], ); } +#[test] +fn recurisve_macro_expanded_in_stmts() { + check_infer( + r#" + macro_rules! ng { + ([$($tts:tt)*]) => { + $($tts)*; + }; + ([$($tts:tt)*] $head:tt $($rest:tt)*) => { + ng! { + [$($tts)* $head] $($rest)* + } + }; + } + fn foo() { + ng!([] let a = 3); + let b = a; + } + "#, + 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} + !3..4 'a': i32 + !5..6 '3': i32 + 196..237 '{ ...= a; }': () + 229..230 'b': i32 + 233..234 'a': i32 + "#]], + ); +} + #[test] fn recursive_inner_item_macro_rules() { check_infer( @@ -246,7 +283,8 @@ fn recursive_inner_item_macro_rules() { "#, expect![[r#" !0..1 '1': i32 - !0..7 'mac!($)': {unknown} + !0..26 'macro_...>{1};}': {unknown} + !0..26 'macro_...>{1};}': {unknown} 107..143 '{ ...!(); }': () 129..130 'a': i32 "#]], -- cgit v1.2.3