diff options
Diffstat (limited to 'crates/ra_hir_ty/src/tests')
-rw-r--r-- | crates/ra_hir_ty/src/tests/patterns.rs | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs index 81d00c2af..76aa32024 100644 --- a/crates/ra_hir_ty/src/tests/patterns.rs +++ b/crates/ra_hir_ty/src/tests/patterns.rs | |||
@@ -53,8 +53,9 @@ fn test(x: &i32) { | |||
53 | [140; 141) 'g': {unknown} | 53 | [140; 141) 'g': {unknown} |
54 | [144; 145) 'e': {unknown} | 54 | [144; 145) 'e': {unknown} |
55 | [158; 205) 'if let... }': () | 55 | [158; 205) 'if let... }': () |
56 | [165; 170) '[val]': {unknown} | 56 | [165; 170) '[val]': [{unknown}] |
57 | [173; 176) 'opt': {unknown} | 57 | [166; 169) 'val': {unknown} |
58 | [173; 176) 'opt': [{unknown}] | ||
58 | [177; 205) '{ ... }': () | 59 | [177; 205) '{ ... }': () |
59 | [191; 192) 'h': {unknown} | 60 | [191; 192) 'h': {unknown} |
60 | [195; 198) 'val': {unknown} | 61 | [195; 198) 'val': {unknown} |
@@ -137,6 +138,94 @@ fn test() { | |||
137 | } | 138 | } |
138 | 139 | ||
139 | #[test] | 140 | #[test] |
141 | fn infer_pattern_match_slice() { | ||
142 | assert_snapshot!( | ||
143 | infer(r#" | ||
144 | fn test() { | ||
145 | let slice: &[f64] = &[0.0]; | ||
146 | match slice { | ||
147 | &[] => {}, | ||
148 | &[a] => { | ||
149 | a; | ||
150 | }, | ||
151 | &[b, c] => { | ||
152 | b; | ||
153 | c; | ||
154 | } | ||
155 | _ => {} | ||
156 | } | ||
157 | } | ||
158 | "#), | ||
159 | @r###" | ||
160 | [11; 210) '{ ... } }': () | ||
161 | [21; 26) 'slice': &[f64] | ||
162 | [37; 43) '&[0.0]': &[f64; _] | ||
163 | [38; 43) '[0.0]': [f64; _] | ||
164 | [39; 42) '0.0': f64 | ||
165 | [49; 208) 'match ... }': () | ||
166 | [55; 60) 'slice': &[f64] | ||
167 | [71; 74) '&[]': &[f64] | ||
168 | [72; 74) '[]': [f64] | ||
169 | [78; 80) '{}': () | ||
170 | [90; 94) '&[a]': &[f64] | ||
171 | [91; 94) '[a]': [f64] | ||
172 | [92; 93) 'a': f64 | ||
173 | [98; 124) '{ ... }': () | ||
174 | [112; 113) 'a': f64 | ||
175 | [134; 141) '&[b, c]': &[f64] | ||
176 | [135; 141) '[b, c]': [f64] | ||
177 | [136; 137) 'b': f64 | ||
178 | [139; 140) 'c': f64 | ||
179 | [145; 186) '{ ... }': () | ||
180 | [159; 160) 'b': f64 | ||
181 | [174; 175) 'c': f64 | ||
182 | [195; 196) '_': &[f64] | ||
183 | [200; 202) '{}': () | ||
184 | "### | ||
185 | ); | ||
186 | } | ||
187 | |||
188 | #[test] | ||
189 | fn infer_pattern_match_arr() { | ||
190 | assert_snapshot!( | ||
191 | infer(r#" | ||
192 | fn test() { | ||
193 | let arr: [f64; 2] = [0.0, 1.0]; | ||
194 | match arr { | ||
195 | [1.0, a] => { | ||
196 | a; | ||
197 | }, | ||
198 | [b, c] => { | ||
199 | b; | ||
200 | c; | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | "#), | ||
205 | @r###" | ||
206 | [11; 180) '{ ... } }': () | ||
207 | [21; 24) 'arr': [f64; _] | ||
208 | [37; 47) '[0.0, 1.0]': [f64; _] | ||
209 | [38; 41) '0.0': f64 | ||
210 | [43; 46) '1.0': f64 | ||
211 | [53; 178) 'match ... }': () | ||
212 | [59; 62) 'arr': [f64; _] | ||
213 | [73; 81) '[1.0, a]': [f64; _] | ||
214 | [74; 77) '1.0': f64 | ||
215 | [79; 80) 'a': f64 | ||
216 | [85; 111) '{ ... }': () | ||
217 | [99; 100) 'a': f64 | ||
218 | [121; 127) '[b, c]': [f64; _] | ||
219 | [122; 123) 'b': f64 | ||
220 | [125; 126) 'c': f64 | ||
221 | [131; 172) '{ ... }': () | ||
222 | [145; 146) 'b': f64 | ||
223 | [160; 161) 'c': f64 | ||
224 | "### | ||
225 | ); | ||
226 | } | ||
227 | |||
228 | #[test] | ||
140 | fn infer_adt_pattern() { | 229 | fn infer_adt_pattern() { |
141 | assert_snapshot!( | 230 | assert_snapshot!( |
142 | infer(r#" | 231 | infer(r#" |