@@ -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
@@ -1325,8 +1327,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13251327 ( result, dep_node)
13261328 }
13271329
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 (
13301332 & self ,
13311333 candidate : SelectionCandidate < ' tcx > ,
13321334 ) -> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
@@ -1336,6 +1338,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13361338 {
13371339 return Err ( Unimplemented ) ;
13381340 }
1341+
1342+ if self . tcx ( ) . has_attr ( def_id, sym:: rustc_reservation_impl) {
1343+ return Ok ( None ) ;
1344+ }
13391345 }
13401346 Ok ( Some ( candidate) )
13411347 }
@@ -1452,7 +1458,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
14521458 // Instead, we select the right impl now but report `Bar does
14531459 // not implement Clone`.
14541460 if candidates. len ( ) == 1 {
1455- return self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) ) ;
1461+ return self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) ) ;
14561462 }
14571463
14581464 // Winnow, but record the exact outcome of evaluation, which
@@ -1527,7 +1533,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15271533 }
15281534
15291535 // Just one candidate left.
1530- self . filter_negative_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
1536+ self . filter_negative_and_reservation_impls ( candidates. pop ( ) . unwrap ( ) . candidate )
15311537 }
15321538
15331539 fn is_knowable < ' o > ( & mut self , stack : & TraitObligationStack < ' o , ' tcx > ) -> Option < Conflict > {
@@ -3727,6 +3733,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
37273733 return Err ( ( ) ) ;
37283734 }
37293735
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+
37303743 debug ! ( "match_impl: success impl_substs={:?}" , impl_substs) ;
37313744 Ok ( Normalized {
37323745 value : impl_substs,
0 commit comments