Move Def out of syntax crate, where it does not belong

This commit is contained in:
Niko Matsakis 2014-05-14 15:31:30 -04:00
parent 14d626a9fa
commit 0f03b5608c
47 changed files with 442 additions and 392 deletions

View file

@ -16,6 +16,7 @@ use syntax::attr::AttrMetaMethods;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
use rustc::middle::def;
use rustc::middle::ty;
use core;
@ -46,22 +47,22 @@ pub fn try_inline(id: ast::NodeId) -> Option<Vec<clean::Item>> {
Some(def) => *def,
None => return None,
};
let did = ast_util::def_id_of_def(def);
let did = def.def_id();
if ast_util::is_local(did) { return None }
try_inline_def(&**cx, tcx, def)
}
fn try_inline_def(cx: &core::DocContext,
tcx: &ty::ctxt,
def: ast::Def) -> Option<Vec<clean::Item>> {
def: def::Def) -> Option<Vec<clean::Item>> {
let mut ret = Vec::new();
let did = ast_util::def_id_of_def(def);
let did = def.def_id();
let inner = match def {
ast::DefTrait(did) => {
def::DefTrait(did) => {
record_extern_fqn(cx, did, clean::TypeTrait);
clean::TraitItem(build_external_trait(tcx, did))
}
ast::DefFn(did, style) => {
def::DefFn(did, style) => {
// If this function is a tuple struct constructor, we just skip it
if csearch::get_tuple_struct_definition_if_ctor(&tcx.sess.cstore,
did).is_some() {
@ -70,20 +71,20 @@ fn try_inline_def(cx: &core::DocContext,
record_extern_fqn(cx, did, clean::TypeFunction);
clean::FunctionItem(build_external_function(tcx, did, style))
}
ast::DefStruct(did) => {
def::DefStruct(did) => {
record_extern_fqn(cx, did, clean::TypeStruct);
ret.extend(build_impls(cx, tcx, did).move_iter());
clean::StructItem(build_struct(tcx, did))
}
ast::DefTy(did) => {
def::DefTy(did) => {
record_extern_fqn(cx, did, clean::TypeEnum);
ret.extend(build_impls(cx, tcx, did).move_iter());
build_type(tcx, did)
}
// Assume that the enum type is reexported next to the variant, and
// variants don't show up in documentation specially.
ast::DefVariant(..) => return Some(Vec::new()),
ast::DefMod(did) => {
def::DefVariant(..) => return Some(Vec::new()),
def::DefMod(did) => {
record_extern_fqn(cx, did, clean::TypeModule);
clean::ModuleItem(build_module(cx, tcx, did))
}
@ -248,7 +249,7 @@ fn build_impls(cx: &core::DocContext,
impls: &mut Vec<Option<clean::Item>>) {
match def {
decoder::DlImpl(did) => impls.push(build_impl(cx, tcx, did)),
decoder::DlDef(ast::DefMod(did)) => {
decoder::DlDef(def::DefMod(did)) => {
csearch::each_child_of_item(&tcx.sess.cstore,
did,
|def, _, _| {

View file

@ -25,6 +25,7 @@ use rustc::driver::driver;
use rustc::metadata::cstore;
use rustc::metadata::csearch;
use rustc::metadata::decoder;
use rustc::middle::def;
use rustc::middle::subst;
use rustc::middle::ty;
@ -191,7 +192,7 @@ impl Clean<ExternalCrate> for cstore::crate_metadata {
self.cnum,
|def, _, _| {
let did = match def {
decoder::DlDef(ast::DefMod(did)) => did,
decoder::DlDef(def::DefMod(did)) => did,
_ => return
};
let attrs = inline::load_attrs(tcx, did);
@ -1949,8 +1950,8 @@ fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound>>,
};
match def {
ast::DefSelfTy(i) => return Self(ast_util::local_def(i)),
ast::DefPrimTy(p) => match p {
def::DefSelfTy(i) => return Self(ast_util::local_def(i)),
def::DefPrimTy(p) => match p {
ast::TyStr => return Primitive(Str),
ast::TyBool => return Primitive(Bool),
ast::TyChar => return Primitive(Char),
@ -1968,24 +1969,24 @@ fn resolve_type(path: Path, tpbs: Option<Vec<TyParamBound>>,
ast::TyFloat(ast::TyF64) => return Primitive(F64),
ast::TyFloat(ast::TyF128) => return Primitive(F128),
},
ast::DefTyParam(i, _) => return Generic(i),
ast::DefTyParamBinder(i) => return TyParamBinder(i),
def::DefTyParam(i, _) => return Generic(i),
def::DefTyParamBinder(i) => return TyParamBinder(i),
_ => {}
};
let did = register_def(&**cx, def);
ResolvedPath { path: path, typarams: tpbs, did: did }
}
fn register_def(cx: &core::DocContext, def: ast::Def) -> ast::DefId {
fn register_def(cx: &core::DocContext, def: def::Def) -> ast::DefId {
let (did, kind) = match def {
ast::DefFn(i, _) => (i, TypeFunction),
ast::DefTy(i) => (i, TypeEnum),
ast::DefTrait(i) => (i, TypeTrait),
ast::DefStruct(i) => (i, TypeStruct),
ast::DefMod(i) => (i, TypeModule),
ast::DefStatic(i, _) => (i, TypeStatic),
ast::DefVariant(i, _, _) => (i, TypeEnum),
_ => return ast_util::def_id_of_def(def),
def::DefFn(i, _) => (i, TypeFunction),
def::DefTy(i) => (i, TypeEnum),
def::DefTrait(i) => (i, TypeTrait),
def::DefStruct(i) => (i, TypeStruct),
def::DefMod(i) => (i, TypeModule),
def::DefStatic(i, _) => (i, TypeStatic),
def::DefVariant(i, _, _) => (i, TypeEnum),
_ => return def.def_id()
};
if ast_util::is_local(did) { return did }
let tcx = match cx.maybe_typed {

View file

@ -195,7 +195,7 @@ impl<'a> RustdocVisitor<'a> {
core::Typed(ref tcx) => tcx,
core::NotTyped(_) => return false
};
let def = ast_util::def_id_of_def(*tcx.def_map.borrow().get(&id));
let def = tcx.def_map.borrow().get(&id).def_id();
if !ast_util::is_local(def) { return false }
let analysis = match self.analysis {
Some(analysis) => analysis, None => return false