diff options
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 165 |
1 files changed, 122 insertions, 43 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 3ac1fbdd5..2872cd27b 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -1077,7 +1077,6 @@ fn test(x: &i32) { | |||
1077 | } | 1077 | } |
1078 | "#), | 1078 | "#), |
1079 | @r###" | 1079 | @r###" |
1080 | |||
1081 | [9; 10) 'x': &i32 | 1080 | [9; 10) 'x': &i32 |
1082 | [18; 369) '{ ...o_x; }': () | 1081 | [18; 369) '{ ...o_x; }': () |
1083 | [28; 29) 'y': &i32 | 1082 | [28; 29) 'y': &i32 |
@@ -1107,8 +1106,8 @@ fn test(x: &i32) { | |||
1107 | [177; 205) '{ ... }': () | 1106 | [177; 205) '{ ... }': () |
1108 | [191; 192) 'h': {unknown} | 1107 | [191; 192) 'h': {unknown} |
1109 | [195; 198) 'val': {unknown} | 1108 | [195; 198) 'val': {unknown} |
1110 | [215; 221) 'lambda': {unknown} | 1109 | [215; 221) 'lambda': |u64, u64, i32| -> i32 |
1111 | [224; 256) '|a: u6...b; c }': {unknown} | 1110 | [224; 256) '|a: u6...b; c }': |u64, u64, i32| -> i32 |
1112 | [225; 226) 'a': u64 | 1111 | [225; 226) 'a': u64 |
1113 | [233; 234) 'b': u64 | 1112 | [233; 234) 'b': u64 |
1114 | [236; 237) 'c': i32 | 1113 | [236; 237) 'c': i32 |
@@ -2836,12 +2835,11 @@ fn test() -> u64 { | |||
2836 | } | 2835 | } |
2837 | "#), | 2836 | "#), |
2838 | @r###" | 2837 | @r###" |
2839 | |||
2840 | [44; 102) '{ ...0(2) }': u64 | 2838 | [44; 102) '{ ...0(2) }': u64 |
2841 | [54; 55) 'a': S | 2839 | [54; 55) 'a': S |
2842 | [58; 59) 'S': S(fn(u32) -> u64) -> S | 2840 | [58; 59) 'S': S(fn(u32) -> u64) -> S |
2843 | [58; 68) 'S(|i| 2*i)': S | 2841 | [58; 68) 'S(|i| 2*i)': S |
2844 | [60; 67) '|i| 2*i': fn(u32) -> u64 | 2842 | [60; 67) '|i| 2*i': |i32| -> i32 |
2845 | [61; 62) 'i': i32 | 2843 | [61; 62) 'i': i32 |
2846 | [64; 65) '2': i32 | 2844 | [64; 65) '2': i32 |
2847 | [64; 67) '2*i': i32 | 2845 | [64; 67) '2*i': i32 |
@@ -3802,13 +3800,13 @@ fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) { | |||
3802 | [296; 299) 'get': fn get<T>(T) -> <T as Trait>::Type | 3800 | [296; 299) 'get': fn get<T>(T) -> <T as Trait>::Type |
3803 | [296; 302) 'get(x)': {unknown} | 3801 | [296; 302) 'get(x)': {unknown} |
3804 | [300; 301) 'x': T | 3802 | [300; 301) 'x': T |
3805 | [308; 312) 'get2': fn get2<{unknown}, S<{unknown}>>(T) -> U | 3803 | [308; 312) 'get2': fn get2<{unknown}, T>(T) -> U |
3806 | [308; 315) 'get2(x)': {unknown} | 3804 | [308; 315) 'get2(x)': {unknown} |
3807 | [313; 314) 'x': T | 3805 | [313; 314) 'x': T |
3808 | [321; 324) 'get': fn get<impl Trait<Type = i64>>(T) -> <T as Trait>::Type | 3806 | [321; 324) 'get': fn get<impl Trait<Type = i64>>(T) -> <T as Trait>::Type |
3809 | [321; 327) 'get(y)': {unknown} | 3807 | [321; 327) 'get(y)': {unknown} |
3810 | [325; 326) 'y': impl Trait<Type = i64> | 3808 | [325; 326) 'y': impl Trait<Type = i64> |
3811 | [333; 337) 'get2': fn get2<{unknown}, S<{unknown}>>(T) -> U | 3809 | [333; 337) 'get2': fn get2<{unknown}, impl Trait<Type = i64>>(T) -> U |
3812 | [333; 340) 'get2(y)': {unknown} | 3810 | [333; 340) 'get2(y)': {unknown} |
3813 | [338; 339) 'y': impl Trait<Type = i64> | 3811 | [338; 339) 'y': impl Trait<Type = i64> |
3814 | [346; 349) 'get': fn get<S<u64>>(T) -> <T as Trait>::Type | 3812 | [346; 349) 'get': fn get<S<u64>>(T) -> <T as Trait>::Type |
@@ -3992,49 +3990,50 @@ fn test<F: FnOnce(u32, u64) -> u128>(f: F) { | |||
3992 | fn closure_1() { | 3990 | fn closure_1() { |
3993 | assert_snapshot!( | 3991 | assert_snapshot!( |
3994 | infer(r#" | 3992 | infer(r#" |
3993 | #[lang = "fn_once"] | ||
3995 | trait FnOnce<Args> { | 3994 | trait FnOnce<Args> { |
3996 | type Output; | 3995 | type Output; |
3997 | } | 3996 | } |
3998 | 3997 | ||
3999 | enum Option<T> { Some(T), None } | 3998 | enum Option<T> { Some(T), None } |
4000 | impl<T> Option<T> { | 3999 | impl<T> Option<T> { |
4001 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> U {} | 4000 | fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Option<U> {} |
4002 | } | 4001 | } |
4003 | 4002 | ||
4004 | fn test() { | 4003 | fn test() { |
4005 | let x = Option::Some(1i32); | 4004 | let x = Option::Some(1u32); |
4006 | x.map(|v| v + 1); | 4005 | x.map(|v| v + 1); |
4007 | x.map(|_v| 1u64); | 4006 | x.map(|_v| 1u64); |
4008 | let y: Option<i64> = x.map(|_v| 1); | 4007 | let y: Option<i64> = x.map(|_v| 1); |
4009 | } | 4008 | } |
4010 | "#), | 4009 | "#), |
4011 | @r###" | 4010 | @r###" |
4012 | [128; 132) 'self': Option<T> | 4011 | [148; 152) 'self': Option<T> |
4013 | [134; 135) 'f': F | 4012 | [154; 155) 'f': F |
4014 | [145; 147) '{}': () | 4013 | [173; 175) '{}': () |
4015 | [161; 280) '{ ... 1); }': () | 4014 | [189; 308) '{ ... 1); }': () |
4016 | [171; 172) 'x': Option<i32> | 4015 | [199; 200) 'x': Option<u32> |
4017 | [175; 187) 'Option::Some': Some<i32>(T) -> Option<T> | 4016 | [203; 215) 'Option::Some': Some<u32>(T) -> Option<T> |
4018 | [175; 193) 'Option...(1i32)': Option<i32> | 4017 | [203; 221) 'Option...(1u32)': Option<u32> |
4019 | [188; 192) '1i32': i32 | 4018 | [216; 220) '1u32': u32 |
4020 | [199; 200) 'x': Option<i32> | 4019 | [227; 228) 'x': Option<u32> |
4021 | [199; 215) 'x.map(...v + 1)': {unknown} | 4020 | [227; 243) 'x.map(...v + 1)': Option<u32> |
4022 | [205; 214) '|v| v + 1': {unknown} | 4021 | [233; 242) '|v| v + 1': |u32| -> u32 |
4023 | [206; 207) 'v': {unknown} | 4022 | [234; 235) 'v': u32 |
4024 | [209; 210) 'v': {unknown} | 4023 | [237; 238) 'v': u32 |
4025 | [209; 214) 'v + 1': i32 | 4024 | [237; 242) 'v + 1': u32 |
4026 | [213; 214) '1': i32 | 4025 | [241; 242) '1': u32 |
4027 | [221; 222) 'x': Option<i32> | 4026 | [249; 250) 'x': Option<u32> |
4028 | [221; 237) 'x.map(... 1u64)': {unknown} | 4027 | [249; 265) 'x.map(... 1u64)': Option<u64> |
4029 | [227; 236) '|_v| 1u64': {unknown} | 4028 | [255; 264) '|_v| 1u64': |u32| -> u64 |
4030 | [228; 230) '_v': {unknown} | 4029 | [256; 258) '_v': u32 |
4031 | [232; 236) '1u64': u64 | 4030 | [260; 264) '1u64': u64 |
4032 | [247; 248) 'y': Option<i64> | 4031 | [275; 276) 'y': Option<i64> |
4033 | [264; 265) 'x': Option<i32> | 4032 | [292; 293) 'x': Option<u32> |
4034 | [264; 277) 'x.map(|_v| 1)': Option<i64> | 4033 | [292; 305) 'x.map(|_v| 1)': Option<i64> |
4035 | [270; 276) '|_v| 1': {unknown} | 4034 | [298; 304) '|_v| 1': |u32| -> i64 |
4036 | [271; 273) '_v': {unknown} | 4035 | [299; 301) '_v': u32 |
4037 | [275; 276) '1': i32 | 4036 | [303; 304) '1': i64 |
4038 | "### | 4037 | "### |
4039 | ); | 4038 | ); |
4040 | } | 4039 | } |
@@ -4060,17 +4059,17 @@ fn test<F: FnOnce(u32) -> u64>(f: F) { | |||
4060 | [85; 86) 'f': F | 4059 | [85; 86) 'f': F |
4061 | [85; 89) 'f(1)': {unknown} | 4060 | [85; 89) 'f(1)': {unknown} |
4062 | [87; 88) '1': i32 | 4061 | [87; 88) '1': i32 |
4063 | [99; 100) 'g': {unknown} | 4062 | [99; 100) 'g': |u64| -> i32 |
4064 | [103; 112) '|v| v + 1': {unknown} | 4063 | [103; 112) '|v| v + 1': |u64| -> i32 |
4065 | [104; 105) 'v': {unknown} | 4064 | [104; 105) 'v': u64 |
4066 | [107; 108) 'v': {unknown} | 4065 | [107; 108) 'v': u64 |
4067 | [107; 112) 'v + 1': i32 | 4066 | [107; 112) 'v + 1': i32 |
4068 | [111; 112) '1': i32 | 4067 | [111; 112) '1': i32 |
4069 | [118; 119) 'g': {unknown} | 4068 | [118; 119) 'g': |u64| -> i32 |
4070 | [118; 125) 'g(1u64)': {unknown} | 4069 | [118; 125) 'g(1u64)': i32 |
4071 | [120; 124) '1u64': u64 | 4070 | [120; 124) '1u64': u64 |
4072 | [135; 136) 'h': {unknown} | 4071 | [135; 136) 'h': |u128| -> u128 |
4073 | [139; 152) '|v| 1u128 + v': {unknown} | 4072 | [139; 152) '|v| 1u128 + v': |u128| -> u128 |
4074 | [140; 141) 'v': u128 | 4073 | [140; 141) 'v': u128 |
4075 | [143; 148) '1u128': u128 | 4074 | [143; 148) '1u128': u128 |
4076 | [143; 152) '1u128 + v': u128 | 4075 | [143; 152) '1u128 + v': u128 |
@@ -4080,6 +4079,86 @@ fn test<F: FnOnce(u32) -> u64>(f: F) { | |||
4080 | } | 4079 | } |
4081 | 4080 | ||
4082 | #[test] | 4081 | #[test] |
4082 | fn closure_as_argument_inference_order() { | ||
4083 | assert_snapshot!( | ||
4084 | infer(r#" | ||
4085 | #[lang = "fn_once"] | ||
4086 | trait FnOnce<Args> { | ||
4087 | type Output; | ||
4088 | } | ||
4089 | |||
4090 | fn foo1<T, U, F: FnOnce(T) -> U>(x: T, f: F) -> U {} | ||
4091 | fn foo2<T, U, F: FnOnce(T) -> U>(f: F, x: T) -> U {} | ||
4092 | |||
4093 | struct S; | ||
4094 | impl S { | ||
4095 | fn method(self) -> u64; | ||
4096 | |||
4097 | fn foo1<T, U, F: FnOnce(T) -> U>(self, x: T, f: F) -> U {} | ||
4098 | fn foo2<T, U, F: FnOnce(T) -> U>(self, f: F, x: T) -> U {} | ||
4099 | } | ||
4100 | |||
4101 | fn test() { | ||
4102 | let x1 = foo1(S, |s| s.method()); | ||
4103 | let x2 = foo2(|s| s.method(), S); | ||
4104 | let x3 = S.foo1(S, |s| s.method()); | ||
4105 | let x4 = S.foo2(|s| s.method(), S); | ||
4106 | } | ||
4107 | "#), | ||
4108 | @r###" | ||
4109 | [95; 96) 'x': T | ||
4110 | [101; 102) 'f': F | ||
4111 | [112; 114) '{}': () | ||
4112 | [148; 149) 'f': F | ||
4113 | [154; 155) 'x': T | ||
4114 | [165; 167) '{}': () | ||
4115 | [202; 206) 'self': S | ||
4116 | [254; 258) 'self': S | ||
4117 | [260; 261) 'x': T | ||
4118 | [266; 267) 'f': F | ||
4119 | [277; 279) '{}': () | ||
4120 | [317; 321) 'self': S | ||
4121 | [323; 324) 'f': F | ||
4122 | [329; 330) 'x': T | ||
4123 | [340; 342) '{}': () | ||
4124 | [356; 515) '{ ... S); }': () | ||
4125 | [366; 368) 'x1': u64 | ||
4126 | [371; 375) 'foo1': fn foo1<S, u64, |S| -> u64>(T, F) -> U | ||
4127 | [371; 394) 'foo1(S...hod())': u64 | ||
4128 | [376; 377) 'S': S | ||
4129 | [379; 393) '|s| s.method()': |S| -> u64 | ||
4130 | [380; 381) 's': S | ||
4131 | [383; 384) 's': S | ||
4132 | [383; 393) 's.method()': u64 | ||
4133 | [404; 406) 'x2': u64 | ||
4134 | [409; 413) 'foo2': fn foo2<S, u64, |S| -> u64>(F, T) -> U | ||
4135 | [409; 432) 'foo2(|...(), S)': u64 | ||
4136 | [414; 428) '|s| s.method()': |S| -> u64 | ||
4137 | [415; 416) 's': S | ||
4138 | [418; 419) 's': S | ||
4139 | [418; 428) 's.method()': u64 | ||
4140 | [430; 431) 'S': S | ||
4141 | [442; 444) 'x3': u64 | ||
4142 | [447; 448) 'S': S | ||
4143 | [447; 472) 'S.foo1...hod())': u64 | ||
4144 | [454; 455) 'S': S | ||
4145 | [457; 471) '|s| s.method()': |S| -> u64 | ||
4146 | [458; 459) 's': S | ||
4147 | [461; 462) 's': S | ||
4148 | [461; 471) 's.method()': u64 | ||
4149 | [482; 484) 'x4': u64 | ||
4150 | [487; 488) 'S': S | ||
4151 | [487; 512) 'S.foo2...(), S)': u64 | ||
4152 | [494; 508) '|s| s.method()': |S| -> u64 | ||
4153 | [495; 496) 's': S | ||
4154 | [498; 499) 's': S | ||
4155 | [498; 508) 's.method()': u64 | ||
4156 | [510; 511) 'S': S | ||
4157 | "### | ||
4158 | ); | ||
4159 | } | ||
4160 | |||
4161 | #[test] | ||
4083 | fn unselected_projection_in_trait_env_1() { | 4162 | fn unselected_projection_in_trait_env_1() { |
4084 | let t = type_at( | 4163 | let t = type_at( |
4085 | r#" | 4164 | r#" |