@@ -211,29 +211,18 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
211
211
return ;
212
212
}
213
213
214
- // Depend on trait/impl predicates always being before method's own predicates,
215
- // to be able to split method predicates into "inherited" and method-specific.
216
- let trait_predicates = tcx. lookup_predicates ( trait_m. container_id ( ) ) . predicates ;
217
- let impl_predicates = tcx. lookup_predicates ( impl_m. container_id ( ) ) . predicates ;
218
- let trait_method_start = trait_predicates. len ( ) ;
219
- let impl_method_start = impl_predicates. len ( ) ;
220
- assert_eq ! ( & trait_predicates[ ..] , & trait_m. predicates. predicates[ ..trait_method_start] ) ;
221
- assert_eq ! ( & impl_predicates[ ..] , & impl_m. predicates. predicates[ ..impl_method_start] ) ;
222
-
223
214
tcx. infer_ctxt ( None , None , Reveal :: NotSpecializable ) . enter ( |mut infcx| {
224
215
let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
225
216
226
- // Normalize the associated types in the trait_bounds.
227
- let trait_bounds = trait_m. predicates . instantiate ( tcx, trait_to_skol_substs) ;
228
-
229
217
// Create obligations for each predicate declared by the impl
230
218
// definition in the context of the trait's parameter
231
219
// environment. We can't just use `impl_env.caller_bounds`,
232
220
// however, because we want to replace all late-bound regions with
233
221
// region variables.
234
- let impl_bounds = impl_m. predicates . instantiate ( tcx, impl_to_skol_substs) ;
222
+ let impl_predicates = tcx. lookup_predicates ( impl_m. predicates . parent . unwrap ( ) ) ;
223
+ let mut hybrid_preds = impl_predicates. instantiate ( tcx, impl_to_skol_substs) ;
235
224
236
- debug ! ( "compare_impl_method: impl_bounds={:?}" , impl_bounds ) ;
225
+ debug ! ( "compare_impl_method: impl_bounds={:?}" , hybrid_preds ) ;
237
226
238
227
// This is the only tricky bit of the new way we check implementation methods
239
228
// We need to build a set of predicates where only the FnSpace bounds
@@ -242,14 +231,14 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
242
231
//
243
232
// We then register the obligations from the impl_m and check to see
244
233
// if all constraints hold.
245
- let hybrid_preds = impl_bounds . predicates [ ..impl_method_start ] . iter ( )
246
- . chain ( trait_bounds . predicates [ trait_method_start.. ] . iter ( ) ) ;
234
+ hybrid_preds. predicates . extend (
235
+ trait_m . predicates . instantiate_own ( tcx , trait_to_skol_substs ) . predicates ) ;
247
236
248
237
// Construct trait parameter environment and then shift it into the skolemized viewpoint.
249
238
// The key step here is to update the caller_bounds's predicates to be
250
239
// the new hybrid bounds we computed.
251
240
let normalize_cause = traits:: ObligationCause :: misc ( impl_m_span, impl_m_body_id) ;
252
- let trait_param_env = impl_param_env. with_caller_bounds ( hybrid_preds. cloned ( ) . collect ( ) ) ;
241
+ let trait_param_env = impl_param_env. with_caller_bounds ( hybrid_preds. predicates ) ;
253
242
let trait_param_env = traits:: normalize_param_env_or_error ( tcx,
254
243
trait_param_env,
255
244
normalize_cause. clone ( ) ) ;
@@ -261,12 +250,13 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
261
250
262
251
let mut selcx = traits:: SelectionContext :: new ( & infcx) ;
263
252
264
- let ( impl_pred_fns, _) =
253
+ let impl_m_own_bounds = impl_m. predicates . instantiate_own ( tcx, impl_to_skol_substs) ;
254
+ let ( impl_m_own_bounds, _) =
265
255
infcx. replace_late_bound_regions_with_fresh_var (
266
256
impl_m_span,
267
257
infer:: HigherRankedType ,
268
- & ty:: Binder ( impl_bounds . predicates [ impl_method_start.. ] . to_vec ( ) ) ) ;
269
- for predicate in impl_pred_fns {
258
+ & ty:: Binder ( impl_m_own_bounds . predicates ) ) ;
259
+ for predicate in impl_m_own_bounds {
270
260
let traits:: Normalized { value : predicate, .. } =
271
261
traits:: normalize ( & mut selcx, normalize_cause. clone ( ) , & predicate) ;
272
262
0 commit comments