@@ -16,6 +16,8 @@ use rustc::infer::InferOk;
1616use std:: fmt:: Debug ;
1717use syntax_pos:: DUMMY_SP ;
1818
19+ use core:: DocAccessLevels ;
20+
1921use super :: * ;
2022
2123pub struct AutoTraitFinder < ' a , ' tcx : ' a , ' rcx : ' a > {
@@ -115,13 +117,38 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
115117 _ => false,
116118 };*/
117119 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) {
119122 continue
120123 }
121124 let t_name = self . cx . tcx . item_name ( trait_def_id) . to_string ( ) ;
122125 self . cx . tcx . for_each_relevant_impl ( trait_def_id, ty, |impl_def_id| {
123126 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+ }*/
124132 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+
125152 let substs = infcx. fresh_substs_for_item ( DUMMY_SP , def_id) ;
126153 let ty2 = ty. subst ( infcx. tcx , substs) ;
127154 let param_env = param_env. subst ( infcx. tcx , substs) ;
@@ -146,50 +173,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
146173 println!("==> {}", infcx.tcx.item_name(trait_def_id).to_string());
147174 }*/
148175 if may_apply {
149- if self . cx . crate_name == Some ( "std" . to_string ( ) ) && t_name == "ToString" {
150- println ! ( "may_apply: {:?}" , t_name) ;
151- }
152176 // FIXME: add crate's id before the name to avoid removing a
153177 // trait which doesn't exist.
154178 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) ) ;
191186 }
192- //traits.insert(trait_def_id, impls);
187+
193188 let trait_ = hir:: TraitRef {
194189 path : get_path_for_type ( infcx. tcx , trait_def_id, hir:: def:: Def :: Trait ) ,
195190 ref_id : ast:: DUMMY_NODE_ID ,
@@ -198,7 +193,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
198193 . into_iter ( )
199194 . map ( |meth| meth. ident . to_string ( ) )
200195 . collect ( ) ;
201- println ! ( "|||> {}" , t_name) ;
202196 traits. insert ( trait_def_id, Item {
203197 source : Span :: empty ( ) ,
204198 name : None ,
@@ -209,7 +203,8 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
209203 deprecation : None ,
210204 inner : ImplItem ( Impl {
211205 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 ) ,
213208 provided_trait_methods,
214209 trait_ : Some ( trait_. clean ( self . cx ) ) ,
215210 for_ : ty. clean ( self . cx ) ,
@@ -279,9 +274,6 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
279274 "get_auto_traits: type {:?} auto_traits {:?}" ,
280275 def_id, auto_traits
281276 ) ;
282- if self . cx . crate_name == Some ( "std" . to_string ( ) ) {
283- println ! ( "((((((> {} {:?}" , auto_traits. len( ) , auto_traits) ;
284- }
285277 auto_traits
286278 }
287279
0 commit comments