@@ -750,6 +750,9 @@ pub struct ctxt<'tcx> {
750
750
/// Maps a trait onto a list of impls of that trait.
751
751
pub trait_impls : RefCell < DefIdMap < Rc < RefCell < Vec < ast:: DefId > > > > > ,
752
752
753
+ /// Maps a trait onto a list of negative impls of that trait.
754
+ pub trait_negative_impls : RefCell < DefIdMap < Rc < RefCell < Vec < ast:: DefId > > > > > ,
755
+
753
756
/// Maps a DefId of a type to a list of its inherent impls.
754
757
/// Contains implementations of methods that are inherent to a type.
755
758
/// Methods in these implementations don't need to be exported.
@@ -2412,6 +2415,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
2412
2415
destructor_for_type : RefCell :: new ( DefIdMap :: new ( ) ) ,
2413
2416
destructors : RefCell :: new ( DefIdSet :: new ( ) ) ,
2414
2417
trait_impls : RefCell :: new ( DefIdMap :: new ( ) ) ,
2418
+ trait_negative_impls : RefCell :: new ( DefIdMap :: new ( ) ) ,
2415
2419
inherent_impls : RefCell :: new ( DefIdMap :: new ( ) ) ,
2416
2420
impl_items : RefCell :: new ( DefIdMap :: new ( ) ) ,
2417
2421
used_unsafe : RefCell :: new ( NodeSet :: new ( ) ) ,
@@ -5025,6 +5029,23 @@ pub fn trait_items<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId)
5025
5029
}
5026
5030
}
5027
5031
5032
+ pub fn trait_impl_polarity < ' tcx > ( cx : & ctxt < ' tcx > , id : ast:: DefId )
5033
+ -> Option < ast:: ImplPolarity > {
5034
+ if id. krate == ast:: LOCAL_CRATE {
5035
+ match cx. map . find ( id. node ) {
5036
+ Some ( ast_map:: NodeItem ( item) ) => {
5037
+ match item. node {
5038
+ ast:: ItemImpl ( _, polarity, _, _, _, _) => Some ( polarity) ,
5039
+ _ => None
5040
+ }
5041
+ }
5042
+ _ => None
5043
+ }
5044
+ } else {
5045
+ csearch:: get_impl_polarity ( cx, id)
5046
+ }
5047
+ }
5048
+
5028
5049
pub fn impl_or_trait_item < ' tcx > ( cx : & ctxt < ' tcx > , id : ast:: DefId )
5029
5050
-> ImplOrTraitItem < ' tcx > {
5030
5051
lookup_locally_or_in_crate_store ( "impl_or_trait_items" ,
@@ -5974,14 +5995,23 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
5974
5995
pub fn record_trait_implementation ( tcx : & ctxt ,
5975
5996
trait_def_id : DefId ,
5976
5997
impl_def_id : DefId ) {
5977
- match tcx. trait_impls . borrow ( ) . get ( & trait_def_id) {
5998
+
5999
+ let trait_impls = match trait_impl_polarity ( tcx, impl_def_id) {
6000
+ Some ( ast:: ImplPolarity :: Positive ) => & tcx. trait_impls ,
6001
+ Some ( ast:: ImplPolarity :: Negative ) => & tcx. trait_negative_impls ,
6002
+ _ => tcx. sess . bug ( & format ! ( "tried to record a non-impl item with id {:?}" ,
6003
+ impl_def_id) [ ] )
6004
+ } ;
6005
+
6006
+ match trait_impls. borrow ( ) . get ( & trait_def_id) {
5978
6007
Some ( impls_for_trait) => {
5979
6008
impls_for_trait. borrow_mut ( ) . push ( impl_def_id) ;
5980
6009
return ;
5981
6010
}
5982
6011
None => { }
5983
6012
}
5984
- tcx. trait_impls . borrow_mut ( ) . insert ( trait_def_id, Rc :: new ( RefCell :: new ( vec ! ( impl_def_id) ) ) ) ;
6013
+
6014
+ trait_impls. borrow_mut ( ) . insert ( trait_def_id, Rc :: new ( RefCell :: new ( vec ! ( impl_def_id) ) ) ) ;
5985
6015
}
5986
6016
5987
6017
/// Populates the type context with all the implementations for the given type
0 commit comments