@@ -5194,7 +5194,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5194
5194
& self ,
5195
5195
res : Res ,
5196
5196
span : Span ,
5197
- ) -> Result < ( DefKind , DefId , Ty < ' tcx > ) , ErrorReported > {
5197
+ ) -> Result < Res , ErrorReported > {
5198
5198
let tcx = self . tcx ;
5199
5199
if let Res :: SelfCtor ( impl_def_id) = res {
5200
5200
let ty = self . impl_self_ty ( span, impl_def_id) . ty ;
@@ -5204,11 +5204,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5204
5204
Some ( adt_def) if adt_def. has_ctor ( ) => {
5205
5205
let variant = adt_def. non_enum_variant ( ) ;
5206
5206
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) )
5212
5208
}
5213
5209
_ => {
5214
5210
let mut err = tcx. sess . struct_span_err ( span,
@@ -5235,15 +5231,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5235
5231
}
5236
5232
}
5237
5233
} 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)
5247
5235
}
5248
5236
}
5249
5237
@@ -5266,27 +5254,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5266
5254
5267
5255
let tcx = self . tcx ;
5268
5256
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,
5281
5259
Err ( ErrorReported ) => return ( tcx. types . err , res) ,
5282
5260
} ;
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
+ } ;
5285
5267
5286
5268
let mut user_self_ty = None ;
5287
5269
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 , _ ) , _) => {
5290
5272
if let Some ( self_ty) = self_ty {
5291
5273
let adt_def = self_ty. ty_adt_def ( ) . unwrap ( ) ;
5292
5274
user_self_ty = Some ( UserSelfTy {
@@ -5296,8 +5278,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5296
5278
is_alias_variant_ctor = true ;
5297
5279
}
5298
5280
}
5299
- DefKind :: Method
5300
- | DefKind :: AssociatedConst => {
5281
+ Res :: Def ( DefKind :: Method , def_id )
5282
+ | Res :: Def ( DefKind :: AssociatedConst , def_id ) => {
5301
5283
let container = tcx. associated_item ( def_id) . container ;
5302
5284
debug ! ( "instantiate_value_path: def_id={:?} container={:?}" , def_id, container) ;
5303
5285
match container {
@@ -5337,6 +5319,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5337
5319
None
5338
5320
}
5339
5321
} ) ) ;
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
+
5340
5333
if generics_has_err {
5341
5334
// Don't try to infer type parameters when prohibited generic arguments were given.
5342
5335
user_self_ty = None ;
@@ -5374,6 +5367,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5374
5367
tcx. generics_of ( * def_id) . has_self
5375
5368
} ) . unwrap_or ( false ) ;
5376
5369
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
+
5377
5376
let substs = AstConv :: create_substs_for_generic_args (
5378
5377
tcx,
5379
5378
def_id,
@@ -5490,7 +5489,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5490
5489
ty_substituted) ;
5491
5490
self . write_substs ( hir_id, substs) ;
5492
5491
5493
- ( ty_substituted, Res :: Def ( kind , def_id ) )
5492
+ ( ty_substituted, res )
5494
5493
}
5495
5494
5496
5495
fn check_rustc_args_require_const ( & self ,
0 commit comments