aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_ty/src/tests/traits.rs')
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs2041
1 files changed, 1169 insertions, 872 deletions
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index e8778d419..27737fa94 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -1,17 +1,13 @@
1use insta::assert_snapshot; 1use insta::assert_snapshot;
2use ra_db::fixture::WithFixture;
3use test_utils::mark; 2use test_utils::mark;
4 3
5use crate::test_db::TestDB; 4use super::{check_types, infer, infer_with_mismatches};
6
7use super::{infer, infer_with_mismatches, type_at, type_at_pos};
8 5
9#[test] 6#[test]
10fn infer_await() { 7fn infer_await() {
11 let (db, pos) = TestDB::with_position( 8 check_types(
12 r#" 9 r#"
13//- /main.rs crate:main deps:std 10//- /main.rs crate:main deps:core
14
15struct IntFuture; 11struct IntFuture;
16 12
17impl Future for IntFuture { 13impl Future for IntFuture {
@@ -21,10 +17,10 @@ impl Future for IntFuture {
21fn test() { 17fn test() {
22 let r = IntFuture; 18 let r = IntFuture;
23 let v = r.await; 19 let v = r.await;
24 v<|>; 20 v;
25} 21} //^ u64
26 22
27//- /std.rs crate:std 23//- /core.rs crate:core
28#[prelude_import] use future::*; 24#[prelude_import] use future::*;
29mod future { 25mod future {
30 #[lang = "future_trait"] 26 #[lang = "future_trait"]
@@ -32,18 +28,15 @@ mod future {
32 type Output; 28 type Output;
33 } 29 }
34} 30}
35
36"#, 31"#,
37 ); 32 );
38 assert_eq!("u64", type_at_pos(&db, pos));
39} 33}
40 34
41#[test] 35#[test]
42fn infer_async() { 36fn infer_async() {
43 let (db, pos) = TestDB::with_position( 37 check_types(
44 r#" 38 r#"
45//- /main.rs crate:main deps:std 39//- /main.rs crate:main deps:core
46
47async fn foo() -> u64 { 40async fn foo() -> u64 {
48 128 41 128
49} 42}
@@ -51,10 +44,10 @@ async fn foo() -> u64 {
51fn test() { 44fn test() {
52 let r = foo(); 45 let r = foo();
53 let v = r.await; 46 let v = r.await;
54 v<|>; 47 v;
55} 48} //^ u64
56 49
57//- /std.rs crate:std 50//- /core.rs crate:core
58#[prelude_import] use future::*; 51#[prelude_import] use future::*;
59mod future { 52mod future {
60 #[lang = "future_trait"] 53 #[lang = "future_trait"]
@@ -62,28 +55,25 @@ mod future {
62 type Output; 55 type Output;
63 } 56 }
64} 57}
65
66"#, 58"#,
67 ); 59 );
68 assert_eq!("u64", type_at_pos(&db, pos));
69} 60}
70 61
71#[test] 62#[test]
72fn infer_desugar_async() { 63fn infer_desugar_async() {
73 let (db, pos) = TestDB::with_position( 64 check_types(
74 r#" 65 r#"
75//- /main.rs crate:main deps:std 66//- /main.rs crate:main deps:core
76
77async fn foo() -> u64 { 67async fn foo() -> u64 {
78 128 68 128
79} 69}
80 70
81fn test() { 71fn test() {
82 let r = foo(); 72 let r = foo();
83 r<|>; 73 r;
84} 74} //^ impl Future<Output = u64>
85 75
86//- /std.rs crate:std 76//- /core.rs crate:core
87#[prelude_import] use future::*; 77#[prelude_import] use future::*;
88mod future { 78mod future {
89 trait Future { 79 trait Future {
@@ -93,23 +83,20 @@ mod future {
93 83
94"#, 84"#,
95 ); 85 );
96 assert_eq!("impl Future<Output = u64>", type_at_pos(&db, pos));
97} 86}
98 87
99#[test] 88#[test]
100fn infer_try() { 89fn infer_try() {
101 let (db, pos) = TestDB::with_position( 90 check_types(
102 r#" 91 r#"
103//- /main.rs crate:main deps:std 92//- /main.rs crate:main deps:core
104
105fn test() { 93fn test() {
106 let r: Result<i32, u64> = Result::Ok(1); 94 let r: Result<i32, u64> = Result::Ok(1);
107 let v = r?; 95 let v = r?;
108 v<|>; 96 v;
109} 97} //^ i32
110
111//- /std.rs crate:std
112 98
99//- /core.rs crate:core
113#[prelude_import] use ops::*; 100#[prelude_import] use ops::*;
114mod ops { 101mod ops {
115 trait Try { 102 trait Try {
@@ -130,30 +117,26 @@ mod result {
130 type Error = E; 117 type Error = E;
131 } 118 }
132} 119}
133
134"#, 120"#,
135 ); 121 );
136 assert_eq!("i32", type_at_pos(&db, pos));
137} 122}
138 123
139#[test] 124#[test]
140fn infer_for_loop() { 125fn infer_for_loop() {
141 let (db, pos) = TestDB::with_position( 126 check_types(
142 r#" 127 r#"
143//- /main.rs crate:main deps:std 128//- /main.rs crate:main deps:core,alloc
144 129use alloc::collections::Vec;
145use std::collections::Vec;
146 130
147fn test() { 131fn test() {
148 let v = Vec::new(); 132 let v = Vec::new();
149 v.push("foo"); 133 v.push("foo");
150 for x in v { 134 for x in v {
151 x<|>; 135 x;
152 } 136 } //^ &str
153} 137}
154 138
155//- /std.rs crate:std 139//- /core.rs crate:core
156
157#[prelude_import] use iter::*; 140#[prelude_import] use iter::*;
158mod iter { 141mod iter {
159 trait IntoIterator { 142 trait IntoIterator {
@@ -161,6 +144,7 @@ mod iter {
161 } 144 }
162} 145}
163 146
147//- /alloc.rs crate:alloc deps:core
164mod collections { 148mod collections {
165 struct Vec<T> {} 149 struct Vec<T> {}
166 impl<T> Vec<T> { 150 impl<T> Vec<T> {
@@ -168,21 +152,19 @@ mod collections {
168 fn push(&mut self, t: T) { } 152 fn push(&mut self, t: T) { }
169 } 153 }
170 154
171 impl<T> crate::iter::IntoIterator for Vec<T> { 155 impl<T> IntoIterator for Vec<T> {
172 type Item=T; 156 type Item=T;
173 } 157 }
174} 158}
175"#, 159"#,
176 ); 160 );
177 assert_eq!("&str", type_at_pos(&db, pos));
178} 161}
179 162
180#[test] 163#[test]
181fn infer_ops_neg() { 164fn infer_ops_neg() {
182 let (db, pos) = TestDB::with_position( 165 check_types(
183 r#" 166 r#"
184//- /main.rs crate:main deps:std 167//- /main.rs crate:main deps:std
185
186struct Bar; 168struct Bar;
187struct Foo; 169struct Foo;
188 170
@@ -193,11 +175,10 @@ impl std::ops::Neg for Bar {
193fn test() { 175fn test() {
194 let a = Bar; 176 let a = Bar;
195 let b = -a; 177 let b = -a;
196 b<|>; 178 b;
197} 179} //^ Foo
198 180
199//- /std.rs crate:std 181//- /std.rs crate:std
200
201#[prelude_import] use ops::*; 182#[prelude_import] use ops::*;
202mod ops { 183mod ops {
203 #[lang = "neg"] 184 #[lang = "neg"]
@@ -207,15 +188,13 @@ mod ops {
207} 188}
208"#, 189"#,
209 ); 190 );
210 assert_eq!("Foo", type_at_pos(&db, pos));
211} 191}
212 192
213#[test] 193#[test]
214fn infer_ops_not() { 194fn infer_ops_not() {
215 let (db, pos) = TestDB::with_position( 195 check_types(
216 r#" 196 r#"
217//- /main.rs crate:main deps:std 197//- /main.rs crate:main deps:std
218
219struct Bar; 198struct Bar;
220struct Foo; 199struct Foo;
221 200
@@ -226,11 +205,10 @@ impl std::ops::Not for Bar {
226fn test() { 205fn test() {
227 let a = Bar; 206 let a = Bar;
228 let b = !a; 207 let b = !a;
229 b<|>; 208 b;
230} 209} //^ Foo
231 210
232//- /std.rs crate:std 211//- /std.rs crate:std
233
234#[prelude_import] use ops::*; 212#[prelude_import] use ops::*;
235mod ops { 213mod ops {
236 #[lang = "not"] 214 #[lang = "not"]
@@ -240,7 +218,6 @@ mod ops {
240} 218}
241"#, 219"#,
242 ); 220 );
243 assert_eq!("Foo", type_at_pos(&db, pos));
244} 221}
245 222
246#[test] 223#[test]
@@ -257,16 +234,16 @@ fn test() {
257} 234}
258"#), 235"#),
259 @r###" 236 @r###"
260 86..87 't': T 237 85..86 't': T
261 92..94 '{}': () 238 91..93 '{}': ()
262 105..144 '{ ...(s); }': () 239 104..143 '{ ...(s); }': ()
263 115..116 's': S<u32> 240 114..115 's': S<u32>
264 119..120 'S': S<u32>(u32) -> S<u32> 241 118..119 'S': S<u32>(u32) -> S<u32>
265 119..129 'S(unknown)': S<u32> 242 118..128 'S(unknown)': S<u32>
266 121..128 'unknown': u32 243 120..127 'unknown': u32
267 135..138 'foo': fn foo<S<u32>>(S<u32>) 244 134..137 'foo': fn foo<S<u32>>(S<u32>)
268 135..141 'foo(s)': () 245 134..140 'foo(s)': ()
269 139..140 's': S<u32> 246 138..139 's': S<u32>
270 "### 247 "###
271 ); 248 );
272} 249}
@@ -285,17 +262,17 @@ fn test() {
285} 262}
286"#), 263"#),
287 @r###" 264 @r###"
288 87..88 't': T 265 86..87 't': T
289 98..100 '{}': () 266 97..99 '{}': ()
290 111..163 '{ ...(s); }': () 267 110..162 '{ ...(s); }': ()
291 121..122 's': S<u32> 268 120..121 's': S<u32>
292 125..126 'S': S<u32>(u32) -> S<u32> 269 124..125 'S': S<u32>(u32) -> S<u32>
293 125..135 'S(unknown)': S<u32> 270 124..134 'S(unknown)': S<u32>
294 127..134 'unknown': u32 271 126..133 'unknown': u32
295 145..146 'x': u32 272 144..145 'x': u32
296 154..157 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32 273 153..156 'foo': fn foo<u32, S<u32>>(S<u32>) -> u32
297 154..160 'foo(s)': u32 274 153..159 'foo(s)': u32
298 158..159 's': S<u32> 275 157..158 's': S<u32>
299 "### 276 "###
300 ); 277 );
301} 278}
@@ -313,12 +290,12 @@ trait Trait {
313} 290}
314"#), 291"#),
315 @r###" 292 @r###"
316 27..31 'self': &Self 293 26..30 'self': &Self
317 53..57 'self': &Self 294 52..56 'self': &Self
318 62..97 '{ ... }': () 295 61..96 '{ ... }': ()
319 76..77 'x': i64 296 75..76 'x': i64
320 80..84 'self': &Self 297 79..83 'self': &Self
321 80..90 'self.foo()': i64 298 79..89 'self.foo()': i64
322 "### 299 "###
323 ); 300 );
324} 301}
@@ -337,12 +314,12 @@ trait Trait: SuperTrait {
337} 314}
338"#), 315"#),
339 @r###" 316 @r###"
340 32..36 'self': &Self 317 31..35 'self': &Self
341 86..90 'self': &Self 318 85..89 'self': &Self
342 95..130 '{ ... }': () 319 94..129 '{ ... }': ()
343 109..110 'x': i64 320 108..109 'x': i64
344 113..117 'self': &Self 321 112..116 'self': &Self
345 113..123 'self.foo()': i64 322 112..122 'self.foo()': i64
346 "### 323 "###
347 ); 324 );
348} 325}
@@ -364,15 +341,15 @@ fn test<T: Iterable>() {
364} 341}
365"#), 342"#),
366 @r###" 343 @r###"
367 108..261 '{ ...ter; }': () 344 107..260 '{ ...ter; }': ()
368 118..119 'x': u32 345 117..118 'x': u32
369 145..146 '1': u32 346 144..145 '1': u32
370 156..157 'y': Iterable::Item<T> 347 155..156 'y': Iterable::Item<T>
371 183..192 'no_matter': Iterable::Item<T> 348 182..191 'no_matter': Iterable::Item<T>
372 202..203 'z': Iterable::Item<T> 349 201..202 'z': Iterable::Item<T>
373 215..224 'no_matter': Iterable::Item<T> 350 214..223 'no_matter': Iterable::Item<T>
374 234..235 'a': Iterable::Item<T> 351 233..234 'a': Iterable::Item<T>
375 249..258 'no_matter': Iterable::Item<T> 352 248..257 'no_matter': Iterable::Item<T>
376 "### 353 "###
377 ); 354 );
378} 355}
@@ -396,25 +373,25 @@ fn test() {
396} 373}
397"#), 374"#),
398 @r###" 375 @r###"
399 106..107 't': T 376 105..106 't': T
400 123..125 '{}': () 377 122..124 '{}': ()
401 147..148 't': T 378 146..147 't': T
402 178..180 '{}': () 379 177..179 '{}': ()
403 202..203 't': T 380 201..202 't': T
404 221..223 '{}': () 381 220..222 '{}': ()
405 234..300 '{ ...(S); }': () 382 233..299 '{ ...(S); }': ()
406 244..245 'x': u32 383 243..244 'x': u32
407 248..252 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item 384 247..251 'foo1': fn foo1<S>(S) -> <S as Iterable>::Item
408 248..255 'foo1(S)': u32 385 247..254 'foo1(S)': u32
409 253..254 'S': S 386 252..253 'S': S
410 265..266 'y': u32 387 264..265 'y': u32
411 269..273 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item 388 268..272 'foo2': fn foo2<S>(S) -> <S as Iterable>::Item
412 269..276 'foo2(S)': u32 389 268..275 'foo2(S)': u32
413 274..275 'S': S 390 273..274 'S': S
414 286..287 'z': u32 391 285..286 'z': u32
415 290..294 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item 392 289..293 'foo3': fn foo3<S>(S) -> <S as Iterable>::Item
416 290..297 'foo3(S)': u32 393 289..296 'foo3(S)': u32
417 295..296 'S': S 394 294..295 'S': S
418 "### 395 "###
419 ); 396 );
420} 397}
@@ -431,9 +408,9 @@ fn test<T: Iterable<Item=u32>>() {
431} 408}
432"#), 409"#),
433 @r###" 410 @r###"
434 67..100 '{ ...own; }': () 411 66..99 '{ ...own; }': ()
435 77..78 'y': u32 412 76..77 'y': u32
436 90..97 'unknown': u32 413 89..96 'unknown': u32
437 "### 414 "###
438 ); 415 );
439} 416}
@@ -446,13 +423,13 @@ const A: u32 = 1 + 1;
446static B: u64 = { let x = 1; x }; 423static B: u64 = { let x = 1; x };
447"#), 424"#),
448 @r###" 425 @r###"
449 16..17 '1': u32 426 15..16 '1': u32
450 16..21 '1 + 1': u32 427 15..20 '1 + 1': u32
451 20..21 '1': u32 428 19..20 '1': u32
452 39..55 '{ let ...1; x }': u64 429 38..54 '{ let ...1; x }': u64
453 45..46 'x': u64 430 44..45 'x': u64
454 49..50 '1': u64 431 48..49 '1': u64
455 52..53 'x': u64 432 51..52 'x': u64
456 "### 433 "###
457 ); 434 );
458} 435}
@@ -469,17 +446,17 @@ fn test() -> u64 {
469} 446}
470"#), 447"#),
471 @r###" 448 @r###"
472 38..87 '{ ... a.1 }': u64 449 37..86 '{ ... a.1 }': u64
473 48..49 'a': S 450 47..48 'a': S
474 52..53 'S': S(i32, u64) -> S 451 51..52 'S': S(i32, u64) -> S
475 52..59 'S(4, 6)': S 452 51..58 'S(4, 6)': S
476 54..55 '4': i32 453 53..54 '4': i32
477 57..58 '6': u64 454 56..57 '6': u64
478 69..70 'b': i32 455 68..69 'b': i32
479 73..74 'a': S 456 72..73 'a': S
480 73..76 'a.0': i32 457 72..75 'a.0': i32
481 82..83 'a': S 458 81..82 'a': S
482 82..85 'a.1': u64 459 81..84 'a.1': u64
483 "### 460 "###
484 ); 461 );
485} 462}
@@ -496,24 +473,24 @@ fn test() -> u64 {
496} 473}
497"#), 474"#),
498 @r###" 475 @r###"
499 44..102 '{ ...0(2) }': u64 476 43..101 '{ ...0(2) }': u64
500 54..55 'a': S 477 53..54 'a': S
501 58..59 'S': S(fn(u32) -> u64) -> S 478 57..58 'S': S(fn(u32) -> u64) -> S
502 58..68 'S(|i| 2*i)': S 479 57..67 'S(|i| 2*i)': S
503 60..67 '|i| 2*i': |u32| -> u64 480 59..66 '|i| 2*i': |u32| -> u64
504 61..62 'i': u32 481 60..61 'i': u32
505 64..65 '2': u32 482 63..64 '2': u32
506 64..67 '2*i': u32 483 63..66 '2*i': u32
507 66..67 'i': u32 484 65..66 'i': u32
508 78..79 'b': u64 485 77..78 'b': u64
509 82..83 'a': S 486 81..82 'a': S
510 82..85 'a.0': fn(u32) -> u64 487 81..84 'a.0': fn(u32) -> u64
511 82..88 'a.0(4)': u64 488 81..87 'a.0(4)': u64
512 86..87 '4': u32 489 85..86 '4': u32
513 94..95 'a': S 490 93..94 'a': S
514 94..97 'a.0': fn(u32) -> u64 491 93..96 'a.0': fn(u32) -> u64
515 94..100 'a.0(2)': u64 492 93..99 'a.0(2)': u64
516 98..99 '2': u32 493 97..98 '2': u32
517 "### 494 "###
518 ); 495 );
519} 496}
@@ -535,10 +512,9 @@ fn indexing_arrays() {
535 512
536#[test] 513#[test]
537fn infer_ops_index() { 514fn infer_ops_index() {
538 let (db, pos) = TestDB::with_position( 515 check_types(
539 r#" 516 r#"
540//- /main.rs crate:main deps:std 517//- /main.rs crate:main deps:std
541
542struct Bar; 518struct Bar;
543struct Foo; 519struct Foo;
544 520
@@ -549,11 +525,46 @@ impl std::ops::Index<u32> for Bar {
549fn test() { 525fn test() {
550 let a = Bar; 526 let a = Bar;
551 let b = a[1u32]; 527 let b = a[1u32];
552 b<|>; 528 b;
553} 529} //^ Foo
554 530
555//- /std.rs crate:std 531//- /std.rs crate:std
532#[prelude_import] use ops::*;
533mod ops {
534 #[lang = "index"]
535 pub trait Index<Idx> {
536 type Output;
537 }
538}
539"#,
540 );
541}
542
543#[test]
544fn infer_ops_index_int() {
545 check_types(
546 r#"
547//- /main.rs crate:main deps:std
548struct Bar;
549struct Foo;
550
551impl std::ops::Index<u32> for Bar {
552 type Output = Foo;
553}
554
555struct Range;
556impl std::ops::Index<Range> for Bar {
557 type Output = Bar;
558}
559
560fn test() {
561 let a = Bar;
562 let b = a[1];
563 b;
564 //^ Foo
565}
556 566
567//- /std.rs crate:std
557#[prelude_import] use ops::*; 568#[prelude_import] use ops::*;
558mod ops { 569mod ops {
559 #[lang = "index"] 570 #[lang = "index"]
@@ -563,19 +574,18 @@ mod ops {
563} 574}
564"#, 575"#,
565 ); 576 );
566 assert_eq!("Foo", type_at_pos(&db, pos));
567} 577}
568 578
569#[test] 579#[test]
570fn infer_ops_index_autoderef() { 580fn infer_ops_index_autoderef() {
571 let (db, pos) = TestDB::with_position( 581 check_types(
572 r#" 582 r#"
573//- /main.rs crate:main deps:std 583//- /main.rs crate:main deps:std
574fn test() { 584fn test() {
575 let a = &[1u32, 2, 3]; 585 let a = &[1u32, 2, 3];
576 let b = a[1u32]; 586 let b = a[1u32];
577 b<|>; 587 b;
578} 588} //^ u32
579 589
580//- /std.rs crate:std 590//- /std.rs crate:std
581impl<T> ops::Index<u32> for [T] { 591impl<T> ops::Index<u32> for [T] {
@@ -591,14 +601,12 @@ mod ops {
591} 601}
592"#, 602"#,
593 ); 603 );
594 assert_eq!("u32", type_at_pos(&db, pos));
595} 604}
596 605
597#[test] 606#[test]
598fn deref_trait() { 607fn deref_trait() {
599 let t = type_at( 608 check_types(
600 r#" 609 r#"
601//- /main.rs
602#[lang = "deref"] 610#[lang = "deref"]
603trait Deref { 611trait Deref {
604 type Target; 612 type Target;
@@ -616,16 +624,15 @@ impl S {
616} 624}
617 625
618fn test(s: Arc<S>) { 626fn test(s: Arc<S>) {
619 (*s, s.foo())<|>; 627 (*s, s.foo());
620} 628} //^ (S, u128)
621"#, 629"#,
622 ); 630 );
623 assert_eq!(t, "(S, u128)");
624} 631}
625 632
626#[test] 633#[test]
627fn deref_trait_with_inference_var() { 634fn deref_trait_with_inference_var() {
628 let t = type_at( 635 check_types(
629 r#" 636 r#"
630//- /main.rs 637//- /main.rs
631#[lang = "deref"] 638#[lang = "deref"]
@@ -645,19 +652,18 @@ fn foo(a: Arc<S>) {}
645 652
646fn test() { 653fn test() {
647 let a = new_arc(); 654 let a = new_arc();
648 let b = (*a)<|>; 655 let b = (*a);
656 //^ S
649 foo(a); 657 foo(a);
650} 658}
651"#, 659"#,
652 ); 660 );
653 assert_eq!(t, "S");
654} 661}
655 662
656#[test] 663#[test]
657fn deref_trait_infinite_recursion() { 664fn deref_trait_infinite_recursion() {
658 let t = type_at( 665 check_types(
659 r#" 666 r#"
660//- /main.rs
661#[lang = "deref"] 667#[lang = "deref"]
662trait Deref { 668trait Deref {
663 type Target; 669 type Target;
@@ -671,18 +677,16 @@ impl Deref for S {
671} 677}
672 678
673fn test(s: S) { 679fn test(s: S) {
674 s.foo()<|>; 680 s.foo();
675} 681} //^ {unknown}
676"#, 682"#,
677 ); 683 );
678 assert_eq!(t, "{unknown}");
679} 684}
680 685
681#[test] 686#[test]
682fn deref_trait_with_question_mark_size() { 687fn deref_trait_with_question_mark_size() {
683 let t = type_at( 688 check_types(
684 r#" 689 r#"
685//- /main.rs
686#[lang = "deref"] 690#[lang = "deref"]
687trait Deref { 691trait Deref {
688 type Target; 692 type Target;
@@ -700,18 +704,16 @@ impl S {
700} 704}
701 705
702fn test(s: Arc<S>) { 706fn test(s: Arc<S>) {
703 (*s, s.foo())<|>; 707 (*s, s.foo());
704} 708} //^ (S, u128)
705"#, 709"#,
706 ); 710 );
707 assert_eq!(t, "(S, u128)");
708} 711}
709 712
710#[test] 713#[test]
711fn obligation_from_function_clause() { 714fn obligation_from_function_clause() {
712 let t = type_at( 715 check_types(
713 r#" 716 r#"
714//- /main.rs
715struct S; 717struct S;
716 718
717trait Trait<T> {} 719trait Trait<T> {}
@@ -720,16 +722,15 @@ impl Trait<u32> for S {}
720fn foo<T: Trait<U>, U>(t: T) -> U {} 722fn foo<T: Trait<U>, U>(t: T) -> U {}
721 723
722fn test(s: S) { 724fn test(s: S) {
723 foo(s)<|>; 725 (foo(s));
724} 726} //^ u32
725"#, 727"#,
726 ); 728 );
727 assert_eq!(t, "u32");
728} 729}
729 730
730#[test] 731#[test]
731fn obligation_from_method_clause() { 732fn obligation_from_method_clause() {
732 let t = type_at( 733 check_types(
733 r#" 734 r#"
734//- /main.rs 735//- /main.rs
735struct S; 736struct S;
@@ -743,18 +744,16 @@ impl O {
743} 744}
744 745
745fn test() { 746fn test() {
746 O.foo(S)<|>; 747 O.foo(S);
747} 748} //^ isize
748"#, 749"#,
749 ); 750 );
750 assert_eq!(t, "isize");
751} 751}
752 752
753#[test] 753#[test]
754fn obligation_from_self_method_clause() { 754fn obligation_from_self_method_clause() {
755 let t = type_at( 755 check_types(
756 r#" 756 r#"
757//- /main.rs
758struct S; 757struct S;
759 758
760trait Trait<T> {} 759trait Trait<T> {}
@@ -765,18 +764,16 @@ impl S {
765} 764}
766 765
767fn test() { 766fn test() {
768 S.foo()<|>; 767 S.foo();
769} 768} //^ i64
770"#, 769"#,
771 ); 770 );
772 assert_eq!(t, "i64");
773} 771}
774 772
775#[test] 773#[test]
776fn obligation_from_impl_clause() { 774fn obligation_from_impl_clause() {
777 let t = type_at( 775 check_types(
778 r#" 776 r#"
779//- /main.rs
780struct S; 777struct S;
781 778
782trait Trait<T> {} 779trait Trait<T> {}
@@ -788,32 +785,30 @@ impl<U, T: Trait<U>> O<T> {
788} 785}
789 786
790fn test(o: O<S>) { 787fn test(o: O<S>) {
791 o.foo()<|>; 788 o.foo();
792} 789} //^ &str
793"#, 790"#,
794 ); 791 );
795 assert_eq!(t, "&str");
796} 792}
797 793
798#[test] 794#[test]
799fn generic_param_env_1() { 795fn generic_param_env_1() {
800 let t = type_at( 796 check_types(
801 r#" 797 r#"
802//- /main.rs
803trait Clone {} 798trait Clone {}
804trait Trait { fn foo(self) -> u128; } 799trait Trait { fn foo(self) -> u128; }
805struct S; 800struct S;
806impl Clone for S {} 801impl Clone for S {}
807impl<T> Trait for T where T: Clone {} 802impl<T> Trait for T where T: Clone {}
808fn test<T: Clone>(t: T) { t.foo()<|>; } 803fn test<T: Clone>(t: T) { t.foo(); }
804 //^ u128
809"#, 805"#,
810 ); 806 );
811 assert_eq!(t, "u128");
812} 807}
813 808
814#[test] 809#[test]
815fn generic_param_env_1_not_met() { 810fn generic_param_env_1_not_met() {
816 let t = type_at( 811 check_types(
817 r#" 812 r#"
818//- /main.rs 813//- /main.rs
819trait Clone {} 814trait Clone {}
@@ -821,45 +816,42 @@ trait Trait { fn foo(self) -> u128; }
821struct S; 816struct S;
822impl Clone for S {} 817impl Clone for S {}
823impl<T> Trait for T where T: Clone {} 818impl<T> Trait for T where T: Clone {}
824fn test<T>(t: T) { t.foo()<|>; } 819fn test<T>(t: T) { t.foo(); }
820 //^ {unknown}
825"#, 821"#,
826 ); 822 );
827 assert_eq!(t, "{unknown}");
828} 823}
829 824
830#[test] 825#[test]
831fn generic_param_env_2() { 826fn generic_param_env_2() {
832 let t = type_at( 827 check_types(
833 r#" 828 r#"
834//- /main.rs
835trait Trait { fn foo(self) -> u128; } 829trait Trait { fn foo(self) -> u128; }
836struct S; 830struct S;
837impl Trait for S {} 831impl Trait for S {}
838fn test<T: Trait>(t: T) { t.foo()<|>; } 832fn test<T: Trait>(t: T) { t.foo(); }
833 //^ u128
839"#, 834"#,
840 ); 835 );
841 assert_eq!(t, "u128");
842} 836}
843 837
844#[test] 838#[test]
845fn generic_param_env_2_not_met() { 839fn generic_param_env_2_not_met() {
846 let t = type_at( 840 check_types(
847 r#" 841 r#"
848//- /main.rs
849trait Trait { fn foo(self) -> u128; } 842trait Trait { fn foo(self) -> u128; }
850struct S; 843struct S;
851impl Trait for S {} 844impl Trait for S {}
852fn test<T>(t: T) { t.foo()<|>; } 845fn test<T>(t: T) { t.foo(); }
846 //^ {unknown}
853"#, 847"#,
854 ); 848 );
855 assert_eq!(t, "{unknown}");
856} 849}
857 850
858#[test] 851#[test]
859fn generic_param_env_deref() { 852fn generic_param_env_deref() {
860 let t = type_at( 853 check_types(
861 r#" 854 r#"
862//- /main.rs
863#[lang = "deref"] 855#[lang = "deref"]
864trait Deref { 856trait Deref {
865 type Target; 857 type Target;
@@ -868,17 +860,17 @@ trait Trait {}
868impl<T> Deref for T where T: Trait { 860impl<T> Deref for T where T: Trait {
869 type Target = i128; 861 type Target = i128;
870} 862}
871fn test<T: Trait>(t: T) { (*t)<|>; } 863fn test<T: Trait>(t: T) { (*t); }
864 //^ i128
872"#, 865"#,
873 ); 866 );
874 assert_eq!(t, "i128");
875} 867}
876 868
877#[test] 869#[test]
878fn associated_type_placeholder() { 870fn associated_type_placeholder() {
879 let t = type_at( 871 // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types].
872 check_types(
880 r#" 873 r#"
881//- /main.rs
882pub trait ApplyL { 874pub trait ApplyL {
883 type Out; 875 type Out;
884} 876}
@@ -891,19 +883,16 @@ impl<T> ApplyL for RefMutL<T> {
891 883
892fn test<T: ApplyL>() { 884fn test<T: ApplyL>() {
893 let y: <RefMutL<T> as ApplyL>::Out = no_matter; 885 let y: <RefMutL<T> as ApplyL>::Out = no_matter;
894 y<|>; 886 y;
895} 887} //^ ApplyL::Out<T>
896"#, 888"#,
897 ); 889 );
898 // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out<T>` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types].
899 assert_eq!(t, "ApplyL::Out<T>");
900} 890}
901 891
902#[test] 892#[test]
903fn associated_type_placeholder_2() { 893fn associated_type_placeholder_2() {
904 let t = type_at( 894 check_types(
905 r#" 895 r#"
906//- /main.rs
907pub trait ApplyL { 896pub trait ApplyL {
908 type Out; 897 type Out;
909} 898}
@@ -911,11 +900,10 @@ fn foo<T: ApplyL>(t: T) -> <T as ApplyL>::Out;
911 900
912fn test<T: ApplyL>(t: T) { 901fn test<T: ApplyL>(t: T) {
913 let y = foo(t); 902 let y = foo(t);
914 y<|>; 903 y;
915} 904} //^ ApplyL::Out<T>
916"#, 905"#,
917 ); 906 );
918 assert_eq!(t, "ApplyL::Out<T>");
919} 907}
920 908
921#[test] 909#[test]
@@ -944,34 +932,34 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
944} 932}
945"#, true), 933"#, true),
946 @r###" 934 @r###"
947 30..34 'self': &Self 935 29..33 'self': &Self
948 55..59 'self': &Self 936 54..58 'self': &Self
949 78..79 'x': impl Trait<u16> 937 77..78 'x': impl Trait<u16>
950 98..100 '{}': () 938 97..99 '{}': ()
951 155..156 'x': impl Trait<u64> 939 154..155 'x': impl Trait<u64>
952 175..176 'y': &impl Trait<u32> 940 174..175 'y': &impl Trait<u32>
953 196..324 '{ ...2(); }': () 941 195..323 '{ ...2(); }': ()
954 202..203 'x': impl Trait<u64> 942 201..202 'x': impl Trait<u64>
955 209..210 'y': &impl Trait<u32> 943 208..209 'y': &impl Trait<u32>
956 220..221 'z': S<u16> 944 219..220 'z': S<u16>
957 224..225 'S': S<u16>(u16) -> S<u16> 945 223..224 'S': S<u16>(u16) -> S<u16>
958 224..228 'S(1)': S<u16> 946 223..227 'S(1)': S<u16>
959 226..227 '1': u16 947 225..226 '1': u16
960 234..237 'bar': fn bar(S<u16>) 948 233..236 'bar': fn bar(S<u16>)
961 234..240 'bar(z)': () 949 233..239 'bar(z)': ()
962 238..239 'z': S<u16> 950 237..238 'z': S<u16>
963 246..247 'x': impl Trait<u64> 951 245..246 'x': impl Trait<u64>
964 246..253 'x.foo()': u64 952 245..252 'x.foo()': u64
965 259..260 'y': &impl Trait<u32> 953 258..259 'y': &impl Trait<u32>
966 259..266 'y.foo()': u32 954 258..265 'y.foo()': u32
967 272..273 'z': S<u16> 955 271..272 'z': S<u16>
968 272..279 'z.foo()': u16 956 271..278 'z.foo()': u16
969 285..286 'x': impl Trait<u64> 957 284..285 'x': impl Trait<u64>
970 285..293 'x.foo2()': i64 958 284..292 'x.foo2()': i64
971 299..300 'y': &impl Trait<u32> 959 298..299 'y': &impl Trait<u32>
972 299..307 'y.foo2()': i64 960 298..306 'y.foo2()': i64
973 313..314 'z': S<u16> 961 312..313 'z': S<u16>
974 313..321 'z.foo2()': i64 962 312..320 'z.foo2()': i64
975 "### 963 "###
976 ); 964 );
977} 965}
@@ -1005,39 +993,39 @@ fn test() {
1005} 993}
1006"#, true), 994"#, true),
1007 @r###" 995 @r###"
1008 156..157 'x': impl Trait 996 155..156 'x': impl Trait
1009 176..187 '{ loop {} }': T 997 175..186 '{ loop {} }': T
1010 178..185 'loop {}': ! 998 177..184 'loop {}': !
1011 183..185 '{}': () 999 182..184 '{}': ()
1012 200..201 'x': impl Trait 1000 199..200 'x': impl Trait
1013 220..231 '{ loop {} }': T 1001 219..230 '{ loop {} }': T
1014 222..229 'loop {}': ! 1002 221..228 'loop {}': !
1015 227..229 '{}': () 1003 226..228 '{}': ()
1016 301..510 '{ ... i32 }': () 1004 300..509 '{ ... i32 }': ()
1017 307..315 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown} 1005 306..314 'Foo::bar': fn bar<{unknown}, {unknown}>(S) -> {unknown}
1018 307..318 'Foo::bar(S)': {unknown} 1006 306..317 'Foo::bar(S)': {unknown}
1019 316..317 'S': S 1007 315..316 'S': S
1020 324..339 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown} 1008 323..338 '<F as Foo>::bar': fn bar<F, {unknown}>(S) -> {unknown}
1021 324..342 '<F as ...bar(S)': {unknown} 1009 323..341 '<F as ...bar(S)': {unknown}
1022 340..341 'S': S 1010 339..340 'S': S
1023 348..354 'F::bar': fn bar<F, {unknown}>(S) -> {unknown} 1011 347..353 'F::bar': fn bar<F, {unknown}>(S) -> {unknown}
1024 348..357 'F::bar(S)': {unknown} 1012 347..356 'F::bar(S)': {unknown}
1025 355..356 'S': S 1013 354..355 'S': S
1026 363..378 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32 1014 362..377 'Foo::bar::<u32>': fn bar<{unknown}, u32>(S) -> u32
1027 363..381 'Foo::b...32>(S)': u32 1015 362..380 'Foo::b...32>(S)': u32
1028 379..380 'S': S 1016 378..379 'S': S
1029 387..409 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32 1017 386..408 '<F as ...:<u32>': fn bar<F, u32>(S) -> u32
1030 387..412 '<F as ...32>(S)': u32 1018 386..411 '<F as ...32>(S)': u32
1031 410..411 'S': S 1019 409..410 'S': S
1032 419..422 'foo': fn foo<{unknown}>(S) -> {unknown} 1020 418..421 'foo': fn foo<{unknown}>(S) -> {unknown}
1033 419..425 'foo(S)': {unknown} 1021 418..424 'foo(S)': {unknown}
1034 423..424 'S': S 1022 422..423 'S': S
1035 431..441 'foo::<u32>': fn foo<u32>(S) -> u32 1023 430..440 'foo::<u32>': fn foo<u32>(S) -> u32
1036 431..444 'foo::<u32>(S)': u32 1024 430..443 'foo::<u32>(S)': u32
1037 442..443 'S': S 1025 441..442 'S': S
1038 450..465 'foo::<u32, i32>': fn foo<u32>(S) -> u32 1026 449..464 'foo::<u32, i32>': fn foo<u32>(S) -> u32
1039 450..468 'foo::<...32>(S)': u32 1027 449..467 'foo::<...32>(S)': u32
1040 466..467 'S': S 1028 465..466 'S': S
1041 "### 1029 "###
1042 ); 1030 );
1043} 1031}
@@ -1062,24 +1050,24 @@ fn test() {
1062} 1050}
1063"#, true), 1051"#, true),
1064 @r###" 1052 @r###"
1065 88..92 'self': F<T> 1053 87..91 'self': F<T>
1066 94..95 'x': impl Trait 1054 93..94 'x': impl Trait
1067 119..130 '{ loop {} }': (T, U) 1055 118..129 '{ loop {} }': (T, U)
1068 121..128 'loop {}': ! 1056 120..127 'loop {}': !
1069 126..128 '{}': () 1057 125..127 '{}': ()
1070 144..284 '{ ...ored }': () 1058 143..283 '{ ...ored }': ()
1071 150..151 'F': F<{unknown}> 1059 149..150 'F': F<{unknown}>
1072 150..158 'F.foo(S)': ({unknown}, {unknown}) 1060 149..157 'F.foo(S)': ({unknown}, {unknown})
1073 156..157 'S': S 1061 155..156 'S': S
1074 164..172 'F::<u32>': F<u32> 1062 163..171 'F::<u32>': F<u32>
1075 164..179 'F::<u32>.foo(S)': (u32, {unknown}) 1063 163..178 'F::<u32>.foo(S)': (u32, {unknown})
1076 177..178 'S': S 1064 176..177 'S': S
1077 185..193 'F::<u32>': F<u32> 1065 184..192 'F::<u32>': F<u32>
1078 185..207 'F::<u3...32>(S)': (u32, i32) 1066 184..206 'F::<u3...32>(S)': (u32, i32)
1079 205..206 'S': S 1067 204..205 'S': S
1080 213..221 'F::<u32>': F<u32> 1068 212..220 'F::<u32>': F<u32>
1081 213..240 'F::<u3...32>(S)': (u32, i32) 1069 212..239 'F::<u3...32>(S)': (u32, i32)
1082 238..239 'S': S 1070 237..238 'S': S
1083 "### 1071 "###
1084 ); 1072 );
1085} 1073}
@@ -1098,19 +1086,18 @@ fn test() {
1098} 1086}
1099"#, true), 1087"#, true),
1100 @r###" 1088 @r###"
1101 23..24 'x': impl Trait 1089 22..23 'x': impl Trait
1102 38..49 '{ loop {} }': () 1090 37..48 '{ loop {} }': ()
1103 40..47 'loop {}': ! 1091 39..46 'loop {}': !
1104 45..47 '{}': () 1092 44..46 '{}': ()
1105 91..124 '{ ...foo; }': () 1093 90..123 '{ ...foo; }': ()
1106 101..102 'f': fn(S) 1094 100..101 'f': fn(S)
1107 118..121 'foo': fn foo(S) 1095 117..120 'foo': fn foo(S)
1108 "### 1096 "###
1109 ); 1097 );
1110} 1098}
1111 1099
1112#[test] 1100#[test]
1113#[ignore]
1114fn impl_trait() { 1101fn impl_trait() {
1115 assert_snapshot!( 1102 assert_snapshot!(
1116 infer(r#" 1103 infer(r#"
@@ -1133,29 +1120,118 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u64>) {
1133} 1120}
1134"#), 1121"#),
1135 @r###" 1122 @r###"
1136 30..34 'self': &Self 1123 29..33 'self': &Self
1137 55..59 'self': &Self 1124 54..58 'self': &Self
1138 99..101 '{}': () 1125 98..100 '{}': ()
1139 111..112 'x': impl Trait<u64> 1126 110..111 'x': impl Trait<u64>
1140 131..132 'y': &impl Trait<u64> 1127 130..131 'y': &impl Trait<u64>
1141 152..269 '{ ...2(); }': () 1128 151..268 '{ ...2(); }': ()
1142 158..159 'x': impl Trait<u64> 1129 157..158 'x': impl Trait<u64>
1143 165..166 'y': &impl Trait<u64> 1130 164..165 'y': &impl Trait<u64>
1144 176..177 'z': impl Trait<u64> 1131 175..176 'z': impl Trait<u64>
1145 180..183 'bar': fn bar() -> impl Trait<u64> 1132 179..182 'bar': fn bar() -> impl Trait<u64>
1146 180..185 'bar()': impl Trait<u64> 1133 179..184 'bar()': impl Trait<u64>
1147 191..192 'x': impl Trait<u64> 1134 190..191 'x': impl Trait<u64>
1148 191..198 'x.foo()': u64 1135 190..197 'x.foo()': u64
1149 204..205 'y': &impl Trait<u64> 1136 203..204 'y': &impl Trait<u64>
1150 204..211 'y.foo()': u64 1137 203..210 'y.foo()': u64
1151 217..218 'z': impl Trait<u64> 1138 216..217 'z': impl Trait<u64>
1152 217..224 'z.foo()': u64 1139 216..223 'z.foo()': u64
1153 230..231 'x': impl Trait<u64> 1140 229..230 'x': impl Trait<u64>
1154 230..238 'x.foo2()': i64 1141 229..237 'x.foo2()': i64
1155 244..245 'y': &impl Trait<u64> 1142 243..244 'y': &impl Trait<u64>
1156 244..252 'y.foo2()': i64 1143 243..251 'y.foo2()': i64
1157 258..259 'z': impl Trait<u64> 1144 257..258 'z': impl Trait<u64>
1158 258..266 'z.foo2()': i64 1145 257..265 'z.foo2()': i64
1146 "###
1147 );
1148}
1149
1150#[test]
1151fn simple_return_pos_impl_trait() {
1152 mark::check!(lower_rpit);
1153 assert_snapshot!(
1154 infer(r#"
1155trait Trait<T> {
1156 fn foo(&self) -> T;
1157}
1158fn bar() -> impl Trait<u64> { loop {} }
1159
1160fn test() {
1161 let a = bar();
1162 a.foo();
1163}
1164"#),
1165 @r###"
1166 29..33 'self': &Self
1167 71..82 '{ loop {} }': !
1168 73..80 'loop {}': !
1169 78..80 '{}': ()
1170 94..129 '{ ...o(); }': ()
1171 104..105 'a': impl Trait<u64>
1172 108..111 'bar': fn bar() -> impl Trait<u64>
1173 108..113 'bar()': impl Trait<u64>
1174 119..120 'a': impl Trait<u64>
1175 119..126 'a.foo()': u64
1176 "###
1177 );
1178}
1179
1180#[test]
1181fn more_return_pos_impl_trait() {
1182 assert_snapshot!(
1183 infer(r#"
1184trait Iterator {
1185 type Item;
1186 fn next(&mut self) -> Self::Item;
1187}
1188trait Trait<T> {
1189 fn foo(&self) -> T;
1190}
1191fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>) { loop {} }
1192fn baz<T>(t: T) -> (impl Iterator<Item = impl Trait<T>>, impl Trait<T>) { loop {} }
1193
1194fn test() {
1195 let (a, b) = bar();
1196 a.next().foo();
1197 b.foo();
1198 let (c, d) = baz(1u128);
1199 c.next().foo();
1200 d.foo();
1201}
1202"#),
1203 @r###"
1204 49..53 'self': &mut Self
1205 101..105 'self': &Self
1206 184..195 '{ loop {} }': ({unknown}, {unknown})
1207 186..193 'loop {}': !
1208 191..193 '{}': ()
1209 206..207 't': T
1210 268..279 '{ loop {} }': ({unknown}, {unknown})
1211 270..277 'loop {}': !
1212 275..277 '{}': ()
1213 291..413 '{ ...o(); }': ()
1214 301..307 '(a, b)': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1215 302..303 'a': impl Iterator<Item = impl Trait<u32>>
1216 305..306 'b': impl Trait<u64>
1217 310..313 'bar': fn bar() -> (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1218 310..315 'bar()': (impl Iterator<Item = impl Trait<u32>>, impl Trait<u64>)
1219 321..322 'a': impl Iterator<Item = impl Trait<u32>>
1220 321..329 'a.next()': impl Trait<u32>
1221 321..335 'a.next().foo()': u32
1222 341..342 'b': impl Trait<u64>
1223 341..348 'b.foo()': u64
1224 358..364 '(c, d)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1225 359..360 'c': impl Iterator<Item = impl Trait<u128>>
1226 362..363 'd': impl Trait<u128>
1227 367..370 'baz': fn baz<u128>(u128) -> (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1228 367..377 'baz(1u128)': (impl Iterator<Item = impl Trait<u128>>, impl Trait<u128>)
1229 371..376 '1u128': u128
1230 383..384 'c': impl Iterator<Item = impl Trait<u128>>
1231 383..391 'c.next()': impl Trait<u128>
1232 383..397 'c.next().foo()': u128
1233 403..404 'd': impl Trait<u128>
1234 403..410 'd.foo()': u128
1159 "### 1235 "###
1160 ); 1236 );
1161} 1237}
@@ -1183,29 +1259,29 @@ fn test(x: dyn Trait<u64>, y: &dyn Trait<u64>) {
1183} 1259}
1184"#), 1260"#),
1185 @r###" 1261 @r###"
1186 30..34 'self': &Self 1262 29..33 'self': &Self
1187 55..59 'self': &Self 1263 54..58 'self': &Self
1188 98..100 '{}': () 1264 97..99 '{}': ()
1189 110..111 'x': dyn Trait<u64> 1265 109..110 'x': dyn Trait<u64>
1190 129..130 'y': &dyn Trait<u64> 1266 128..129 'y': &dyn Trait<u64>
1191 149..266 '{ ...2(); }': () 1267 148..265 '{ ...2(); }': ()
1192 155..156 'x': dyn Trait<u64> 1268 154..155 'x': dyn Trait<u64>
1193 162..163 'y': &dyn Trait<u64> 1269 161..162 'y': &dyn Trait<u64>
1194 173..174 'z': dyn Trait<u64> 1270 172..173 'z': dyn Trait<u64>
1195 177..180 'bar': fn bar() -> dyn Trait<u64> 1271 176..179 'bar': fn bar() -> dyn Trait<u64>
1196 177..182 'bar()': dyn Trait<u64> 1272 176..181 'bar()': dyn Trait<u64>
1197 188..189 'x': dyn Trait<u64> 1273 187..188 'x': dyn Trait<u64>
1198 188..195 'x.foo()': u64 1274 187..194 'x.foo()': u64
1199 201..202 'y': &dyn Trait<u64> 1275 200..201 'y': &dyn Trait<u64>
1200 201..208 'y.foo()': u64 1276 200..207 'y.foo()': u64
1201 214..215 'z': dyn Trait<u64> 1277 213..214 'z': dyn Trait<u64>
1202 214..221 'z.foo()': u64 1278 213..220 'z.foo()': u64
1203 227..228 'x': dyn Trait<u64> 1279 226..227 'x': dyn Trait<u64>
1204 227..235 'x.foo2()': i64 1280 226..234 'x.foo2()': i64
1205 241..242 'y': &dyn Trait<u64> 1281 240..241 'y': &dyn Trait<u64>
1206 241..249 'y.foo2()': i64 1282 240..248 'y.foo2()': i64
1207 255..256 'z': dyn Trait<u64> 1283 254..255 'z': dyn Trait<u64>
1208 255..263 'z.foo2()': i64 1284 254..262 'z.foo2()': i64
1209 "### 1285 "###
1210 ); 1286 );
1211} 1287}
@@ -1231,17 +1307,17 @@ fn test(s: S<u32, i32>) {
1231} 1307}
1232"#), 1308"#),
1233 @r###" 1309 @r###"
1234 33..37 'self': &Self 1310 32..36 'self': &Self
1235 103..107 'self': &S<T, U> 1311 102..106 'self': &S<T, U>
1236 129..140 '{ loop {} }': &dyn Trait<T, U> 1312 128..139 '{ loop {} }': &dyn Trait<T, U>
1237 131..138 'loop {}': ! 1313 130..137 'loop {}': !
1238 136..138 '{}': () 1314 135..137 '{}': ()
1239 176..180 'self': &Self 1315 175..179 'self': &Self
1240 252..253 's': S<u32, i32> 1316 251..252 's': S<u32, i32>
1241 268..290 '{ ...z(); }': () 1317 267..289 '{ ...z(); }': ()
1242 274..275 's': S<u32, i32> 1318 273..274 's': S<u32, i32>
1243 274..281 's.bar()': &dyn Trait<u32, i32> 1319 273..280 's.bar()': &dyn Trait<u32, i32>
1244 274..287 's.bar().baz()': (u32, i32) 1320 273..286 's.bar().baz()': (u32, i32)
1245 "### 1321 "###
1246 ); 1322 );
1247} 1323}
@@ -1265,22 +1341,22 @@ fn test(x: Trait, y: &Trait) -> u64 {
1265} 1341}
1266"#), 1342"#),
1267 @r###" 1343 @r###"
1268 27..31 'self': &Self 1344 26..30 'self': &Self
1269 61..63 '{}': () 1345 60..62 '{}': ()
1270 73..74 'x': dyn Trait 1346 72..73 'x': dyn Trait
1271 83..84 'y': &dyn Trait 1347 82..83 'y': &dyn Trait
1272 101..176 '{ ...o(); }': () 1348 100..175 '{ ...o(); }': ()
1273 107..108 'x': dyn Trait 1349 106..107 'x': dyn Trait
1274 114..115 'y': &dyn Trait 1350 113..114 'y': &dyn Trait
1275 125..126 'z': dyn Trait 1351 124..125 'z': dyn Trait
1276 129..132 'bar': fn bar() -> dyn Trait 1352 128..131 'bar': fn bar() -> dyn Trait
1277 129..134 'bar()': dyn Trait 1353 128..133 'bar()': dyn Trait
1278 140..141 'x': dyn Trait 1354 139..140 'x': dyn Trait
1279 140..147 'x.foo()': u64 1355 139..146 'x.foo()': u64
1280 153..154 'y': &dyn Trait 1356 152..153 'y': &dyn Trait
1281 153..160 'y.foo()': u64 1357 152..159 'y.foo()': u64
1282 166..167 'z': dyn Trait 1358 165..166 'z': dyn Trait
1283 166..173 'z.foo()': u64 1359 165..172 'z.foo()': u64
1284 "### 1360 "###
1285 ); 1361 );
1286} 1362}
@@ -1294,13 +1370,13 @@ fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl (
1294} 1370}
1295"#), 1371"#),
1296 @r###" 1372 @r###"
1297 24..25 'a': impl Trait + {error} 1373 23..24 'a': impl Trait + {error}
1298 51..52 'b': impl {error} 1374 50..51 'b': impl {error}
1299 70..71 'c': impl Trait 1375 69..70 'c': impl Trait
1300 87..88 'd': impl {error} 1376 86..87 'd': impl {error}
1301 108..109 'e': impl {error} 1377 107..108 'e': impl {error}
1302 124..125 'f': impl Trait + {error} 1378 123..124 'f': impl Trait + {error}
1303 148..151 '{ }': () 1379 147..150 '{ }': ()
1304 "### 1380 "###
1305 ); 1381 );
1306} 1382}
@@ -1308,19 +1384,17 @@ fn test(a: impl Trait + 'lifetime, b: impl 'lifetime, c: impl (Trait), d: impl (
1308#[test] 1384#[test]
1309#[ignore] 1385#[ignore]
1310fn error_bound_chalk() { 1386fn error_bound_chalk() {
1311 let t = type_at( 1387 check_types(
1312 r#" 1388 r#"
1313//- /main.rs
1314trait Trait { 1389trait Trait {
1315 fn foo(&self) -> u32 {} 1390 fn foo(&self) -> u32 {}
1316} 1391}
1317 1392
1318fn test(x: (impl Trait + UnknownTrait)) { 1393fn test(x: (impl Trait + UnknownTrait)) {
1319 x.foo()<|>; 1394 x.foo();
1320} 1395} //^ u32
1321"#, 1396"#,
1322 ); 1397 );
1323 assert_eq!(t, "u32");
1324} 1398}
1325 1399
1326#[test] 1400#[test]
@@ -1349,48 +1423,48 @@ fn test<T: Trait<Type = u32>>(x: T, y: impl Trait<Type = i64>) {
1349} 1423}
1350"#), 1424"#),
1351 @r###" 1425 @r###"
1352 50..51 't': T 1426 49..50 't': T
1353 78..80 '{}': () 1427 77..79 '{}': ()
1354 112..113 't': T 1428 111..112 't': T
1355 123..125 '{}': () 1429 122..124 '{}': ()
1356 155..156 't': T 1430 154..155 't': T
1357 166..169 '{t}': T 1431 165..168 '{t}': T
1358 167..168 't': T 1432 166..167 't': T
1359 257..258 'x': T 1433 256..257 'x': T
1360 263..264 'y': impl Trait<Type = i64> 1434 262..263 'y': impl Trait<Type = i64>
1361 290..398 '{ ...r>); }': () 1435 289..397 '{ ...r>); }': ()
1362 296..299 'get': fn get<T>(T) -> <T as Trait>::Type 1436 295..298 'get': fn get<T>(T) -> <T as Trait>::Type
1363 296..302 'get(x)': u32 1437 295..301 'get(x)': u32
1364 300..301 'x': T 1438 299..300 'x': T
1365 308..312 'get2': fn get2<u32, T>(T) -> u32 1439 307..311 'get2': fn get2<u32, T>(T) -> u32
1366 308..315 'get2(x)': u32 1440 307..314 'get2(x)': u32
1367 313..314 'x': T 1441 312..313 'x': T
1368 321..324 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type 1442 320..323 'get': fn get<impl Trait<Type = i64>>(impl Trait<Type = i64>) -> <impl Trait<Type = i64> as Trait>::Type
1369 321..327 'get(y)': i64 1443 320..326 'get(y)': i64
1370 325..326 'y': impl Trait<Type = i64> 1444 324..325 'y': impl Trait<Type = i64>
1371 333..337 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64 1445 332..336 'get2': fn get2<i64, impl Trait<Type = i64>>(impl Trait<Type = i64>) -> i64
1372 333..340 'get2(y)': i64 1446 332..339 'get2(y)': i64
1373 338..339 'y': impl Trait<Type = i64> 1447 337..338 'y': impl Trait<Type = i64>
1374 346..349 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type 1448 345..348 'get': fn get<S<u64>>(S<u64>) -> <S<u64> as Trait>::Type
1375 346..357 'get(set(S))': u64 1449 345..356 'get(set(S))': u64
1376 350..353 'set': fn set<S<u64>>(S<u64>) -> S<u64> 1450 349..352 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1377 350..356 'set(S)': S<u64> 1451 349..355 'set(S)': S<u64>
1378 354..355 'S': S<u64> 1452 353..354 'S': S<u64>
1379 363..367 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64 1453 362..366 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1380 363..375 'get2(set(S))': u64 1454 362..374 'get2(set(S))': u64
1381 368..371 'set': fn set<S<u64>>(S<u64>) -> S<u64> 1455 367..370 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1382 368..374 'set(S)': S<u64> 1456 367..373 'set(S)': S<u64>
1383 372..373 'S': S<u64> 1457 371..372 'S': S<u64>
1384 381..385 'get2': fn get2<str, S<str>>(S<str>) -> str 1458 380..384 'get2': fn get2<str, S<str>>(S<str>) -> str
1385 381..395 'get2(S::<str>)': str 1459 380..394 'get2(S::<str>)': str
1386 386..394 'S::<str>': S<str> 1460 385..393 'S::<str>': S<str>
1387 "### 1461 "###
1388 ); 1462 );
1389} 1463}
1390 1464
1391#[test] 1465#[test]
1392fn impl_trait_assoc_binding_projection_bug() { 1466fn impl_trait_assoc_binding_projection_bug() {
1393 let (db, pos) = TestDB::with_position( 1467 check_types(
1394 r#" 1468 r#"
1395//- /main.rs crate:main deps:std 1469//- /main.rs crate:main deps:std
1396pub trait Language { 1470pub trait Language {
@@ -1409,8 +1483,8 @@ trait Clone {
1409 1483
1410fn api_walkthrough() { 1484fn api_walkthrough() {
1411 for node in foo() { 1485 for node in foo() {
1412 node.clone()<|>; 1486 node.clone();
1413 } 1487 } //^ {unknown}
1414} 1488}
1415 1489
1416//- /std.rs crate:std 1490//- /std.rs crate:std
@@ -1428,7 +1502,6 @@ mod iter {
1428} 1502}
1429"#, 1503"#,
1430 ); 1504 );
1431 assert_eq!("{unknown}", type_at_pos(&db, pos));
1432} 1505}
1433 1506
1434#[test] 1507#[test]
@@ -1448,20 +1521,19 @@ fn test<T: Trait1<Type = u32>>(x: T) {
1448} 1521}
1449"#), 1522"#),
1450 @r###" 1523 @r###"
1451 62..66 'self': Self 1524 61..65 'self': Self
1452 164..165 'x': T 1525 163..164 'x': T
1453 170..186 '{ ...o(); }': () 1526 169..185 '{ ...o(); }': ()
1454 176..177 'x': T 1527 175..176 'x': T
1455 176..183 'x.foo()': u32 1528 175..182 'x.foo()': u32
1456 "### 1529 "###
1457 ); 1530 );
1458} 1531}
1459 1532
1460#[test] 1533#[test]
1461fn where_clause_trait_in_scope_for_method_resolution() { 1534fn where_clause_trait_in_scope_for_method_resolution() {
1462 let t = type_at( 1535 check_types(
1463 r#" 1536 r#"
1464//- /main.rs
1465mod foo { 1537mod foo {
1466 trait Trait { 1538 trait Trait {
1467 fn foo(&self) -> u32 {} 1539 fn foo(&self) -> u32 {}
@@ -1469,11 +1541,10 @@ mod foo {
1469} 1541}
1470 1542
1471fn test<T: foo::Trait>(x: T) { 1543fn test<T: foo::Trait>(x: T) {
1472 x.foo()<|>; 1544 x.foo();
1473} 1545} //^ u32
1474"#, 1546"#,
1475 ); 1547 );
1476 assert_eq!(t, "u32");
1477} 1548}
1478 1549
1479#[test] 1550#[test]
@@ -1494,15 +1565,15 @@ fn test<T: Trait1, U: Trait2>(x: T, y: U) {
1494} 1565}
1495"#), 1566"#),
1496 @r###" 1567 @r###"
1497 50..54 'self': &Self 1568 49..53 'self': &Self
1498 63..65 '{}': () 1569 62..64 '{}': ()
1499 182..183 'x': T 1570 181..182 'x': T
1500 188..189 'y': U 1571 187..188 'y': U
1501 194..223 '{ ...o(); }': () 1572 193..222 '{ ...o(); }': ()
1502 200..201 'x': T 1573 199..200 'x': T
1503 200..207 'x.foo()': u32 1574 199..206 'x.foo()': u32
1504 213..214 'y': U 1575 212..213 'y': U
1505 213..220 'y.foo()': u32 1576 212..219 'y.foo()': u32
1506 "### 1577 "###
1507 ); 1578 );
1508} 1579}
@@ -1523,12 +1594,12 @@ fn test(x: &impl Trait1) {
1523} 1594}
1524"#), 1595"#),
1525 @r###" 1596 @r###"
1526 50..54 'self': &Self 1597 49..53 'self': &Self
1527 63..65 '{}': () 1598 62..64 '{}': ()
1528 116..117 'x': &impl Trait1 1599 115..116 'x': &impl Trait1
1529 133..149 '{ ...o(); }': () 1600 132..148 '{ ...o(); }': ()
1530 139..140 'x': &impl Trait1 1601 138..139 'x': &impl Trait1
1531 139..146 'x.foo()': u32 1602 138..145 'x.foo()': u32
1532 "### 1603 "###
1533 ); 1604 );
1534} 1605}
@@ -1546,10 +1617,10 @@ fn test<T: A>(x: T) {
1546} 1617}
1547"#), 1618"#),
1548 @r###" 1619 @r###"
1549 44..45 'x': T 1620 43..44 'x': T
1550 50..66 '{ ...o(); }': () 1621 49..65 '{ ...o(); }': ()
1551 56..57 'x': T 1622 55..56 'x': T
1552 56..63 'x.foo()': {unknown} 1623 55..62 'x.foo()': {unknown}
1553 "### 1624 "###
1554 ); 1625 );
1555} 1626}
@@ -1573,17 +1644,17 @@ fn test() {
1573} 1644}
1574"#), 1645"#),
1575 @r###" 1646 @r###"
1576 103..104 't': T 1647 102..103 't': T
1577 114..116 '{}': () 1648 113..115 '{}': ()
1578 146..147 't': T 1649 145..146 't': T
1579 157..160 '{t}': T 1650 156..159 '{t}': T
1580 158..159 't': T 1651 157..158 't': T
1581 259..280 '{ ...S)); }': () 1652 258..279 '{ ...S)); }': ()
1582 265..269 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64 1653 264..268 'get2': fn get2<u64, S<u64>>(S<u64>) -> u64
1583 265..277 'get2(set(S))': u64 1654 264..276 'get2(set(S))': u64
1584 270..273 'set': fn set<S<u64>>(S<u64>) -> S<u64> 1655 269..272 'set': fn set<S<u64>>(S<u64>) -> S<u64>
1585 270..276 'set(S)': S<u64> 1656 269..275 'set(S)': S<u64>
1586 274..275 'S': S<u64> 1657 273..274 'S': S<u64>
1587 "### 1658 "###
1588 ); 1659 );
1589} 1660}
@@ -1603,15 +1674,15 @@ fn test<F: FnOnce(u32, u64) -> u128>(f: F) {
1603} 1674}
1604"#), 1675"#),
1605 @r###" 1676 @r###"
1606 57..61 'self': Self 1677 56..60 'self': Self
1607 63..67 'args': Args 1678 62..66 'args': Args
1608 150..151 'f': F 1679 149..150 'f': F
1609 156..184 '{ ...2)); }': () 1680 155..183 '{ ...2)); }': ()
1610 162..163 'f': F 1681 161..162 'f': F
1611 162..181 'f.call...1, 2))': u128 1682 161..180 'f.call...1, 2))': u128
1612 174..180 '(1, 2)': (u32, u64) 1683 173..179 '(1, 2)': (u32, u64)
1613 175..176 '1': u32 1684 174..175 '1': u32
1614 178..179 '2': u64 1685 177..178 '2': u64
1615 "### 1686 "###
1616 ); 1687 );
1617} 1688}
@@ -1652,24 +1723,24 @@ fn test() {
1652} 1723}
1653"#), 1724"#),
1654 @r###" 1725 @r###"
165575..79 'self': Self 1726 74..78 'self': Self
165681..85 'args': Args 1727 80..84 'args': Args
1657140..144 'self': &Self 1728 139..143 'self': &Self
1658244..248 'self': &Bar<F> 1729 243..247 'self': &Bar<F>
1659261..263 '{}': () 1730 260..262 '{}': ()
1660347..351 'self': Opt<T> 1731 346..350 'self': Opt<T>
1661353..354 'f': F 1732 352..353 'f': F
1662369..371 '{}': () 1733 368..370 '{}': ()
1663385..501 '{ ...(f); }': () 1734 384..500 '{ ...(f); }': ()
1664395..398 'bar': Bar<fn(u8) -> u32> 1735 394..397 'bar': Bar<fn(u8) -> u32>
1665424..427 'bar': Bar<fn(u8) -> u32> 1736 423..426 'bar': Bar<fn(u8) -> u32>
1666424..433 'bar.foo()': {unknown} 1737 423..432 'bar.foo()': (u8, u32)
1667444..447 'opt': Opt<u8> 1738 443..446 'opt': Opt<u8>
1668466..467 'f': fn(u8) -> u32 1739 465..466 'f': fn(u8) -> u32
1669488..491 'opt': Opt<u8> 1740 487..490 'opt': Opt<u8>
1670488..498 'opt.map(f)': Opt<FnOnce::Output<fn(u8) -> u32, (u8,)>> 1741 487..497 'opt.map(f)': Opt<u32>
1671496..497 'f': fn(u8) -> u32 1742 495..496 'f': fn(u8) -> u32
1672"### 1743 "###
1673 ); 1744 );
1674} 1745}
1675 1746
@@ -1718,33 +1789,33 @@ fn test() {
1718} 1789}
1719"#), 1790"#),
1720 @r###" 1791 @r###"
172165..69 'self': &Self 1792 64..68 'self': &Self
1722166..170 'self': Self 1793 165..169 'self': Self
1723172..176 'args': Args 1794 171..175 'args': Args
1724240..244 'self': &Foo 1795 239..243 'self': &Foo
1725255..257 '{}': () 1796 254..256 '{}': ()
1726335..336 'f': F 1797 334..335 'f': F
1727355..357 '{}': () 1798 354..356 '{}': ()
1728444..690 '{ ...o(); }': () 1799 443..689 '{ ...o(); }': ()
1729454..459 'lazy1': Lazy<Foo, fn() -> T> 1800 453..458 'lazy1': Lazy<Foo, || -> Foo>
1730476..485 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> 1801 475..484 'Lazy::new': fn new<Foo, || -> Foo>(|| -> Foo) -> Lazy<Foo, || -> Foo>
1731476..493 'Lazy::...| Foo)': Lazy<Foo, fn() -> T> 1802 475..492 'Lazy::...| Foo)': Lazy<Foo, || -> Foo>
1732486..492 '|| Foo': || -> T 1803 485..491 '|| Foo': || -> Foo
1733489..492 'Foo': Foo 1804 488..491 'Foo': Foo
1734503..505 'r1': {unknown} 1805 502..504 'r1': usize
1735508..513 'lazy1': Lazy<Foo, fn() -> T> 1806 507..512 'lazy1': Lazy<Foo, || -> Foo>
1736508..519 'lazy1.foo()': {unknown} 1807 507..518 'lazy1.foo()': usize
1737561..576 'make_foo_fn_ptr': fn() -> Foo 1808 560..575 'make_foo_fn_ptr': fn() -> Foo
1738592..603 'make_foo_fn': fn make_foo_fn() -> Foo 1809 591..602 'make_foo_fn': fn make_foo_fn() -> Foo
1739613..618 'lazy2': Lazy<Foo, fn() -> T> 1810 612..617 'lazy2': Lazy<Foo, fn() -> Foo>
1740635..644 'Lazy::new': fn new<Foo, fn() -> T>(fn() -> T) -> Lazy<Foo, fn() -> T> 1811 634..643 'Lazy::new': fn new<Foo, fn() -> Foo>(fn() -> Foo) -> Lazy<Foo, fn() -> Foo>
1741635..661 'Lazy::...n_ptr)': Lazy<Foo, fn() -> T> 1812 634..660 'Lazy::...n_ptr)': Lazy<Foo, fn() -> Foo>
1742645..660 'make_foo_fn_ptr': fn() -> Foo 1813 644..659 'make_foo_fn_ptr': fn() -> Foo
1743671..673 'r2': {unknown} 1814 670..672 'r2': usize
1744676..681 'lazy2': Lazy<Foo, fn() -> T> 1815 675..680 'lazy2': Lazy<Foo, fn() -> Foo>
1745676..687 'lazy2.foo()': {unknown} 1816 675..686 'lazy2.foo()': usize
1746550..552 '{}': () 1817 549..551 '{}': ()
1747"### 1818 "###
1748 ); 1819 );
1749} 1820}
1750 1821
@@ -1770,32 +1841,32 @@ fn test() {
1770} 1841}
1771"#), 1842"#),
1772 @r###" 1843 @r###"
1773 148..152 'self': Option<T> 1844 147..151 'self': Option<T>
1774 154..155 'f': F 1845 153..154 'f': F
1775 173..175 '{}': () 1846 172..174 '{}': ()
1776 189..308 '{ ... 1); }': () 1847 188..307 '{ ... 1); }': ()
1777 199..200 'x': Option<u32> 1848 198..199 'x': Option<u32>
1778 203..215 'Option::Some': Some<u32>(u32) -> Option<u32> 1849 202..214 'Option::Some': Some<u32>(u32) -> Option<u32>
1779 203..221 'Option...(1u32)': Option<u32> 1850 202..220 'Option...(1u32)': Option<u32>
1780 216..220 '1u32': u32 1851 215..219 '1u32': u32
1781 227..228 'x': Option<u32> 1852 226..227 'x': Option<u32>
1782 227..243 'x.map(...v + 1)': Option<u32> 1853 226..242 'x.map(...v + 1)': Option<u32>
1783 233..242 '|v| v + 1': |u32| -> u32 1854 232..241 '|v| v + 1': |u32| -> u32
1784 234..235 'v': u32 1855 233..234 'v': u32
1785 237..238 'v': u32 1856 236..237 'v': u32
1786 237..242 'v + 1': u32 1857 236..241 'v + 1': u32
1787 241..242 '1': u32 1858 240..241 '1': u32
1788 249..250 'x': Option<u32> 1859 248..249 'x': Option<u32>
1789 249..265 'x.map(... 1u64)': Option<u64> 1860 248..264 'x.map(... 1u64)': Option<u64>
1790 255..264 '|_v| 1u64': |u32| -> u64 1861 254..263 '|_v| 1u64': |u32| -> u64
1791 256..258 '_v': u32 1862 255..257 '_v': u32
1792 260..264 '1u64': u64 1863 259..263 '1u64': u64
1793 275..276 'y': Option<i64> 1864 274..275 'y': Option<i64>
1794 292..293 'x': Option<u32> 1865 291..292 'x': Option<u32>
1795 292..305 'x.map(|_v| 1)': Option<i64> 1866 291..304 'x.map(|_v| 1)': Option<i64>
1796 298..304 '|_v| 1': |u32| -> i64 1867 297..303 '|_v| 1': |u32| -> i64
1797 299..301 '_v': u32 1868 298..300 '_v': u32
1798 303..304 '1': i64 1869 302..303 '1': i64
1799 "### 1870 "###
1800 ); 1871 );
1801} 1872}
@@ -1816,26 +1887,26 @@ fn test<F: FnOnce(u32) -> u64>(f: F) {
1816} 1887}
1817"#), 1888"#),
1818 @r###" 1889 @r###"
1819 73..74 'f': F 1890 72..73 'f': F
1820 79..155 '{ ...+ v; }': () 1891 78..154 '{ ...+ v; }': ()
1821 85..86 'f': F 1892 84..85 'f': F
1822 85..89 'f(1)': {unknown} 1893 84..88 'f(1)': {unknown}
1823 87..88 '1': i32 1894 86..87 '1': i32
1824 99..100 'g': |u64| -> i32 1895 98..99 'g': |u64| -> i32
1825 103..112 '|v| v + 1': |u64| -> i32 1896 102..111 '|v| v + 1': |u64| -> i32
1826 104..105 'v': u64 1897 103..104 'v': u64
1827 107..108 'v': u64 1898 106..107 'v': u64
1828 107..112 'v + 1': i32 1899 106..111 'v + 1': i32
1829 111..112 '1': i32 1900 110..111 '1': i32
1830 118..119 'g': |u64| -> i32 1901 117..118 'g': |u64| -> i32
1831 118..125 'g(1u64)': i32 1902 117..124 'g(1u64)': i32
1832 120..124 '1u64': u64 1903 119..123 '1u64': u64
1833 135..136 'h': |u128| -> u128 1904 134..135 'h': |u128| -> u128
1834 139..152 '|v| 1u128 + v': |u128| -> u128 1905 138..151 '|v| 1u128 + v': |u128| -> u128
1835 140..141 'v': u128 1906 139..140 'v': u128
1836 143..148 '1u128': u128 1907 142..147 '1u128': u128
1837 143..152 '1u128 + v': u128 1908 142..151 '1u128 + v': u128
1838 151..152 'v': u128 1909 150..151 'v': u128
1839 "### 1910 "###
1840 ); 1911 );
1841} 1912}
@@ -1868,61 +1939,83 @@ fn test() {
1868} 1939}
1869"#), 1940"#),
1870 @r###" 1941 @r###"
1871 95..96 'x': T 1942 94..95 'x': T
1872 101..102 'f': F 1943 100..101 'f': F
1873 112..114 '{}': () 1944 111..113 '{}': ()
1874 148..149 'f': F 1945 147..148 'f': F
1875 154..155 'x': T 1946 153..154 'x': T
1876 165..167 '{}': () 1947 164..166 '{}': ()
1877 202..206 'self': S 1948 201..205 'self': S
1878 254..258 'self': S 1949 253..257 'self': S
1879 260..261 'x': T 1950 259..260 'x': T
1880 266..267 'f': F 1951 265..266 'f': F
1881 277..279 '{}': () 1952 276..278 '{}': ()
1882 317..321 'self': S 1953 316..320 'self': S
1883 323..324 'f': F 1954 322..323 'f': F
1884 329..330 'x': T 1955 328..329 'x': T
1885 340..342 '{}': () 1956 339..341 '{}': ()
1886 356..515 '{ ... S); }': () 1957 355..514 '{ ... S); }': ()
1887 366..368 'x1': u64 1958 365..367 'x1': u64
1888 371..375 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64 1959 370..374 'foo1': fn foo1<S, u64, |S| -> u64>(S, |S| -> u64) -> u64
1889 371..394 'foo1(S...hod())': u64 1960 370..393 'foo1(S...hod())': u64
1890 376..377 'S': S 1961 375..376 'S': S
1891 379..393 '|s| s.method()': |S| -> u64 1962 378..392 '|s| s.method()': |S| -> u64
1892 380..381 's': S 1963 379..380 's': S
1893 383..384 's': S 1964 382..383 's': S
1894 383..393 's.method()': u64 1965 382..392 's.method()': u64
1895 404..406 'x2': u64 1966 403..405 'x2': u64
1896 409..413 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64 1967 408..412 'foo2': fn foo2<S, u64, |S| -> u64>(|S| -> u64, S) -> u64
1897 409..432 'foo2(|...(), S)': u64 1968 408..431 'foo2(|...(), S)': u64
1898 414..428 '|s| s.method()': |S| -> u64 1969 413..427 '|s| s.method()': |S| -> u64
1899 415..416 's': S 1970 414..415 's': S
1900 418..419 's': S 1971 417..418 's': S
1901 418..428 's.method()': u64 1972 417..427 's.method()': u64
1902 430..431 'S': S 1973 429..430 'S': S
1903 442..444 'x3': u64 1974 441..443 'x3': u64
1904 447..448 'S': S 1975 446..447 'S': S
1905 447..472 'S.foo1...hod())': u64 1976 446..471 'S.foo1...hod())': u64
1906 454..455 'S': S 1977 453..454 'S': S
1907 457..471 '|s| s.method()': |S| -> u64 1978 456..470 '|s| s.method()': |S| -> u64
1908 458..459 's': S 1979 457..458 's': S
1909 461..462 's': S 1980 460..461 's': S
1910 461..471 's.method()': u64 1981 460..470 's.method()': u64
1911 482..484 'x4': u64 1982 481..483 'x4': u64
1912 487..488 'S': S 1983 486..487 'S': S
1913 487..512 'S.foo2...(), S)': u64 1984 486..511 'S.foo2...(), S)': u64
1914 494..508 '|s| s.method()': |S| -> u64 1985 493..507 '|s| s.method()': |S| -> u64
1915 495..496 's': S 1986 494..495 's': S
1916 498..499 's': S 1987 497..498 's': S
1917 498..508 's.method()': u64 1988 497..507 's.method()': u64
1918 510..511 'S': S 1989 509..510 'S': S
1919 "### 1990 "###
1920 ); 1991 );
1921} 1992}
1922 1993
1923#[test] 1994#[test]
1995fn fn_item_fn_trait() {
1996 check_types(
1997 r#"
1998#[lang = "fn_once"]
1999trait FnOnce<Args> {
2000 type Output;
2001}
2002
2003struct S;
2004
2005fn foo() -> S {}
2006
2007fn takes_closure<U, F: FnOnce() -> U>(f: F) -> U { f() }
2008
2009fn test() {
2010 takes_closure(foo);
2011} //^^^^^^^^^^^^^^^^^^ S
2012"#,
2013 );
2014}
2015
2016#[test]
1924fn unselected_projection_in_trait_env_1() { 2017fn unselected_projection_in_trait_env_1() {
1925 let t = type_at( 2018 check_types(
1926 r#" 2019 r#"
1927//- /main.rs 2020//- /main.rs
1928trait Trait { 2021trait Trait {
@@ -1935,18 +2028,16 @@ trait Trait2 {
1935 2028
1936fn test<T: Trait>() where T::Item: Trait2 { 2029fn test<T: Trait>() where T::Item: Trait2 {
1937 let x: T::Item = no_matter; 2030 let x: T::Item = no_matter;
1938 x.foo()<|>; 2031 x.foo();
1939} 2032} //^ u32
1940"#, 2033"#,
1941 ); 2034 );
1942 assert_eq!(t, "u32");
1943} 2035}
1944 2036
1945#[test] 2037#[test]
1946fn unselected_projection_in_trait_env_2() { 2038fn unselected_projection_in_trait_env_2() {
1947 let t = type_at( 2039 check_types(
1948 r#" 2040 r#"
1949//- /main.rs
1950trait Trait<T> { 2041trait Trait<T> {
1951 type Item; 2042 type Item;
1952} 2043}
@@ -1957,11 +2048,10 @@ trait Trait2 {
1957 2048
1958fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> { 2049fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
1959 let x: T::Item = no_matter; 2050 let x: T::Item = no_matter;
1960 x.foo()<|>; 2051 x.foo();
1961} 2052} //^ u32
1962"#, 2053"#,
1963 ); 2054 );
1964 assert_eq!(t, "u32");
1965} 2055}
1966 2056
1967#[test] 2057#[test]
@@ -1990,26 +2080,25 @@ impl Trait for S2 {
1990} 2080}
1991"#, 2081"#,
1992 ), @r###" 2082 ), @r###"
1993 54..58 'self': &Self 2083 40..44 'self': &Self
1994 60..61 'x': Trait::Item<Self> 2084 46..47 'x': Trait::Item<Self>
1995 140..144 'self': &S 2085 126..130 'self': &S
1996 146..147 'x': u32 2086 132..133 'x': u32
1997 161..175 '{ let y = x; }': () 2087 147..161 '{ let y = x; }': ()
1998 167..168 'y': u32 2088 153..154 'y': u32
1999 171..172 'x': u32 2089 157..158 'x': u32
2000 242..246 'self': &S2 2090 228..232 'self': &S2
2001 248..249 'x': i32 2091 234..235 'x': i32
2002 265..279 '{ let y = x; }': () 2092 251..265 '{ let y = x; }': ()
2003 271..272 'y': i32 2093 257..258 'y': i32
2004 275..276 'x': i32 2094 261..262 'x': i32
2005 "###); 2095 "###);
2006} 2096}
2007 2097
2008#[test] 2098#[test]
2009fn unselected_projection_on_trait_self() { 2099fn unselected_projection_on_trait_self() {
2010 let t = type_at( 2100 check_types(
2011 r#" 2101 r#"
2012//- /main.rs
2013trait Trait { 2102trait Trait {
2014 type Item; 2103 type Item;
2015 2104
@@ -2022,18 +2111,16 @@ impl Trait for S {
2022} 2111}
2023 2112
2024fn test() { 2113fn test() {
2025 S.f()<|>; 2114 S.f();
2026} 2115} //^ u32
2027"#, 2116"#,
2028 ); 2117 );
2029 assert_eq!(t, "u32");
2030} 2118}
2031 2119
2032#[test] 2120#[test]
2033fn unselected_projection_chalk_fold() { 2121fn unselected_projection_chalk_fold() {
2034 let t = type_at( 2122 check_types(
2035 r#" 2123 r#"
2036//- /main.rs
2037trait Interner {} 2124trait Interner {}
2038trait Fold<I: Interner, TI = I> { 2125trait Fold<I: Interner, TI = I> {
2039 type Result; 2126 type Result;
@@ -2052,18 +2139,16 @@ where
2052} 2139}
2053 2140
2054fn foo<I: Interner>(interner: &I, t: Ty<I>) { 2141fn foo<I: Interner>(interner: &I, t: Ty<I>) {
2055 fold(interner, t)<|>; 2142 fold(interner, t);
2056} 2143} //^ Ty<I>
2057"#, 2144"#,
2058 ); 2145 );
2059 assert_eq!(t, "Ty<I>");
2060} 2146}
2061 2147
2062#[test] 2148#[test]
2063fn trait_impl_self_ty() { 2149fn trait_impl_self_ty() {
2064 let t = type_at( 2150 check_types(
2065 r#" 2151 r#"
2066//- /main.rs
2067trait Trait<T> { 2152trait Trait<T> {
2068 fn foo(&self); 2153 fn foo(&self);
2069} 2154}
@@ -2073,18 +2158,16 @@ struct S;
2073impl Trait<Self> for S {} 2158impl Trait<Self> for S {}
2074 2159
2075fn test() { 2160fn test() {
2076 S.foo()<|>; 2161 S.foo();
2077} 2162} //^ ()
2078"#, 2163"#,
2079 ); 2164 );
2080 assert_eq!(t, "()");
2081} 2165}
2082 2166
2083#[test] 2167#[test]
2084fn trait_impl_self_ty_cycle() { 2168fn trait_impl_self_ty_cycle() {
2085 let t = type_at( 2169 check_types(
2086 r#" 2170 r#"
2087//- /main.rs
2088trait Trait { 2171trait Trait {
2089 fn foo(&self); 2172 fn foo(&self);
2090} 2173}
@@ -2094,18 +2177,17 @@ struct S<T>;
2094impl Trait for S<Self> {} 2177impl Trait for S<Self> {}
2095 2178
2096fn test() { 2179fn test() {
2097 S.foo()<|>; 2180 S.foo();
2098} 2181} //^ {unknown}
2099"#, 2182"#,
2100 ); 2183 );
2101 assert_eq!(t, "{unknown}");
2102} 2184}
2103 2185
2104#[test] 2186#[test]
2105fn unselected_projection_in_trait_env_cycle_1() { 2187fn unselected_projection_in_trait_env_cycle_1() {
2106 let t = type_at( 2188 // this is a legitimate cycle
2189 check_types(
2107 r#" 2190 r#"
2108//- /main.rs
2109trait Trait { 2191trait Trait {
2110 type Item; 2192 type Item;
2111} 2193}
@@ -2113,17 +2195,16 @@ trait Trait {
2113trait Trait2<T> {} 2195trait Trait2<T> {}
2114 2196
2115fn test<T: Trait>() where T: Trait2<T::Item> { 2197fn test<T: Trait>() where T: Trait2<T::Item> {
2116 let x: T::Item = no_matter<|>; 2198 let x: T::Item = no_matter;
2117} 2199} //^ {unknown}
2118"#, 2200"#,
2119 ); 2201 );
2120 // this is a legitimate cycle
2121 assert_eq!(t, "{unknown}");
2122} 2202}
2123 2203
2124#[test] 2204#[test]
2125fn unselected_projection_in_trait_env_cycle_2() { 2205fn unselected_projection_in_trait_env_cycle_2() {
2126 let t = type_at( 2206 // this is a legitimate cycle
2207 check_types(
2127 r#" 2208 r#"
2128//- /main.rs 2209//- /main.rs
2129trait Trait<T> { 2210trait Trait<T> {
@@ -2131,19 +2212,16 @@ trait Trait<T> {
2131} 2212}
2132 2213
2133fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> { 2214fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
2134 let x: T::Item = no_matter<|>; 2215 let x: T::Item = no_matter;
2135} 2216} //^ {unknown}
2136"#, 2217"#,
2137 ); 2218 );
2138 // this is a legitimate cycle
2139 assert_eq!(t, "{unknown}");
2140} 2219}
2141 2220
2142#[test] 2221#[test]
2143fn inline_assoc_type_bounds_1() { 2222fn inline_assoc_type_bounds_1() {
2144 let t = type_at( 2223 check_types(
2145 r#" 2224 r#"
2146//- /main.rs
2147trait Iterator { 2225trait Iterator {
2148 type Item; 2226 type Item;
2149} 2227}
@@ -2159,29 +2237,26 @@ impl<T: Iterator> Iterator for S<T> {
2159 2237
2160fn test<I: Iterator<Item: OtherTrait<u32>>>() { 2238fn test<I: Iterator<Item: OtherTrait<u32>>>() {
2161 let x: <S<I> as Iterator>::Item; 2239 let x: <S<I> as Iterator>::Item;
2162 x.foo()<|>; 2240 x.foo();
2163} 2241} //^ u32
2164"#, 2242"#,
2165 ); 2243 );
2166 assert_eq!(t, "u32");
2167} 2244}
2168 2245
2169#[test] 2246#[test]
2170fn inline_assoc_type_bounds_2() { 2247fn inline_assoc_type_bounds_2() {
2171 let t = type_at( 2248 check_types(
2172 r#" 2249 r#"
2173//- /main.rs
2174trait Iterator { 2250trait Iterator {
2175 type Item; 2251 type Item;
2176} 2252}
2177 2253
2178fn test<I: Iterator<Item: Iterator<Item = u32>>>() { 2254fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
2179 let x: <<I as Iterator>::Item as Iterator>::Item; 2255 let x: <<I as Iterator>::Item as Iterator>::Item;
2180 x<|>; 2256 x;
2181} 2257} //^ u32
2182"#, 2258"#,
2183 ); 2259 );
2184 assert_eq!(t, "u32");
2185} 2260}
2186 2261
2187#[test] 2262#[test]
@@ -2241,15 +2316,15 @@ impl TokenStream for Rustc {
2241} 2316}
2242"#), 2317"#),
2243 @r###" 2318 @r###"
2244 1062..1073 '{ loop {} }': T 2319 1061..1072 '{ loop {} }': T
2245 1064..1071 'loop {}': ! 2320 1063..1070 'loop {}': !
2246 1069..1071 '{}': () 2321 1068..1070 '{}': ()
2247 1137..1200 '{ ... }': T 2322 1136..1199 '{ ... }': T
2248 1151..1156 'group': G 2323 1150..1155 'group': G
2249 1172..1176 'make': fn make<G>() -> G 2324 1171..1175 'make': fn make<G>() -> G
2250 1172..1178 'make()': G 2325 1171..1177 'make()': G
2251 1188..1192 'make': fn make<T>() -> T 2326 1187..1191 'make': fn make<T>() -> T
2252 1188..1194 'make()': T 2327 1187..1193 'make()': T
2253 "### 2328 "###
2254 ); 2329 );
2255} 2330}
@@ -2276,37 +2351,37 @@ fn test() -> impl Trait<i32> {
2276} 2351}
2277"#, true), 2352"#, true),
2278 @r###" 2353 @r###"
2279 27..28 'x': impl Trait<u32> 2354 26..27 'x': impl Trait<u32>
2280 47..58 '{ loop {} }': () 2355 46..57 '{ loop {} }': ()
2281 49..56 'loop {}': ! 2356 48..55 'loop {}': !
2282 54..56 '{}': () 2357 53..55 '{}': ()
2283 69..70 'x': impl Trait<T> 2358 68..69 'x': impl Trait<T>
2284 92..103 '{ loop {} }': T 2359 91..102 '{ loop {} }': T
2285 94..101 'loop {}': ! 2360 93..100 'loop {}': !
2286 99..101 '{}': () 2361 98..100 '{}': ()
2287 172..183 '{ loop {} }': T 2362 171..182 '{ loop {} }': T
2288 174..181 'loop {}': ! 2363 173..180 'loop {}': !
2289 179..181 '{}': () 2364 178..180 '{}': ()
2290 214..310 '{ ...t()) }': S<{unknown}> 2365 213..309 '{ ...t()) }': S<{unknown}>
2291 224..226 's1': S<u32> 2366 223..225 's1': S<u32>
2292 229..230 'S': S<u32>(u32) -> S<u32> 2367 228..229 'S': S<u32>(u32) -> S<u32>
2293 229..241 'S(default())': S<u32> 2368 228..240 'S(default())': S<u32>
2294 231..238 'default': fn default<u32>() -> u32 2369 230..237 'default': fn default<u32>() -> u32
2295 231..240 'default()': u32 2370 230..239 'default()': u32
2296 247..250 'foo': fn foo(S<u32>) 2371 246..249 'foo': fn foo(S<u32>)
2297 247..254 'foo(s1)': () 2372 246..253 'foo(s1)': ()
2298 251..253 's1': S<u32> 2373 250..252 's1': S<u32>
2299 264..265 'x': i32 2374 263..264 'x': i32
2300 273..276 'bar': fn bar<i32>(S<i32>) -> i32 2375 272..275 'bar': fn bar<i32>(S<i32>) -> i32
2301 273..290 'bar(S(...lt()))': i32 2376 272..289 'bar(S(...lt()))': i32
2302 277..278 'S': S<i32>(i32) -> S<i32> 2377 276..277 'S': S<i32>(i32) -> S<i32>
2303 277..289 'S(default())': S<i32> 2378 276..288 'S(default())': S<i32>
2304 279..286 'default': fn default<i32>() -> i32 2379 278..285 'default': fn default<i32>() -> i32
2305 279..288 'default()': i32 2380 278..287 'default()': i32
2306 296..297 'S': S<{unknown}>({unknown}) -> S<{unknown}> 2381 295..296 'S': S<{unknown}>({unknown}) -> S<{unknown}>
2307 296..308 'S(default())': S<{unknown}> 2382 295..307 'S(default())': S<{unknown}>
2308 298..305 'default': fn default<{unknown}>() -> {unknown} 2383 297..304 'default': fn default<{unknown}>() -> {unknown}
2309 298..307 'default()': {unknown} 2384 297..306 'default()': {unknown}
2310 "### 2385 "###
2311 ); 2386 );
2312} 2387}
@@ -2340,24 +2415,23 @@ fn main() {
2340} 2415}
2341"#), 2416"#),
2342 @r###" 2417 @r###"
2343 147..149 '_v': F 2418 133..135 '_v': F
2344 192..195 '{ }': () 2419 178..181 '{ }': ()
2345 207..238 '{ ... }); }': () 2420 193..224 '{ ... }); }': ()
2346 213..223 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ()) 2421 199..209 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
2347 213..235 'f::<()... z; })': () 2422 199..221 'f::<()... z; })': ()
2348 224..234 '|z| { z; }': |&()| -> () 2423 210..220 '|z| { z; }': |&()| -> ()
2349 225..226 'z': &() 2424 211..212 'z': &()
2350 228..234 '{ z; }': () 2425 214..220 '{ z; }': ()
2351 230..231 'z': &() 2426 216..217 'z': &()
2352 "### 2427 "###
2353 ); 2428 );
2354} 2429}
2355 2430
2356#[test] 2431#[test]
2357fn associated_type_bound() { 2432fn associated_type_bound() {
2358 let t = type_at( 2433 check_types(
2359 r#" 2434 r#"
2360//- /main.rs
2361pub trait Trait { 2435pub trait Trait {
2362 type Item: OtherTrait<u32>; 2436 type Item: OtherTrait<u32>;
2363} 2437}
@@ -2373,18 +2447,16 @@ impl<T: Trait> Trait for S<T> {
2373 2447
2374fn test<T: Trait>() { 2448fn test<T: Trait>() {
2375 let y: <S<T> as Trait>::Item = no_matter; 2449 let y: <S<T> as Trait>::Item = no_matter;
2376 y.foo()<|>; 2450 y.foo();
2377} 2451} //^ u32
2378"#, 2452"#,
2379 ); 2453 );
2380 assert_eq!(t, "u32");
2381} 2454}
2382 2455
2383#[test] 2456#[test]
2384fn dyn_trait_through_chalk() { 2457fn dyn_trait_through_chalk() {
2385 let t = type_at( 2458 check_types(
2386 r#" 2459 r#"
2387//- /main.rs
2388struct Box<T> {} 2460struct Box<T> {}
2389#[lang = "deref"] 2461#[lang = "deref"]
2390trait Deref { 2462trait Deref {
@@ -2398,18 +2470,16 @@ trait Trait {
2398} 2470}
2399 2471
2400fn test(x: Box<dyn Trait>) { 2472fn test(x: Box<dyn Trait>) {
2401 x.foo()<|>; 2473 x.foo();
2402} 2474} //^ ()
2403"#, 2475"#,
2404 ); 2476 );
2405 assert_eq!(t, "()");
2406} 2477}
2407 2478
2408#[test] 2479#[test]
2409fn string_to_owned() { 2480fn string_to_owned() {
2410 let t = type_at( 2481 check_types(
2411 r#" 2482 r#"
2412//- /main.rs
2413struct String {} 2483struct String {}
2414pub trait ToOwned { 2484pub trait ToOwned {
2415 type Owned; 2485 type Owned;
@@ -2419,11 +2489,10 @@ impl ToOwned for str {
2419 type Owned = String; 2489 type Owned = String;
2420} 2490}
2421fn test() { 2491fn test() {
2422 "foo".to_owned()<|>; 2492 "foo".to_owned();
2423} 2493} //^ String
2424"#, 2494"#,
2425 ); 2495 );
2426 assert_eq!(t, "String");
2427} 2496}
2428 2497
2429#[test] 2498#[test]
@@ -2501,55 +2570,54 @@ fn main() {
2501} 2570}
2502"#), 2571"#),
2503 @r###" 2572 @r###"
2504 240..244 'self': Self 2573 226..230 'self': Self
2505 246..247 'f': F 2574 232..233 'f': F
2506 331..342 '{ loop {} }': FilterMap<Self, F> 2575 317..328 '{ loop {} }': FilterMap<Self, F>
2507 333..340 'loop {}': ! 2576 319..326 'loop {}': !
2508 338..340 '{}': () 2577 324..326 '{}': ()
2509 363..367 'self': Self 2578 349..353 'self': Self
2510 369..370 'f': F 2579 355..356 'f': F
2511 419..430 '{ loop {} }': () 2580 405..416 '{ loop {} }': ()
2512 421..428 'loop {}': ! 2581 407..414 'loop {}': !
2513 426..428 '{}': () 2582 412..414 '{}': ()
2514 539..543 'self': Self 2583 525..529 'self': Self
2515 868..872 'self': I 2584 854..858 'self': I
2516 879..899 '{ ... }': I 2585 865..885 '{ ... }': I
2517 889..893 'self': I 2586 875..879 'self': I
2518 958..969 '{ loop {} }': Vec<T> 2587 944..955 '{ loop {} }': Vec<T>
2519 960..967 'loop {}': ! 2588 946..953 'loop {}': !
2520 965..967 '{}': () 2589 951..953 '{}': ()
2521 1156..1287 '{ ... }); }': () 2590 1142..1273 '{ ... }); }': ()
2522 1162..1177 'Vec::<i32>::new': fn new<i32>() -> Vec<i32> 2591 1148..1163 'Vec::<i32>::new': fn new<i32>() -> Vec<i32>
2523 1162..1179 'Vec::<...:new()': Vec<i32> 2592 1148..1165 'Vec::<...:new()': Vec<i32>
2524 1162..1191 'Vec::<...iter()': IntoIter<i32> 2593 1148..1177 'Vec::<...iter()': IntoIter<i32>
2525 1162..1256 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>> 2594 1148..1242 'Vec::<...one })': FilterMap<IntoIter<i32>, |i32| -> Option<u32>>
2526 1162..1284 'Vec::<... y; })': () 2595 1148..1270 'Vec::<... y; })': ()
2527 1210..1255 '|x| if...None }': |i32| -> Option<u32> 2596 1196..1241 '|x| if...None }': |i32| -> Option<u32>
2528 1211..1212 'x': i32 2597 1197..1198 'x': i32
2529 1214..1255 'if x >...None }': Option<u32> 2598 1200..1241 'if x >...None }': Option<u32>
2530 1217..1218 'x': i32 2599 1203..1204 'x': i32
2531 1217..1222 'x > 0': bool 2600 1203..1208 'x > 0': bool
2532 1221..1222 '0': i32 2601 1207..1208 '0': i32
2533 1223..1241 '{ Some...u32) }': Option<u32> 2602 1209..1227 '{ Some...u32) }': Option<u32>
2534 1225..1229 'Some': Some<u32>(u32) -> Option<u32> 2603 1211..1215 'Some': Some<u32>(u32) -> Option<u32>
2535 1225..1239 'Some(x as u32)': Option<u32> 2604 1211..1225 'Some(x as u32)': Option<u32>
2536 1230..1231 'x': i32 2605 1216..1217 'x': i32
2537 1230..1238 'x as u32': u32 2606 1216..1224 'x as u32': u32
2538 1247..1255 '{ None }': Option<u32> 2607 1233..1241 '{ None }': Option<u32>
2539 1249..1253 'None': Option<u32> 2608 1235..1239 'None': Option<u32>
2540 1273..1283 '|y| { y; }': |u32| -> () 2609 1259..1269 '|y| { y; }': |u32| -> ()
2541 1274..1275 'y': u32 2610 1260..1261 'y': u32
2542 1277..1283 '{ y; }': () 2611 1263..1269 '{ y; }': ()
2543 1279..1280 'y': u32 2612 1265..1266 'y': u32
2544 "### 2613 "###
2545 ); 2614 );
2546} 2615}
2547 2616
2548#[test] 2617#[test]
2549fn nested_assoc() { 2618fn nested_assoc() {
2550 let t = type_at( 2619 check_types(
2551 r#" 2620 r#"
2552//- /main.rs
2553struct Bar; 2621struct Bar;
2554struct Foo; 2622struct Foo;
2555 2623
@@ -2572,11 +2640,10 @@ impl<T:A> B for T {
2572} 2640}
2573 2641
2574fn main() { 2642fn main() {
2575 Bar::foo()<|>; 2643 Bar::foo();
2576} 2644} //^ Foo
2577"#, 2645"#,
2578 ); 2646 );
2579 assert_eq!(t, "Foo");
2580} 2647}
2581 2648
2582#[test] 2649#[test]
@@ -2592,13 +2659,13 @@ fn test(x: &dyn Foo) {
2592} 2659}
2593"#, true), 2660"#, true),
2594 @r###" 2661 @r###"
2595 22..23 'x': &dyn Foo 2662 21..22 'x': &dyn Foo
2596 35..37 '{}': () 2663 34..36 '{}': ()
2597 47..48 'x': &dyn Foo 2664 46..47 'x': &dyn Foo
2598 60..75 '{ foo(x); }': () 2665 59..74 '{ foo(x); }': ()
2599 66..69 'foo': fn foo(&dyn Foo) 2666 65..68 'foo': fn foo(&dyn Foo)
2600 66..72 'foo(x)': () 2667 65..71 'foo(x)': ()
2601 70..71 'x': &dyn Foo 2668 69..70 'x': &dyn Foo
2602 "### 2669 "###
2603 ); 2670 );
2604} 2671}
@@ -2625,20 +2692,20 @@ fn test() {
2625} 2692}
2626"#, true), 2693"#, true),
2627 @r###" 2694 @r###"
2628 111..115 'self': &Self 2695 110..114 'self': &Self
2629 167..268 '{ ...t(); }': () 2696 166..267 '{ ...t(); }': ()
2630 173..179 'IsCopy': IsCopy 2697 172..178 'IsCopy': IsCopy
2631 173..186 'IsCopy.test()': bool 2698 172..185 'IsCopy.test()': bool
2632 192..199 'NotCopy': NotCopy 2699 191..198 'NotCopy': NotCopy
2633 192..206 'NotCopy.test()': {unknown} 2700 191..205 'NotCopy.test()': {unknown}
2634 212..228 '(IsCop...sCopy)': (IsCopy, IsCopy) 2701 211..227 '(IsCop...sCopy)': (IsCopy, IsCopy)
2635 212..235 '(IsCop...test()': bool 2702 211..234 '(IsCop...test()': bool
2636 213..219 'IsCopy': IsCopy 2703 212..218 'IsCopy': IsCopy
2637 221..227 'IsCopy': IsCopy 2704 220..226 'IsCopy': IsCopy
2638 241..258 '(IsCop...tCopy)': (IsCopy, NotCopy) 2705 240..257 '(IsCop...tCopy)': (IsCopy, NotCopy)
2639 241..265 '(IsCop...test()': {unknown} 2706 240..264 '(IsCop...test()': {unknown}
2640 242..248 'IsCopy': IsCopy 2707 241..247 'IsCopy': IsCopy
2641 250..257 'NotCopy': NotCopy 2708 249..256 'NotCopy': NotCopy
2642 "### 2709 "###
2643 ); 2710 );
2644} 2711}
@@ -2666,20 +2733,20 @@ fn test() {
2666} 2733}
2667"#, true), 2734"#, true),
2668 @r###" 2735 @r###"
2669 42..44 '{}': () 2736 41..43 '{}': ()
2670 61..62 'T': {unknown} 2737 60..61 'T': {unknown}
2671 69..71 '{}': () 2738 68..70 '{}': ()
2672 69..71: expected T, got () 2739 68..70: expected T, got ()
2673 146..150 'self': &Self 2740 145..149 'self': &Self
2674 202..282 '{ ...t(); }': () 2741 201..281 '{ ...t(); }': ()
2675 208..211 'foo': fn foo() 2742 207..210 'foo': fn foo()
2676 208..218 'foo.test()': bool 2743 207..217 'foo.test()': bool
2677 224..227 'bar': fn bar<{unknown}>({unknown}) -> {unknown} 2744 223..226 'bar': fn bar<{unknown}>({unknown}) -> {unknown}
2678 224..234 'bar.test()': bool 2745 223..233 'bar.test()': bool
2679 240..246 'Struct': Struct(usize) -> Struct 2746 239..245 'Struct': Struct(usize) -> Struct
2680 240..253 'Struct.test()': bool 2747 239..252 'Struct.test()': bool
2681 259..272 'Enum::Variant': Variant(usize) -> Enum 2748 258..271 'Enum::Variant': Variant(usize) -> Enum
2682 259..279 'Enum::...test()': bool 2749 258..278 'Enum::...test()': bool
2683 "### 2750 "###
2684 ); 2751 );
2685} 2752}
@@ -2701,17 +2768,17 @@ fn test(f1: fn(), f2: fn(usize) -> u8, f3: fn(u8, u8) -> &u8) {
2701} 2768}
2702"#, true), 2769"#, true),
2703 @r###" 2770 @r###"
2704 55..59 'self': &Self 2771 54..58 'self': &Self
2705 109..111 'f1': fn() 2772 108..110 'f1': fn()
2706 119..121 'f2': fn(usize) -> u8 2773 118..120 'f2': fn(usize) -> u8
2707 140..142 'f3': fn(u8, u8) -> &u8 2774 139..141 'f3': fn(u8, u8) -> &u8
2708 163..211 '{ ...t(); }': () 2775 162..210 '{ ...t(); }': ()
2709 169..171 'f1': fn() 2776 168..170 'f1': fn()
2710 169..178 'f1.test()': bool 2777 168..177 'f1.test()': bool
2711 184..186 'f2': fn(usize) -> u8 2778 183..185 'f2': fn(usize) -> u8
2712 184..193 'f2.test()': bool 2779 183..192 'f2.test()': bool
2713 199..201 'f3': fn(u8, u8) -> &u8 2780 198..200 'f3': fn(u8, u8) -> &u8
2714 199..208 'f3.test()': bool 2781 198..207 'f3.test()': bool
2715 "### 2782 "###
2716 ); 2783 );
2717} 2784}
@@ -2734,36 +2801,36 @@ fn test() {
2734} 2801}
2735"#, true), 2802"#, true),
2736 @r###" 2803 @r###"
2737 57..61 'self': &Self 2804 56..60 'self': &Self
2738 114..229 '{ ...ized }': () 2805 113..228 '{ ...ized }': ()
2739 120..123 '1u8': u8 2806 119..122 '1u8': u8
2740 120..130 '1u8.test()': bool 2807 119..129 '1u8.test()': bool
2741 136..151 '(*"foo").test()': {unknown} 2808 135..150 '(*"foo").test()': {unknown}
2742 137..143 '*"foo"': str 2809 136..142 '*"foo"': str
2743 138..143 '"foo"': &str 2810 137..142 '"foo"': &str
2744 170..180 '(1u8, 1u8)': (u8, u8) 2811 169..179 '(1u8, 1u8)': (u8, u8)
2745 170..187 '(1u8, ...test()': bool 2812 169..186 '(1u8, ...test()': bool
2746 171..174 '1u8': u8 2813 170..173 '1u8': u8
2747 176..179 '1u8': u8 2814 175..178 '1u8': u8
2748 193..206 '(1u8, *"foo")': (u8, str) 2815 192..205 '(1u8, *"foo")': (u8, str)
2749 193..213 '(1u8, ...test()': {unknown} 2816 192..212 '(1u8, ...test()': {unknown}
2750 194..197 '1u8': u8 2817 193..196 '1u8': u8
2751 199..205 '*"foo"': str 2818 198..204 '*"foo"': str
2752 200..205 '"foo"': &str 2819 199..204 '"foo"': &str
2753 "### 2820 "###
2754 ); 2821 );
2755} 2822}
2756 2823
2757#[test] 2824#[test]
2758fn integer_range_iterate() { 2825fn integer_range_iterate() {
2759 let t = type_at( 2826 check_types(
2760 r#" 2827 r#"
2761//- /main.rs crate:main deps:std 2828//- /main.rs crate:main deps:core
2762fn test() { 2829fn test() {
2763 for x in 0..100 { x<|>; } 2830 for x in 0..100 { x; }
2764} 2831} //^ i32
2765 2832
2766//- /std.rs crate:std 2833//- /core.rs crate:core
2767pub mod ops { 2834pub mod ops {
2768 pub struct Range<Idx> { 2835 pub struct Range<Idx> {
2769 pub start: Idx, 2836 pub start: Idx,
@@ -2796,5 +2863,235 @@ impl<A: Step> iter::Iterator for ops::Range<A> {
2796} 2863}
2797"#, 2864"#,
2798 ); 2865 );
2799 assert_eq!(t, "i32"); 2866}
2867
2868#[test]
2869fn infer_closure_arg() {
2870 assert_snapshot!(
2871 infer(
2872 r#"
2873 //- /lib.rs
2874
2875 enum Option<T> {
2876 None,
2877 Some(T)
2878 }
2879
2880 fn foo() {
2881 let s = Option::None;
2882 let f = |x: Option<i32>| {};
2883 (&f)(s)
2884 }
2885 "#
2886 ),
2887 @r###"
2888 52..126 '{ ...)(s) }': ()
2889 62..63 's': Option<i32>
2890 66..78 'Option::None': Option<i32>
2891 88..89 'f': |Option<i32>| -> ()
2892 92..111 '|x: Op...2>| {}': |Option<i32>| -> ()
2893 93..94 'x': Option<i32>
2894 109..111 '{}': ()
2895 117..124 '(&f)(s)': ()
2896 118..120 '&f': &|Option<i32>| -> ()
2897 119..120 'f': |Option<i32>| -> ()
2898 122..123 's': Option<i32>
2899 "###
2900 );
2901}
2902
2903#[test]
2904fn infer_fn_trait_arg() {
2905 assert_snapshot!(
2906 infer(
2907 r#"
2908 //- /lib.rs deps:std
2909
2910 #[lang = "fn_once"]
2911 pub trait FnOnce<Args> {
2912 type Output;
2913
2914 extern "rust-call" fn call_once(&self, args: Args) -> Self::Output;
2915 }
2916
2917 #[lang = "fn"]
2918 pub trait Fn<Args>:FnOnce<Args> {
2919 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
2920 }
2921
2922 enum Option<T> {
2923 None,
2924 Some(T)
2925 }
2926
2927 fn foo<F, T>(f: F) -> T
2928 where
2929 F: Fn(Option<i32>) -> T,
2930 {
2931 let s = None;
2932 f(s)
2933 }
2934 "#
2935 ),
2936 @r###"
2937 101..105 'self': &Self
2938 107..111 'args': Args
2939 220..224 'self': &Self
2940 226..230 'args': Args
2941 313..314 'f': F
2942 359..389 '{ ...f(s) }': T
2943 369..370 's': Option<i32>
2944 373..377 'None': Option<i32>
2945 383..384 'f': F
2946 383..387 'f(s)': T
2947 385..386 's': Option<i32>
2948 "###
2949 );
2950}
2951
2952#[test]
2953fn infer_box_fn_arg() {
2954 assert_snapshot!(
2955 infer(
2956 r#"
2957 //- /lib.rs deps:std
2958
2959 #[lang = "fn_once"]
2960 pub trait FnOnce<Args> {
2961 type Output;
2962
2963 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
2964 }
2965
2966 #[lang = "deref"]
2967 pub trait Deref {
2968 type Target: ?Sized;
2969
2970 fn deref(&self) -> &Self::Target;
2971 }
2972
2973 #[lang = "owned_box"]
2974 pub struct Box<T: ?Sized> {
2975 inner: *mut T,
2976 }
2977
2978 impl<T: ?Sized> Deref for Box<T> {
2979 type Target = T;
2980
2981 fn deref(&self) -> &T {
2982 &self.inner
2983 }
2984 }
2985
2986 enum Option<T> {
2987 None,
2988 Some(T)
2989 }
2990
2991 fn foo() {
2992 let s = Option::None;
2993 let f: Box<dyn FnOnce(&Option<i32>)> = box (|ps| {});
2994 f(&s)
2995 }
2996 "#
2997 ),
2998 @r###"
2999 100..104 'self': Self
3000 106..110 'args': Args
3001 214..218 'self': &Self
3002 384..388 'self': &Box<T>
3003 396..423 '{ ... }': &T
3004 406..417 '&self.inner': &*mut T
3005 407..411 'self': &Box<T>
3006 407..417 'self.inner': *mut T
3007 478..575 '{ ...(&s) }': FnOnce::Output<dyn FnOnce<(&Option<i32>,)>, (&Option<i32>,)>
3008 488..489 's': Option<i32>
3009 492..504 'Option::None': Option<i32>
3010 514..515 'f': Box<dyn FnOnce<(&Option<i32>,)>>
3011 549..562 'box (|ps| {})': Box<|{unknown}| -> ()>
3012 554..561 '|ps| {}': |{unknown}| -> ()
3013 555..557 'ps': {unknown}
3014 559..561 '{}': ()
3015 568..569 'f': Box<dyn FnOnce<(&Option<i32>,)>>
3016 568..573 'f(&s)': FnOnce::Output<dyn FnOnce<(&Option<i32>,)>, (&Option<i32>,)>
3017 570..572 '&s': &Option<i32>
3018 571..572 's': Option<i32>
3019 "###
3020 );
3021}
3022
3023#[test]
3024fn infer_dyn_fn_output() {
3025 check_types(
3026 r#"
3027#[lang = "fn_once"]
3028pub trait FnOnce<Args> {
3029 type Output;
3030 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3031}
3032
3033#[lang = "fn"]
3034pub trait Fn<Args>: FnOnce<Args> {
3035 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3036}
3037
3038fn foo() {
3039 let f: &dyn Fn() -> i32;
3040 f();
3041 //^^^ i32
3042}"#,
3043 );
3044}
3045
3046#[test]
3047fn infer_dyn_fn_once_output() {
3048 check_types(
3049 r#"
3050#[lang = "fn_once"]
3051pub trait FnOnce<Args> {
3052 type Output;
3053 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3054}
3055
3056fn foo() {
3057 let f: dyn FnOnce() -> i32;
3058 f();
3059 //^^^ i32
3060}"#,
3061 );
3062}
3063
3064#[test]
3065fn variable_kinds_1() {
3066 check_types(
3067 r#"
3068trait Trait<T> { fn get(self, t: T) -> T; }
3069struct S;
3070impl Trait<u128> for S {}
3071impl Trait<f32> for S {}
3072fn test() {
3073 S.get(1);
3074 //^^^^^^^^ u128
3075 S.get(1.);
3076 //^^^^^^^^ f32
3077}
3078 "#,
3079 );
3080}
3081
3082#[test]
3083fn variable_kinds_2() {
3084 check_types(
3085 r#"
3086trait Trait { fn get(self) -> Self; }
3087impl Trait for u128 {}
3088impl Trait for f32 {}
3089fn test() {
3090 1.get();
3091 //^^^^^^^ u128
3092 (1.).get();
3093 //^^^^^^^^^^ f32
3094}
3095 "#,
3096 );
2800} 3097}