@@ -50,6 +50,8 @@ use std::iter;
5050use std:: rc:: Rc ;
5151use crate :: util:: nodemap:: { FxHashMap , FxHashSet } ;
5252
53+ use syntax:: symbol:: sym;
54+
5355pub struct SelectionContext < ' cx , ' tcx > {
5456 infcx : & ' cx InferCtxt < ' cx , ' tcx > ,
5557
@@ -1326,8 +1328,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13261328 ( result, dep_node)
13271329 }
13281330
1329- // Treat negative impls as unimplemented
1330- fn filter_negative_impls (
1331+ // Treat negative impls as unimplemented, and reservation impls as Ok(None)
1332+ fn filter_negative_and_reservation_impls (
13311333 & self ,
13321334 candidate : SelectionCandidate < ' tcx > ,
13331335 ) -> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
@@ -1337,6 +1339,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13371339 {
13381340 return Err ( Unimplemented ) ;
13391341 }
1342+
1343+ if self . tcx ( ) . has_attr ( def_id, sym:: rustc_reservation_impl) {
1344+ return Ok ( None ) ;
1345+ }
13401346 }
13411347 Ok ( Some ( candidate) )
13421348 }
@@ -1453,7 +1459,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14531459 // Instead, we select the right impl now but report `Bar does
14541460 // not implement Clone`.
14551461 if candidates. len ( ) == 1 {
1456- return self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) ) ;
1462+ return self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) ) ;
14571463 }
14581464
14591465 // Winnow, but record the exact outcome of evaluation, which
@@ -1528,7 +1534,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15281534 }
15291535
15301536 // Just one candidate left.
1531- self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
1537+ self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
15321538 }
15331539
15341540 fn is_knowable < ' o > ( & mut self , stack : & TraitObligationStack < ' o , ' tcx > ) -> Option < Conflict > {
@@ -3728,6 +3734,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
37283734 return Err ( ( ) ) ;
37293735 }
37303736
3737+ if self . intercrate . is_none ( ) &&
3738+ self . tcx ( ) . has_attr ( impl_def_id, sym:: rustc_reservation_impl)
3739+ {
3740+ debug ! ( "match_impl: reservation impls only apply in intercrate mode" ) ;
3741+ return Err ( ( ) ) ;
3742+ }
3743+
37313744 debug ! ( "match_impl: success impl_substs={:?}" , impl_substs) ;
37323745 Ok ( Normalized {
37333746 value : impl_substs,
0 commit comments