@@ -126,6 +126,15 @@ impl<'tcx> ObligationCause<'tcx> {
126
126
self
127
127
}
128
128
129
+ pub fn derived_host_cause (
130
+ mut self ,
131
+ parent_host_pred : ty:: Binder < ' tcx , ty:: HostEffectPredicate < ' tcx > > ,
132
+ variant : impl FnOnce ( DerivedHostCause < ' tcx > ) -> ObligationCauseCode < ' tcx > ,
133
+ ) -> ObligationCause < ' tcx > {
134
+ self . code = variant ( DerivedHostCause { parent_host_pred, parent_code : self . code } ) . into ( ) ;
135
+ self
136
+ }
137
+
129
138
pub fn to_constraint_category ( & self ) -> ConstraintCategory < ' tcx > {
130
139
match self . code ( ) {
131
140
ObligationCauseCode :: MatchImpl ( cause, _) => cause. to_constraint_category ( ) ,
@@ -270,6 +279,14 @@ pub enum ObligationCauseCode<'tcx> {
270
279
/// Derived obligation for WF goals.
271
280
WellFormedDerived ( DerivedCause < ' tcx > ) ,
272
281
282
+ /// Derived obligation (i.e. `where` clause) on an user-provided impl
283
+ /// or a trait alias.
284
+ ImplDerivedHost ( Box < ImplDerivedHostCause < ' tcx > > ) ,
285
+
286
+ /// Derived obligation (i.e. `where` clause) on an user-provided impl
287
+ /// or a trait alias.
288
+ BuiltinDerivedHost ( DerivedHostCause < ' tcx > ) ,
289
+
273
290
/// Derived obligation refined to point at a specific argument in
274
291
/// a call or method expression.
275
292
FunctionArg {
@@ -429,20 +446,6 @@ pub enum WellFormedLoc {
429
446
} ,
430
447
}
431
448
432
- #[ derive( Clone , Debug , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
433
- #[ derive( TypeVisitable , TypeFoldable ) ]
434
- pub struct ImplDerivedCause < ' tcx > {
435
- pub derived : DerivedCause < ' tcx > ,
436
- /// The `DefId` of the `impl` that gave rise to the `derived` obligation.
437
- /// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
438
- /// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
439
- /// that exceptional case where appropriate.
440
- pub impl_or_alias_def_id : DefId ,
441
- /// The index of the derived predicate in the parent impl's predicates.
442
- pub impl_def_predicate_index : Option < usize > ,
443
- pub span : Span ,
444
- }
445
-
446
449
impl < ' tcx > ObligationCauseCode < ' tcx > {
447
450
/// Returns the base obligation, ignoring derived obligations.
448
451
pub fn peel_derives ( & self ) -> & Self {
@@ -546,6 +549,42 @@ pub struct DerivedCause<'tcx> {
546
549
pub parent_code : InternedObligationCauseCode < ' tcx > ,
547
550
}
548
551
552
+ #[ derive( Clone , Debug , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
553
+ #[ derive( TypeVisitable , TypeFoldable ) ]
554
+ pub struct ImplDerivedCause < ' tcx > {
555
+ pub derived : DerivedCause < ' tcx > ,
556
+ /// The `DefId` of the `impl` that gave rise to the `derived` obligation.
557
+ /// If the `derived` obligation arose from a trait alias, which conceptually has a synthetic impl,
558
+ /// then this will be the `DefId` of that trait alias. Care should therefore be taken to handle
559
+ /// that exceptional case where appropriate.
560
+ pub impl_or_alias_def_id : DefId ,
561
+ /// The index of the derived predicate in the parent impl's predicates.
562
+ pub impl_def_predicate_index : Option < usize > ,
563
+ pub span : Span ,
564
+ }
565
+
566
+ #[ derive( Clone , Debug , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
567
+ #[ derive( TypeVisitable , TypeFoldable ) ]
568
+ pub struct DerivedHostCause < ' tcx > {
569
+ /// The trait predicate of the parent obligation that led to the
570
+ /// current obligation. Note that only trait obligations lead to
571
+ /// derived obligations, so we just store the trait predicate here
572
+ /// directly.
573
+ pub parent_host_pred : ty:: Binder < ' tcx , ty:: HostEffectPredicate < ' tcx > > ,
574
+
575
+ /// The parent trait had this cause.
576
+ pub parent_code : InternedObligationCauseCode < ' tcx > ,
577
+ }
578
+
579
+ #[ derive( Clone , Debug , PartialEq , Eq , HashStable , TyEncodable , TyDecodable ) ]
580
+ #[ derive( TypeVisitable , TypeFoldable ) ]
581
+ pub struct ImplDerivedHostCause < ' tcx > {
582
+ pub derived : DerivedHostCause < ' tcx > ,
583
+ /// The `DefId` of the `impl` that gave rise to the `derived` obligation.
584
+ pub impl_def_id : DefId ,
585
+ pub span : Span ,
586
+ }
587
+
549
588
#[ derive( Clone , Debug , TypeVisitable ) ]
550
589
pub enum SelectionError < ' tcx > {
551
590
/// The trait is not implemented.
0 commit comments