Skip to content

Commit 2bc7c03

Browse files
Add filter over non generic impls
1 parent e8cca55 commit 2bc7c03

File tree

3 files changed

+38
-54
lines changed

3 files changed

+38
-54
lines changed

src/librustdoc/clean/auto_trait.rs

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use rustc::infer::InferOk;
1616
use std::fmt::Debug;
1717
use syntax_pos::DUMMY_SP;
1818

19+
use core::DocAccessLevels;
20+
1921
use super::*;
2022

2123
pub 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

src/librustdoc/clean/inline.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,6 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec<clean:
275275
if auto_traits {
276276
let auto_impls = get_auto_traits_with_def_id(cx, did);
277277
let mut renderinfo = cx.renderinfo.borrow_mut();
278-
279-
if cx.crate_name == Some("std".to_string()) {
280-
println!("=====> {} {:?}\n", auto_impls.len(), auto_impls);
281-
}
282278
let new_impls: Vec<clean::Item> = auto_impls.into_iter()
283279
.filter(|i| renderinfo.inlined.insert(i.def_id)).collect();
284280

@@ -340,9 +336,6 @@ pub fn build_impls(cx: &DocContext, did: DefId, auto_traits: bool) -> Vec<clean:
340336
build_impl(cx, def_id, &mut impls);
341337

342338
let auto_impls = get_auto_traits_with_def_id(cx, def_id);
343-
if cx.crate_name == Some("std".to_string()) {
344-
println!("-----> {} {:?}\n", auto_impls.len(), auto_impls);
345-
}
346339
let mut renderinfo = cx.renderinfo.borrow_mut();
347340

348341
let new_impls: Vec<clean::Item> = auto_impls.into_iter()

src/librustdoc/html/render.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3584,7 +3584,6 @@ fn render_assoc_items(w: &mut fmt::Formatter,
35843584
Some(v) => v,
35853585
None => return Ok(()),
35863586
};
3587-
//println!("=======> {:?}", containing_item.name);
35883587
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| {
35893588
/*if let Some(ref t) = i.inner_impl().trait_ {
35903589
println!("++++++> {:?}", t);

0 commit comments

Comments
 (0)