mirror of https://github.com/rust-lang/rust.git
part 2
This commit is contained in:
parent
39849d5128
commit
ccdf4ae814
|
@ -91,18 +91,13 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
let ty = self.cx.tcx.type_of(def_id);
|
||||
let mut traits = FxHashMap();
|
||||
if let ty::TyAdt(_adt, _) = ty.sty {
|
||||
use std::rc::Rc;
|
||||
|
||||
let name = Rc::new(name.clone());
|
||||
let param_env = self.cx.tcx.param_env(def_id);
|
||||
for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() {
|
||||
let name = name.clone();
|
||||
self.cx.tcx.for_each_relevant_impl(trait_def_id, ty, |impl_def_id| {
|
||||
let name = name.clone();
|
||||
self.cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
let trait_ref = infcx.tcx.impl_trait_ref(impl_def_id).unwrap();
|
||||
let substs = infcx.fresh_substs_for_item(DUMMY_SP, def_id);
|
||||
let ty = ty.subst(infcx.tcx, substs);
|
||||
let ty2 = ty.subst(infcx.tcx, substs);
|
||||
let param_env = param_env.subst(infcx.tcx, substs);
|
||||
|
||||
let impl_substs = infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id);
|
||||
|
@ -111,7 +106,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
// Require the type the impl is implemented on to match
|
||||
// our type, and ignore the impl if there was a mismatch.
|
||||
let cause = traits::ObligationCause::dummy();
|
||||
let eq_result = infcx.at(&cause, param_env).eq(trait_ref.self_ty(), ty);
|
||||
let eq_result = infcx.at(&cause, param_env).eq(trait_ref.self_ty(), ty2);
|
||||
if let Ok(InferOk { value: (), obligations }) = eq_result {
|
||||
// FIXME(eddyb) ignoring `obligations` might cause false positives.
|
||||
drop(obligations);
|
||||
|
@ -137,57 +132,40 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
traits.insert(trait_name, i);
|
||||
}*/
|
||||
|
||||
let path = get_path_for_type(infcx.tcx, def_id, def_ctor);
|
||||
let mut segments = path.clone().segments.into_vec();
|
||||
let last = segments.pop().unwrap();
|
||||
let mut impls = Vec::new();
|
||||
::clean::inline::build_impl(&self.cx, impl_def_id, &mut impls);
|
||||
/*if ::std::env::var("LOL").is_ok() {
|
||||
println!("=> {} ::> {}",
|
||||
infcx.tcx.item_name(trait_def_id).to_string(),
|
||||
impls.len());
|
||||
println!("{:?}", impls);
|
||||
}*/
|
||||
for impl_ in &mut impls {
|
||||
if let ImplItem(ref mut i) = impl_.inner {
|
||||
i.synthetic = true;
|
||||
i.for_ = ty.clean(&self.cx);
|
||||
}
|
||||
}
|
||||
traits.insert(trait_def_id, impls);
|
||||
|
||||
use std::ops::Deref;
|
||||
let t_name: Option<String> = name.deref().clone();
|
||||
let real_name = t_name.map(|name| Ident::from_str(&name)).unwrap_or(last.ident);
|
||||
/*use ::clean::{self, inline::*};
|
||||
|
||||
segments.push(hir::PathSegment::new(
|
||||
real_name,
|
||||
self.generics_to_path_params(generics.clone()),
|
||||
false,
|
||||
));
|
||||
let new_path = hir::Path {
|
||||
span: path.span,
|
||||
def: path.def,
|
||||
segments: HirVec::from_vec(segments),
|
||||
};
|
||||
let ty = hir::Ty {
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
node: hir::Ty_::TyPath(hir::QPath::Resolved(None, P(new_path))),
|
||||
span: DUMMY_SP,
|
||||
hir_id: hir::DUMMY_HIR_ID,
|
||||
};
|
||||
traits.insert(trait_def_id, Item {
|
||||
source: Span::empty(),
|
||||
name: None,
|
||||
attrs: Default::default(),
|
||||
visibility: None,
|
||||
def_id: self.next_def_id(def_id.krate),
|
||||
stability: None,
|
||||
deprecation: None,
|
||||
inner: ImplItem(Impl {
|
||||
unsafety: hir::Unsafety::Normal,
|
||||
generics: Generics {
|
||||
params: generics.params.clean(self.cx),
|
||||
where_predicates: Vec::new(),
|
||||
},
|
||||
provided_trait_methods: FxHashSet(),
|
||||
trait_: Some(hir::TraitRef {
|
||||
path,
|
||||
ref_id: ast::DUMMY_NODE_ID,
|
||||
}.clean(self.cx)),
|
||||
|
||||
//Some(trait_ref.clean(self.cx)),
|
||||
for_: ty.clean(self.cx),
|
||||
items: Vec::new(),
|
||||
polarity: None,
|
||||
synthetic: true,
|
||||
})
|
||||
let mut ret = Vec::with_capacity(2);
|
||||
record_extern_fqn(self.cx, trait_def_id, clean::TypeKind::Trait);
|
||||
ret.extend(build_impls(self.cx, trait_def_id, false));
|
||||
let inner = clean::TraitItem(build_external_trait(self.cx, trait_def_id));
|
||||
let cx = self.cx;
|
||||
ret.push(clean::Item {
|
||||
source: infcx.tcx.def_span(trait_def_id).clean(cx),
|
||||
name: Some(infcx.tcx.item_name(trait_def_id).to_string()),
|
||||
attrs: load_attrs(cx, trait_def_id),
|
||||
inner,
|
||||
visibility: Some(clean::Public),
|
||||
stability: cx.tcx.lookup_stability(trait_def_id).clean(cx),
|
||||
deprecation: cx.tcx.lookup_deprecation(trait_def_id).clean(cx),
|
||||
def_id: trait_def_id,
|
||||
});
|
||||
traits.insert(trait_def_id, ret);*/
|
||||
}
|
||||
//println!("=> {}", infcx.tcx.item_name(trait_def_id).to_string());
|
||||
}
|
||||
|
@ -236,13 +214,18 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
|
|||
def_ctor,
|
||||
tcx.require_lang_item(lang_items::SyncTraitLangItem),
|
||||
).into_iter())
|
||||
.chain(traits.into_iter().map(|(_, v)| v))
|
||||
.chain(traits.into_iter().flat_map(|(_, v)| v.into_iter()))
|
||||
.collect();
|
||||
|
||||
debug!(
|
||||
"get_auto_traits: type {:?} auto_traits {:?}",
|
||||
def_id, auto_traits
|
||||
);
|
||||
if ::std::env::var("LOL").is_ok() {
|
||||
for x in &auto_traits {
|
||||
println!("\n=> {:?}", x);
|
||||
}
|
||||
}
|
||||
auto_traits
|
||||
}
|
||||
|
||||
|
|
|
@ -2082,7 +2082,6 @@ where F: Fn(&mut fmt::Formatter) -> fmt::Result {
|
|||
impl<'a> fmt::Display for Item<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
debug_assert!(!self.item.is_stripped());
|
||||
println!("=> {:?}", self.item.name);
|
||||
// Write the breadcrumb trail header for the top
|
||||
write!(fmt, "<h1 class='fqn'><span class='in-band'>")?;
|
||||
match self.item.inner {
|
||||
|
@ -3586,6 +3585,11 @@ fn render_assoc_items(w: &mut fmt::Formatter,
|
|||
None => return Ok(()),
|
||||
};
|
||||
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| {
|
||||
if ::std::env::var("LOL").is_ok() {
|
||||
if let Some(ref t) = i.inner_impl().trait_ {
|
||||
println!("==> {:?}", t);
|
||||
}
|
||||
}
|
||||
i.inner_impl().trait_.is_none()
|
||||
});
|
||||
if !non_trait.is_empty() {
|
||||
|
|
Loading…
Reference in New Issue