From e2c1da36f59cd99d4da4c1d5f8f323626d3dbe61 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Sat, 10 Apr 2021 23:12:02 +0200 Subject: Support macros in pattern position --- crates/hir_ty/src/tests/macros.rs | 2 +- crates/hir_ty/src/tests/patterns.rs | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) (limited to 'crates/hir_ty/src') diff --git a/crates/hir_ty/src/tests/macros.rs b/crates/hir_ty/src/tests/macros.rs index 86e3d8b86..b8e373ed8 100644 --- a/crates/hir_ty/src/tests/macros.rs +++ b/crates/hir_ty/src/tests/macros.rs @@ -1065,11 +1065,11 @@ fn macro_in_arm() { } "#, expect![[r#" + !0..2 '()': () 51..110 '{ ... }; }': () 61..62 'x': u32 65..107 'match ... }': u32 71..73 '()': () - 84..91 'unit!()': () 95..100 '92u32': u32 "#]], ); diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 85a28e76b..f514b3efe 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs @@ -1,6 +1,6 @@ use expect_test::expect; -use super::{check_infer, check_infer_with_mismatches}; +use super::{check_infer, check_infer_with_mismatches, check_types}; #[test] fn infer_pattern() { @@ -825,3 +825,29 @@ fn foo(foo: Foo) { "#]], ); } + +#[test] +fn macro_pat() { + check_types( + r#" +macro_rules! pat { + ($name:ident) => { Enum::Variant1($name) } +} + +enum Enum { + Variant1(u8), + Variant2, +} + +fn f(e: Enum) { + match e { + pat!(bind) => { + bind; + //^^^^ u8 + } + Enum::Variant2 => {} + } +} + "#, + ) +} -- cgit v1.2.3