@@ -93,6 +93,11 @@ pub struct SelectionContext<'cx, 'gcx: 'cx+'tcx, 'tcx: 'cx> {
93
93
inferred_obligations : SnapshotVec < InferredObligationsSnapshotVecDelegate < ' tcx > > ,
94
94
95
95
intercrate_ambiguity_causes : Option < Vec < IntercrateAmbiguityCause > > ,
96
+
97
+ /// Controls whether or not to filter out negative impls when selecting.
98
+ /// This is used in librustdoc to distinguish between the lack of an impl
99
+ /// and a negative impl
100
+ allow_negative_impls : bool
96
101
}
97
102
98
103
#[ derive( Clone , Debug ) ]
@@ -424,6 +429,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
424
429
intercrate : None ,
425
430
inferred_obligations : SnapshotVec :: new ( ) ,
426
431
intercrate_ambiguity_causes : None ,
432
+ allow_negative_impls : false ,
427
433
}
428
434
}
429
435
@@ -436,6 +442,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
436
442
intercrate : Some ( mode) ,
437
443
inferred_obligations : SnapshotVec :: new ( ) ,
438
444
intercrate_ambiguity_causes : None ,
445
+ allow_negative_impls : false ,
446
+ }
447
+ }
448
+
449
+ pub fn with_negative ( infcx : & ' cx InferCtxt < ' cx , ' gcx , ' tcx > ,
450
+ allow_negative_impls : bool ) -> SelectionContext < ' cx , ' gcx , ' tcx > {
451
+ debug ! ( "with_negative({:?})" , allow_negative_impls) ;
452
+ SelectionContext {
453
+ infcx,
454
+ freshener : infcx. freshener ( ) ,
455
+ intercrate : None ,
456
+ inferred_obligations : SnapshotVec :: new ( ) ,
457
+ intercrate_ambiguity_causes : None ,
458
+ allow_negative_impls,
439
459
}
440
460
}
441
461
@@ -1086,7 +1106,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1086
1106
fn filter_negative_impls ( & self , candidate : SelectionCandidate < ' tcx > )
1087
1107
-> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
1088
1108
if let ImplCandidate ( def_id) = candidate {
1089
- if self . tcx ( ) . impl_polarity ( def_id) == hir:: ImplPolarity :: Negative {
1109
+ if !self . allow_negative_impls &&
1110
+ self . tcx ( ) . impl_polarity ( def_id) == hir:: ImplPolarity :: Negative {
1090
1111
return Err ( Unimplemented )
1091
1112
}
1092
1113
}
@@ -3337,6 +3358,10 @@ impl<'tcx> SelectionCache<'tcx> {
3337
3358
hashmap : RefCell :: new ( FxHashMap ( ) )
3338
3359
}
3339
3360
}
3361
+
3362
+ pub fn clear ( & self ) {
3363
+ * self . hashmap . borrow_mut ( ) = FxHashMap ( )
3364
+ }
3340
3365
}
3341
3366
3342
3367
impl < ' tcx > EvaluationCache < ' tcx > {
@@ -3345,6 +3370,10 @@ impl<'tcx> EvaluationCache<'tcx> {
3345
3370
hashmap : RefCell :: new ( FxHashMap ( ) )
3346
3371
}
3347
3372
}
3373
+
3374
+ pub fn clear ( & self ) {
3375
+ * self . hashmap . borrow_mut ( ) = FxHashMap ( )
3376
+ }
3348
3377
}
3349
3378
3350
3379
impl < ' o , ' tcx > TraitObligationStack < ' o , ' tcx > {
0 commit comments