@@ -757,8 +757,8 @@ pub struct ctxt<'tcx> {
757
757
/// Maps a trait onto a list of impls of that trait.
758
758
pub trait_impls : RefCell < DefIdMap < Rc < RefCell < Vec < ast:: DefId > > > > > ,
759
759
760
- /// Maps a trait onto a list of * default* trait implementations
761
- default_trait_impls : RefCell < DefIdMap < ast :: DefId > > ,
760
+ /// A set of traits that have a default impl
761
+ traits_with_default_impls : RefCell < DefIdMap < ( ) > > ,
762
762
763
763
/// Maps a DefId of a type to a list of its inherent impls.
764
764
/// Contains implementations of methods that are inherent to a type.
@@ -2591,7 +2591,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
2591
2591
destructor_for_type : RefCell :: new ( DefIdMap ( ) ) ,
2592
2592
destructors : RefCell :: new ( DefIdSet ( ) ) ,
2593
2593
trait_impls : RefCell :: new ( DefIdMap ( ) ) ,
2594
- default_trait_impls : RefCell :: new ( DefIdMap ( ) ) ,
2594
+ traits_with_default_impls : RefCell :: new ( DefIdMap ( ) ) ,
2595
2595
inherent_impls : RefCell :: new ( DefIdMap ( ) ) ,
2596
2596
impl_items : RefCell :: new ( DefIdMap ( ) ) ,
2597
2597
used_unsafe : RefCell :: new ( NodeSet ( ) ) ,
@@ -5975,32 +5975,22 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
5975
5975
|| Rc :: new ( csearch:: get_item_variances ( & tcx. sess . cstore , item_id) ) )
5976
5976
}
5977
5977
5978
- pub fn trait_default_impl ( tcx : & ctxt , trait_def_id : DefId ) -> Option < ast:: DefId > {
5979
- match tcx. default_trait_impls . borrow ( ) . get ( & trait_def_id) {
5980
- Some ( id) => Some ( * id) ,
5981
- None => None
5982
- }
5983
- }
5984
-
5985
5978
pub fn trait_has_default_impl ( tcx : & ctxt , trait_def_id : DefId ) -> bool {
5979
+ populate_implementations_for_trait_if_necessary ( tcx, trait_def_id) ;
5986
5980
match tcx. lang_items . to_builtin_kind ( trait_def_id) {
5987
5981
Some ( BoundSend ) | Some ( BoundSync ) => true ,
5988
- _ => tcx. default_trait_impls . borrow ( ) . contains_key ( & trait_def_id)
5982
+ _ => tcx. traits_with_default_impls . borrow ( ) . contains_key ( & trait_def_id) ,
5989
5983
}
5990
5984
}
5991
5985
5992
5986
/// Records a trait-to-implementation mapping.
5993
- pub fn record_default_trait_implementation ( tcx : & ctxt ,
5994
- trait_def_id : DefId ,
5995
- impl_def_id : DefId ) {
5996
-
5987
+ pub fn record_trait_has_default_impl ( tcx : & ctxt , trait_def_id : DefId ) {
5997
5988
// We're using the latest implementation found as the reference one.
5998
5989
// Duplicated implementations are caught and reported in the coherence
5999
5990
// step.
6000
- tcx. default_trait_impls . borrow_mut ( ) . insert ( trait_def_id, impl_def_id ) ;
5991
+ tcx. traits_with_default_impls . borrow_mut ( ) . insert ( trait_def_id, ( ) ) ;
6001
5992
}
6002
5993
6003
-
6004
5994
/// Records a trait-to-implementation mapping.
6005
5995
pub fn record_trait_implementation ( tcx : & ctxt ,
6006
5996
trait_def_id : DefId ,
@@ -6031,8 +6021,7 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
6031
6021
debug ! ( "populate_implementations_for_type_if_necessary: searching for {:?}" , type_id) ;
6032
6022
6033
6023
let mut inherent_impls = Vec :: new ( ) ;
6034
- csearch:: each_implementation_for_type ( & tcx. sess . cstore , type_id,
6035
- |impl_def_id| {
6024
+ csearch:: each_implementation_for_type ( & tcx. sess . cstore , type_id, |impl_def_id| {
6036
6025
let impl_items = csearch:: get_impl_items ( & tcx. sess . cstore , impl_def_id) ;
6037
6026
6038
6027
// Record the trait->implementation mappings, if applicable.
@@ -6078,27 +6067,20 @@ pub fn populate_implementations_for_trait_if_necessary(
6078
6067
if trait_id. krate == LOCAL_CRATE {
6079
6068
return
6080
6069
}
6070
+
6081
6071
if tcx. populated_external_traits . borrow ( ) . contains ( & trait_id) {
6082
6072
return
6083
6073
}
6084
6074
6085
- csearch:: each_implementation_for_trait ( & tcx. sess . cstore , trait_id,
6086
- |implementation_def_id| {
6087
- let impl_items = csearch :: get_impl_items ( & tcx . sess . cstore , implementation_def_id ) ;
6075
+ if csearch:: is_defaulted_trait ( & tcx. sess . cstore , trait_id) {
6076
+ record_trait_has_default_impl ( tcx , trait_id ) ;
6077
+ }
6088
6078
6089
- if csearch:: is_default_trait ( & tcx. sess . cstore , implementation_def_id) {
6090
- record_default_trait_implementation ( tcx, trait_id,
6091
- implementation_def_id) ;
6092
- tcx. populated_external_traits . borrow_mut ( ) . insert ( trait_id) ;
6079
+ csearch:: each_implementation_for_trait ( & tcx. sess . cstore , trait_id, |implementation_def_id| {
6080
+ let impl_items = csearch:: get_impl_items ( & tcx. sess . cstore , implementation_def_id) ;
6093
6081
6094
- // Nothing else to do for default trait implementations since
6095
- // they are not allowed to have type parameters, methods, or any
6096
- // other item that could be associated to a trait implementation.
6097
- return ;
6098
- } else {
6099
- // Record the trait->implementation mapping.
6100
- record_trait_implementation ( tcx, trait_id, implementation_def_id) ;
6101
- }
6082
+ // Record the trait->implementation mapping.
6083
+ record_trait_implementation ( tcx, trait_id, implementation_def_id) ;
6102
6084
6103
6085
// For any methods that use a default implementation, add them to
6104
6086
// the map. This is a bit unfortunate.
@@ -6108,8 +6090,8 @@ pub fn populate_implementations_for_trait_if_necessary(
6108
6090
MethodTraitItem ( method) => {
6109
6091
if let Some ( source) = method. provided_source {
6110
6092
tcx. provided_method_sources
6111
- . borrow_mut ( )
6112
- . insert ( method_def_id, source) ;
6093
+ . borrow_mut ( )
6094
+ . insert ( method_def_id, source) ;
6113
6095
}
6114
6096
}
6115
6097
TypeTraitItem ( _) => { }
0 commit comments