@@ -5195,7 +5195,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5195
5195
& self ,
5196
5196
res : Res ,
5197
5197
span : Span ,
5198
- ) -> Result < ( DefKind , DefId , Ty < ' tcx > ) , ErrorReported > {
5198
+ ) -> Result < Res , ErrorReported > {
5199
5199
let tcx = self . tcx ;
5200
5200
if let Res :: SelfCtor ( impl_def_id) = res {
5201
5201
let ty = self . impl_self_ty ( span, impl_def_id) . ty ;
@@ -5205,11 +5205,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5205
5205
Some ( adt_def) if adt_def. has_ctor ( ) => {
5206
5206
let variant = adt_def. non_enum_variant ( ) ;
5207
5207
let ctor_def_id = variant. ctor_def_id . unwrap ( ) ;
5208
- Ok ( (
5209
- DefKind :: Ctor ( CtorOf :: Struct , variant. ctor_kind ) ,
5210
- ctor_def_id,
5211
- tcx. type_of ( ctor_def_id) ,
5212
- ) )
5208
+ Ok ( Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , variant. ctor_kind ) , ctor_def_id) )
5213
5209
}
5214
5210
_ => {
5215
5211
let mut err = tcx. sess . struct_span_err ( span,
@@ -5236,15 +5232,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5236
5232
}
5237
5233
}
5238
5234
} else {
5239
- match res {
5240
- Res :: Def ( kind, def_id) => {
5241
- // The things we are substituting into the type should not contain
5242
- // escaping late-bound regions, and nor should the base type scheme.
5243
- let ty = tcx. type_of ( def_id) ;
5244
- Ok ( ( kind, def_id, ty) )
5245
- }
5246
- _ => span_bug ! ( span, "unexpected res in rewrite_self_ctor: {:?}" , res) ,
5247
- }
5235
+ Ok ( res)
5248
5236
}
5249
5237
}
5250
5238
@@ -5267,27 +5255,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5267
5255
5268
5256
let tcx = self . tcx ;
5269
5257
5270
- match res {
5271
- Res :: Local ( hid) | Res :: Upvar ( hid, ..) => {
5272
- let ty = self . local_ty ( span, hid) . decl_ty ;
5273
- let ty = self . normalize_associated_types_in ( span, & ty) ;
5274
- self . write_ty ( hir_id, ty) ;
5275
- return ( ty, res) ;
5276
- }
5277
- _ => { }
5278
- }
5279
-
5280
- let ( kind, def_id, ty) = match self . rewrite_self_ctor ( res, span) {
5281
- Ok ( result) => result,
5258
+ let res = match self . rewrite_self_ctor ( res, span) {
5259
+ Ok ( res) => res,
5282
5260
Err ( ErrorReported ) => return ( tcx. types . err , res) ,
5283
5261
} ;
5284
- let path_segs =
5285
- AstConv :: def_ids_for_value_path_segments ( self , segments, self_ty, kind, def_id) ;
5262
+ let path_segs = match res {
5263
+ Res :: Local ( _) | Res :: Upvar ( ..) => Vec :: new ( ) ,
5264
+ Res :: Def ( kind, def_id) =>
5265
+ AstConv :: def_ids_for_value_path_segments ( self , segments, self_ty, kind, def_id) ,
5266
+ _ => bug ! ( "instantiate_value_path on {:?}" , res) ,
5267
+ } ;
5286
5268
5287
5269
let mut user_self_ty = None ;
5288
5270
let mut is_alias_variant_ctor = false ;
5289
- match kind {
5290
- DefKind :: Ctor ( CtorOf :: Variant , _) => {
5271
+ match res {
5272
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , _ ) , _) => {
5291
5273
if let Some ( self_ty) = self_ty {
5292
5274
let adt_def = self_ty. ty_adt_def ( ) . unwrap ( ) ;
5293
5275
user_self_ty = Some ( UserSelfTy {
@@ -5297,8 +5279,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5297
5279
is_alias_variant_ctor = true ;
5298
5280
}
5299
5281
}
5300
- DefKind :: Method
5301
- | DefKind :: AssociatedConst => {
5282
+ Res :: Def ( DefKind :: Method , def_id )
5283
+ | Res :: Def ( DefKind :: AssociatedConst , def_id ) => {
5302
5284
let container = tcx. associated_item ( def_id) . container ;
5303
5285
debug ! ( "instantiate_value_path: def_id={:?} container={:?}" , def_id, container) ;
5304
5286
match container {
@@ -5338,6 +5320,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5338
5320
None
5339
5321
}
5340
5322
} ) ) ;
5323
+
5324
+ match res {
5325
+ Res :: Local ( hid) | Res :: Upvar ( hid, ..) => {
5326
+ let ty = self . local_ty ( span, hid) . decl_ty ;
5327
+ let ty = self . normalize_associated_types_in ( span, & ty) ;
5328
+ self . write_ty ( hir_id, ty) ;
5329
+ return ( ty, res) ;
5330
+ }
5331
+ _ => { }
5332
+ }
5333
+
5341
5334
if generics_has_err {
5342
5335
// Don't try to infer type parameters when prohibited generic arguments were given.
5343
5336
user_self_ty = None ;
@@ -5375,6 +5368,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5375
5368
tcx. generics_of ( * def_id) . has_self
5376
5369
} ) . unwrap_or ( false ) ;
5377
5370
5371
+ let def_id = res. 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
+
5378
5377
let substs = AstConv :: create_substs_for_generic_args (
5379
5378
tcx,
5380
5379
def_id,
@@ -5491,7 +5490,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5491
5490
ty_substituted) ;
5492
5491
self . write_substs ( hir_id, substs) ;
5493
5492
5494
- ( ty_substituted, Res :: Def ( kind , def_id ) )
5493
+ ( ty_substituted, res )
5495
5494
}
5496
5495
5497
5496
fn check_rustc_args_require_const ( & self ,
0 commit comments