@@ -66,7 +66,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
66
66
debug ! ( "add_deref_target: type {:?}, target {:?}" , type_did, target) ;
67
67
if let Some ( target_prim) = target. primitive_type ( ) {
68
68
cleaner. prims . insert ( target_prim) ;
69
- } else if let Some ( target_did) = target. def_id ( ) {
69
+ } else if let Some ( target_did) = target. def_id_no_primitives ( ) {
70
70
// `impl Deref<Target = S> for S`
71
71
if target_did == type_did {
72
72
// Avoid infinite cycles
@@ -82,7 +82,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
82
82
for it in & new_items {
83
83
if let ImplItem ( Impl { ref for_, ref trait_, ref items, .. } ) = * it. kind {
84
84
if trait_. as_ref ( ) . map ( |t| t. def_id ( ) ) == cx. tcx . lang_items ( ) . deref_trait ( )
85
- && cleaner. keep_impl ( for_)
85
+ && cleaner. keep_impl ( for_, true )
86
86
{
87
87
let target = items
88
88
. iter ( )
@@ -97,7 +97,7 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
97
97
} else if let Some ( did) = target. def_id ( & cx. cache ) {
98
98
cleaner. items . insert ( did. into ( ) ) ;
99
99
}
100
- if let Some ( for_did) = for_. def_id ( ) {
100
+ if let Some ( for_did) = for_. def_id_no_primitives ( ) {
101
101
if type_did_to_deref_target. insert ( for_did, target) . is_none ( ) {
102
102
// Since only the `DefId` portion of the `Type` instances is known to be same for both the
103
103
// `Deref` target type and the impl for type positions, this map of types is keyed by
@@ -113,10 +113,10 @@ crate fn collect_trait_impls(krate: Crate, cx: &mut DocContext<'_>) -> Crate {
113
113
114
114
new_items. retain ( |it| {
115
115
if let ImplItem ( Impl { ref for_, ref trait_, ref blanket_impl, .. } ) = * it. kind {
116
- cleaner. keep_impl ( for_ )
117
- || trait_
118
- . as_ref ( )
119
- . map_or ( false , |t| cleaner. keep_impl_with_def_id ( t. def_id ( ) . into ( ) ) )
116
+ cleaner. keep_impl (
117
+ for_ ,
118
+ trait_ . as_ref ( ) . map ( |t| t . def_id ( ) ) == cx . tcx . lang_items ( ) . deref_trait ( ) ,
119
+ ) || trait_ . as_ref ( ) . map_or ( false , |t| cleaner. keep_impl_with_def_id ( t. def_id ( ) . into ( ) ) )
120
120
|| blanket_impl. is_some ( )
121
121
} else {
122
122
true
@@ -215,17 +215,14 @@ struct BadImplStripper {
215
215
}
216
216
217
217
impl BadImplStripper {
218
- fn keep_impl ( & self , ty : & Type ) -> bool {
218
+ fn keep_impl ( & self , ty : & Type , is_deref : bool ) -> bool {
219
219
if let Generic ( _) = ty {
220
220
// keep impls made on generics
221
221
true
222
222
} else if let Some ( prim) = ty. primitive_type ( ) {
223
223
self . prims . contains ( & prim)
224
- } else if ty. def_id_no_primitives ( ) . is_some ( ) {
225
- // We want to keep *ALL* deref implementations in case some of them are used in
226
- // the current crate.
227
- // FIXME: Try to filter the one actually used...
228
- true
224
+ } else if let Some ( did) = ty. def_id_no_primitives ( ) {
225
+ is_deref || self . keep_impl_with_def_id ( did. into ( ) )
229
226
} else {
230
227
false
231
228
}
0 commit comments