]> git.lizzy.rs Git - rust.git/blobdiff - crates/hir_ty/src/tests/patterns.rs
Add lowering of array lengths in types
[rust.git] / crates / hir_ty / src / tests / patterns.rs
index 85a28e76b2367be08a19ad73db24859381b67a28..b36e77e91e596c65ff6d5fe17883214b4c752f5f 100644 (file)
@@ -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() {
@@ -243,8 +243,8 @@ fn test() {
         expect![[r#"
             10..209 '{     ...   } }': ()
             20..25 'slice': &[f64]
-            36..42 '&[0.0]': &[f64; _]
-            37..42 '[0.0]': [f64; _]
+            36..42 '&[0.0]': &[f64; 1]
+            37..42 '[0.0]': [f64; 1]
             38..41 '0.0': f64
             48..207 'match ...     }': ()
             54..59 'slice': &[f64]
@@ -345,19 +345,19 @@ fn test() {
         "#,
         expect![[r#"
             10..179 '{     ...   } }': ()
-            20..23 'arr': [f64; _]
-            36..46 '[0.0, 1.0]': [f64; _]
+            20..23 'arr': [f64; 2]
+            36..46 '[0.0, 1.0]': [f64; 2]
             37..40 '0.0': f64
             42..45 '1.0': f64
             52..177 'match ...     }': ()
-            58..61 'arr': [f64; _]
-            72..80 '[1.0, a]': [f64; _]
+            58..61 'arr': [f64; 2]
+            72..80 '[1.0, a]': [f64; 2]
             73..76 '1.0': f64
             73..76 '1.0': f64
             78..79 'a': f64
             84..110 '{     ...     }': ()
             98..99 'a': f64
-            120..126 '[b, c]': [f64; _]
+            120..126 '[b, c]': [f64; 2]
             121..122 'b': f64
             124..125 'c': f64
             130..171 '{     ...     }': ()
@@ -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 => {}
+    }
+}
+    "#,
+    )
+}