1
Fork 0

Move an extension trait method onto the type directly and reuse it

This commit is contained in:
Oli Scherer 2022-05-10 09:26:09 +00:00
parent 7e2e3d4ebe
commit 704bbe5210
5 changed files with 36 additions and 46 deletions

View file

@ -69,7 +69,7 @@ impl<'tcx> PredicateObligation<'tcx> {
}
}
impl TraitObligation<'_> {
impl<'tcx> TraitObligation<'tcx> {
/// Returns `true` if the trait predicate is considered `const` in its ParamEnv.
pub fn is_const(&self) -> bool {
match (self.predicate.skip_binder().constness, self.param_env.constness()) {
@ -77,6 +77,13 @@ impl TraitObligation<'_> {
_ => false,
}
}
pub fn derived_cause(
&self,
variant: fn(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
) -> ObligationCause<'tcx> {
self.cause.clone().derived_cause(self.predicate, variant)
}
}
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.