@@ -1463,6 +1463,9 @@ pub struct Resolver<'a, 'b: 'a> {
1463
1463
/// it's not used during normal resolution, only for better error reporting.
1464
1464
struct_constructors : DefIdMap < ( Def , ty:: Visibility ) > ,
1465
1465
1466
+ /// Map from tuple struct's DefId to VariantData's Def
1467
+ tuple_structs : DefIdMap < Def > ,
1468
+
1466
1469
/// Only used for better errors on `fn(): fn()`
1467
1470
current_type_ascription : Vec < Span > ,
1468
1471
@@ -1764,6 +1767,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
1764
1767
warned_proc_macros : FxHashSet ( ) ,
1765
1768
potentially_unused_imports : Vec :: new ( ) ,
1766
1769
struct_constructors : DefIdMap ( ) ,
1770
+ tuple_structs : DefIdMap ( ) ,
1767
1771
found_unresolved_macro : false ,
1768
1772
unused_macros : FxHashSet ( ) ,
1769
1773
current_type_ascription : Vec :: new ( ) ,
@@ -2204,6 +2208,19 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2204
2208
None
2205
2209
}
2206
2210
2211
+ fn resolve_adt ( & mut self , item : & Item , generics : & Generics ) {
2212
+ self . with_type_parameter_rib ( HasTypeParameters ( generics, ItemRibKind ) , |this| {
2213
+ let item_def_id = this. definitions . local_def_id ( item. id ) ;
2214
+ if this. session . features_untracked ( ) . self_in_typedefs {
2215
+ this. with_self_rib ( Def :: SelfTy ( None , Some ( item_def_id) ) , |this| {
2216
+ visit:: walk_item ( this, item) ;
2217
+ } ) ;
2218
+ } else {
2219
+ visit:: walk_item ( this, item) ;
2220
+ }
2221
+ } ) ;
2222
+ }
2223
+
2207
2224
fn resolve_item ( & mut self , item : & Item ) {
2208
2225
let name = item. ident . name ;
2209
2226
debug ! ( "(resolving item) resolving {}" , name) ;
@@ -2216,19 +2233,25 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2216
2233
|this| visit:: walk_item ( this, item) ) ;
2217
2234
}
2218
2235
2236
+ ItemKind :: Struct ( ref variant, ref generics) => {
2237
+ if variant. is_tuple ( ) || variant. is_unit ( ) {
2238
+ if let Some ( def_id) = self . definitions . opt_local_def_id ( item. id ) {
2239
+ if let Some ( variant_id) = self . definitions . opt_local_def_id ( variant. id ( ) ) {
2240
+ let variant_def = if variant. is_tuple ( ) {
2241
+ Def :: StructCtor ( variant_id, CtorKind :: Fn )
2242
+ } else {
2243
+ Def :: StructCtor ( variant_id, CtorKind :: Const )
2244
+ } ;
2245
+ self . tuple_structs . insert ( def_id, variant_def) ;
2246
+ }
2247
+ }
2248
+ }
2249
+ self . resolve_adt ( item, generics) ;
2250
+ }
2251
+
2219
2252
ItemKind :: Enum ( _, ref generics) |
2220
- ItemKind :: Struct ( _, ref generics) |
2221
2253
ItemKind :: Union ( _, ref generics) => {
2222
- self . with_type_parameter_rib ( HasTypeParameters ( generics, ItemRibKind ) , |this| {
2223
- let item_def_id = this. definitions . local_def_id ( item. id ) ;
2224
- if this. session . features_untracked ( ) . self_in_typedefs {
2225
- this. with_self_rib ( Def :: SelfTy ( None , Some ( item_def_id) ) , |this| {
2226
- visit:: walk_item ( this, item) ;
2227
- } ) ;
2228
- } else {
2229
- visit:: walk_item ( this, item) ;
2230
- }
2231
- } ) ;
2254
+ self . resolve_adt ( item, generics) ;
2232
2255
}
2233
2256
2234
2257
ItemKind :: Impl ( .., ref generics, ref opt_trait_ref, ref self_type, ref impl_items) =>
@@ -2503,6 +2526,32 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2503
2526
self . ribs [ TypeNS ] . pop ( ) ;
2504
2527
}
2505
2528
2529
+ fn with_tuple_struct_self_ctor_rib < F > ( & mut self , self_ty : & Ty , f : F )
2530
+ where F : FnOnce ( & mut Resolver )
2531
+ {
2532
+ let variant_def = if self . session . features_untracked ( ) . tuple_struct_self_ctor {
2533
+ let base_def = self . def_map . get ( & self_ty. id ) . map ( |r| r. base_def ( ) ) ;
2534
+ if let Some ( Def :: Struct ( ref def_id) ) = base_def {
2535
+ self . tuple_structs . get ( def_id) . cloned ( )
2536
+ } else {
2537
+ None
2538
+ }
2539
+ } else {
2540
+ None
2541
+ } ;
2542
+
2543
+ // when feature gate is enabled and `Self` is a tuple struct
2544
+ if let Some ( variant_def) = variant_def {
2545
+ let mut self_type_rib = Rib :: new ( NormalRibKind ) ;
2546
+ self_type_rib. bindings . insert ( keywords:: SelfType . ident ( ) , variant_def) ;
2547
+ self . ribs [ ValueNS ] . push ( self_type_rib) ;
2548
+ f ( self ) ;
2549
+ self . ribs [ ValueNS ] . pop ( ) ;
2550
+ } else {
2551
+ f ( self ) ;
2552
+ }
2553
+ }
2554
+
2506
2555
fn resolve_implementation ( & mut self ,
2507
2556
generics : & Generics ,
2508
2557
opt_trait_reference : & Option < TraitRef > ,
@@ -2554,8 +2603,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2554
2603
ValueNS ,
2555
2604
impl_item. span ,
2556
2605
|n, s| MethodNotMemberOfTrait ( n, s) ) ;
2557
-
2558
- visit:: walk_impl_item ( this, impl_item) ;
2606
+ this. with_tuple_struct_self_ctor_rib ( self_type, |this| {
2607
+ visit:: walk_impl_item ( this, impl_item) ;
2608
+ } ) ;
2559
2609
}
2560
2610
ImplItemKind :: Type ( ref ty) => {
2561
2611
// If this is a trait impl, ensure the type
0 commit comments