@@ -165,12 +165,9 @@ impl<'tcx> ObligationCause<'tcx> {
165
165
166
166
pub fn map_code (
167
167
& mut self ,
168
- f : impl FnOnce ( Lrc < ObligationCauseCode < ' tcx > > ) -> Lrc < ObligationCauseCode < ' tcx > > ,
168
+ f : impl FnOnce ( InternedObligationCauseCode < ' tcx > ) -> Lrc < ObligationCauseCode < ' tcx > > ,
169
169
) {
170
- self . code = Some ( f ( match self . code . take ( ) {
171
- Some ( code) => code,
172
- None => Lrc :: new ( MISC_OBLIGATION_CAUSE_CODE ) ,
173
- } ) ) ;
170
+ self . code = Some ( f ( InternedObligationCauseCode { code : self . code . take ( ) } ) ) ;
174
171
}
175
172
176
173
pub fn derived_cause (
@@ -206,6 +203,19 @@ pub struct UnifyReceiverContext<'tcx> {
206
203
pub substs : SubstsRef < ' tcx > ,
207
204
}
208
205
206
+ #[ derive( Clone , Debug , PartialEq , Eq , Hash , Lift ) ]
207
+ pub struct InternedObligationCauseCode < ' tcx > {
208
+ code : Option < Lrc < ObligationCauseCode < ' tcx > > > ,
209
+ }
210
+
211
+ impl < ' tcx > std:: ops:: Deref for InternedObligationCauseCode < ' tcx > {
212
+ type Target = ObligationCauseCode < ' tcx > ;
213
+
214
+ fn deref ( & self ) -> & Self :: Target {
215
+ self . code . as_deref ( ) . unwrap_or ( & MISC_OBLIGATION_CAUSE_CODE )
216
+ }
217
+ }
218
+
209
219
#[ derive( Clone , Debug , PartialEq , Eq , Hash , Lift ) ]
210
220
pub enum ObligationCauseCode < ' tcx > {
211
221
/// Not well classified or should be obvious from the span.
@@ -293,7 +303,7 @@ pub enum ObligationCauseCode<'tcx> {
293
303
/// The node of the function call.
294
304
call_hir_id : hir:: HirId ,
295
305
/// The obligation introduced by this argument.
296
- parent_code : Lrc < ObligationCauseCode < ' tcx > > ,
306
+ parent_code : InternedObligationCauseCode < ' tcx > ,
297
307
} ,
298
308
299
309
/// Error derived when matching traits/impls; see ObligationCause for more details
0 commit comments