@@ -22,7 +22,7 @@ use rustc_middle::ty::error::TypeError;
22
22
use rustc_middle:: ty:: fold:: TypeFoldable ;
23
23
use rustc_middle:: ty:: visit:: TypeVisitable ;
24
24
use rustc_middle:: ty:: {
25
- self , AdtKind , CanonicalUserType , DefIdTree , EarlyBinder , GenericParamDefKind , Ty , UserType ,
25
+ self , AdtKind , CanonicalUserType , DefIdTree , GenericParamDefKind , Ty , UserType ,
26
26
} ;
27
27
use rustc_middle:: ty:: { GenericArgKind , InternalSubsts , SubstsRef , UserSelfTy , UserSubsts } ;
28
28
use rustc_session:: lint;
@@ -333,22 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
333
333
}
334
334
}
335
335
336
- /// Basically whenever we are converting from a type scheme into
337
- /// the fn body space, we always want to normalize associated
338
- /// types as well. This function combines the two.
339
- fn instantiate_type_scheme < T > ( & self , span : Span , substs : SubstsRef < ' tcx > , value : T ) -> T
340
- where
341
- T : TypeFoldable < ' tcx > ,
342
- {
343
- debug ! ( "instantiate_type_scheme(value={:?}, substs={:?})" , value, substs) ;
344
- let value = EarlyBinder ( value) . subst ( self . tcx , substs) ;
345
- let result = self . normalize ( span, value) ;
346
- debug ! ( "instantiate_type_scheme = {:?}" , result) ;
347
- result
348
- }
349
-
350
- /// As `instantiate_type_scheme`, but for the bounds found in a
351
- /// generic type scheme.
336
+ /// Instantiates and normalizes the bounds for a given item
352
337
pub ( in super :: super ) fn instantiate_bounds (
353
338
& self ,
354
339
span : Span ,
@@ -1160,10 +1145,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1160
1145
} ;
1161
1146
let def_id = res. def_id ( ) ;
1162
1147
1163
- // The things we are substituting into the type should not contain
1164
- // escaping late-bound regions, and nor should the base type scheme.
1165
- let ty = tcx. type_of ( def_id) ;
1166
-
1167
1148
let arg_count = GenericArgCountResult {
1168
1149
explicit_late_bound,
1169
1150
correct : if infer_args_for_err. is_empty ( ) {
@@ -1286,8 +1267,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1286
1267
} ,
1287
1268
)
1288
1269
} ) ;
1289
- assert ! ( !substs. has_escaping_bound_vars( ) ) ;
1290
- assert ! ( !ty. has_escaping_bound_vars( ) ) ;
1291
1270
1292
1271
// First, store the "user substs" for later.
1293
1272
self . write_user_type_annotation_from_substs ( hir_id, def_id, substs, user_self_ty) ;
@@ -1296,17 +1275,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1296
1275
1297
1276
// Substitute the values for the type parameters into the type of
1298
1277
// the referenced item.
1299
- let ty_substituted = self . instantiate_type_scheme ( span, & substs, ty) ;
1278
+ let ty = tcx. bound_type_of ( def_id) ;
1279
+ assert ! ( !substs. has_escaping_bound_vars( ) ) ;
1280
+ assert ! ( !ty. 0 . has_escaping_bound_vars( ) ) ;
1281
+ let ty_substituted = self . normalize ( span, ty. subst ( tcx, substs) ) ;
1300
1282
1301
1283
if let Some ( UserSelfTy { impl_def_id, self_ty } ) = user_self_ty {
1302
1284
// In the case of `Foo<T>::method` and `<Foo<T>>::method`, if `method`
1303
1285
// is inherent, there is no `Self` parameter; instead, the impl needs
1304
1286
// type parameters, which we can infer by unifying the provided `Self`
1305
1287
// with the substituted impl type.
1306
1288
// This also occurs for an enum variant on a type alias.
1307
- let ty = tcx. type_of ( impl_def_id) ;
1308
-
1309
- let impl_ty = self . instantiate_type_scheme ( span, & substs, ty) ;
1289
+ let impl_ty = self . normalize ( span, tcx. bound_type_of ( impl_def_id) . subst ( tcx, substs) ) ;
1310
1290
match self . at ( & self . misc ( span) , self . param_env ) . eq ( impl_ty, self_ty) {
1311
1291
Ok ( ok) => self . register_infer_ok_obligations ( ok) ,
1312
1292
Err ( _) => {
0 commit comments