@@ -1463,6 +1463,9 @@ pub struct Resolver<'a, 'b: 'a> {
14631463 /// it's not used during normal resolution, only for better error reporting.
14641464 struct_constructors : DefIdMap < ( Def , ty:: Visibility ) > ,
14651465
1466+ /// Map from tuple struct's DefId to VariantData's Def
1467+ tuple_structs : DefIdMap < Def > ,
1468+
14661469 /// Only used for better errors on `fn(): fn()`
14671470 current_type_ascription : Vec < Span > ,
14681471
@@ -1764,6 +1767,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17641767 warned_proc_macros : FxHashSet ( ) ,
17651768 potentially_unused_imports : Vec :: new ( ) ,
17661769 struct_constructors : DefIdMap ( ) ,
1770+ tuple_structs : DefIdMap ( ) ,
17671771 found_unresolved_macro : false ,
17681772 unused_macros : FxHashSet ( ) ,
17691773 current_type_ascription : Vec :: new ( ) ,
@@ -2204,6 +2208,19 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
22042208 None
22052209 }
22062210
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+
22072224 fn resolve_item ( & mut self , item : & Item ) {
22082225 let name = item. ident . name ;
22092226 debug ! ( "(resolving item) resolving {}" , name) ;
@@ -2216,19 +2233,25 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
22162233 |this| visit:: walk_item ( this, item) ) ;
22172234 }
22182235
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+
22192252 ItemKind :: Enum ( _, ref generics) |
2220- ItemKind :: Struct ( _, ref generics) |
22212253 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) ;
22322255 }
22332256
22342257 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> {
25032526 self . ribs [ TypeNS ] . pop ( ) ;
25042527 }
25052528
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+
25062555 fn resolve_implementation ( & mut self ,
25072556 generics : & Generics ,
25082557 opt_trait_reference : & Option < TraitRef > ,
@@ -2554,8 +2603,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
25542603 ValueNS ,
25552604 impl_item. span ,
25562605 |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+ } ) ;
25592609 }
25602610 ImplItemKind :: Type ( ref ty) => {
25612611 // If this is a trait impl, ensure the type
0 commit comments