@@ -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 ( ) ) ,
@@ -5035,6 +5039,23 @@ pub fn trait_items<'tcx>(cx: &ctxt<'tcx>, trait_did: ast::DefId)
5035
5039
}
5036
5040
}
5037
5041
5042
+ pub fn trait_impl_polarity < ' tcx > ( cx : & ctxt < ' tcx > , id : ast:: DefId )
5043
+ -> Option < ast:: ImplPolarity > {
5044
+ if id. krate == ast:: LOCAL_CRATE {
5045
+ match cx. map . find ( id. node ) {
5046
+ Some ( ast_map:: NodeItem ( item) ) => {
5047
+ match item. node {
5048
+ ast:: ItemImpl ( _, polarity, _, _, _, _) => Some ( polarity) ,
5049
+ _ => None
5050
+ }
5051
+ }
5052
+ _ => None
5053
+ }
5054
+ } else {
5055
+ csearch:: get_impl_polarity ( cx, id)
5056
+ }
5057
+ }
5058
+
5038
5059
pub fn impl_or_trait_item < ' tcx > ( cx : & ctxt < ' tcx > , id : ast:: DefId )
5039
5060
-> ImplOrTraitItem < ' tcx > {
5040
5061
lookup_locally_or_in_crate_store ( "impl_or_trait_items" ,
@@ -5984,14 +6005,23 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
5984
6005
pub fn record_trait_implementation ( tcx : & ctxt ,
5985
6006
trait_def_id : DefId ,
5986
6007
impl_def_id : DefId ) {
5987
- match tcx. trait_impls . borrow ( ) . get ( & trait_def_id) {
6008
+
6009
+ let trait_impls = match trait_impl_polarity ( tcx, impl_def_id) {
6010
+ Some ( ast:: ImplPolarity :: Positive ) => & tcx. trait_impls ,
6011
+ Some ( ast:: ImplPolarity :: Negative ) => & tcx. trait_negative_impls ,
6012
+ _ => tcx. sess . bug ( & format ! ( "tried to record a non-impl item with id {:?}" ,
6013
+ impl_def_id) [ ] )
6014
+ } ;
6015
+
6016
+ match trait_impls. borrow ( ) . get ( & trait_def_id) {
5988
6017
Some ( impls_for_trait) => {
5989
6018
impls_for_trait. borrow_mut ( ) . push ( impl_def_id) ;
5990
6019
return ;
5991
6020
}
5992
6021
None => { }
5993
6022
}
5994
- tcx. trait_impls . borrow_mut ( ) . insert ( trait_def_id, Rc :: new ( RefCell :: new ( vec ! ( impl_def_id) ) ) ) ;
6023
+
6024
+ trait_impls. borrow_mut ( ) . insert ( trait_def_id, Rc :: new ( RefCell :: new ( vec ! ( impl_def_id) ) ) ) ;
5995
6025
}
5996
6026
5997
6027
/// Populates the type context with all the implementations for the given type
0 commit comments