@@ -294,30 +294,28 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
294294 let obligations = self . nominal_obligations ( trait_ref. def_id , trait_ref. substs ) ;
295295
296296 debug ! ( "compute_trait_ref obligations {:?}" , obligations) ;
297- let cause = self . cause ( traits:: MiscObligation ) ;
298297 let param_env = self . param_env ;
299298 let depth = self . recursion_depth ;
300299
301300 let item = self . item ;
302301
303- let extend = |obligation : traits:: PredicateObligation < ' tcx > | {
304- let mut cause = cause. clone ( ) ;
305- if let Some ( parent_trait_pred) = obligation. predicate . to_opt_poly_trait_pred ( ) {
306- let derived_cause = traits:: DerivedObligationCause {
307- parent_trait_pred,
308- parent_code : obligation. cause . clone_code ( ) ,
309- } ;
310- * cause. make_mut_code ( ) =
311- traits:: ObligationCauseCode :: DerivedObligation ( derived_cause) ;
302+ let extend = |traits:: PredicateObligation { predicate, mut cause, .. } | {
303+ if let Some ( parent_trait_pred) = predicate. to_opt_poly_trait_pred ( ) {
304+ cause. map_code ( |parent_code| {
305+ {
306+ traits:: ObligationCauseCode :: DerivedObligation (
307+ traits:: DerivedObligationCause { parent_trait_pred, parent_code } ,
308+ )
309+ }
310+ . into ( )
311+ } ) ;
312+ } else {
313+ cause = traits:: ObligationCause :: misc ( self . span , self . body_id ) ;
312314 }
313315 extend_cause_with_original_assoc_item_obligation (
314- tcx,
315- trait_ref,
316- item,
317- & mut cause,
318- obligation. predicate ,
316+ tcx, trait_ref, item, & mut cause, predicate,
319317 ) ;
320- traits:: Obligation :: with_depth ( cause, depth, param_env, obligation . predicate )
318+ traits:: Obligation :: with_depth ( cause, depth, param_env, predicate)
321319 } ;
322320
323321 if let Elaborate :: All = elaborate {
@@ -339,17 +337,17 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
339337 } )
340338 . filter ( |( _, arg) | !arg. has_escaping_bound_vars ( ) )
341339 . map ( |( i, arg) | {
342- let mut new_cause = cause . clone ( ) ;
340+ let mut cause = traits :: ObligationCause :: misc ( self . span , self . body_id ) ;
343341 // The first subst is the self ty - use the correct span for it.
344342 if i == 0 {
345343 if let Some ( hir:: ItemKind :: Impl ( hir:: Impl { self_ty, .. } ) ) =
346344 item. map ( |i| & i. kind )
347345 {
348- new_cause . span = self_ty. span ;
346+ cause . span = self_ty. span ;
349347 }
350348 }
351349 traits:: Obligation :: with_depth (
352- new_cause ,
350+ cause ,
353351 depth,
354352 param_env,
355353 ty:: Binder :: dummy ( ty:: PredicateKind :: WellFormed ( arg) ) . to_predicate ( tcx) ,
0 commit comments