@@ -5330,7 +5330,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53305330 }
53315331
53325332 // Rewrite `SelfCtor` to `Ctor`
5333- pub fn rewrite_self_ctor ( & self , def : Def , span : Span ) -> ( Def , DefId , Ty < ' tcx > ) {
5333+ pub fn rewrite_self_ctor ( & self , def : Def , span : Span ) -> Def {
53345334 let tcx = self . tcx ;
53355335 if let Def :: SelfCtor ( impl_def_id) = def {
53365336 let ty = self . impl_self_ty ( span, impl_def_id) . ty ;
@@ -5340,8 +5340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53405340 Some ( adt_def) if adt_def. has_ctor ( ) => {
53415341 let variant = adt_def. non_enum_variant ( ) ;
53425342 let ctor_def_id = variant. ctor_def_id . unwrap ( ) ;
5343- let def = Def :: Ctor ( ctor_def_id, CtorOf :: Struct , variant. ctor_kind ) ;
5344- ( def, ctor_def_id, tcx. type_of ( ctor_def_id) )
5343+ Def :: Ctor ( ctor_def_id, CtorOf :: Struct , variant. ctor_kind )
53455344 }
53465345 _ => {
53475346 let mut err = tcx. sess . struct_span_err ( span,
@@ -5364,16 +5363,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53645363 }
53655364 err. emit ( ) ;
53665365
5367- ( def, impl_def_id , tcx . types . err )
5366+ def
53685367 }
53695368 }
53705369 } else {
5371- let def_id = def. def_id ( ) ;
5372-
5373- // The things we are substituting into the type should not contain
5374- // escaping late-bound regions, and nor should the base type scheme.
5375- let ty = tcx. type_of ( def_id) ;
5376- ( def, def_id, ty)
5370+ def
53775371 }
53785372 }
53795373
@@ -5396,7 +5390,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53965390
53975391 let tcx = self . tcx ;
53985392
5399- let ( def, def_id , ty ) = self . rewrite_self_ctor ( def, span) ;
5393+ let def = self . rewrite_self_ctor ( def, span) ;
54005394 let path_segs = AstConv :: def_ids_for_path_segments ( self , segments, self_ty, def) ;
54015395
54025396 let mut user_self_ty = None ;
@@ -5501,6 +5495,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
55015495 tcx. generics_of ( * def_id) . has_self
55025496 } ) . unwrap_or ( false ) ;
55035497
5498+ let ( def_id, ty) = if let Def :: SelfCtor ( impl_def_id) = def {
5499+ // NOTE(eddyb) an error has already been emitted by `rewrite_self_ctor`,
5500+ // avoid using the wrong type here. This isn't in `rewrite_self_ctor`
5501+ // itself because that runs too early (see #60989).
5502+ ( impl_def_id, tcx. types . err )
5503+ } else {
5504+ let def_id = def. def_id ( ) ;
5505+
5506+ // The things we are substituting into the type should not contain
5507+ // escaping late-bound regions, and nor should the base type scheme.
5508+ let ty = tcx. type_of ( def_id) ;
5509+ ( def_id, ty)
5510+ } ;
5511+
55045512 let substs = AstConv :: create_substs_for_generic_args (
55055513 tcx,
55065514 def_id,
0 commit comments