From dd6ec81d658f7cd06b7ed37174b170f0e8930eed Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 10 Jan 2020 22:00:41 +0100 Subject: Add test for macro expansion in various expressions --- crates/ra_hir_ty/src/tests/macros.rs | 81 ++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) (limited to 'crates/ra_hir_ty/src') diff --git a/crates/ra_hir_ty/src/tests/macros.rs b/crates/ra_hir_ty/src/tests/macros.rs index 69c695cc8..9d09d93a7 100644 --- a/crates/ra_hir_ty/src/tests/macros.rs +++ b/crates/ra_hir_ty/src/tests/macros.rs @@ -135,6 +135,87 @@ fn main() { ); } +#[test] +fn expr_macro_expanded_in_various_places() { + assert_snapshot!( + infer(r#" +macro_rules! spam { + () => (1isize); +} + +fn spam() { + spam!(); + (spam!()); + spam!().spam(spam!()); + for _ in spam!() {} + || spam!(); + while spam!() {} + break spam!(); + return spam!(); + match spam!() { + _ if spam!() => spam!(), + } + spam!()(spam!()); + Spam { spam: spam!() }; + spam!()[spam!()]; + await spam!(); + spam!() as usize; + &spam!(); + -spam!(); + spam!()..spam!(); + spam!() + spam!(); +} +"#), + @r###" + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + ![0; 6) '1isize': isize + [54; 457) '{ ...!(); }': ! + [88; 109) 'spam!(...am!())': {unknown} + [115; 134) 'for _ ...!() {}': () + [119; 120) '_': {unknown} + [132; 134) '{}': () + [139; 149) '|| spam!()': || -> isize + [155; 171) 'while ...!() {}': () + [169; 171) '{}': () + [176; 189) 'break spam!()': ! + [195; 209) 'return spam!()': ! + [215; 269) 'match ... }': isize + [239; 240) '_': isize + [274; 290) 'spam!(...am!())': {unknown} + [296; 318) 'Spam {...m!() }': {unknown} + [324; 340) 'spam!(...am!()]': {unknown} + [365; 381) 'spam!(... usize': usize + [387; 395) '&spam!()': &isize + [401; 409) '-spam!()': isize + [415; 431) 'spam!(...pam!()': {unknown} + [437; 454) 'spam!(...pam!()': isize + "### + ); +} + #[test] fn infer_type_value_macro_having_same_name() { assert_snapshot!( -- cgit v1.2.3