aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/patterns.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/patterns.rs46
1 files changed, 45 insertions, 1 deletions
diff --git a/crates/ra_hir_ty/src/tests/patterns.rs b/crates/ra_hir_ty/src/tests/patterns.rs
index e25d6dbc4..81d00c2af 100644
--- a/crates/ra_hir_ty/src/tests/patterns.rs
+++ b/crates/ra_hir_ty/src/tests/patterns.rs
@@ -1,4 +1,4 @@
1use super::infer; 1use super::{infer, infer_with_mismatches};
2use insta::assert_snapshot; 2use insta::assert_snapshot;
3use test_utils::covers; 3use test_utils::covers;
4 4
@@ -236,3 +236,47 @@ fn test(a1: A<u32>, o: Option<u64>) {
236 "### 236 "###
237 ); 237 );
238} 238}
239
240#[test]
241fn infer_const_pattern() {
242 assert_snapshot!(
243 infer_with_mismatches(r#"
244enum Option<T> { None }
245use Option::None;
246struct Foo;
247const Bar: usize = 1;
248
249fn test() {
250 let a: Option<u32> = None;
251 let b: Option<i64> = match a {
252 None => None,
253 };
254 let _: () = match () { Foo => Foo }; // Expected mismatch
255 let _: () = match () { Bar => Bar }; // Expected mismatch
256}
257"#, true),
258 @r###"
259 [74; 75) '1': usize
260 [88; 310) '{ ...atch }': ()
261 [98; 99) 'a': Option<u32>
262 [115; 119) 'None': Option<u32>
263 [129; 130) 'b': Option<i64>
264 [146; 183) 'match ... }': Option<i64>
265 [152; 153) 'a': Option<u32>
266 [164; 168) 'None': Option<u32>
267 [172; 176) 'None': Option<i64>
268 [193; 194) '_': ()
269 [201; 224) 'match ... Foo }': Foo
270 [207; 209) '()': ()
271 [212; 215) 'Foo': Foo
272 [219; 222) 'Foo': Foo
273 [255; 256) '_': ()
274 [263; 286) 'match ... Bar }': usize
275 [269; 271) '()': ()
276 [274; 277) 'Bar': usize
277 [281; 284) 'Bar': usize
278 [201; 224): expected (), got Foo
279 [263; 286): expected (), got usize
280 "###
281 );
282}