From f5efa17515a543c1405ecad2caf93ed25052500e Mon Sep 17 00:00:00 2001 From: Josh Mcguigan Date: Sun, 1 Mar 2020 14:02:32 -0800 Subject: handle array pattern matching type inference --- crates/ra_hir_ty/src/tests/patterns.rs | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'crates/ra_hir_ty/src/tests') diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index d8e95112f..76aa32024 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs @@ -54,6 +54,7 @@ fn test(x: &i32) { [144; 145) 'e': {unknown} [158; 205) 'if let... }': () [165; 170) '[val]': [{unknown}] + [166; 169) 'val': {unknown} [173; 176) 'opt': [{unknown}] [177; 205) '{ ... }': () [191; 192) 'h': {unknown} @@ -184,6 +185,46 @@ fn test() { ); } +#[test] +fn infer_pattern_match_arr() { + assert_snapshot!( + infer(r#" +fn test() { + let arr: [f64; 2] = [0.0, 1.0]; + match arr { + [1.0, a] => { + a; + }, + [b, c] => { + b; + c; + } + } +} +"#), + @r###" + [11; 180) '{ ... } }': () + [21; 24) 'arr': [f64; _] + [37; 47) '[0.0, 1.0]': [f64; _] + [38; 41) '0.0': f64 + [43; 46) '1.0': f64 + [53; 178) 'match ... }': () + [59; 62) 'arr': [f64; _] + [73; 81) '[1.0, a]': [f64; _] + [74; 77) '1.0': f64 + [79; 80) 'a': f64 + [85; 111) '{ ... }': () + [99; 100) 'a': f64 + [121; 127) '[b, c]': [f64; _] + [122; 123) 'b': f64 + [125; 126) 'c': f64 + [131; 172) '{ ... }': () + [145; 146) 'b': f64 + [160; 161) 'c': f64 + "### + ); +} + #[test] fn infer_adt_pattern() { assert_snapshot!( -- cgit v1.2.3