@@ -5194,7 +5194,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
51945194 & self ,
51955195 res : Res ,
51965196 span : Span ,
5197- ) -> Result < ( DefKind , DefId , Ty < ' tcx > ) , ErrorReported > {
5197+ ) -> Result < Res , ErrorReported > {
51985198 let tcx = self . tcx ;
51995199 if let Res :: SelfCtor ( impl_def_id) = res {
52005200 let ty = self . impl_self_ty ( span, impl_def_id) . ty ;
@@ -5204,11 +5204,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52045204 Some ( adt_def) if adt_def. has_ctor ( ) => {
52055205 let variant = adt_def. non_enum_variant ( ) ;
52065206 let ctor_def_id = variant. ctor_def_id . unwrap ( ) ;
5207- Ok ( (
5208- DefKind :: Ctor ( CtorOf :: Struct , variant. ctor_kind ) ,
5209- ctor_def_id,
5210- tcx. type_of ( ctor_def_id) ,
5211- ) )
5207+ Ok ( Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , variant. ctor_kind ) , ctor_def_id) )
52125208 }
52135209 _ => {
52145210 let mut err = tcx. sess . struct_span_err ( span,
@@ -5235,15 +5231,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52355231 }
52365232 }
52375233 } else {
5238- match res {
5239- Res :: Def ( kind, def_id) => {
5240- // The things we are substituting into the type should not contain
5241- // escaping late-bound regions, and nor should the base type scheme.
5242- let ty = tcx. type_of ( def_id) ;
5243- Ok ( ( kind, def_id, ty) )
5244- }
5245- _ => span_bug ! ( span, "unexpected res in rewrite_self_ctor: {:?}" , res) ,
5246- }
5234+ Ok ( res)
52475235 }
52485236 }
52495237
@@ -5266,27 +5254,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52665254
52675255 let tcx = self . tcx ;
52685256
5269- match res {
5270- Res :: Local ( hid) | Res :: Upvar ( hid, ..) => {
5271- let ty = self . local_ty ( span, hid) . decl_ty ;
5272- let ty = self . normalize_associated_types_in ( span, & ty) ;
5273- self . write_ty ( hir_id, ty) ;
5274- return ( ty, res) ;
5275- }
5276- _ => { }
5277- }
5278-
5279- let ( kind, def_id, ty) = match self . rewrite_self_ctor ( res, span) {
5280- Ok ( result) => result,
5257+ let res = match self . rewrite_self_ctor ( res, span) {
5258+ Ok ( res) => res,
52815259 Err ( ErrorReported ) => return ( tcx. types . err , res) ,
52825260 } ;
5283- let path_segs =
5284- AstConv :: def_ids_for_value_path_segments ( self , segments, self_ty, kind, def_id) ;
5261+ let path_segs = match res {
5262+ Res :: Local ( _) | Res :: Upvar ( ..) => Vec :: new ( ) ,
5263+ Res :: Def ( kind, def_id) =>
5264+ AstConv :: def_ids_for_value_path_segments ( self , segments, self_ty, kind, def_id) ,
5265+ _ => bug ! ( "instantiate_value_path on {:?}" , res) ,
5266+ } ;
52855267
52865268 let mut user_self_ty = None ;
52875269 let mut is_alias_variant_ctor = false ;
5288- match kind {
5289- DefKind :: Ctor ( CtorOf :: Variant , _) => {
5270+ match res {
5271+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , _ ) , _) => {
52905272 if let Some ( self_ty) = self_ty {
52915273 let adt_def = self_ty. ty_adt_def ( ) . unwrap ( ) ;
52925274 user_self_ty = Some ( UserSelfTy {
@@ -5296,8 +5278,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
52965278 is_alias_variant_ctor = true ;
52975279 }
52985280 }
5299- DefKind :: Method
5300- | DefKind :: AssociatedConst => {
5281+ Res :: Def ( DefKind :: Method , def_id )
5282+ | Res :: Def ( DefKind :: AssociatedConst , def_id ) => {
53015283 let container = tcx. associated_item ( def_id) . container ;
53025284 debug ! ( "instantiate_value_path: def_id={:?} container={:?}" , def_id, container) ;
53035285 match container {
@@ -5337,6 +5319,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53375319 None
53385320 }
53395321 } ) ) ;
5322+
5323+ match res {
5324+ Res :: Local ( hid) | Res :: Upvar ( hid, ..) => {
5325+ let ty = self . local_ty ( span, hid) . decl_ty ;
5326+ let ty = self . normalize_associated_types_in ( span, & ty) ;
5327+ self . write_ty ( hir_id, ty) ;
5328+ return ( ty, res) ;
5329+ }
5330+ _ => { }
5331+ }
5332+
53405333 if generics_has_err {
53415334 // Don't try to infer type parameters when prohibited generic arguments were given.
53425335 user_self_ty = None ;
@@ -5374,6 +5367,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
53745367 tcx. generics_of ( * def_id) . has_self
53755368 } ) . unwrap_or ( false ) ;
53765369
5370+ let def_id = res. def_id ( ) ;
5371+
5372+ // The things we are substituting into the type should not contain
5373+ // escaping late-bound regions, and nor should the base type scheme.
5374+ let ty = tcx. type_of ( def_id) ;
5375+
53775376 let substs = AstConv :: create_substs_for_generic_args (
53785377 tcx,
53795378 def_id,
@@ -5490,7 +5489,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
54905489 ty_substituted) ;
54915490 self . write_substs ( hir_id, substs) ;
54925491
5493- ( ty_substituted, Res :: Def ( kind , def_id ) )
5492+ ( ty_substituted, res )
54945493 }
54955494
54965495 fn check_rustc_args_require_const ( & self ,
0 commit comments