X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_middle%2Fsrc%2Ftraits%2Fmod.rs;h=3ed7836074b258b8d038d4f13c1d33b3266c84c2;hb=5fd37862d95a7fd898342e49ae5273edc8886b83;hp=45610fa77d35e0b368a9a5d6bc54172b7c1cc892;hpb=463e516b0c53683fc8f5c3d2b4d1341b2b69e0fe;p=rust.git diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 45610fa77d3..3ed7836074b 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -257,7 +257,7 @@ pub enum ObligationCauseCode<'tcx> { BuiltinDerivedObligation(DerivedObligationCause<'tcx>), - ImplDerivedObligation(DerivedObligationCause<'tcx>), + ImplDerivedObligation(Box>), 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 } @@ -577,7 +590,7 @@ pub enum ImplSource<'tcx, N> { TraitAlias(ImplSourceTraitAliasData<'tcx, N>), /// ImplSource for a `const Drop` implementation. - ConstDrop(ImplSourceConstDropData), + ConstDestruct(ImplSourceConstDestructData), } impl<'tcx, N> ImplSource<'tcx, N> { @@ -595,7 +608,7 @@ pub fn nested_obligations(self) -> Vec { | ImplSource::Pointee(ImplSourcePointeeData) => Vec::new(), ImplSource::TraitAlias(d) => d.nested, ImplSource::TraitUpcasting(d) => d.nested, - ImplSource::ConstDrop(i) => i.nested, + ImplSource::ConstDestruct(i) => i.nested, } } @@ -613,7 +626,7 @@ pub fn borrow_nested_obligations(&self) -> &[N] { | ImplSource::Pointee(ImplSourcePointeeData) => &[], ImplSource::TraitAlias(d) => &d.nested, ImplSource::TraitUpcasting(d) => &d.nested, - ImplSource::ConstDrop(i) => &i.nested, + ImplSource::ConstDestruct(i) => &i.nested, } } @@ -672,9 +685,11 @@ pub fn map(self, f: F) -> ImplSource<'tcx, M> nested: d.nested.into_iter().map(f).collect(), }) } - ImplSource::ConstDrop(i) => ImplSource::ConstDrop(ImplSourceConstDropData { - nested: i.nested.into_iter().map(f).collect(), - }), + ImplSource::ConstDestruct(i) => { + ImplSource::ConstDestruct(ImplSourceConstDestructData { + nested: i.nested.into_iter().map(f).collect(), + }) + } } } } @@ -767,7 +782,7 @@ pub struct ImplSourceFnPointerData<'tcx, N> { pub struct ImplSourcePointeeData; #[derive(Clone, PartialEq, Eq, TyEncodable, TyDecodable, HashStable, TypeFoldable, Lift)] -pub struct ImplSourceConstDropData { +pub struct ImplSourceConstDestructData { pub nested: Vec, }