Auto merge of #91030 - estebank:trait-bounds-are-tricky-2, r=oli-obk
Properly track `ImplObligations` Instead of probing for all possible `impl`s that could have caused an `ImplObligation`, keep track of its `DefId` and obligation spans for accurate error reporting. Follow to #89580. Addresses #89418.
This commit is contained in:
commit
d2df372bca
24 changed files with 426 additions and 218 deletions
|
@ -257,7 +257,7 @@ pub enum ObligationCauseCode<'tcx> {
|
|||
|
||||
BuiltinDerivedObligation(DerivedObligationCause<'tcx>),
|
||||
|
||||
ImplDerivedObligation(DerivedObligationCause<'tcx>),
|
||||
ImplDerivedObligation(Box<ImplDerivedObligationCause<'tcx>>),
|
||||
|
||||
DerivedObligation(DerivedObligationCause<'tcx>),
|
||||
|
||||
|
@ -396,16 +396,29 @@ pub enum WellFormedLoc {
|
|||
},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift)]
|
||||
pub struct ImplDerivedObligationCause<'tcx> {
|
||||
pub derived: DerivedObligationCause<'tcx>,
|
||||
pub impl_def_id: DefId,
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
impl ObligationCauseCode<'_> {
|
||||
// Return the base obligation, ignoring derived obligations.
|
||||
pub fn peel_derives(&self) -> &Self {
|
||||
let mut base_cause = self;
|
||||
while let BuiltinDerivedObligation(DerivedObligationCause { parent_code, .. })
|
||||
| ImplDerivedObligation(DerivedObligationCause { parent_code, .. })
|
||||
| DerivedObligation(DerivedObligationCause { parent_code, .. })
|
||||
| FunctionArgumentObligation { parent_code, .. } = base_cause
|
||||
{
|
||||
base_cause = &parent_code;
|
||||
loop {
|
||||
match base_cause {
|
||||
BuiltinDerivedObligation(DerivedObligationCause { parent_code, .. })
|
||||
| DerivedObligation(DerivedObligationCause { parent_code, .. })
|
||||
| FunctionArgumentObligation { parent_code, .. } => {
|
||||
base_cause = &parent_code;
|
||||
}
|
||||
ImplDerivedObligation(obligation_cause) => {
|
||||
base_cause = &*obligation_cause.derived.parent_code;
|
||||
}
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
base_cause
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue