1
- mod m1 {
1
+ mod field_access {
2
+ #[ derive( Debug ) ]
3
+ struct S ;
4
+
5
+ #[ derive( Debug ) ]
6
+ struct MyThing {
7
+ a : S ,
8
+ }
9
+
10
+ #[ derive( Debug ) ]
11
+ enum MyOption < T > {
12
+ MyNone ( ) ,
13
+ MySome ( T ) ,
14
+ }
15
+
16
+ #[ derive( Debug ) ]
17
+ struct GenericThing < A > {
18
+ a : A ,
19
+ }
20
+
21
+ struct OptionS {
22
+ a : MyOption < S > ,
23
+ }
24
+
25
+ fn simple_field_access ( ) {
26
+ let x = MyThing { a : S } ;
27
+ println ! ( "{:?}" , x. a) ;
28
+ }
29
+
30
+ fn generic_field_access ( ) {
31
+ // Explicit type argument
32
+ let x = GenericThing :: < S > { a : S } ;
33
+ println ! ( "{:?}" , x. a) ;
34
+
35
+ // Implicit type argument
36
+ let y = GenericThing { a : S } ;
37
+ println ! ( "{:?}" , x. a) ;
38
+
39
+ // The type of the field `a` can only be infered from the concrete type
40
+ // in the struct declaration.
41
+ let x = OptionS {
42
+ a : MyOption :: MyNone ( ) ,
43
+ } ;
44
+ println ! ( "{:?}" , x. a) ;
45
+
46
+ // The type of the field `a` can only be infered from the type argument
47
+ let x = GenericThing :: < MyOption < S > > {
48
+ a : MyOption :: MyNone ( ) ,
49
+ } ;
50
+ println ! ( "{:?}" , x. a) ;
51
+
52
+ let mut x = GenericThing {
53
+ a : MyOption :: MyNone ( ) ,
54
+ } ;
55
+ // Only after this access can we infer the type parameter of `x`
56
+ let a: MyOption < S > = x. a ;
57
+ println ! ( "{:?}" , a) ;
58
+ }
59
+
60
+ pub fn f ( ) {
61
+ simple_field_access ( ) ;
62
+ generic_field_access ( ) ;
63
+ }
64
+ }
65
+
66
+ mod method_impl {
2
67
pub struct Foo { }
3
68
4
69
impl Foo {
@@ -25,7 +90,7 @@ mod m1 {
25
90
}
26
91
}
27
92
28
- mod m2 {
93
+ mod method_non_parametric_impl {
29
94
#[ derive( Debug ) ]
30
95
struct MyThing < A > {
31
96
a : A ,
@@ -58,6 +123,10 @@ mod m2 {
58
123
let x = MyThing { a : S1 } ;
59
124
let y = MyThing { a : S2 } ;
60
125
126
+ // simple field access
127
+ println ! ( "{:?}" , x. a) ;
128
+ println ! ( "{:?}" , y. a) ;
129
+
61
130
println ! ( "{:?}" , x. m1( ) ) ; // missing call target
62
131
println ! ( "{:?}" , y. m1( ) . a) ; // missing call target
63
132
@@ -69,7 +138,7 @@ mod m2 {
69
138
}
70
139
}
71
140
72
- mod m3 {
141
+ mod method_non_parametric_trait_impl {
73
142
#[ derive( Debug ) ]
74
143
struct MyThing < A > {
75
144
a : A ,
@@ -122,7 +191,7 @@ mod m3 {
122
191
}
123
192
}
124
193
125
- mod m4 {
194
+ mod function_trait_bounds {
126
195
#[ derive( Debug ) ]
127
196
struct MyThing < A > {
128
197
a : A ,
@@ -175,7 +244,7 @@ mod m4 {
175
244
}
176
245
}
177
246
178
- mod m5 {
247
+ mod trait_associated_type {
179
248
trait MyTrait {
180
249
type AssociatedType ;
181
250
@@ -210,7 +279,7 @@ mod m5 {
210
279
}
211
280
}
212
281
213
- mod m6 {
282
+ mod generic_enum {
214
283
#[ derive( Debug ) ]
215
284
enum MyEnum < A > {
216
285
C1 ( A ) ,
@@ -240,7 +309,7 @@ mod m6 {
240
309
}
241
310
}
242
311
243
- mod m7 {
312
+ mod method_supertraits {
244
313
#[ derive( Debug ) ]
245
314
struct MyThing < A > {
246
315
a : A ,
@@ -325,7 +394,7 @@ mod m7 {
325
394
}
326
395
}
327
396
328
- mod m8 {
397
+ mod function_trait_bounds_2 {
329
398
use std:: convert:: From ;
330
399
use std:: fmt:: Debug ;
331
400
@@ -374,7 +443,7 @@ mod m8 {
374
443
}
375
444
}
376
445
377
- mod m9 {
446
+ mod option_methods {
378
447
#[ derive( Debug ) ]
379
448
enum MyOption < T > {
380
449
MyNone ( ) ,
@@ -456,7 +525,7 @@ mod m9 {
456
525
}
457
526
}
458
527
459
- mod m10 {
528
+ mod method_call_type_conversion {
460
529
461
530
#[ derive( Debug , Copy , Clone ) ]
462
531
struct S < T > ( T ) ;
@@ -508,7 +577,7 @@ mod m10 {
508
577
}
509
578
}
510
579
511
- mod m11 {
580
+ mod trait_implicit_self_borrow {
512
581
trait MyTrait {
513
582
fn foo ( & self ) -> & Self ;
514
583
@@ -531,7 +600,7 @@ mod m11 {
531
600
}
532
601
}
533
602
534
- mod m12 {
603
+ mod implicit_self_borrow {
535
604
struct S ;
536
605
537
606
struct MyStruct < T > ( T ) ;
@@ -548,7 +617,7 @@ mod m12 {
548
617
}
549
618
}
550
619
551
- mod m13 {
620
+ mod borrowed_typed {
552
621
struct S ;
553
622
554
623
impl S {
@@ -578,18 +647,19 @@ mod m13 {
578
647
}
579
648
580
649
fn main ( ) {
581
- m1:: f ( ) ;
582
- m1:: g ( m1:: Foo { } , m1:: Foo { } ) ;
583
- m2:: f ( ) ;
584
- m3:: f ( ) ;
585
- m4:: f ( ) ;
586
- m5:: f ( ) ;
587
- m6:: f ( ) ;
588
- m7:: f ( ) ;
589
- m8:: f ( ) ;
590
- m9:: f ( ) ;
591
- m10:: f ( ) ;
592
- m11:: f ( ) ;
593
- m12:: f ( ) ;
594
- m13:: f ( ) ;
650
+ field_access:: f ( ) ;
651
+ method_impl:: f ( ) ;
652
+ method_impl:: g ( method_impl:: Foo { } , method_impl:: Foo { } ) ;
653
+ method_non_parametric_impl:: f ( ) ;
654
+ method_non_parametric_trait_impl:: f ( ) ;
655
+ function_trait_bounds:: f ( ) ;
656
+ trait_associated_type:: f ( ) ;
657
+ generic_enum:: f ( ) ;
658
+ method_supertraits:: f ( ) ;
659
+ function_trait_bounds_2:: f ( ) ;
660
+ option_methods:: f ( ) ;
661
+ method_call_type_conversion:: f ( ) ;
662
+ trait_implicit_self_borrow:: f ( ) ;
663
+ implicit_self_borrow:: f ( ) ;
664
+ borrowed_typed:: f ( ) ;
595
665
}
0 commit comments