@@ -19,14 +19,13 @@ use rustc_span::def_id::DefId;
19
19
use crate :: traits:: project:: { normalize_with_depth, normalize_with_depth_to} ;
20
20
use crate :: traits:: util:: { self , closure_trait_ref_and_return_type, predicate_for_trait_def} ;
21
21
use crate :: traits:: {
22
- BuiltinDerivedObligation , DerivedObligationCause , ImplDerivedObligation ,
23
- ImplDerivedObligationCause , ImplSource , ImplSourceAutoImplData , ImplSourceBuiltinData ,
24
- ImplSourceClosureData , ImplSourceConstDestructData , ImplSourceDiscriminantKindData ,
25
- ImplSourceFnPointerData , ImplSourceGeneratorData , ImplSourceObjectData , ImplSourcePointeeData ,
26
- ImplSourceTraitAliasData , ImplSourceTraitUpcastingData , ImplSourceUserDefinedData , Normalized ,
27
- ObjectCastObligation , Obligation , ObligationCause , OutputTypeParameterMismatch ,
28
- PredicateObligation , Selection , SelectionError , TraitNotObjectSafe , TraitObligation ,
29
- Unimplemented , VtblSegment ,
22
+ BuiltinDerivedObligation , ImplDerivedObligation , ImplDerivedObligationCause , ImplSource ,
23
+ ImplSourceAutoImplData , ImplSourceBuiltinData , ImplSourceClosureData ,
24
+ ImplSourceConstDestructData , ImplSourceDiscriminantKindData , ImplSourceFnPointerData ,
25
+ ImplSourceGeneratorData , ImplSourceObjectData , ImplSourcePointeeData , ImplSourceTraitAliasData ,
26
+ ImplSourceTraitUpcastingData , ImplSourceUserDefinedData , Normalized , ObjectCastObligation ,
27
+ Obligation , ObligationCause , OutputTypeParameterMismatch , PredicateObligation , Selection ,
28
+ SelectionError , TraitNotObjectSafe , TraitObligation , Unimplemented , VtblSegment ,
30
29
} ;
31
30
32
31
use super :: BuiltinImplConditions ;
@@ -1125,21 +1124,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1125
1124
let substs = self . rematch_impl ( impl_def_id, & new_obligation) ;
1126
1125
debug ! ( ?substs, "impl substs" ) ;
1127
1126
1128
- let derived = DerivedObligationCause {
1129
- parent_trait_pred : obligation. predicate ,
1130
- parent_code : obligation. cause . clone_code ( ) ,
1131
- } ;
1132
- let derived_code = ImplDerivedObligation ( Box :: new ( ImplDerivedObligationCause {
1133
- derived,
1134
- impl_def_id,
1135
- span : obligation. cause . span ,
1136
- } ) ) ;
1137
-
1138
- let cause = ObligationCause :: new (
1139
- obligation. cause . span ,
1140
- obligation. cause . body_id ,
1141
- derived_code,
1142
- ) ;
1127
+ let cause = obligation. derived_cause ( |derived| {
1128
+ ImplDerivedObligation ( Box :: new ( ImplDerivedObligationCause {
1129
+ derived,
1130
+ impl_def_id,
1131
+ span : obligation. cause . span ,
1132
+ } ) )
1133
+ } ) ;
1143
1134
ensure_sufficient_stack ( || {
1144
1135
self . vtable_impl (
1145
1136
impl_def_id,
0 commit comments