@@ -16,6 +16,8 @@ use rustc::infer::InferOk;
16
16
use std:: fmt:: Debug ;
17
17
use syntax_pos:: DUMMY_SP ;
18
18
19
+ use core:: DocAccessLevels ;
20
+
19
21
use super :: * ;
20
22
21
23
pub struct AutoTraitFinder < ' a , ' tcx : ' a , ' rcx : ' a > {
@@ -115,13 +117,38 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
115
117
_ => false,
116
118
};*/
117
119
for & trait_def_id in self . cx . all_traits . iter ( ) {
118
- if traits. get ( & trait_def_id) . is_some ( ) {
120
+ if traits. get ( & trait_def_id) . is_some ( ) ||
121
+ !self . cx . access_levels . borrow ( ) . is_doc_reachable ( trait_def_id) {
119
122
continue
120
123
}
121
124
let t_name = self . cx . tcx . item_name ( trait_def_id) . to_string ( ) ;
122
125
self . cx . tcx . for_each_relevant_impl ( trait_def_id, ty, |impl_def_id| {
123
126
self . cx . tcx . infer_ctxt ( ) . enter ( |infcx| {
127
+ let generics = infcx. tcx . generics_of ( impl_def_id) ;
128
+
129
+ /*if generics.count() == 0 {
130
+ return;
131
+ }*/
124
132
let trait_ref = infcx. tcx . impl_trait_ref ( impl_def_id) . unwrap ( ) ;
133
+ /*if !trait_ref.substs.iter().any(|x| match x.unpack() {
134
+ ::rustc::ty::subst::UnpackedKind::Type(ref t) => {
135
+ match t.sty {
136
+ ::rustc::ty::TypeVariants::TyParam(_) => true,
137
+ _ => false,
138
+ }
139
+ }
140
+ _ => false,
141
+ }) {
142
+ return;
143
+ }*/
144
+
145
+ if !match infcx. tcx . type_of ( impl_def_id) . sty {
146
+ :: rustc:: ty:: TypeVariants :: TyParam ( _) => true ,
147
+ _ => false ,
148
+ } {
149
+ return ;
150
+ }
151
+
125
152
let substs = infcx. fresh_substs_for_item ( DUMMY_SP , def_id) ;
126
153
let ty2 = ty. subst ( infcx. tcx , substs) ;
127
154
let param_env = param_env. subst ( infcx. tcx , substs) ;
@@ -146,50 +173,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
146
173
println!("==> {}", infcx.tcx.item_name(trait_def_id).to_string());
147
174
}*/
148
175
if may_apply {
149
- if self . cx . crate_name == Some ( "std" . to_string ( ) ) && t_name == "ToString" {
150
- println ! ( "may_apply: {:?}" , t_name) ;
151
- }
152
176
// FIXME: add crate's id before the name to avoid removing a
153
177
// trait which doesn't exist.
154
178
if traits. get ( & trait_def_id) . is_none ( ) {
155
- if self . cx . crate_name == Some ( "std" . to_string ( ) ) && t_name == "ToString" {
156
- println ! ( "in!" ) ;
157
- }
158
- /*if print {
159
- println!("> {}", infcx.tcx.item_name(trait_def_id).to_string());
160
- }*/
161
- /*let generics = (infcx.tcx.generics_of(trait_def_id), &predicates).clean(cx);
162
- get_path_for_type(self.cx.tcx, trait_def_id, hir::def::Def::Trait)*/
163
- /*if let Some(i) = self.get_auto_trait_impl_for(
164
- def_id,
165
- name.clone(),
166
- generics.clone(),
167
- def_ctor,
168
- trait_def_id,
169
- ) {
170
- traits.insert(trait_name, i);
171
- }*/
172
-
173
- let mut impls = Vec :: new ( ) ;
174
- :: clean:: inline:: build_impl ( & self . cx , impl_def_id, & mut impls) ;
175
- /*if ::std::env::var("LOL").is_ok() {
176
- println!("=> {} ::> {}",
177
- infcx.tcx.item_name(trait_def_id).to_string(),
178
- impls.len());
179
- println!("{:?}", impls);
180
- }*/
181
- for impl_ in & mut impls {
182
- if let ImplItem ( ref mut i) = impl_. inner {
183
- i. synthetic = true ;
184
- i. for_ = ty. clean ( & self . cx ) ;
185
- //i.visibility = None;
186
- }
187
- //impl_.visibility = None;
188
- if self . cx . crate_name == Some ( "std" . to_string ( ) ) && t_name == "ToString" {
189
- println ! ( "**> {:?}" , impl_) ;
190
- }
179
+ if self . cx . crate_name == Some ( "std" . to_string ( ) ) {
180
+ println ! ( "visibility: ({} {}) [{} {:?}] [{} {:?}]" ,
181
+ self . cx. tcx. item_name( def_id) . to_string( ) , t_name,
182
+ impl_def_id. krate, impl_def_id. index,
183
+ trait_def_id. krate, trait_def_id. index) ;
184
+ println ! ( "{:?}" , infcx. tcx. visibility( impl_def_id) ) ;
185
+ println ! ( "{:?}" , infcx. tcx. visibility( trait_def_id) ) ;
191
186
}
192
- //traits.insert(trait_def_id, impls);
187
+
193
188
let trait_ = hir:: TraitRef {
194
189
path : get_path_for_type ( infcx. tcx , trait_def_id, hir:: def:: Def :: Trait ) ,
195
190
ref_id : ast:: DUMMY_NODE_ID ,
@@ -198,7 +193,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
198
193
. into_iter ( )
199
194
. map ( |meth| meth. ident . to_string ( ) )
200
195
. collect ( ) ;
201
- println ! ( "|||> {}" , t_name) ;
202
196
traits. insert ( trait_def_id, Item {
203
197
source : Span :: empty ( ) ,
204
198
name : None ,
@@ -209,7 +203,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
209
203
deprecation : None ,
210
204
inner : ImplItem ( Impl {
211
205
unsafety : hir:: Unsafety :: Normal ,
212
- generics : ( infcx. tcx . generics_of ( trait_def_id) , & Default :: default ( ) ) . clean ( self . cx ) ,
206
+ generics : ( generics,
207
+ & tcx. predicates_of ( impl_def_id) ) . clean ( self . cx ) ,
213
208
provided_trait_methods,
214
209
trait_ : Some ( trait_. clean ( self . cx ) ) ,
215
210
for_ : ty. clean ( self . cx ) ,
@@ -279,9 +274,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
279
274
"get_auto_traits: type {:?} auto_traits {:?}" ,
280
275
def_id, auto_traits
281
276
) ;
282
- if self . cx . crate_name == Some ( "std" . to_string ( ) ) {
283
- println ! ( "((((((> {} {:?}" , auto_traits. len( ) , auto_traits) ;
284
- }
285
277
auto_traits
286
278
}
287
279
0 commit comments