@@ -50,6 +50,8 @@ use std::iter;
50
50
use std:: rc:: Rc ;
51
51
use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
52
52
53
+ use syntax:: symbol:: sym;
54
+
53
55
pub struct SelectionContext < ' cx , ' tcx > {
54
56
infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
55
57
@@ -1325,8 +1327,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1325
1327
( result, dep_node)
1326
1328
}
1327
1329
1328
- // Treat negative impls as unimplemented
1329
- fn filter_negative_impls (
1330
+ // Treat negative impls as unimplemented, and reservation impls as Ok(None)
1331
+ fn filter_negative_and_reservation_impls (
1330
1332
& self ,
1331
1333
candidate : SelectionCandidate < ' tcx > ,
1332
1334
) -> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
@@ -1336,6 +1338,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1336
1338
{
1337
1339
return Err ( Unimplemented ) ;
1338
1340
}
1341
+
1342
+ if self . tcx ( ) . has_attr ( def_id, sym:: rustc_reservation_impl) {
1343
+ return Ok ( None ) ;
1344
+ }
1339
1345
}
1340
1346
Ok ( Some ( candidate) )
1341
1347
}
@@ -1452,7 +1458,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1452
1458
// Instead, we select the right impl now but report `Bar does
1453
1459
// not implement Clone`.
1454
1460
if candidates. len ( ) == 1 {
1455
- return self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) ) ;
1461
+ return self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) ) ;
1456
1462
}
1457
1463
1458
1464
// Winnow, but record the exact outcome of evaluation, which
@@ -1527,7 +1533,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1527
1533
}
1528
1534
1529
1535
// Just one candidate left.
1530
- self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
1536
+ self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
1531
1537
}
1532
1538
1533
1539
fn is_knowable < ' o > ( & mut self , stack : & TraitObligationStack < ' o , ' tcx > ) -> Option < Conflict > {
@@ -3727,6 +3733,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
3727
3733
return Err ( ( ) ) ;
3728
3734
}
3729
3735
3736
+ if self . intercrate . is_none ( ) &&
3737
+ self . tcx ( ) . has_attr ( impl_def_id, sym:: rustc_reservation_impl)
3738
+ {
3739
+ debug ! ( "match_impl: reservation impls only apply in intercrate mode" ) ;
3740
+ return Err ( ( ) ) ;
3741
+ }
3742
+
3730
3743
debug ! ( "match_impl: success impl_substs={:?}" , impl_substs) ;
3731
3744
Ok ( Normalized {
3732
3745
value : impl_substs,
0 commit comments