From 35dd62e915905b6a93e2069a6d155cdf00cd254a Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 24 Nov 2020 13:41:21 +0100 Subject: Properly infer tuple patterns when encountering ellipsis --- crates/hir_ty/src/tests/patterns.rs | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 6a965ac4f..5776de280 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs @@ -679,3 +679,50 @@ fn box_pattern() { "#]], ); } + +#[test] +fn tuple_ellipsis_pattern() { + check_infer( + r#" +fn foo(tuple: (u8, i16, f32)) { + match tuple { + (.., b, c) => {}, + (a, .., c) => {}, + (a, b, ..) => {}, + (a, b) => {/*too short*/} + (a, b, c, d) => {/*too long*/} + _ => {} + } +}"#, + expect![[r#" + 7..12 'tuple': (u8, i16, f32) + 30..224 '{ ... } }': () + 36..222 'match ... }': () + 42..47 'tuple': (u8, i16, f32) + 58..68 '(.., b, c)': (u8, i16, f32) + 63..64 'b': i16 + 66..67 'c': f32 + 72..74 '{}': () + 84..94 '(a, .., c)': (u8, i16, f32) + 85..86 'a': u8 + 92..93 'c': f32 + 98..100 '{}': () + 110..120 '(a, b, ..)': (u8, i16, f32) + 111..112 'a': u8 + 114..115 'b': i16 + 124..126 '{}': () + 136..142 '(a, b)': (u8, i16, f32) + 137..138 'a': u8 + 140..141 'b': i16 + 146..161 '{/*too short*/}': () + 170..182 '(a, b, c, d)': (u8, i16, f32, {unknown}) + 171..172 'a': u8 + 174..175 'b': i16 + 177..178 'c': f32 + 180..181 'd': {unknown} + 186..200 '{/*too long*/}': () + 209..210 '_': (u8, i16, f32) + 214..216 '{}': () + "#]], + ); +} -- cgit v1.2.3 From a5efefd3d788a6c5a7fb6a56a0da32f9bf62584e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 24 Nov 2020 14:52:46 +0100 Subject: Properly infer tuple struct patterns when encountering ellipsis --- crates/hir_ty/src/tests/patterns.rs | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'crates/hir_ty/src/tests') diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs index 5776de280..5a5f48fd0 100644 --- a/crates/hir_ty/src/tests/patterns.rs +++ b/crates/hir_ty/src/tests/patterns.rs @@ -726,3 +726,51 @@ fn foo(tuple: (u8, i16, f32)) { "#]], ); } + +#[test] +fn tuple_struct_ellipsis_pattern() { + check_infer( + r#" +struct Tuple(u8, i16, f32); +fn foo(tuple: Tuple) { + match tuple { + Tuple(.., b, c) => {}, + Tuple(a, .., c) => {}, + Tuple(a, b, ..) => {}, + Tuple(a, b) => {/*too short*/} + Tuple(a, b, c, d) => {/*too long*/} + _ => {} + } +}"#, + expect![[r#" + 35..40 'tuple': Tuple + 49..268 '{ ... } }': () + 55..266 'match ... }': () + 61..66 'tuple': Tuple + 77..92 'Tuple(.., b, c)': Tuple + 87..88 'b': i16 + 90..91 'c': f32 + 96..98 '{}': () + 108..123 'Tuple(a, .., c)': Tuple + 114..115 'a': u8 + 121..122 'c': f32 + 127..129 '{}': () + 139..154 'Tuple(a, b, ..)': Tuple + 145..146 'a': u8 + 148..149 'b': i16 + 158..160 '{}': () + 170..181 'Tuple(a, b)': Tuple + 176..177 'a': u8 + 179..180 'b': i16 + 185..200 '{/*too short*/}': () + 209..226 'Tuple(... c, d)': Tuple + 215..216 'a': u8 + 218..219 'b': i16 + 221..222 'c': f32 + 224..225 'd': {unknown} + 230..244 '{/*too long*/}': () + 253..254 '_': Tuple + 258..260 '{}': () + "#]], + ); +} -- cgit v1.2.3