Add a helper function for a common piece of code
This commit is contained in:
parent
05a62c5527
commit
5b5b549580
3 changed files with 32 additions and 68 deletions
|
@ -2,11 +2,10 @@ pub mod on_unimplemented;
|
|||
pub mod suggestions;
|
||||
|
||||
use super::{
|
||||
DerivedObligationCause, EvaluationResult, FulfillmentContext, FulfillmentError,
|
||||
FulfillmentErrorCode, ImplDerivedObligationCause, MismatchedProjectionTypes, Obligation,
|
||||
ObligationCause, ObligationCauseCode, OnUnimplementedDirective, OnUnimplementedNote,
|
||||
OutputTypeParameterMismatch, Overflow, PredicateObligation, SelectionContext, SelectionError,
|
||||
TraitNotObjectSafe,
|
||||
EvaluationResult, FulfillmentContext, FulfillmentError, FulfillmentErrorCode,
|
||||
MismatchedProjectionTypes, Obligation, ObligationCause, ObligationCauseCode,
|
||||
OnUnimplementedDirective, OnUnimplementedNote, OutputTypeParameterMismatch, Overflow,
|
||||
PredicateObligation, SelectionContext, SelectionError, TraitNotObjectSafe,
|
||||
};
|
||||
|
||||
use crate::infer::error_reporting::{TyCategory, TypeAnnotationNeeded as ErrorCode};
|
||||
|
@ -684,32 +683,12 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
let mut code = obligation.cause.code();
|
||||
let mut trait_pred = trait_predicate;
|
||||
let mut peeled = false;
|
||||
loop {
|
||||
match &*code {
|
||||
ObligationCauseCode::FunctionArgumentObligation {
|
||||
parent_code,
|
||||
..
|
||||
} => {
|
||||
code = &parent_code;
|
||||
}
|
||||
ObligationCauseCode::ImplDerivedObligation(
|
||||
box ImplDerivedObligationCause {
|
||||
derived,
|
||||
..
|
||||
},
|
||||
)
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(
|
||||
derived,
|
||||
)
|
||||
| ObligationCauseCode::DerivedObligation(
|
||||
derived,
|
||||
) => {
|
||||
peeled = true;
|
||||
code = &derived.parent_code;
|
||||
trait_pred = derived.parent_trait_pred;
|
||||
}
|
||||
_ => break,
|
||||
};
|
||||
while let Some((parent_code, parent_trait_pred)) = code.parent() {
|
||||
code = parent_code;
|
||||
if let Some(parent_trait_pred) = parent_trait_pred {
|
||||
trait_pred = parent_trait_pred;
|
||||
peeled = true;
|
||||
}
|
||||
}
|
||||
let def_id = trait_pred.def_id();
|
||||
// Mention *all* the `impl`s for the *top most* obligation, the
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::{
|
||||
DerivedObligationCause, EvaluationResult, ImplDerivedObligationCause, Obligation,
|
||||
ObligationCause, ObligationCauseCode, PredicateObligation, SelectionContext,
|
||||
EvaluationResult, Obligation, ObligationCause, ObligationCauseCode, PredicateObligation,
|
||||
SelectionContext,
|
||||
};
|
||||
|
||||
use crate::autoderef::Autoderef;
|
||||
|
@ -623,28 +623,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
|||
let span = obligation.cause.span;
|
||||
let mut real_trait_pred = trait_pred;
|
||||
let mut code = obligation.cause.code();
|
||||
loop {
|
||||
match &code {
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
code = &parent_code;
|
||||
}
|
||||
ObligationCauseCode::ImplDerivedObligation(box ImplDerivedObligationCause {
|
||||
derived: DerivedObligationCause { parent_code, parent_trait_pred },
|
||||
..
|
||||
})
|
||||
| ObligationCauseCode::BuiltinDerivedObligation(DerivedObligationCause {
|
||||
parent_code,
|
||||
parent_trait_pred,
|
||||
})
|
||||
| ObligationCauseCode::DerivedObligation(DerivedObligationCause {
|
||||
parent_code,
|
||||
parent_trait_pred,
|
||||
}) => {
|
||||
code = &parent_code;
|
||||
real_trait_pred = *parent_trait_pred;
|
||||
}
|
||||
_ => break,
|
||||
};
|
||||
while let Some((parent_code, parent_trait_pred)) = code.parent() {
|
||||
code = parent_code;
|
||||
if let Some(parent_trait_pred) = parent_trait_pred {
|
||||
real_trait_pred = parent_trait_pred;
|
||||
}
|
||||
let Some(real_ty) = real_trait_pred.self_ty().no_bound_vars() else {
|
||||
continue;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue