@@ -191,9 +191,10 @@ impl<'tcx> ObligationCause<'tcx> {
191
191
// NOTE(flaper87): As of now, it keeps track of the whole error
192
192
// chain. Ideally, we should have a way to configure this either
193
193
// by using -Z verbose or just a CLI argument.
194
- self . map_code ( |parent_code| {
195
- variant ( DerivedObligationCause { parent_trait_pred, parent_code } ) . into ( )
196
- } ) ;
194
+ self . code = Some (
195
+ variant ( DerivedObligationCause { parent_trait_pred, parent_code : self . code . take ( ) } )
196
+ . into ( ) ,
197
+ ) ;
197
198
self
198
199
}
199
200
}
@@ -443,7 +444,7 @@ impl<'tcx> ObligationCauseCode<'tcx> {
443
444
BuiltinDerivedObligation ( derived)
444
445
| DerivedObligation ( derived)
445
446
| ImplDerivedObligation ( box ImplDerivedObligationCause { derived, .. } ) => {
446
- Some ( ( & derived. parent_code , Some ( derived. parent_trait_pred ) ) )
447
+ Some ( ( derived. parent_code ( ) , Some ( derived. parent_trait_pred ) ) )
447
448
}
448
449
_ => None ,
449
450
}
@@ -497,14 +498,14 @@ pub struct DerivedObligationCause<'tcx> {
497
498
pub parent_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
498
499
499
500
/// The parent trait had this cause.
500
- parent_code : Lrc < ObligationCauseCode < ' tcx > > ,
501
+ parent_code : Option < Lrc < ObligationCauseCode < ' tcx > > > ,
501
502
}
502
503
503
504
impl < ' tcx > DerivedObligationCause < ' tcx > {
504
505
/// Get a reference to the derived obligation cause's parent code.
505
506
#[ must_use]
506
507
pub fn parent_code ( & self ) -> & ObligationCauseCode < ' tcx > {
507
- self . parent_code . as_ref ( )
508
+ self . parent_code . as_deref ( ) . unwrap_or ( & MISC_OBLIGATION_CAUSE_CODE )
508
509
}
509
510
}
510
511
0 commit comments