Convert DefId to use DefIndex, which is an index into a list of
paths, and construct paths for all definitions. Also, stop rewriting DefIds for closures, and instead just load the closure data from the original def-id, which may be in another crate.
This commit is contained in:
parent
a6fee06741
commit
01f32ace03
40 changed files with 1125 additions and 783 deletions
|
|
@ -39,7 +39,7 @@ use rustc::metadata::cstore;
|
|||
use rustc::metadata::csearch;
|
||||
use rustc::metadata::decoder;
|
||||
use rustc::middle::def;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::def_id::{DefId, DefIndex};
|
||||
use rustc::middle::subst::{self, ParamSpace, VecPerParamSpace};
|
||||
use rustc::middle::ty;
|
||||
use rustc::middle::stability;
|
||||
|
|
@ -188,7 +188,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|||
attrs: child.attrs.clone(),
|
||||
visibility: Some(hir::Public),
|
||||
stability: None,
|
||||
def_id: DefId::xxx_local(prim.to_node_id()),
|
||||
def_id: DefId::local(prim.to_def_index()),
|
||||
inner: PrimitiveItem(prim),
|
||||
});
|
||||
}
|
||||
|
|
@ -1559,8 +1559,9 @@ impl PrimitiveType {
|
|||
/// Creates a rustdoc-specific node id for primitive types.
|
||||
///
|
||||
/// These node ids are generally never used by the AST itself.
|
||||
pub fn to_node_id(&self) -> ast::NodeId {
|
||||
u32::MAX - 1 - (*self as u32)
|
||||
pub fn to_def_index(&self) -> DefIndex {
|
||||
let x = u32::MAX - 1 - (*self as u32);
|
||||
DefIndex::new(x as usize)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1744,7 +1745,7 @@ impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
|
|||
let (name, attrs) = if self.name == unnamed_field.name {
|
||||
(None, None)
|
||||
} else {
|
||||
(Some(self.name), Some(attr_map.get(&self.did.xxx_node).unwrap()))
|
||||
(Some(self.name), Some(attr_map.get(&self.did).unwrap()))
|
||||
};
|
||||
|
||||
Item {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,8 @@ use std::fmt;
|
|||
use std::iter::repeat;
|
||||
|
||||
use rustc::metadata::cstore::LOCAL_CRATE;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use syntax::abi::Abi;
|
||||
use syntax::ast;
|
||||
use rustc_front::hir;
|
||||
|
||||
use clean;
|
||||
|
|
@ -387,7 +386,7 @@ fn primitive_link(f: &mut fmt::Formatter,
|
|||
Some(&cnum) => {
|
||||
let path = &m.paths[&DefId {
|
||||
krate: cnum,
|
||||
xxx_node: ast::CRATE_NODE_ID,
|
||||
index: CRATE_DEF_INDEX,
|
||||
}];
|
||||
let loc = match m.extern_locations[&cnum] {
|
||||
(_, render::Remote(ref s)) => Some(s.to_string()),
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ use externalfiles::ExternalHtml;
|
|||
use serialize::json::{self, ToJson};
|
||||
use syntax::{abi, ast, attr};
|
||||
use rustc::metadata::cstore::LOCAL_CRATE;
|
||||
use rustc::middle::def_id::DefId;
|
||||
use rustc::middle::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use rustc::util::nodemap::DefIdSet;
|
||||
use rustc_front::hir;
|
||||
|
||||
|
|
@ -413,7 +413,7 @@ pub fn run(mut krate: clean::Crate,
|
|||
for &(n, ref e) in &krate.externs {
|
||||
cache.extern_locations.insert(n, (e.name.clone(),
|
||||
extern_location(e, &cx.dst)));
|
||||
let did = DefId { krate: n, xxx_node: ast::CRATE_NODE_ID };
|
||||
let did = DefId { krate: n, index: CRATE_DEF_INDEX };
|
||||
cache.paths.insert(did, (vec![e.name.to_string()], ItemType::Module));
|
||||
}
|
||||
|
||||
|
|
@ -1034,7 +1034,7 @@ impl DocFolder for Cache {
|
|||
ref t => {
|
||||
match t.primitive_type() {
|
||||
Some(prim) => {
|
||||
let did = DefId::xxx_local(prim.to_node_id()); // TODO
|
||||
let did = DefId::local(prim.to_def_index());
|
||||
self.parent_stack.push(did);
|
||||
true
|
||||
}
|
||||
|
|
@ -1079,8 +1079,8 @@ impl DocFolder for Cache {
|
|||
ref t => {
|
||||
t.primitive_type().and_then(|t| {
|
||||
self.primitive_locations.get(&t).map(|n| {
|
||||
let id = t.to_node_id();
|
||||
DefId { krate: *n, xxx_node: id }
|
||||
let id = t.to_def_index();
|
||||
DefId { krate: *n, index: id }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
@ -1421,7 +1421,7 @@ impl<'a> Item<'a> {
|
|||
root = root,
|
||||
path = path[..path.len() - 1].join("/"),
|
||||
file = item_path(self.item),
|
||||
goto = self.item.def_id.xxx_node))
|
||||
goto = self.item.def_id.index.as_usize()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1481,7 +1481,7 @@ impl<'a> fmt::Display for Item<'a> {
|
|||
Some(l) => {
|
||||
try!(write!(fmt, "<a id='src-{}' class='srclink' \
|
||||
href='{}' title='{}'>[src]</a>",
|
||||
self.item.def_id.xxx_node, l, "goto source code"));
|
||||
self.item.def_id.index.as_usize(), l, "goto source code"));
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
|
@ -2337,7 +2337,7 @@ fn render_deref_methods(w: &mut fmt::Formatter, cx: &Context, impl_: &Impl) -> f
|
|||
_ => {
|
||||
if let Some(prim) = target.primitive_type() {
|
||||
if let Some(c) = cache().primitive_locations.get(&prim) {
|
||||
let did = DefId { krate: *c, xxx_node: prim.to_node_id() };
|
||||
let did = DefId { krate: *c, index: prim.to_def_index() };
|
||||
try!(render_assoc_items(w, cx, did, what));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue