aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
authorMichael Killough <[email protected]>2019-03-16 18:13:13 +0000
committerMichael Killough <[email protected]>2019-03-16 18:13:13 +0000
commitb42c5ced68c019108e079dc01d0bd29606efc10c (patch)
tree340dd45df03b6841103cad9e3980dfe261f8b4e7 /crates/ra_hir/src/ty/tests.rs
parent97a87bf3a68338b1acc2b7a02dfa43096bf47e05 (diff)
Implement BindingMode for pattern matching.
Implement `BindingMode` for pattern matching, so that types can be correctly inferred using match ergonomics. The binding mode defaults to `Move` (referred to as 'BindingMode::BindByValue` in rustc), and is updated by automatic dereferencing of the value being matched.
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs121
1 files changed, 76 insertions, 45 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index c7d409e6d..b12ea4334 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -756,6 +756,8 @@ fn test(x: &str, y: isize) {
756fn infer_pattern() { 756fn infer_pattern() {
757 assert_snapshot_matches!( 757 assert_snapshot_matches!(
758 infer(r#" 758 infer(r#"
759struct A<T>(T);
760
759fn test(x: &i32) { 761fn test(x: &i32) {
760 let y = x; 762 let y = x;
761 let &z = x; 763 let &z = x;
@@ -772,6 +774,12 @@ fn test(x: &i32) {
772 774
773 let lambda = |a: u64, b, c: i32| { a + b; c }; 775 let lambda = |a: u64, b, c: i32| { a + b; c };
774 776
777 let A(n) = &A(1);
778 let A(n) = &mut A(1);
779
780 let v = &(1, &2);
781 let (_, &w) = v;
782
775 let ref ref_to_x = x; 783 let ref ref_to_x = x;
776 let mut mut_x = x; 784 let mut mut_x = x;
777 let ref mut mut_ref_to_x = x; 785 let ref mut mut_ref_to_x = x;
@@ -779,53 +787,76 @@ fn test(x: &i32) {
779} 787}
780"#), 788"#),
781 @r###" 789 @r###"
782[9; 10) 'x': &i32 790[26; 27) 'x': &i32
783[18; 369) '{ ...o_x; }': () 791[35; 479) '{ ...o_x; }': ()
784[28; 29) 'y': &i32 792[45; 46) 'y': &i32
785[32; 33) 'x': &i32 793[49; 50) 'x': &i32
786[43; 45) '&z': &i32 794[60; 62) '&z': &i32
787[44; 45) 'z': i32 795[61; 62) 'z': i32
788[48; 49) 'x': &i32 796[65; 66) 'x': &i32
789[59; 60) 'a': i32 797[76; 77) 'a': i32
790[63; 64) 'z': i32 798[80; 81) 'z': i32
791[74; 80) '(c, d)': (i32, &str) 799[91; 97) '(c, d)': (i32, &str)
792[75; 76) 'c': i32 800[92; 93) 'c': i32
793[78; 79) 'd': &str 801[95; 96) 'd': &str
794[83; 95) '(1, "hello")': (i32, &str) 802[100; 112) '(1, "hello")': (i32, &str)
795[84; 85) '1': i32 803[101; 102) '1': i32
796[87; 94) '"hello"': &str 804[104; 111) '"hello"': &str
797[102; 152) 'for (e... }': () 805[119; 169) 'for (e... }': ()
798[106; 112) '(e, f)': ({unknown}, {unknown}) 806[123; 129) '(e, f)': ({unknown}, {unknown})
799[107; 108) 'e': {unknown} 807[124; 125) 'e': {unknown}
800[110; 111) 'f': {unknown} 808[127; 128) 'f': {unknown}
801[116; 125) 'some_iter': {unknown} 809[133; 142) 'some_iter': {unknown}
802[126; 152) '{ ... }': () 810[143; 169) '{ ... }': ()
803[140; 141) 'g': {unknown} 811[157; 158) 'g': {unknown}
804[144; 145) 'e': {unknown} 812[161; 162) 'e': {unknown}
805[158; 205) 'if let... }': () 813[175; 222) 'if let... }': ()
806[165; 170) '[val]': {unknown} 814[182; 187) '[val]': {unknown}
807[173; 176) 'opt': {unknown} 815[190; 193) 'opt': {unknown}
808[177; 205) '{ ... }': () 816[194; 222) '{ ... }': ()
809[191; 192) 'h': {unknown} 817[208; 209) 'h': {unknown}
810[195; 198) 'val': {unknown} 818[212; 215) 'val': {unknown}
811[215; 221) 'lambda': {unknown} 819[232; 238) 'lambda': {unknown}
812[224; 256) '|a: u6...b; c }': {unknown} 820[241; 273) '|a: u6...b; c }': {unknown}
813[225; 226) 'a': u64 821[242; 243) 'a': u64
814[233; 234) 'b': u64
815[236; 237) 'c': i32
816[244; 256) '{ a + b; c }': i32
817[246; 247) 'a': u64
818[246; 251) 'a + b': u64
819[250; 251) 'b': u64 822[250; 251) 'b': u64
820[253; 254) 'c': i32 823[253; 254) 'c': i32
821[267; 279) 'ref ref_to_x': &&i32 824[261; 273) '{ a + b; c }': i32
822[282; 283) 'x': &i32 825[263; 264) 'a': u64
823[293; 302) 'mut mut_x': &i32 826[263; 268) 'a + b': u64
824[305; 306) 'x': &i32 827[267; 268) 'b': u64
825[316; 336) 'ref mu...f_to_x': &mut &i32 828[270; 271) 'c': i32
826[339; 340) 'x': &i32 829[284; 288) 'A(n)': A<i32>
827[350; 351) 'k': &mut &i32 830[286; 287) 'n': &i32
828[354; 366) 'mut_ref_to_x': &mut &i32"### 831[291; 296) '&A(1)': &A<i32>
832[292; 293) 'A': A<i32>(T) -> A<T>
833[292; 296) 'A(1)': A<i32>
834[294; 295) '1': i32
835[306; 310) 'A(n)': A<i32>
836[308; 309) 'n': &mut i32
837[313; 322) '&mut A(1)': &mut A<i32>
838[318; 319) 'A': A<i32>(T) -> A<T>
839[318; 322) 'A(1)': A<i32>
840[320; 321) '1': i32
841[333; 334) 'v': &(i32, &i32)
842[337; 345) '&(1, &2)': &(i32, &i32)
843[338; 345) '(1, &2)': (i32, &i32)
844[339; 340) '1': i32
845[342; 344) '&2': &i32
846[343; 344) '2': i32
847[355; 362) '(_, &w)': (i32, &i32)
848[356; 357) '_': i32
849[359; 361) '&w': &i32
850[360; 361) 'w': i32
851[365; 366) 'v': &(i32, &i32)
852[377; 389) 'ref ref_to_x': &&i32
853[392; 393) 'x': &i32
854[403; 412) 'mut mut_x': &i32
855[415; 416) 'x': &i32
856[426; 446) 'ref mu...f_to_x': &mut &i32
857[449; 450) 'x': &i32
858[460; 461) 'k': &mut &i32
859[464; 476) 'mut_ref_to_x': &mut &i32"###
829 ); 860 );
830} 861}
831 862