aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/method_resolution.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/method_resolution.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/method_resolution.rs1150
1 files changed, 575 insertions, 575 deletions
diff --git a/crates/ra_hir_ty/src/tests/method_resolution.rs b/crates/ra_hir_ty/src/tests/method_resolution.rs
index 9c8f22314..fa68355aa 100644
--- a/crates/ra_hir_ty/src/tests/method_resolution.rs
+++ b/crates/ra_hir_ty/src/tests/method_resolution.rs
@@ -1,245 +1,245 @@
1use insta::assert_snapshot; 1use expect::expect;
2 2
3use super::{check_types, infer}; 3use super::{check_infer, check_types};
4 4
5#[test] 5#[test]
6fn infer_slice_method() { 6fn infer_slice_method() {
7 assert_snapshot!( 7 check_infer(
8 infer(r#" 8 r#"
9#[lang = "slice"] 9 #[lang = "slice"]
10impl<T> [T] { 10 impl<T> [T] {
11 fn foo(&self) -> T { 11 fn foo(&self) -> T {
12 loop {} 12 loop {}
13 } 13 }
14} 14 }
15 15
16#[lang = "slice_alloc"] 16 #[lang = "slice_alloc"]
17impl<T> [T] {} 17 impl<T> [T] {}
18 18
19fn test(x: &[u8]) { 19 fn test(x: &[u8]) {
20 <[_]>::foo(x); 20 <[_]>::foo(x);
21} 21 }
22"#), 22 "#,
23 @r###" 23 expect![[r#"
24 44..48 'self': &[T] 24 44..48 'self': &[T]
25 55..78 '{ ... }': T 25 55..78 '{ ... }': T
26 65..72 'loop {}': ! 26 65..72 'loop {}': !
27 70..72 '{}': () 27 70..72 '{}': ()
28 130..131 'x': &[u8] 28 130..131 'x': &[u8]
29 140..162 '{ ...(x); }': () 29 140..162 '{ ...(x); }': ()
30 146..156 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8 30 146..156 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8
31 146..159 '<[_]>::foo(x)': u8 31 146..159 '<[_]>::foo(x)': u8
32 157..158 'x': &[u8] 32 157..158 'x': &[u8]
33 "### 33 "#]],
34 ); 34 );
35} 35}
36 36
37#[test] 37#[test]
38fn infer_associated_method_struct() { 38fn infer_associated_method_struct() {
39 assert_snapshot!( 39 check_infer(
40 infer(r#" 40 r#"
41struct A { x: u32 } 41 struct A { x: u32 }
42 42
43impl A { 43 impl A {
44 fn new() -> A { 44 fn new() -> A {
45 A { x: 0 } 45 A { x: 0 }
46 } 46 }
47} 47 }
48fn test() { 48 fn test() {
49 let a = A::new(); 49 let a = A::new();
50 a.x; 50 a.x;
51} 51 }
52"#), 52 "#,
53 @r###" 53 expect![[r#"
54 48..74 '{ ... }': A 54 48..74 '{ ... }': A
55 58..68 'A { x: 0 }': A 55 58..68 'A { x: 0 }': A
56 65..66 '0': u32 56 65..66 '0': u32
57 87..121 '{ ...a.x; }': () 57 87..121 '{ ...a.x; }': ()
58 97..98 'a': A 58 97..98 'a': A
59 101..107 'A::new': fn new() -> A 59 101..107 'A::new': fn new() -> A
60 101..109 'A::new()': A 60 101..109 'A::new()': A
61 115..116 'a': A 61 115..116 'a': A
62 115..118 'a.x': u32 62 115..118 'a.x': u32
63 "### 63 "#]],
64 ); 64 );
65} 65}
66 66
67#[test] 67#[test]
68fn infer_associated_method_enum() { 68fn infer_associated_method_enum() {
69 assert_snapshot!( 69 check_infer(
70 infer(r#" 70 r#"
71enum A { B, C } 71 enum A { B, C }
72 72
73impl A { 73 impl A {
74 pub fn b() -> A { 74 pub fn b() -> A {
75 A::B 75 A::B
76 } 76 }
77 pub fn c() -> A { 77 pub fn c() -> A {
78 A::C 78 A::C
79 } 79 }
80} 80 }
81fn test() { 81 fn test() {
82 let a = A::b(); 82 let a = A::b();
83 a; 83 a;
84 let c = A::c(); 84 let c = A::c();
85 c; 85 c;
86} 86 }
87"#), 87 "#,
88 @r###" 88 expect![[r#"
89 46..66 '{ ... }': A 89 46..66 '{ ... }': A
90 56..60 'A::B': A 90 56..60 'A::B': A
91 87..107 '{ ... }': A 91 87..107 '{ ... }': A
92 97..101 'A::C': A 92 97..101 'A::C': A
93 120..177 '{ ... c; }': () 93 120..177 '{ ... c; }': ()
94 130..131 'a': A 94 130..131 'a': A
95 134..138 'A::b': fn b() -> A 95 134..138 'A::b': fn b() -> A
96 134..140 'A::b()': A 96 134..140 'A::b()': A
97 146..147 'a': A 97 146..147 'a': A
98 157..158 'c': A 98 157..158 'c': A
99 161..165 'A::c': fn c() -> A 99 161..165 'A::c': fn c() -> A
100 161..167 'A::c()': A 100 161..167 'A::c()': A
101 173..174 'c': A 101 173..174 'c': A
102 "### 102 "#]],
103 ); 103 );
104} 104}
105 105
106#[test] 106#[test]
107fn infer_associated_method_with_modules() { 107fn infer_associated_method_with_modules() {
108 assert_snapshot!( 108 check_infer(
109 infer(r#" 109 r#"
110mod a { 110 mod a {
111 struct A; 111 struct A;
112 impl A { pub fn thing() -> A { A {} }} 112 impl A { pub fn thing() -> A { A {} }}
113} 113 }
114 114
115mod b { 115 mod b {
116 struct B; 116 struct B;
117 impl B { pub fn thing() -> u32 { 99 }} 117 impl B { pub fn thing() -> u32 { 99 }}
118 118
119 mod c { 119 mod c {
120 struct C; 120 struct C;
121 impl C { pub fn thing() -> C { C {} }} 121 impl C { pub fn thing() -> C { C {} }}
122 } 122 }
123} 123 }
124use b::c; 124 use b::c;
125 125
126fn test() { 126 fn test() {
127 let x = a::A::thing(); 127 let x = a::A::thing();
128 let y = b::B::thing(); 128 let y = b::B::thing();
129 let z = c::C::thing(); 129 let z = c::C::thing();
130} 130 }
131"#), 131 "#,
132 @r###" 132 expect![[r#"
133 55..63 '{ A {} }': A 133 55..63 '{ A {} }': A
134 57..61 'A {}': A 134 57..61 'A {}': A
135 125..131 '{ 99 }': u32 135 125..131 '{ 99 }': u32
136 127..129 '99': u32 136 127..129 '99': u32
137 201..209 '{ C {} }': C 137 201..209 '{ C {} }': C
138 203..207 'C {}': C 138 203..207 'C {}': C
139 240..324 '{ ...g(); }': () 139 240..324 '{ ...g(); }': ()
140 250..251 'x': A 140 250..251 'x': A
141 254..265 'a::A::thing': fn thing() -> A 141 254..265 'a::A::thing': fn thing() -> A
142 254..267 'a::A::thing()': A 142 254..267 'a::A::thing()': A
143 277..278 'y': u32 143 277..278 'y': u32
144 281..292 'b::B::thing': fn thing() -> u32 144 281..292 'b::B::thing': fn thing() -> u32
145 281..294 'b::B::thing()': u32 145 281..294 'b::B::thing()': u32
146 304..305 'z': C 146 304..305 'z': C
147 308..319 'c::C::thing': fn thing() -> C 147 308..319 'c::C::thing': fn thing() -> C
148 308..321 'c::C::thing()': C 148 308..321 'c::C::thing()': C
149 "### 149 "#]],
150 ); 150 );
151} 151}
152 152
153#[test] 153#[test]
154fn infer_associated_method_generics() { 154fn infer_associated_method_generics() {
155 assert_snapshot!( 155 check_infer(
156 infer(r#" 156 r#"
157struct Gen<T> { 157 struct Gen<T> {
158 val: T 158 val: T
159} 159 }
160 160
161impl<T> Gen<T> { 161 impl<T> Gen<T> {
162 pub fn make(val: T) -> Gen<T> { 162 pub fn make(val: T) -> Gen<T> {
163 Gen { val } 163 Gen { val }
164 } 164 }
165} 165 }
166 166
167fn test() { 167 fn test() {
168 let a = Gen::make(0u32); 168 let a = Gen::make(0u32);
169} 169 }
170"#), 170 "#,
171 @r###" 171 expect![[r#"
172 63..66 'val': T 172 63..66 'val': T
173 81..108 '{ ... }': Gen<T> 173 81..108 '{ ... }': Gen<T>
174 91..102 'Gen { val }': Gen<T> 174 91..102 'Gen { val }': Gen<T>
175 97..100 'val': T 175 97..100 'val': T
176 122..154 '{ ...32); }': () 176 122..154 '{ ...32); }': ()
177 132..133 'a': Gen<u32> 177 132..133 'a': Gen<u32>
178 136..145 'Gen::make': fn make<u32>(u32) -> Gen<u32> 178 136..145 'Gen::make': fn make<u32>(u32) -> Gen<u32>
179 136..151 'Gen::make(0u32)': Gen<u32> 179 136..151 'Gen::make(0u32)': Gen<u32>
180 146..150 '0u32': u32 180 146..150 '0u32': u32
181 "### 181 "#]],
182 ); 182 );
183} 183}
184 184
185#[test] 185#[test]
186fn infer_associated_method_generics_without_args() { 186fn infer_associated_method_generics_without_args() {
187 assert_snapshot!( 187 check_infer(
188 infer(r#" 188 r#"
189struct Gen<T> { 189 struct Gen<T> {
190 val: T 190 val: T
191} 191 }
192 192
193impl<T> Gen<T> { 193 impl<T> Gen<T> {
194 pub fn make() -> Gen<T> { 194 pub fn make() -> Gen<T> {
195 loop { } 195 loop { }
196 } 196 }
197} 197 }
198 198
199fn test() { 199 fn test() {
200 let a = Gen::<u32>::make(); 200 let a = Gen::<u32>::make();
201} 201 }
202"#), 202 "#,
203 @r###" 203 expect![[r#"
204 75..99 '{ ... }': Gen<T> 204 75..99 '{ ... }': Gen<T>
205 85..93 'loop { }': ! 205 85..93 'loop { }': !
206 90..93 '{ }': () 206 90..93 '{ }': ()
207 113..148 '{ ...e(); }': () 207 113..148 '{ ...e(); }': ()
208 123..124 'a': Gen<u32> 208 123..124 'a': Gen<u32>
209 127..143 'Gen::<...::make': fn make<u32>() -> Gen<u32> 209 127..143 'Gen::<...::make': fn make<u32>() -> Gen<u32>
210 127..145 'Gen::<...make()': Gen<u32> 210 127..145 'Gen::<...make()': Gen<u32>
211 "### 211 "#]],
212 ); 212 );
213} 213}
214 214
215#[test] 215#[test]
216fn infer_associated_method_generics_2_type_params_without_args() { 216fn infer_associated_method_generics_2_type_params_without_args() {
217 assert_snapshot!( 217 check_infer(
218 infer(r#" 218 r#"
219struct Gen<T, U> { 219 struct Gen<T, U> {
220 val: T, 220 val: T,
221 val2: U, 221 val2: U,
222} 222 }
223 223
224impl<T> Gen<u32, T> { 224 impl<T> Gen<u32, T> {
225 pub fn make() -> Gen<u32,T> { 225 pub fn make() -> Gen<u32,T> {
226 loop { } 226 loop { }
227 } 227 }
228} 228 }
229 229
230fn test() { 230 fn test() {
231 let a = Gen::<u32, u64>::make(); 231 let a = Gen::<u32, u64>::make();
232} 232 }
233"#), 233 "#,
234 @r###" 234 expect![[r#"
235 101..125 '{ ... }': Gen<u32, T> 235 101..125 '{ ... }': Gen<u32, T>
236 111..119 'loop { }': ! 236 111..119 'loop { }': !
237 116..119 '{ }': () 237 116..119 '{ }': ()
238 139..179 '{ ...e(); }': () 238 139..179 '{ ...e(); }': ()
239 149..150 'a': Gen<u32, u64> 239 149..150 'a': Gen<u32, u64>
240 153..174 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64> 240 153..174 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64>
241 153..176 'Gen::<...make()': Gen<u32, u64> 241 153..176 'Gen::<...make()': Gen<u32, u64>
242 "### 242 "#]],
243 ); 243 );
244} 244}
245 245
@@ -267,416 +267,416 @@ mod foo {
267#[test] 267#[test]
268fn infer_trait_method_simple() { 268fn infer_trait_method_simple() {
269 // the trait implementation is intentionally incomplete -- it shouldn't matter 269 // the trait implementation is intentionally incomplete -- it shouldn't matter
270 assert_snapshot!( 270 check_infer(
271 infer(r#" 271 r#"
272trait Trait1 { 272 trait Trait1 {
273 fn method(&self) -> u32; 273 fn method(&self) -> u32;
274} 274 }
275struct S1; 275 struct S1;
276impl Trait1 for S1 {} 276 impl Trait1 for S1 {}
277trait Trait2 { 277 trait Trait2 {
278 fn method(&self) -> i128; 278 fn method(&self) -> i128;
279} 279 }
280struct S2; 280 struct S2;
281impl Trait2 for S2 {} 281 impl Trait2 for S2 {}
282fn test() { 282 fn test() {
283 S1.method(); // -> u32 283 S1.method(); // -> u32
284 S2.method(); // -> i128 284 S2.method(); // -> i128
285} 285 }
286"#), 286 "#,
287 @r###" 287 expect![[r#"
288 30..34 'self': &Self 288 30..34 'self': &Self
289 109..113 'self': &Self 289 109..113 'self': &Self
290 169..227 '{ ...i128 }': () 290 169..227 '{ ...i128 }': ()
291 175..177 'S1': S1 291 175..177 'S1': S1
292 175..186 'S1.method()': u32 292 175..186 'S1.method()': u32
293 202..204 'S2': S2 293 202..204 'S2': S2
294 202..213 'S2.method()': i128 294 202..213 'S2.method()': i128
295 "### 295 "#]],
296 ); 296 );
297} 297}
298 298
299#[test] 299#[test]
300fn infer_trait_method_scoped() { 300fn infer_trait_method_scoped() {
301 // the trait implementation is intentionally incomplete -- it shouldn't matter 301 // the trait implementation is intentionally incomplete -- it shouldn't matter
302 assert_snapshot!( 302 check_infer(
303 infer(r#" 303 r#"
304struct S; 304 struct S;
305mod foo { 305 mod foo {
306 pub trait Trait1 { 306 pub trait Trait1 {
307 fn method(&self) -> u32; 307 fn method(&self) -> u32;
308 } 308 }
309 impl Trait1 for super::S {} 309 impl Trait1 for super::S {}
310} 310 }
311mod bar { 311 mod bar {
312 pub trait Trait2 { 312 pub trait Trait2 {
313 fn method(&self) -> i128; 313 fn method(&self) -> i128;
314 } 314 }
315 impl Trait2 for super::S {} 315 impl Trait2 for super::S {}
316} 316 }
317 317
318mod foo_test { 318 mod foo_test {
319 use super::S; 319 use super::S;
320 use super::foo::Trait1; 320 use super::foo::Trait1;
321 fn test() { 321 fn test() {
322 S.method(); // -> u32 322 S.method(); // -> u32
323 } 323 }
324} 324 }
325 325
326mod bar_test { 326 mod bar_test {
327 use super::S; 327 use super::S;
328 use super::bar::Trait2; 328 use super::bar::Trait2;
329 fn test() { 329 fn test() {
330 S.method(); // -> i128 330 S.method(); // -> i128
331 } 331 }
332} 332 }
333"#), 333 "#,
334 @r###" 334 expect![[r#"
335 62..66 'self': &Self 335 62..66 'self': &Self
336 168..172 'self': &Self 336 168..172 'self': &Self
337 299..336 '{ ... }': () 337 299..336 '{ ... }': ()
338 309..310 'S': S 338 309..310 'S': S
339 309..319 'S.method()': u32 339 309..319 'S.method()': u32
340 415..453 '{ ... }': () 340 415..453 '{ ... }': ()
341 425..426 'S': S 341 425..426 'S': S
342 425..435 'S.method()': i128 342 425..435 'S.method()': i128
343 "### 343 "#]],
344 ); 344 );
345} 345}
346 346
347#[test] 347#[test]
348fn infer_trait_method_generic_1() { 348fn infer_trait_method_generic_1() {
349 // the trait implementation is intentionally incomplete -- it shouldn't matter 349 // the trait implementation is intentionally incomplete -- it shouldn't matter
350 assert_snapshot!( 350 check_infer(
351 infer(r#" 351 r#"
352trait Trait<T> { 352 trait Trait<T> {
353 fn method(&self) -> T; 353 fn method(&self) -> T;
354} 354 }
355struct S; 355 struct S;
356impl Trait<u32> for S {} 356 impl Trait<u32> for S {}
357fn test() { 357 fn test() {
358 S.method(); 358 S.method();
359} 359 }
360"#), 360 "#,
361 @r###" 361 expect![[r#"
362 32..36 'self': &Self 362 32..36 'self': &Self
363 91..110 '{ ...d(); }': () 363 91..110 '{ ...d(); }': ()
364 97..98 'S': S 364 97..98 'S': S
365 97..107 'S.method()': u32 365 97..107 'S.method()': u32
366 "### 366 "#]],
367 ); 367 );
368} 368}
369 369
370#[test] 370#[test]
371fn infer_trait_method_generic_more_params() { 371fn infer_trait_method_generic_more_params() {
372 // the trait implementation is intentionally incomplete -- it shouldn't matter 372 // the trait implementation is intentionally incomplete -- it shouldn't matter
373 assert_snapshot!( 373 check_infer(
374 infer(r#" 374 r#"
375trait Trait<T1, T2, T3> { 375 trait Trait<T1, T2, T3> {
376 fn method1(&self) -> (T1, T2, T3); 376 fn method1(&self) -> (T1, T2, T3);
377 fn method2(&self) -> (T3, T2, T1); 377 fn method2(&self) -> (T3, T2, T1);
378} 378 }
379struct S1; 379 struct S1;
380impl Trait<u8, u16, u32> for S1 {} 380 impl Trait<u8, u16, u32> for S1 {}
381struct S2; 381 struct S2;
382impl<T> Trait<i8, i16, T> for S2 {} 382 impl<T> Trait<i8, i16, T> for S2 {}
383fn test() { 383 fn test() {
384 S1.method1(); // u8, u16, u32 384 S1.method1(); // u8, u16, u32
385 S1.method2(); // u32, u16, u8 385 S1.method2(); // u32, u16, u8
386 S2.method1(); // i8, i16, {unknown} 386 S2.method1(); // i8, i16, {unknown}
387 S2.method2(); // {unknown}, i16, i8 387 S2.method2(); // {unknown}, i16, i8
388} 388 }
389"#), 389 "#,
390 @r###" 390 expect![[r#"
391 42..46 'self': &Self 391 42..46 'self': &Self
392 81..85 'self': &Self 392 81..85 'self': &Self
393 209..360 '{ ..., i8 }': () 393 209..360 '{ ..., i8 }': ()
394 215..217 'S1': S1 394 215..217 'S1': S1
395 215..227 'S1.method1()': (u8, u16, u32) 395 215..227 'S1.method1()': (u8, u16, u32)
396 249..251 'S1': S1 396 249..251 'S1': S1
397 249..261 'S1.method2()': (u32, u16, u8) 397 249..261 'S1.method2()': (u32, u16, u8)
398 283..285 'S2': S2 398 283..285 'S2': S2
399 283..295 'S2.method1()': (i8, i16, {unknown}) 399 283..295 'S2.method1()': (i8, i16, {unknown})
400 323..325 'S2': S2 400 323..325 'S2': S2
401 323..335 'S2.method2()': ({unknown}, i16, i8) 401 323..335 'S2.method2()': ({unknown}, i16, i8)
402 "### 402 "#]],
403 ); 403 );
404} 404}
405 405
406#[test] 406#[test]
407fn infer_trait_method_generic_2() { 407fn infer_trait_method_generic_2() {
408 // the trait implementation is intentionally incomplete -- it shouldn't matter 408 // the trait implementation is intentionally incomplete -- it shouldn't matter
409 assert_snapshot!( 409 check_infer(
410 infer(r#" 410 r#"
411trait Trait<T> { 411 trait Trait<T> {
412 fn method(&self) -> T; 412 fn method(&self) -> T;
413} 413 }
414struct S<T>(T); 414 struct S<T>(T);
415impl<U> Trait<U> for S<U> {} 415 impl<U> Trait<U> for S<U> {}
416fn test() { 416 fn test() {
417 S(1u32).method(); 417 S(1u32).method();
418} 418 }
419"#), 419 "#,
420 @r###" 420 expect![[r#"
421 32..36 'self': &Self 421 32..36 'self': &Self
422 101..126 '{ ...d(); }': () 422 101..126 '{ ...d(); }': ()
423 107..108 'S': S<u32>(u32) -> S<u32> 423 107..108 'S': S<u32>(u32) -> S<u32>
424 107..114 'S(1u32)': S<u32> 424 107..114 'S(1u32)': S<u32>
425 107..123 'S(1u32...thod()': u32 425 107..123 'S(1u32...thod()': u32
426 109..113 '1u32': u32 426 109..113 '1u32': u32
427 "### 427 "#]],
428 ); 428 );
429} 429}
430 430
431#[test] 431#[test]
432fn infer_trait_assoc_method() { 432fn infer_trait_assoc_method() {
433 assert_snapshot!( 433 check_infer(
434 infer(r#" 434 r#"
435trait Default { 435 trait Default {
436 fn default() -> Self; 436 fn default() -> Self;
437} 437 }
438struct S; 438 struct S;
439impl Default for S {} 439 impl Default for S {}
440fn test() { 440 fn test() {
441 let s1: S = Default::default(); 441 let s1: S = Default::default();
442 let s2 = S::default(); 442 let s2 = S::default();
443 let s3 = <S as Default>::default(); 443 let s3 = <S as Default>::default();
444} 444 }
445"#), 445 "#,
446 @r###" 446 expect![[r#"
447 86..192 '{ ...t(); }': () 447 86..192 '{ ...t(); }': ()
448 96..98 's1': S 448 96..98 's1': S
449 104..120 'Defaul...efault': fn default<S>() -> S 449 104..120 'Defaul...efault': fn default<S>() -> S
450 104..122 'Defaul...ault()': S 450 104..122 'Defaul...ault()': S
451 132..134 's2': S 451 132..134 's2': S
452 137..147 'S::default': fn default<S>() -> S 452 137..147 'S::default': fn default<S>() -> S
453 137..149 'S::default()': S 453 137..149 'S::default()': S
454 159..161 's3': S 454 159..161 's3': S
455 164..187 '<S as ...efault': fn default<S>() -> S 455 164..187 '<S as ...efault': fn default<S>() -> S
456 164..189 '<S as ...ault()': S 456 164..189 '<S as ...ault()': S
457 "### 457 "#]],
458 ); 458 );
459} 459}
460 460
461#[test] 461#[test]
462fn infer_trait_assoc_method_generics_1() { 462fn infer_trait_assoc_method_generics_1() {
463 assert_snapshot!( 463 check_infer(
464 infer(r#" 464 r#"
465trait Trait<T> { 465 trait Trait<T> {
466 fn make() -> T; 466 fn make() -> T;
467} 467 }
468struct S; 468 struct S;
469impl Trait<u32> for S {} 469 impl Trait<u32> for S {}
470struct G<T>; 470 struct G<T>;
471impl<T> Trait<T> for G<T> {} 471 impl<T> Trait<T> for G<T> {}
472fn test() { 472 fn test() {
473 let a = S::make(); 473 let a = S::make();
474 let b = G::<u64>::make(); 474 let b = G::<u64>::make();
475 let c: f64 = G::make(); 475 let c: f64 = G::make();
476} 476 }
477"#), 477 "#,
478 @r###" 478 expect![[r#"
479 126..210 '{ ...e(); }': () 479 126..210 '{ ...e(); }': ()
480 136..137 'a': u32 480 136..137 'a': u32
481 140..147 'S::make': fn make<S, u32>() -> u32 481 140..147 'S::make': fn make<S, u32>() -> u32
482 140..149 'S::make()': u32 482 140..149 'S::make()': u32
483 159..160 'b': u64 483 159..160 'b': u64
484 163..177 'G::<u64>::make': fn make<G<u64>, u64>() -> u64 484 163..177 'G::<u64>::make': fn make<G<u64>, u64>() -> u64
485 163..179 'G::<u6...make()': u64 485 163..179 'G::<u6...make()': u64
486 189..190 'c': f64 486 189..190 'c': f64
487 198..205 'G::make': fn make<G<f64>, f64>() -> f64 487 198..205 'G::make': fn make<G<f64>, f64>() -> f64
488 198..207 'G::make()': f64 488 198..207 'G::make()': f64
489 "### 489 "#]],
490 ); 490 );
491} 491}
492 492
493#[test] 493#[test]
494fn infer_trait_assoc_method_generics_2() { 494fn infer_trait_assoc_method_generics_2() {
495 assert_snapshot!( 495 check_infer(
496 infer(r#" 496 r#"
497trait Trait<T> { 497 trait Trait<T> {
498 fn make<U>() -> (T, U); 498 fn make<U>() -> (T, U);
499} 499 }
500struct S; 500 struct S;
501impl Trait<u32> for S {} 501 impl Trait<u32> for S {}
502struct G<T>; 502 struct G<T>;
503impl<T> Trait<T> for G<T> {} 503 impl<T> Trait<T> for G<T> {}
504fn test() { 504 fn test() {
505 let a = S::make::<i64>(); 505 let a = S::make::<i64>();
506 let b: (_, i64) = S::make(); 506 let b: (_, i64) = S::make();
507 let c = G::<u32>::make::<i64>(); 507 let c = G::<u32>::make::<i64>();
508 let d: (u32, _) = G::make::<i64>(); 508 let d: (u32, _) = G::make::<i64>();
509 let e: (u32, i64) = G::make(); 509 let e: (u32, i64) = G::make();
510} 510 }
511"#), 511 "#,
512 @r###" 512 expect![[r#"
513 134..312 '{ ...e(); }': () 513 134..312 '{ ...e(); }': ()
514 144..145 'a': (u32, i64) 514 144..145 'a': (u32, i64)
515 148..162 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64) 515 148..162 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64)
516 148..164 'S::mak...i64>()': (u32, i64) 516 148..164 'S::mak...i64>()': (u32, i64)
517 174..175 'b': (u32, i64) 517 174..175 'b': (u32, i64)
518 188..195 'S::make': fn make<S, u32, i64>() -> (u32, i64) 518 188..195 'S::make': fn make<S, u32, i64>() -> (u32, i64)
519 188..197 'S::make()': (u32, i64) 519 188..197 'S::make()': (u32, i64)
520 207..208 'c': (u32, i64) 520 207..208 'c': (u32, i64)
521 211..232 'G::<u3...:<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64) 521 211..232 'G::<u3...:<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
522 211..234 'G::<u3...i64>()': (u32, i64) 522 211..234 'G::<u3...i64>()': (u32, i64)
523 244..245 'd': (u32, i64) 523 244..245 'd': (u32, i64)
524 258..272 'G::make::<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64) 524 258..272 'G::make::<i64>': fn make<G<u32>, u32, i64>() -> (u32, i64)
525 258..274 'G::mak...i64>()': (u32, i64) 525 258..274 'G::mak...i64>()': (u32, i64)
526 284..285 'e': (u32, i64) 526 284..285 'e': (u32, i64)
527 300..307 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64) 527 300..307 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64)
528 300..309 'G::make()': (u32, i64) 528 300..309 'G::make()': (u32, i64)
529 "### 529 "#]],
530 ); 530 );
531} 531}
532 532
533#[test] 533#[test]
534fn infer_trait_assoc_method_generics_3() { 534fn infer_trait_assoc_method_generics_3() {
535 assert_snapshot!( 535 check_infer(
536 infer(r#" 536 r#"
537trait Trait<T> { 537 trait Trait<T> {
538 fn make() -> (Self, T); 538 fn make() -> (Self, T);
539} 539 }
540struct S<T>; 540 struct S<T>;
541impl Trait<i64> for S<i32> {} 541 impl Trait<i64> for S<i32> {}
542fn test() { 542 fn test() {
543 let a = S::make(); 543 let a = S::make();
544} 544 }
545"#), 545 "#,
546 @r###" 546 expect![[r#"
547 100..126 '{ ...e(); }': () 547 100..126 '{ ...e(); }': ()
548 110..111 'a': (S<i32>, i64) 548 110..111 'a': (S<i32>, i64)
549 114..121 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64) 549 114..121 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64)
550 114..123 'S::make()': (S<i32>, i64) 550 114..123 'S::make()': (S<i32>, i64)
551 "### 551 "#]],
552 ); 552 );
553} 553}
554 554
555#[test] 555#[test]
556fn infer_trait_assoc_method_generics_4() { 556fn infer_trait_assoc_method_generics_4() {
557 assert_snapshot!( 557 check_infer(
558 infer(r#" 558 r#"
559trait Trait<T> { 559 trait Trait<T> {
560 fn make() -> (Self, T); 560 fn make() -> (Self, T);
561} 561 }
562struct S<T>; 562 struct S<T>;
563impl Trait<i64> for S<u64> {} 563 impl Trait<i64> for S<u64> {}
564impl Trait<i32> for S<u32> {} 564 impl Trait<i32> for S<u32> {}
565fn test() { 565 fn test() {
566 let a: (S<u64>, _) = S::make(); 566 let a: (S<u64>, _) = S::make();
567 let b: (_, i32) = S::make(); 567 let b: (_, i32) = S::make();
568} 568 }
569"#), 569 "#,
570 @r###" 570 expect![[r#"
571 130..202 '{ ...e(); }': () 571 130..202 '{ ...e(); }': ()
572 140..141 'a': (S<u64>, i64) 572 140..141 'a': (S<u64>, i64)
573 157..164 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64) 573 157..164 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64)
574 157..166 'S::make()': (S<u64>, i64) 574 157..166 'S::make()': (S<u64>, i64)
575 176..177 'b': (S<u32>, i32) 575 176..177 'b': (S<u32>, i32)
576 190..197 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32) 576 190..197 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32)
577 190..199 'S::make()': (S<u32>, i32) 577 190..199 'S::make()': (S<u32>, i32)
578 "### 578 "#]],
579 ); 579 );
580} 580}
581 581
582#[test] 582#[test]
583fn infer_trait_assoc_method_generics_5() { 583fn infer_trait_assoc_method_generics_5() {
584 assert_snapshot!( 584 check_infer(
585 infer(r#" 585 r#"
586trait Trait<T> { 586 trait Trait<T> {
587 fn make<U>() -> (Self, T, U); 587 fn make<U>() -> (Self, T, U);
588} 588 }
589struct S<T>; 589 struct S<T>;
590impl Trait<i64> for S<u64> {} 590 impl Trait<i64> for S<u64> {}
591fn test() { 591 fn test() {
592 let a = <S as Trait<i64>>::make::<u8>(); 592 let a = <S as Trait<i64>>::make::<u8>();
593 let b: (S<u64>, _, _) = Trait::<i64>::make::<u8>(); 593 let b: (S<u64>, _, _) = Trait::<i64>::make::<u8>();
594} 594 }
595"#), 595 "#,
596 @r###" 596 expect![[r#"
597 106..210 '{ ...>(); }': () 597 106..210 '{ ...>(); }': ()
598 116..117 'a': (S<u64>, i64, u8) 598 116..117 'a': (S<u64>, i64, u8)
599 120..149 '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8) 599 120..149 '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
600 120..151 '<S as ...<u8>()': (S<u64>, i64, u8) 600 120..151 '<S as ...<u8>()': (S<u64>, i64, u8)
601 161..162 'b': (S<u64>, i64, u8) 601 161..162 'b': (S<u64>, i64, u8)
602 181..205 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8) 602 181..205 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
603 181..207 'Trait:...<u8>()': (S<u64>, i64, u8) 603 181..207 'Trait:...<u8>()': (S<u64>, i64, u8)
604 "### 604 "#]],
605 ); 605 );
606} 606}
607 607
608#[test] 608#[test]
609fn infer_call_trait_method_on_generic_param_1() { 609fn infer_call_trait_method_on_generic_param_1() {
610 assert_snapshot!( 610 check_infer(
611 infer(r#" 611 r#"
612trait Trait { 612 trait Trait {
613 fn method(&self) -> u32; 613 fn method(&self) -> u32;
614} 614 }
615fn test<T: Trait>(t: T) { 615 fn test<T: Trait>(t: T) {
616 t.method(); 616 t.method();
617} 617 }
618"#), 618 "#,
619 @r###" 619 expect![[r#"
620 29..33 'self': &Self 620 29..33 'self': &Self
621 63..64 't': T 621 63..64 't': T
622 69..88 '{ ...d(); }': () 622 69..88 '{ ...d(); }': ()
623 75..76 't': T 623 75..76 't': T
624 75..85 't.method()': u32 624 75..85 't.method()': u32
625 "### 625 "#]],
626 ); 626 );
627} 627}
628 628
629#[test] 629#[test]
630fn infer_call_trait_method_on_generic_param_2() { 630fn infer_call_trait_method_on_generic_param_2() {
631 assert_snapshot!( 631 check_infer(
632 infer(r#" 632 r#"
633trait Trait<T> { 633 trait Trait<T> {
634 fn method(&self) -> T; 634 fn method(&self) -> T;
635} 635 }
636fn test<U, T: Trait<U>>(t: T) { 636 fn test<U, T: Trait<U>>(t: T) {
637 t.method(); 637 t.method();
638} 638 }
639"#), 639 "#,
640 @r###" 640 expect![[r#"
641 32..36 'self': &Self 641 32..36 'self': &Self
642 70..71 't': T 642 70..71 't': T
643 76..95 '{ ...d(); }': () 643 76..95 '{ ...d(); }': ()
644 82..83 't': T 644 82..83 't': T
645 82..92 't.method()': U 645 82..92 't.method()': U
646 "### 646 "#]],
647 ); 647 );
648} 648}
649 649
650#[test] 650#[test]
651fn infer_with_multiple_trait_impls() { 651fn infer_with_multiple_trait_impls() {
652 assert_snapshot!( 652 check_infer(
653 infer(r#" 653 r#"
654trait Into<T> { 654 trait Into<T> {
655 fn into(self) -> T; 655 fn into(self) -> T;
656} 656 }
657struct S; 657 struct S;
658impl Into<u32> for S {} 658 impl Into<u32> for S {}
659impl Into<u64> for S {} 659 impl Into<u64> for S {}
660fn test() { 660 fn test() {
661 let x: u32 = S.into(); 661 let x: u32 = S.into();
662 let y: u64 = S.into(); 662 let y: u64 = S.into();
663 let z = Into::<u64>::into(S); 663 let z = Into::<u64>::into(S);
664} 664 }
665"#), 665 "#,
666 @r###" 666 expect![[r#"
667 28..32 'self': Self 667 28..32 'self': Self
668 110..201 '{ ...(S); }': () 668 110..201 '{ ...(S); }': ()
669 120..121 'x': u32 669 120..121 'x': u32
670 129..130 'S': S 670 129..130 'S': S
671 129..137 'S.into()': u32 671 129..137 'S.into()': u32
672 147..148 'y': u64 672 147..148 'y': u64
673 156..157 'S': S 673 156..157 'S': S
674 156..164 'S.into()': u64 674 156..164 'S.into()': u64
675 174..175 'z': u64 675 174..175 'z': u64
676 178..195 'Into::...::into': fn into<S, u64>(S) -> u64 676 178..195 'Into::...::into': fn into<S, u64>(S) -> u64
677 178..198 'Into::...nto(S)': u64 677 178..198 'Into::...nto(S)': u64
678 196..197 'S': S 678 196..197 'S': S
679 "### 679 "#]],
680 ); 680 );
681} 681}
682 682
@@ -1023,31 +1023,31 @@ fn test() { (S {}).method(); }
1023 1023
1024#[test] 1024#[test]
1025fn dyn_trait_super_trait_not_in_scope() { 1025fn dyn_trait_super_trait_not_in_scope() {
1026 assert_snapshot!( 1026 check_infer(
1027 infer(r#" 1027 r#"
1028mod m { 1028 mod m {
1029 pub trait SuperTrait { 1029 pub trait SuperTrait {
1030 fn foo(&self) -> u32 { 0 } 1030 fn foo(&self) -> u32 { 0 }
1031 } 1031 }
1032} 1032 }
1033trait Trait: m::SuperTrait {} 1033 trait Trait: m::SuperTrait {}
1034 1034
1035struct S; 1035 struct S;
1036impl m::SuperTrait for S {} 1036 impl m::SuperTrait for S {}
1037impl Trait for S {} 1037 impl Trait for S {}
1038 1038
1039fn test(d: &dyn Trait) { 1039 fn test(d: &dyn Trait) {
1040 d.foo(); 1040 d.foo();
1041} 1041 }
1042"#), 1042 "#,
1043 @r###" 1043 expect![[r#"
1044 51..55 'self': &Self 1044 51..55 'self': &Self
1045 64..69 '{ 0 }': u32 1045 64..69 '{ 0 }': u32
1046 66..67 '0': u32 1046 66..67 '0': u32
1047 176..177 'd': &dyn Trait 1047 176..177 'd': &dyn Trait
1048 191..207 '{ ...o(); }': () 1048 191..207 '{ ...o(); }': ()
1049 197..198 'd': &dyn Trait 1049 197..198 'd': &dyn Trait
1050 197..204 'd.foo()': u32 1050 197..204 'd.foo()': u32
1051 "### 1051 "#]],
1052 ); 1052 );
1053} 1053}