2014-05-24 11:56:38 -07:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
//! Support for inlining external documentation into the current AST.
|
|
|
|
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::ast_util;
|
|
|
|
use syntax::attr::AttrMetaMethods;
|
|
|
|
|
|
|
|
use rustc::metadata::csearch;
|
|
|
|
use rustc::metadata::decoder;
|
2014-05-14 15:31:30 -04:00
|
|
|
use rustc::middle::def;
|
2014-05-24 11:56:38 -07:00
|
|
|
use rustc::middle::ty;
|
2014-07-25 09:07:20 -07:00
|
|
|
use rustc::middle::subst;
|
2014-06-26 11:37:39 -07:00
|
|
|
use rustc::middle::stability;
|
2014-05-24 11:56:38 -07:00
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
use core::DocContext;
|
2014-05-24 11:56:38 -07:00
|
|
|
use doctree;
|
|
|
|
use clean;
|
|
|
|
|
|
|
|
use super::Clean;
|
|
|
|
|
|
|
|
/// Attempt to inline the definition of a local node id into this AST.
|
|
|
|
///
|
|
|
|
/// This function will fetch the definition of the id specified, and if it is
|
|
|
|
/// from another crate it will attempt to inline the documentation from the
|
|
|
|
/// other crate into this crate.
|
|
|
|
///
|
|
|
|
/// This is primarily used for `pub use` statements which are, in general,
|
|
|
|
/// implementation details. Inlining the documentation should help provide a
|
|
|
|
/// better experience when reading the documentation in this use case.
|
|
|
|
///
|
|
|
|
/// The returned value is `None` if the `id` could not be inlined, and `Some`
|
|
|
|
/// of a vector of items if it was successfully expanded.
|
2014-09-06 19:13:40 +03:00
|
|
|
pub fn try_inline(cx: &DocContext, id: ast::NodeId, into: Option<ast::Ident>)
|
2014-07-25 10:16:41 -07:00
|
|
|
-> Option<Vec<clean::Item>> {
|
2014-09-06 19:13:40 +03:00
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
|
|
|
None => return None,
|
2014-05-24 11:56:38 -07:00
|
|
|
};
|
2014-11-06 12:25:16 -05:00
|
|
|
let def = match tcx.def_map.borrow().get(&id) {
|
2014-05-24 11:56:38 -07:00
|
|
|
Some(def) => *def,
|
|
|
|
None => return None,
|
|
|
|
};
|
2014-05-14 15:31:30 -04:00
|
|
|
let did = def.def_id();
|
2014-05-24 11:56:38 -07:00
|
|
|
if ast_util::is_local(did) { return None }
|
2014-09-06 19:13:40 +03:00
|
|
|
try_inline_def(cx, tcx, def).map(|vec| {
|
2014-09-14 20:27:36 -07:00
|
|
|
vec.into_iter().map(|mut item| {
|
2014-07-25 10:16:41 -07:00
|
|
|
match into {
|
|
|
|
Some(into) if item.name.is_some() => {
|
2014-09-06 19:13:40 +03:00
|
|
|
item.name = Some(into.clean(cx));
|
2014-07-25 10:16:41 -07:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
item
|
|
|
|
}).collect()
|
|
|
|
})
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn try_inline_def(cx: &DocContext, tcx: &ty::ctxt,
|
2014-05-14 15:31:30 -04:00
|
|
|
def: def::Def) -> Option<Vec<clean::Item>> {
|
2014-05-24 11:56:38 -07:00
|
|
|
let mut ret = Vec::new();
|
2014-05-14 15:31:30 -04:00
|
|
|
let did = def.def_id();
|
2014-05-24 11:56:38 -07:00
|
|
|
let inner = match def {
|
2015-02-07 14:24:34 +01:00
|
|
|
def::DefaultImpl(did) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeTrait);
|
2014-09-06 19:13:40 +03:00
|
|
|
clean::TraitItem(build_external_trait(cx, tcx, did))
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-10-31 15:00:35 +13:00
|
|
|
def::DefFn(did, false) => {
|
2014-05-29 15:52:03 -07:00
|
|
|
// If this function is a tuple struct constructor, we just skip it
|
2014-05-24 11:56:38 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeFunction);
|
2014-10-31 15:00:35 +13:00
|
|
|
clean::FunctionItem(build_external_function(cx, tcx, did))
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefStruct(did) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeStruct);
|
2014-09-14 20:27:36 -07:00
|
|
|
ret.extend(build_impls(cx, tcx, did).into_iter());
|
2014-09-06 19:13:40 +03:00
|
|
|
clean::StructItem(build_struct(cx, tcx, did))
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-09-16 09:13:00 +12:00
|
|
|
def::DefTy(did, false) => {
|
|
|
|
record_extern_fqn(cx, did, clean::TypeTypedef);
|
|
|
|
ret.extend(build_impls(cx, tcx, did).into_iter());
|
|
|
|
build_type(cx, tcx, did)
|
|
|
|
}
|
|
|
|
def::DefTy(did, true) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeEnum);
|
2014-09-14 20:27:36 -07:00
|
|
|
ret.extend(build_impls(cx, tcx, did).into_iter());
|
2014-09-06 19:13:40 +03:00
|
|
|
build_type(cx, tcx, did)
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
// Assume that the enum type is reexported next to the variant, and
|
|
|
|
// variants don't show up in documentation specially.
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefVariant(..) => return Some(Vec::new()),
|
|
|
|
def::DefMod(did) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeModule);
|
|
|
|
clean::ModuleItem(build_module(cx, tcx, did))
|
|
|
|
}
|
2014-06-06 20:17:19 -07:00
|
|
|
def::DefStatic(did, mtbl) => {
|
2014-06-05 17:20:59 -07:00
|
|
|
record_extern_fqn(cx, did, clean::TypeStatic);
|
2014-09-06 19:13:40 +03:00
|
|
|
clean::StaticItem(build_static(cx, tcx, did, mtbl))
|
2014-06-05 17:20:59 -07:00
|
|
|
}
|
2014-12-12 04:13:36 -08:00
|
|
|
def::DefConst(did) => {
|
|
|
|
record_extern_fqn(cx, did, clean::TypeConst);
|
|
|
|
clean::ConstantItem(build_const(cx, tcx, did))
|
|
|
|
}
|
2014-05-24 11:56:38 -07:00
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
let fqn = csearch::get_item_path(tcx, did);
|
2014-08-18 17:52:38 -07:00
|
|
|
cx.inlined.borrow_mut().as_mut().unwrap().insert(did);
|
2014-05-24 11:56:38 -07:00
|
|
|
ret.push(clean::Item {
|
|
|
|
source: clean::Span::empty(),
|
2014-06-21 03:39:03 -07:00
|
|
|
name: Some(fqn.last().unwrap().to_string()),
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: load_attrs(cx, tcx, did),
|
2014-05-24 11:56:38 -07:00
|
|
|
inner: inner,
|
|
|
|
visibility: Some(ast::Public),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: stability::lookup(tcx, did).clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
def_id: did,
|
|
|
|
});
|
|
|
|
Some(ret)
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
pub fn load_attrs(cx: &DocContext, tcx: &ty::ctxt,
|
|
|
|
did: ast::DefId) -> Vec<clean::Attribute> {
|
2015-01-11 18:16:02 +01:00
|
|
|
let attrs = csearch::get_item_attrs(&tcx.sess.cstore, did);
|
|
|
|
attrs.into_iter().map(|a| a.clean(cx)).collect()
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Record an external fully qualified name in the external_paths cache.
|
|
|
|
///
|
|
|
|
/// These names are used later on by HTML rendering to generate things like
|
|
|
|
/// source links back to the original item.
|
2014-09-06 19:13:40 +03:00
|
|
|
pub fn record_extern_fqn(cx: &DocContext, did: ast::DefId, kind: clean::TypeKind) {
|
|
|
|
match cx.tcx_opt() {
|
|
|
|
Some(tcx) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
let fqn = csearch::get_item_path(tcx, did);
|
2014-09-14 20:27:36 -07:00
|
|
|
let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
|
2014-08-18 17:52:38 -07:00
|
|
|
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
None => {}
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt,
|
|
|
|
did: ast::DefId) -> clean::Trait {
|
2015-01-14 07:28:37 -08:00
|
|
|
use clean::TraitMethod;
|
|
|
|
|
2014-05-24 11:56:38 -07:00
|
|
|
let def = ty::lookup_trait_def(tcx, did);
|
2014-09-06 19:13:40 +03:00
|
|
|
let trait_items = ty::trait_items(tcx, did).clean(cx);
|
2014-06-02 00:09:44 -07:00
|
|
|
let provided = ty::provided_trait_methods(tcx, did);
|
2014-11-06 09:32:37 -08:00
|
|
|
let items = trait_items.into_iter().map(|trait_item| {
|
2015-01-14 07:28:37 -08:00
|
|
|
match trait_item.inner {
|
|
|
|
clean::TyMethodItem(_) => {
|
|
|
|
if provided.iter().any(|a| a.def_id == trait_item.def_id) {
|
|
|
|
TraitMethod::ProvidedMethod(trait_item)
|
|
|
|
} else {
|
|
|
|
TraitMethod::RequiredMethod(trait_item)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
clean::AssociatedTypeItem(_) => TraitMethod::TypeTraitItem(trait_item),
|
|
|
|
_ => unreachable!()
|
2014-06-02 00:09:44 -07:00
|
|
|
}
|
|
|
|
});
|
2014-08-27 21:46:52 -04:00
|
|
|
let trait_def = ty::lookup_trait_def(tcx, did);
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2014-12-24 22:34:57 +13:00
|
|
|
let bounds = trait_def.bounds.clean(cx);
|
2014-05-24 11:56:38 -07:00
|
|
|
clean::Trait {
|
2014-12-09 19:59:20 -05:00
|
|
|
unsafety: def.unsafety,
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&def.generics, &predicates, subst::TypeSpace).clean(cx),
|
2014-08-04 13:56:56 -07:00
|
|
|
items: items.collect(),
|
2014-08-27 21:46:52 -04:00
|
|
|
bounds: bounds,
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-31 15:00:35 +13:00
|
|
|
fn build_external_function(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Function {
|
2014-05-24 11:56:38 -07:00
|
|
|
let t = ty::lookup_item_type(tcx, did);
|
2014-10-31 10:51:16 +02:00
|
|
|
let (decl, style) = match t.ty.sty {
|
2014-11-26 06:01:28 -05:00
|
|
|
ty::ty_bare_fn(_, ref f) => ((did, &f.sig).clean(cx), f.unsafety),
|
2014-10-31 15:00:35 +13:00
|
|
|
_ => panic!("bad function"),
|
|
|
|
};
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2014-05-24 11:56:38 -07:00
|
|
|
clean::Function {
|
2014-10-31 15:00:35 +13:00
|
|
|
decl: decl,
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&t.generics, &predicates, subst::FnSpace).clean(cx),
|
2014-12-09 10:36:46 -05:00
|
|
|
unsafety: style,
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_struct(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::Struct {
|
2014-05-24 11:56:38 -07:00
|
|
|
use syntax::parse::token::special_idents::unnamed_field;
|
|
|
|
|
|
|
|
let t = ty::lookup_item_type(tcx, did);
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2014-05-24 11:56:38 -07:00
|
|
|
let fields = ty::lookup_struct_fields(tcx, did);
|
|
|
|
|
|
|
|
clean::Struct {
|
2015-02-01 21:53:25 -05:00
|
|
|
struct_type: match &*fields {
|
2014-05-24 11:56:38 -07:00
|
|
|
[] => doctree::Unit,
|
|
|
|
[ref f] if f.name == unnamed_field.name => doctree::Newtype,
|
|
|
|
[ref f, ..] if f.name == unnamed_field.name => doctree::Tuple,
|
|
|
|
_ => doctree::Plain,
|
|
|
|
},
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
|
2014-09-06 19:13:40 +03:00
|
|
|
fields: fields.clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
fields_stripped: false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEnum {
|
2014-05-24 11:56:38 -07:00
|
|
|
let t = ty::lookup_item_type(tcx, did);
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2014-10-31 10:51:16 +02:00
|
|
|
match t.ty.sty {
|
2014-06-09 12:56:37 -07:00
|
|
|
ty::ty_enum(edid, _) if !csearch::is_typedef(&tcx.sess.cstore, did) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
return clean::EnumItem(clean::Enum {
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
variants_stripped: false,
|
2014-09-06 19:13:40 +03:00
|
|
|
variants: ty::enum_variants(tcx, edid).clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
|
|
|
|
clean::TypedefItem(clean::Typedef {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: t.ty.clean(cx),
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&t.generics, &predicates, subst::TypeSpace).clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
|
2014-05-24 11:56:38 -07:00
|
|
|
did: ast::DefId) -> Vec<clean::Item> {
|
|
|
|
ty::populate_implementations_for_type_if_necessary(tcx, did);
|
|
|
|
let mut impls = Vec::new();
|
|
|
|
|
2014-11-06 12:25:16 -05:00
|
|
|
match tcx.inherent_impls.borrow().get(&did) {
|
2014-05-24 11:56:38 -07:00
|
|
|
None => {}
|
|
|
|
Some(i) => {
|
2014-09-12 10:54:08 -04:00
|
|
|
impls.extend(i.iter().map(|&did| { build_impl(cx, tcx, did) }));
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 01:35:44 -07:00
|
|
|
// If this is the first time we've inlined something from this crate, then
|
|
|
|
// we inline *all* impls from the crate into this crate. Note that there's
|
|
|
|
// currently no way for us to filter this based on type, and we likely need
|
|
|
|
// many impls for a variety of reasons.
|
|
|
|
//
|
|
|
|
// 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) {
|
|
|
|
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
|
|
|
|
did.krate,
|
|
|
|
|def, _, _| {
|
2014-06-01 11:16:18 -07:00
|
|
|
populate_impls(cx, tcx, def, &mut impls)
|
2014-05-29 01:35:44 -07:00
|
|
|
});
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn populate_impls(cx: &DocContext, tcx: &ty::ctxt,
|
2014-05-29 01:35:44 -07:00
|
|
|
def: decoder::DefLike,
|
2014-06-01 11:16:18 -07:00
|
|
|
impls: &mut Vec<Option<clean::Item>>) {
|
2014-05-29 01:35:44 -07:00
|
|
|
match def {
|
2014-06-01 11:16:18 -07:00
|
|
|
decoder::DlImpl(did) => impls.push(build_impl(cx, tcx, did)),
|
2014-05-14 15:31:30 -04:00
|
|
|
decoder::DlDef(def::DefMod(did)) => {
|
2014-05-29 01:35:44 -07:00
|
|
|
csearch::each_child_of_item(&tcx.sess.cstore,
|
|
|
|
did,
|
|
|
|
|def, _, _| {
|
2014-06-01 11:16:18 -07:00
|
|
|
populate_impls(cx, tcx, def, impls)
|
2014-05-29 01:35:44 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-14 20:27:36 -07:00
|
|
|
impls.into_iter().filter_map(|a| a).collect()
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
|
2014-06-01 11:16:18 -07:00
|
|
|
did: ast::DefId) -> Option<clean::Item> {
|
2014-08-18 17:52:38 -07:00
|
|
|
if !cx.inlined.borrow_mut().as_mut().unwrap().insert(did) {
|
2014-06-01 11:16:18 -07:00
|
|
|
return None
|
|
|
|
}
|
|
|
|
|
2014-05-24 11:56:38 -07:00
|
|
|
let associated_trait = csearch::get_impl_trait(tcx, did);
|
2014-07-25 08:26:17 -07:00
|
|
|
// If this is an impl for a #[doc(hidden)] trait, be sure to not inline it.
|
|
|
|
match associated_trait {
|
|
|
|
Some(ref t) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
let trait_attrs = load_attrs(cx, tcx, t.def_id);
|
2014-07-25 08:26:17 -07:00
|
|
|
if trait_attrs.iter().any(|a| is_doc_hidden(a)) {
|
|
|
|
return None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
let attrs = load_attrs(cx, tcx, did);
|
2014-05-24 11:56:38 -07:00
|
|
|
let ty = ty::lookup_item_type(tcx, did);
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2014-08-04 13:56:56 -07:00
|
|
|
let trait_items = csearch::get_impl_items(&tcx.sess.cstore, did)
|
|
|
|
.iter()
|
|
|
|
.filter_map(|did| {
|
|
|
|
let did = did.def_id();
|
|
|
|
let impl_item = ty::impl_or_trait_item(tcx, did);
|
|
|
|
match impl_item {
|
|
|
|
ty::MethodTraitItem(method) => {
|
|
|
|
if method.vis != ast::Public && associated_trait.is_none() {
|
|
|
|
return None
|
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
let mut item = method.clean(cx);
|
2014-08-04 13:56:56 -07:00
|
|
|
item.inner = match item.inner.clone() {
|
|
|
|
clean::TyMethodItem(clean::TyMethod {
|
2015-02-06 00:51:38 -08:00
|
|
|
unsafety, decl, self_, generics, abi
|
2014-08-04 13:56:56 -07:00
|
|
|
}) => {
|
|
|
|
clean::MethodItem(clean::Method {
|
2014-12-09 10:36:46 -05:00
|
|
|
unsafety: unsafety,
|
2014-08-04 13:56:56 -07:00
|
|
|
decl: decl,
|
|
|
|
self_: self_,
|
|
|
|
generics: generics,
|
2015-02-06 00:51:38 -08:00
|
|
|
abi: abi
|
2014-08-04 13:56:56 -07:00
|
|
|
})
|
|
|
|
}
|
2014-10-09 15:17:22 -04:00
|
|
|
_ => panic!("not a tymethod"),
|
2014-08-04 13:56:56 -07:00
|
|
|
};
|
|
|
|
Some(item)
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2015-01-17 22:39:01 -08:00
|
|
|
ty::TypeTraitItem(ref assoc_ty) => {
|
|
|
|
let did = assoc_ty.def_id;
|
|
|
|
let type_scheme = ty::lookup_item_type(tcx, did);
|
2015-02-11 10:28:52 -05:00
|
|
|
let predicates = ty::lookup_predicates(tcx, did);
|
2015-01-17 22:39:01 -08:00
|
|
|
// Not sure the choice of ParamSpace actually matters here, because an
|
|
|
|
// associated type won't have generics on the LHS
|
2015-02-11 10:28:52 -05:00
|
|
|
let typedef = (type_scheme, predicates, subst::ParamSpace::TypeSpace).clean(cx);
|
2015-01-17 22:39:01 -08:00
|
|
|
Some(clean::Item {
|
|
|
|
name: Some(assoc_ty.name.clean(cx)),
|
|
|
|
inner: clean::TypedefItem(typedef),
|
|
|
|
source: clean::Span::empty(),
|
|
|
|
attrs: vec![],
|
|
|
|
visibility: None,
|
|
|
|
stability: stability::lookup(tcx, did).clean(cx),
|
|
|
|
def_id: did
|
|
|
|
})
|
2014-08-05 19:44:21 -07:00
|
|
|
}
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
2014-05-24 11:56:38 -07:00
|
|
|
}).collect();
|
2015-01-21 04:35:57 +00:00
|
|
|
let polarity = csearch::get_impl_polarity(tcx, did);
|
2014-07-25 08:26:17 -07:00
|
|
|
return Some(clean::Item {
|
2014-05-24 11:56:38 -07:00
|
|
|
inner: clean::ImplItem(clean::Impl {
|
2015-02-01 21:53:25 -05:00
|
|
|
derived: clean::detect_derived(&attrs),
|
2014-09-06 19:13:40 +03:00
|
|
|
trait_: associated_trait.clean(cx).map(|bound| {
|
2014-05-24 11:56:38 -07:00
|
|
|
match bound {
|
2014-12-24 22:34:57 +13:00
|
|
|
clean::TraitBound(polyt, _) => polyt.trait_,
|
2014-10-06 02:22:40 -07:00
|
|
|
clean::RegionBound(..) => unreachable!(),
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}),
|
2014-09-06 19:13:40 +03:00
|
|
|
for_: ty.ty.clean(cx),
|
2015-02-11 10:28:52 -05:00
|
|
|
generics: (&ty.generics, &predicates, subst::TypeSpace).clean(cx),
|
2014-08-04 13:56:56 -07:00
|
|
|
items: trait_items,
|
2015-01-21 04:35:57 +00:00
|
|
|
polarity: polarity.map(|p| { p.clean(cx) }),
|
2014-05-24 11:56:38 -07:00
|
|
|
}),
|
|
|
|
source: clean::Span::empty(),
|
|
|
|
name: None,
|
|
|
|
attrs: attrs,
|
|
|
|
visibility: Some(ast::Inherited),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: stability::lookup(tcx, did).clean(cx),
|
2014-05-24 11:56:38 -07:00
|
|
|
def_id: did,
|
2014-07-25 08:26:17 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
fn is_doc_hidden(a: &clean::Attribute) -> bool {
|
|
|
|
match *a {
|
2014-11-27 14:19:27 -05:00
|
|
|
clean::List(ref name, ref inner) if *name == "doc" => {
|
2014-07-25 08:26:17 -07:00
|
|
|
inner.iter().any(|a| {
|
|
|
|
match *a {
|
2014-11-27 14:19:27 -05:00
|
|
|
clean::Word(ref s) => *s == "hidden",
|
2014-07-25 08:26:17 -07:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
_ => false
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_module(cx: &DocContext, tcx: &ty::ctxt,
|
2014-05-24 11:56:38 -07:00
|
|
|
did: ast::DefId) -> clean::Module {
|
|
|
|
let mut items = Vec::new();
|
2014-07-25 10:37:23 -07:00
|
|
|
fill_in(cx, tcx, did, &mut items);
|
|
|
|
return clean::Module {
|
|
|
|
items: items,
|
|
|
|
is_crate: false,
|
|
|
|
};
|
2014-05-24 11:56:38 -07:00
|
|
|
|
|
|
|
// FIXME: this doesn't handle reexports inside the module itself.
|
|
|
|
// Should they be handled?
|
2014-09-06 19:13:40 +03:00
|
|
|
fn fill_in(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId,
|
2014-07-25 10:37:23 -07:00
|
|
|
items: &mut Vec<clean::Item>) {
|
|
|
|
csearch::each_child_of_item(&tcx.sess.cstore, did, |def, _, vis| {
|
|
|
|
match def {
|
|
|
|
decoder::DlDef(def::DefForeignMod(did)) => {
|
|
|
|
fill_in(cx, tcx, did, items);
|
|
|
|
}
|
|
|
|
decoder::DlDef(def) if vis == ast::Public => {
|
|
|
|
match try_inline_def(cx, tcx, def) {
|
2014-09-14 20:27:36 -07:00
|
|
|
Some(i) => items.extend(i.into_iter()),
|
2014-07-25 10:37:23 -07:00
|
|
|
None => {}
|
|
|
|
}
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-07-25 10:37:23 -07:00
|
|
|
decoder::DlDef(..) => {}
|
|
|
|
// All impls were inlined above
|
|
|
|
decoder::DlImpl(..) => {}
|
2014-10-09 15:17:22 -04:00
|
|
|
decoder::DlField => panic!("unimplemented field"),
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
2014-07-25 10:37:23 -07:00
|
|
|
});
|
2014-05-24 11:56:38 -07:00
|
|
|
}
|
|
|
|
}
|
2014-06-05 17:20:59 -07:00
|
|
|
|
2014-12-12 04:13:36 -08:00
|
|
|
fn build_const(cx: &DocContext, tcx: &ty::ctxt,
|
|
|
|
did: ast::DefId) -> clean::Constant {
|
|
|
|
use rustc::middle::const_eval;
|
|
|
|
use syntax::print::pprust;
|
|
|
|
|
|
|
|
let expr = const_eval::lookup_const_by_id(tcx, did).unwrap_or_else(|| {
|
2014-12-20 00:09:35 -08:00
|
|
|
panic!("expected lookup_const_by_id to succeed for {:?}", did);
|
2014-12-12 04:13:36 -08:00
|
|
|
});
|
2014-12-20 00:09:35 -08:00
|
|
|
debug!("converting constant expr {:?} to snippet", expr);
|
2014-12-12 04:13:36 -08:00
|
|
|
let sn = pprust::expr_to_string(expr);
|
|
|
|
debug!("got snippet {}", sn);
|
|
|
|
|
|
|
|
clean::Constant {
|
|
|
|
type_: ty::lookup_item_type(tcx, did).ty.clean(cx),
|
|
|
|
expr: sn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn build_static(cx: &DocContext, tcx: &ty::ctxt,
|
2014-06-05 17:20:59 -07:00
|
|
|
did: ast::DefId,
|
|
|
|
mutable: bool) -> clean::Static {
|
|
|
|
clean::Static {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: ty::lookup_item_type(tcx, did).ty.clean(cx),
|
2014-06-05 17:20:59 -07:00
|
|
|
mutability: if mutable {clean::Mutable} else {clean::Immutable},
|
|
|
|
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
|
|
|
|
}
|
|
|
|
}
|