Move an extension trait method onto the type directly and reuse it
This commit is contained in:
parent
7e2e3d4ebe
commit
704bbe5210
5 changed files with 36 additions and 46 deletions
|
@ -17,7 +17,6 @@ use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
|
|||
use rustc_span::def_id::DefId;
|
||||
|
||||
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
|
||||
use crate::traits::select::TraitObligationExt;
|
||||
use crate::traits::util::{self, closure_trait_ref_and_return_type, predicate_for_trait_def};
|
||||
use crate::traits::{
|
||||
BuiltinDerivedObligation, DerivedObligationCause, ImplDerivedObligation,
|
||||
|
|
|
@ -2342,42 +2342,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
trait TraitObligationExt<'tcx> {
|
||||
fn derived_cause(
|
||||
&self,
|
||||
variant: fn(DerivedObligationCause<'tcx>) -> ObligationCauseCode<'tcx>,
|
||||
) -> ObligationCause<'tcx>;
|
||||
}
|
||||
|
||||
impl<'tcx> TraitObligationExt<'tcx> for TraitObligation<'tcx> {
|
||||
fn derived_cause(
|
||||
&self,
|
||||
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.
|
||||
*/
|
||||
|
||||
let obligation = self;
|
||||
|
||||
// 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.
|
||||
let derived_cause = DerivedObligationCause {
|
||||
parent_trait_pred: obligation.predicate,
|
||||
parent_code: obligation.cause.clone_code(),
|
||||
};
|
||||
let derived_code = variant(derived_cause);
|
||||
ObligationCause::new(obligation.cause.span, obligation.cause.body_id, derived_code)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
|
||||
fn list(&'o self) -> TraitObligationStackList<'o, 'tcx> {
|
||||
TraitObligationStackList::with(self)
|
||||
|
|
|
@ -301,14 +301,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
|
||||
let extend = |traits::PredicateObligation { predicate, mut cause, .. }| {
|
||||
if let Some(parent_trait_pred) = predicate.to_opt_poly_trait_pred() {
|
||||
cause.map_code(|parent_code| {
|
||||
{
|
||||
traits::ObligationCauseCode::DerivedObligation(
|
||||
traits::DerivedObligationCause { parent_trait_pred, parent_code },
|
||||
)
|
||||
}
|
||||
.into()
|
||||
});
|
||||
cause = cause.derived_cause(
|
||||
parent_trait_pred,
|
||||
traits::ObligationCauseCode::DerivedObligation,
|
||||
);
|
||||
}
|
||||
extend_cause_with_original_assoc_item_obligation(
|
||||
tcx, trait_ref, item, &mut cause, predicate,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue