}, false)
}
-pub fn build_impls(cx: &DocContext, tcx: &TyCtxt,
+pub fn build_impls(cx: &DocContext,
+ tcx: &TyCtxt,
did: DefId) -> Vec<clean::Item> {
tcx.populate_inherent_implementations_for_type_if_necessary(did);
let mut impls = Vec::new();
// Primarily, the impls will be used to populate the documentation for this
// type being inlined, but impls can also be used when generating
// documentation for primitives (no way to find those specifically).
- if cx.populated_crate_impls.borrow_mut().insert(did.krate) {
+ if !cx.all_crate_impls.borrow_mut().contains_key(&did.krate) {
+ let mut impls = Vec::new();
for item in tcx.sess.cstore.crate_top_level_items(did.krate) {
populate_impls(cx, tcx, item.def, &mut impls);
}
+ cx.all_crate_impls.borrow_mut().insert(did.krate, impls);
fn populate_impls(cx: &DocContext, tcx: &TyCtxt,
def: cstore::DefLike,
}
}
+ let mut candidates = cx.all_crate_impls.borrow_mut();
+ let candidates = candidates.get_mut(&did.krate).unwrap();
+ for i in (0..candidates.len()).rev() {
+ let remove = match candidates[i].inner {
+ clean::ImplItem(ref i) => {
+ i.for_.def_id() == Some(did) || i.for_.primitive_type().is_some()
+ }
+ _ => continue,
+ };
+ if remove {
+ impls.push(candidates.swap_remove(i));
+ }
+ }
+
return impls;
}
_ => None,
}
}
+
+ fn def_id(&self) -> Option<DefId> {
+ match *self {
+ ResolvedPath { did, .. } => Some(did),
+ _ => None,
+ }
+ }
}
impl PrimitiveType {
pub external_traits: RefCell<Option<HashMap<DefId, clean::Trait>>>,
pub external_typarams: RefCell<Option<HashMap<DefId, String>>>,
pub inlined: RefCell<Option<HashSet<DefId>>>,
- pub populated_crate_impls: RefCell<HashSet<ast::CrateNum>>,
+ pub all_crate_impls: RefCell<HashMap<ast::CrateNum, Vec<clean::Item>>>,
pub deref_trait_did: Cell<Option<DefId>>,
}
external_typarams: RefCell::new(Some(HashMap::new())),
external_paths: RefCell::new(Some(HashMap::new())),
inlined: RefCell::new(Some(HashSet::new())),
- populated_crate_impls: RefCell::new(HashSet::new()),
+ all_crate_impls: RefCell::new(HashMap::new()),
deref_trait_did: Cell::new(None),
};
debug!("crate: {:?}", ctxt.map.krate());
#![allow(deprecated)]
use std::cell::{RefCell, Cell};
-use std::collections::{HashSet, HashMap};
+use std::collections::HashMap;
use std::dynamic_lib::DynamicLibrary;
use std::env;
use std::ffi::OsString;
external_traits: RefCell::new(None),
external_typarams: RefCell::new(None),
inlined: RefCell::new(None),
- populated_crate_impls: RefCell::new(HashSet::new()),
+ all_crate_impls: RefCell::new(HashMap::new()),
deref_trait_did: Cell::new(None),
};