aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/tests/patterns.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/tests/patterns.rs')
-rw-r--r--crates/hir_ty/src/tests/patterns.rs133
1 files changed, 53 insertions, 80 deletions
diff --git a/crates/hir_ty/src/tests/patterns.rs b/crates/hir_ty/src/tests/patterns.rs
index 7d00cee9b..5adbe9c45 100644
--- a/crates/hir_ty/src/tests/patterns.rs
+++ b/crates/hir_ty/src/tests/patterns.rs
@@ -1,6 +1,6 @@
1use expect_test::expect; 1use expect_test::expect;
2 2
3use super::{check_infer, check_infer_with_mismatches, check_types}; 3use super::{check_infer, check_infer_with_mismatches, check_mismatches, check_types};
4 4
5#[test] 5#[test]
6fn infer_pattern() { 6fn infer_pattern() {
@@ -518,47 +518,24 @@ fn infer_generics_in_patterns() {
518 518
519#[test] 519#[test]
520fn infer_const_pattern() { 520fn infer_const_pattern() {
521 check_infer_with_mismatches( 521 check_mismatches(
522 r#" 522 r#"
523 enum Option<T> { None } 523enum Option<T> { None }
524 use Option::None; 524use Option::None;
525 struct Foo; 525struct Foo;
526 const Bar: usize = 1; 526const Bar: usize = 1;
527 527
528 fn test() { 528fn test() {
529 let a: Option<u32> = None; 529 let a: Option<u32> = None;
530 let b: Option<i64> = match a { 530 let b: Option<i64> = match a {
531 None => None, 531 None => None,
532 }; 532 };
533 let _: () = match () { Foo => Foo }; // Expected mismatch 533 let _: () = match () { Foo => () };
534 let _: () = match () { Bar => Bar }; // Expected mismatch 534 // ^^^ expected (), got Foo
535 } 535 let _: () = match () { Bar => () };
536 // ^^^ expected (), got usize
537}
536 "#, 538 "#,
537 expect![[r#"
538 73..74 '1': usize
539 87..309 '{ ...atch }': ()
540 97..98 'a': Option<u32>
541 114..118 'None': Option<u32>
542 128..129 'b': Option<i64>
543 145..182 'match ... }': Option<i64>
544 151..152 'a': Option<u32>
545 163..167 'None': Option<u32>
546 171..175 'None': Option<i64>
547 192..193 '_': ()
548 200..223 'match ... Foo }': Foo
549 206..208 '()': ()
550 211..214 'Foo': Foo
551 218..221 'Foo': Foo
552 254..255 '_': ()
553 262..285 'match ... Bar }': usize
554 268..270 '()': ()
555 273..276 'Bar': usize
556 280..283 'Bar': usize
557 200..223: expected (), got Foo
558 211..214: expected (), got Foo
559 262..285: expected (), got usize
560 273..276: expected (), got usize
561 "#]],
562 ); 539 );
563} 540}
564 541
@@ -594,48 +571,44 @@ fn main() {
594fn match_ergonomics_in_closure_params() { 571fn match_ergonomics_in_closure_params() {
595 check_infer( 572 check_infer(
596 r#" 573 r#"
597 #[lang = "fn_once"] 574//- minicore: fn
598 trait FnOnce<Args> { 575fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} }
599 type Output;
600 }
601
602 fn foo<T, U, F: FnOnce(T) -> U>(t: T, f: F) -> U { loop {} }
603 576
604 fn test() { 577fn test() {
605 foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics 578 foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics
606 foo(&(1, "a"), |(x, y)| x); 579 foo(&(1, "a"), |(x, y)| x);
607 } 580}
608 "#, 581"#,
609 expect![[r#" 582 expect![[r#"
610 93..94 't': T 583 32..33 't': T
611 99..100 'f': F 584 38..39 'f': F
612 110..121 '{ loop {} }': U 585 49..60 '{ loop {} }': U
613 112..119 'loop {}': ! 586 51..58 'loop {}': !
614 117..119 '{}': () 587 56..58 '{}': ()
615 133..232 '{ ... x); }': () 588 72..171 '{ ... x); }': ()
616 139..142 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32 589 78..81 'foo': fn foo<&(i32, &str), i32, |&(i32, &str)| -> i32>(&(i32, &str), |&(i32, &str)| -> i32) -> i32
617 139..166 'foo(&(...y)| x)': i32 590 78..105 'foo(&(...y)| x)': i32
618 143..152 '&(1, "a")': &(i32, &str) 591 82..91 '&(1, "a")': &(i32, &str)
619 144..152 '(1, "a")': (i32, &str) 592 83..91 '(1, "a")': (i32, &str)
620 145..146 '1': i32 593 84..85 '1': i32
621 148..151 '"a"': &str 594 87..90 '"a"': &str
622 154..165 '|&(x, y)| x': |&(i32, &str)| -> i32 595 93..104 '|&(x, y)| x': |&(i32, &str)| -> i32
623 155..162 '&(x, y)': &(i32, &str) 596 94..101 '&(x, y)': &(i32, &str)
624 156..162 '(x, y)': (i32, &str) 597 95..101 '(x, y)': (i32, &str)
625 157..158 'x': i32 598 96..97 'x': i32
626 160..161 'y': &str 599 99..100 'y': &str
627 164..165 'x': i32 600 103..104 'x': i32
628 203..206 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32 601 142..145 'foo': fn foo<&(i32, &str), &i32, |&(i32, &str)| -> &i32>(&(i32, &str), |&(i32, &str)| -> &i32) -> &i32
629 203..229 'foo(&(...y)| x)': &i32 602 142..168 'foo(&(...y)| x)': &i32
630 207..216 '&(1, "a")': &(i32, &str) 603 146..155 '&(1, "a")': &(i32, &str)
631 208..216 '(1, "a")': (i32, &str) 604 147..155 '(1, "a")': (i32, &str)
632 209..210 '1': i32 605 148..149 '1': i32
633 212..215 '"a"': &str 606 151..154 '"a"': &str
634 218..228 '|(x, y)| x': |&(i32, &str)| -> &i32 607 157..167 '|(x, y)| x': |&(i32, &str)| -> &i32
635 219..225 '(x, y)': (i32, &str) 608 158..164 '(x, y)': (i32, &str)
636 220..221 'x': &i32 609 159..160 'x': &i32
637 223..224 'y': &&str 610 162..163 'y': &&str
638 227..228 'x': &i32 611 166..167 'x': &i32
639 "#]], 612 "#]],
640 ); 613 );
641} 614}