Move an extension trait method onto the type directly and reuse it
This commit is contained in:
@@ -179,6 +179,30 @@ impl<'tcx> ObligationCause<'tcx> {
|
||||
None => Lrc::new(MISC_OBLIGATION_CAUSE_CODE),
|
||||
}));
|
||||
}
|
||||
|
||||
pub fn derived_cause(
|
||||
mut self,
|
||||
parent_trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
variant: fn(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||
) -> ObligationCause<'tcx> {
|
||||
/*!
|
||||
* Creates a cause for obligations that are derived from
|
||||
* `obligation` by a recursive search (e.g., for a builtin
|
||||
* bound, or eventually a `auto trait Foo`). If `obligation`
|
||||
* is itself a derived obligation, this is just a clone, but
|
||||
* otherwise we create a "derived obligation" cause so as to
|
||||
* keep track of the original root obligation for error
|
||||
* reporting.
|
||||
*/
|
||||
|
||||
// NOTE(flaper87): As of now, it keeps track of the whole error
|
||||
// chain. Ideally, we should have a way to configure this either
|
||||
// by using -Z verbose or just a CLI argument.
|
||||
self.map_code(|parent_code| {
|
||||
variant(DerivedObligationCause { parent_trait_pred, parent_code }).into()
|
||||
});
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
||||
|
||||
Reference in New Issue
Block a user