2013-09-12 21:10:51 -04: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.
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
//! This module contains the "cleaned" pieces of the AST, and the functions
|
|
|
|
//! that clean them.
|
|
|
|
|
2014-11-06 00:05:53 -08:00
|
|
|
pub use self::ImplMethod::*;
|
|
|
|
pub use self::Type::*;
|
|
|
|
pub use self::PrimitiveType::*;
|
|
|
|
pub use self::TypeKind::*;
|
|
|
|
pub use self::StructField::*;
|
|
|
|
pub use self::VariantKind::*;
|
|
|
|
pub use self::Mutability::*;
|
|
|
|
pub use self::ViewItemInner::*;
|
|
|
|
pub use self::ViewPath::*;
|
|
|
|
pub use self::ItemEnum::*;
|
|
|
|
pub use self::Attribute::*;
|
|
|
|
pub use self::TyParamBound::*;
|
|
|
|
pub use self::SelfTy::*;
|
|
|
|
pub use self::FunctionRetTy::*;
|
|
|
|
pub use self::TraitMethod::*;
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
use syntax;
|
|
|
|
use syntax::ast;
|
2013-09-24 13:55:22 -07:00
|
|
|
use syntax::ast_util;
|
2014-07-14 16:31:52 -07:00
|
|
|
use syntax::ast_util::PostExpansionMethod;
|
2013-09-26 12:53:06 -07:00
|
|
|
use syntax::attr;
|
2014-05-22 22:00:18 -07:00
|
|
|
use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
2014-10-06 13:36:53 +13:00
|
|
|
use syntax::codemap::{DUMMY_SP, Pos, Spanned};
|
2014-01-08 10:35:15 -08:00
|
|
|
use syntax::parse::token::InternedString;
|
|
|
|
use syntax::parse::token;
|
2014-05-18 16:56:13 +03:00
|
|
|
use syntax::ptr::P;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-11-15 20:30:33 -05:00
|
|
|
use rustc_trans::back::link;
|
|
|
|
use rustc_trans::driver::driver;
|
2013-10-02 15:39:32 -07:00
|
|
|
use rustc::metadata::cstore;
|
|
|
|
use rustc::metadata::csearch;
|
|
|
|
use rustc::metadata::decoder;
|
2014-05-14 15:31:30 -04:00
|
|
|
use rustc::middle::def;
|
2014-05-13 11:35:42 -04:00
|
|
|
use rustc::middle::subst;
|
2014-05-31 18:53:13 -04:00
|
|
|
use rustc::middle::subst::VecPerParamSpace;
|
2014-05-03 02:08:58 -07:00
|
|
|
use rustc::middle::ty;
|
2014-06-26 11:37:39 -07:00
|
|
|
use rustc::middle::stability;
|
2013-10-02 15:39:32 -07:00
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
use std::rc::Rc;
|
2014-05-28 19:53:37 -07:00
|
|
|
use std::u32;
|
2014-11-06 00:05:53 -08:00
|
|
|
use std::str::Str as StrTrait; // Conflicts with Str variant
|
|
|
|
use std::char::Char as CharTrait; // Conflicts with Char variant
|
2013-10-02 15:39:32 -07:00
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
use core::DocContext;
|
2013-08-15 16:28:54 -04:00
|
|
|
use doctree;
|
|
|
|
use visit_ast;
|
|
|
|
|
2014-04-26 22:45:50 +09:00
|
|
|
/// A stable identifier to the particular version of JSON output.
|
|
|
|
/// Increment this when the `Crate` and related structures change.
|
2014-06-21 05:03:33 -07:00
|
|
|
pub static SCHEMA_VERSION: &'static str = "0.8.3";
|
2014-04-26 22:45:50 +09:00
|
|
|
|
2014-05-24 11:56:38 -07:00
|
|
|
mod inline;
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
// extract the stability index for a node from tcx, if possible
|
|
|
|
fn get_stability(cx: &DocContext, def_id: ast::DefId) -> Option<Stability> {
|
|
|
|
cx.tcx_opt().and_then(|tcx| stability::lookup(tcx, def_id)).clean(cx)
|
2014-06-26 11:37:39 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
pub trait Clean<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> T;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-02-28 17:46:09 -08:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for Vec<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<U> {
|
|
|
|
self.iter().map(|x| x.clean(cx)).collect()
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
impl<T: Clean<U>, U> Clean<VecPerParamSpace<U>> for VecPerParamSpace<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> VecPerParamSpace<U> {
|
|
|
|
self.map(|x| x.clean(cx))
|
2014-05-31 18:53:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-18 16:56:13 +03:00
|
|
|
impl<T: Clean<U>, U> Clean<U> for P<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> U {
|
|
|
|
(**self).clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
impl<T: Clean<U>, U> Clean<U> for Rc<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> U {
|
|
|
|
(**self).clean(cx)
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl<T: Clean<U>, U> Clean<Option<U>> for Option<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Option<U> {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
|
|
|
&None => None,
|
2014-09-06 19:13:40 +03:00
|
|
|
&Some(ref v) => Some(v.clean(cx))
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-20 01:52:37 +11:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for syntax::owned_slice::OwnedSlice<T> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<U> {
|
|
|
|
self.iter().map(|x| x.clean(cx)).collect()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Crate {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub module: Option<Item>,
|
|
|
|
pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
|
2014-09-11 17:07:49 +12:00
|
|
|
pub primitives: Vec<PrimitiveType>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Crate {
|
2014-03-05 15:28:08 -08:00
|
|
|
let mut externs = Vec::new();
|
2014-03-05 16:36:01 +02:00
|
|
|
cx.sess().cstore.iter_crate_data(|n, meta| {
|
2014-09-06 19:13:40 +03:00
|
|
|
externs.push((n, meta.clean(cx)));
|
2013-11-21 15:42:55 -08:00
|
|
|
});
|
2014-06-03 17:55:30 -07:00
|
|
|
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-05-28 19:53:37 -07:00
|
|
|
// Figure out the name of this crate
|
2014-05-02 16:15:12 -07:00
|
|
|
let input = driver::FileInput(cx.src.clone());
|
2014-07-05 12:37:43 -07:00
|
|
|
let name = link::find_crate_name(None, self.attrs.as_slice(), &input);
|
2014-05-28 19:53:37 -07:00
|
|
|
|
2014-05-29 13:50:47 -07:00
|
|
|
// Clean the crate, translating the entire libsyntax AST to one that is
|
2014-05-28 19:53:37 -07:00
|
|
|
// understood by rustdoc.
|
2014-09-06 19:13:40 +03:00
|
|
|
let mut module = self.module.clean(cx);
|
2014-05-28 19:53:37 -07:00
|
|
|
|
|
|
|
// Collect all inner modules which are tagged as implementations of
|
|
|
|
// primitives.
|
2014-05-29 13:50:47 -07:00
|
|
|
//
|
|
|
|
// Note that this loop only searches the top-level items of the crate,
|
|
|
|
// and this is intentional. If we were to search the entire crate for an
|
|
|
|
// item tagged with `#[doc(primitive)]` then we we would also have to
|
|
|
|
// search the entirety of external modules for items tagged
|
|
|
|
// `#[doc(primitive)]`, which is a pretty inefficient process (decoding
|
|
|
|
// all that metadata unconditionally).
|
|
|
|
//
|
|
|
|
// In order to keep the metadata load under control, the
|
|
|
|
// `#[doc(primitive)]` feature is explicitly designed to only allow the
|
|
|
|
// primitive tags to show up as the top level items in a crate.
|
|
|
|
//
|
|
|
|
// Also note that this does not attempt to deal with modules tagged
|
|
|
|
// duplicately for the same primitive. This is handled later on when
|
|
|
|
// rendering by delegating everything to a hash map.
|
2014-05-28 19:53:37 -07:00
|
|
|
let mut primitives = Vec::new();
|
|
|
|
{
|
|
|
|
let m = match module.inner {
|
|
|
|
ModuleItem(ref mut m) => m,
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
let mut tmp = Vec::new();
|
2014-09-14 20:27:36 -07:00
|
|
|
for child in m.items.iter_mut() {
|
2014-06-03 17:55:30 -07:00
|
|
|
let inner = match child.inner {
|
|
|
|
ModuleItem(ref mut m) => m,
|
2014-05-28 19:53:37 -07:00
|
|
|
_ => continue,
|
2014-06-03 17:55:30 -07:00
|
|
|
};
|
2014-09-11 17:07:49 +12:00
|
|
|
let prim = match PrimitiveType::find(child.attrs.as_slice()) {
|
2014-05-28 19:53:37 -07:00
|
|
|
Some(prim) => prim,
|
|
|
|
None => continue,
|
|
|
|
};
|
|
|
|
primitives.push(prim);
|
2014-06-03 17:55:30 -07:00
|
|
|
let mut i = Item {
|
2014-05-28 19:53:37 -07:00
|
|
|
source: Span::empty(),
|
|
|
|
name: Some(prim.to_url_str().to_string()),
|
2014-06-03 17:55:30 -07:00
|
|
|
attrs: Vec::new(),
|
|
|
|
visibility: None,
|
2014-06-26 11:37:39 -07:00
|
|
|
stability: None,
|
2014-05-28 19:53:37 -07:00
|
|
|
def_id: ast_util::local_def(prim.to_node_id()),
|
|
|
|
inner: PrimitiveItem(prim),
|
2014-06-03 17:55:30 -07:00
|
|
|
};
|
|
|
|
// Push one copy to get indexed for the whole crate, and push a
|
|
|
|
// another copy in the proper location which will actually get
|
|
|
|
// documented. The first copy will also serve as a redirect to
|
|
|
|
// the other copy.
|
|
|
|
tmp.push(i.clone());
|
|
|
|
i.visibility = Some(ast::Public);
|
|
|
|
i.attrs = child.attrs.clone();
|
|
|
|
inner.items.push(i);
|
|
|
|
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
2014-09-14 20:27:36 -07:00
|
|
|
m.items.extend(tmp.into_iter());
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
Crate {
|
2014-06-06 13:21:18 -07:00
|
|
|
name: name.to_string(),
|
2014-05-28 19:53:37 -07:00
|
|
|
module: Some(module),
|
2013-10-02 15:39:32 -07:00
|
|
|
externs: externs,
|
2014-05-28 19:53:37 -07:00
|
|
|
primitives: primitives,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ExternalCrate {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute>,
|
2014-09-11 17:07:49 +12:00
|
|
|
pub primitives: Vec<PrimitiveType>,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<ExternalCrate> for cstore::crate_metadata {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> ExternalCrate {
|
2014-05-28 19:53:37 -07:00
|
|
|
let mut primitives = Vec::new();
|
2014-09-06 19:13:40 +03:00
|
|
|
cx.tcx_opt().map(|tcx| {
|
2014-06-26 11:37:39 -07:00
|
|
|
csearch::each_top_level_item_of_crate(&tcx.sess.cstore,
|
|
|
|
self.cnum,
|
|
|
|
|def, _, _| {
|
|
|
|
let did = match def {
|
|
|
|
decoder::DlDef(def::DefMod(did)) => did,
|
|
|
|
_ => return
|
|
|
|
};
|
2014-09-06 19:13:40 +03:00
|
|
|
let attrs = inline::load_attrs(cx, tcx, did);
|
2014-09-11 17:07:49 +12:00
|
|
|
PrimitiveType::find(attrs.as_slice()).map(|prim| primitives.push(prim));
|
2014-06-26 11:37:39 -07:00
|
|
|
})
|
|
|
|
});
|
2013-10-02 15:39:32 -07:00
|
|
|
ExternalCrate {
|
2014-05-25 03:17:19 -07:00
|
|
|
name: self.name.to_string(),
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: decoder::get_crate_attributes(self.data()).clean(cx),
|
2014-05-28 19:53:37 -07:00
|
|
|
primitives: primitives,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Anything with a source location and set of attributes and, optionally, a
|
|
|
|
/// name. That is, anything that can be documented. This doesn't correspond
|
|
|
|
/// directly to the AST's concept of an item; it's a strict superset.
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Item {
|
|
|
|
/// Stringified span
|
2014-03-28 10:27:24 -07:00
|
|
|
pub source: Span,
|
2013-08-15 16:28:54 -04:00
|
|
|
/// Not everything has a name. E.g., impls
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: Option<String>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute> ,
|
|
|
|
pub inner: ItemEnum,
|
|
|
|
pub visibility: Option<Visibility>,
|
2014-05-03 02:08:58 -07:00
|
|
|
pub def_id: ast::DefId,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stability: Option<Stability>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
impl Item {
|
|
|
|
/// Finds the `doc` attribute as a List and returns the list of attributes
|
|
|
|
/// nested inside.
|
|
|
|
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
|
|
|
|
for attr in self.attrs.iter() {
|
|
|
|
match *attr {
|
2014-05-12 13:44:59 -07:00
|
|
|
List(ref x, ref list) if "doc" == x.as_slice() => {
|
|
|
|
return Some(list.as_slice());
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finds the `doc` attribute as a NameValue and returns the corresponding
|
|
|
|
/// value found.
|
|
|
|
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
|
|
|
|
for attr in self.attrs.iter() {
|
|
|
|
match *attr {
|
2014-05-12 13:44:59 -07:00
|
|
|
NameValue(ref x, ref v) if "doc" == x.as_slice() => {
|
|
|
|
return Some(v.as_slice());
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None;
|
|
|
|
}
|
|
|
|
|
2014-04-29 03:59:48 +09:00
|
|
|
pub fn is_hidden_from_doc(&self) -> bool {
|
|
|
|
match self.doc_list() {
|
|
|
|
Some(ref l) => {
|
|
|
|
for innerattr in l.iter() {
|
|
|
|
match *innerattr {
|
2014-05-12 13:44:59 -07:00
|
|
|
Word(ref s) if "hidden" == s.as_slice() => {
|
|
|
|
return true
|
|
|
|
}
|
2014-04-29 03:59:48 +09:00
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
None => ()
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_mod(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { ModuleItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_trait(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { TraitItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_struct(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { StructItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_enum(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { EnumItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_fn(&self) -> bool {
|
2013-11-28 12:22:53 -08:00
|
|
|
match self.inner { FunctionItem(..) => true, _ => false }
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ItemEnum {
|
|
|
|
StructItem(Struct),
|
|
|
|
EnumItem(Enum),
|
|
|
|
FunctionItem(Function),
|
|
|
|
ModuleItem(Module),
|
|
|
|
TypedefItem(Typedef),
|
|
|
|
StaticItem(Static),
|
2014-10-06 17:41:15 -07:00
|
|
|
ConstantItem(Constant),
|
2013-08-15 16:28:54 -04:00
|
|
|
TraitItem(Trait),
|
|
|
|
ImplItem(Impl),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `use` and `extern crate`
|
2013-08-15 16:28:54 -04:00
|
|
|
ViewItemItem(ViewItem),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// A method signature only. Used for required methods in traits (ie,
|
|
|
|
/// non-default-methods).
|
2013-08-15 16:28:54 -04:00
|
|
|
TyMethodItem(TyMethod),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// A method with a body.
|
2013-08-15 16:28:54 -04:00
|
|
|
MethodItem(Method),
|
|
|
|
StructFieldItem(StructField),
|
|
|
|
VariantItem(Variant),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `fn`s from an extern block
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignFunctionItem(Function),
|
2014-03-16 19:12:00 -04:00
|
|
|
/// `static`s from an extern block
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignStaticItem(Static),
|
2014-02-16 21:40:26 -08:00
|
|
|
MacroItem(Macro),
|
2014-09-11 17:07:49 +12:00
|
|
|
PrimitiveItem(PrimitiveType),
|
2014-08-05 19:44:21 -07:00
|
|
|
AssociatedTypeItem,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Module {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub items: Vec<Item>,
|
|
|
|
pub is_crate: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Module {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
let name = if self.name.is_some() {
|
2014-09-06 19:13:40 +03:00
|
|
|
self.name.unwrap().clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
} else {
|
2014-05-25 03:17:19 -07:00
|
|
|
"".to_string()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2014-03-05 15:28:08 -08:00
|
|
|
let mut foreigns = Vec::new();
|
2014-09-14 20:27:36 -07:00
|
|
|
for subforeigns in self.foreigns.clean(cx).into_iter() {
|
|
|
|
for foreign in subforeigns.into_iter() {
|
2014-02-28 17:46:09 -08:00
|
|
|
foreigns.push(foreign)
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 15:28:08 -08:00
|
|
|
let items: Vec<Vec<Item> > = vec!(
|
2014-09-06 19:13:40 +03:00
|
|
|
self.structs.clean(cx),
|
|
|
|
self.enums.clean(cx),
|
|
|
|
self.fns.clean(cx),
|
2014-02-28 17:46:09 -08:00
|
|
|
foreigns,
|
2014-09-06 19:13:40 +03:00
|
|
|
self.mods.clean(cx),
|
|
|
|
self.typedefs.clean(cx),
|
|
|
|
self.statics.clean(cx),
|
2014-10-06 17:41:15 -07:00
|
|
|
self.constants.clean(cx),
|
2014-09-06 19:13:40 +03:00
|
|
|
self.traits.clean(cx),
|
|
|
|
self.impls.clean(cx),
|
2014-09-14 20:27:36 -07:00
|
|
|
self.view_items.clean(cx).into_iter()
|
|
|
|
.flat_map(|s| s.into_iter()).collect(),
|
2014-09-06 19:13:40 +03:00
|
|
|
self.macros.clean(cx),
|
2014-03-05 15:28:08 -08:00
|
|
|
);
|
2014-04-27 05:08:36 +09:00
|
|
|
|
|
|
|
// determine if we should display the inner contents or
|
|
|
|
// the outer `mod` item for the source code.
|
2014-08-11 09:32:26 -07:00
|
|
|
let whence = {
|
2014-09-06 19:13:40 +03:00
|
|
|
let cm = cx.sess().codemap();
|
2014-04-27 05:08:36 +09:00
|
|
|
let outer = cm.lookup_char_pos(self.where_outer.lo);
|
|
|
|
let inner = cm.lookup_char_pos(self.where_inner.lo);
|
|
|
|
if outer.file.start_pos == inner.file.start_pos {
|
|
|
|
// mod foo { ... }
|
|
|
|
self.where_outer
|
|
|
|
} else {
|
|
|
|
// mod foo; (and a separate FileMap for the contents)
|
|
|
|
self.where_inner
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: Some(name),
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: whence.clean(cx),
|
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: ModuleItem(Module {
|
2014-02-28 22:33:45 +01:00
|
|
|
is_crate: self.is_crate,
|
2014-03-05 15:28:08 -08:00
|
|
|
items: items.iter()
|
|
|
|
.flat_map(|x| x.iter().map(|x| (*x).clone()))
|
|
|
|
.collect(),
|
2013-08-15 16:28:54 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Attribute {
|
2014-05-22 16:57:53 -07:00
|
|
|
Word(String),
|
|
|
|
List(String, Vec<Attribute> ),
|
|
|
|
NameValue(String, String)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Attribute> for ast::MetaItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Attribute {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self.node {
|
2014-05-25 03:17:19 -07:00
|
|
|
ast::MetaWord(ref s) => Word(s.get().to_string()),
|
2014-01-08 10:35:15 -08:00
|
|
|
ast::MetaList(ref s, ref l) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
List(s.get().to_string(), l.clean(cx))
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
|
|
|
ast::MetaNameValue(ref s, ref v) => {
|
2014-06-21 03:39:03 -07:00
|
|
|
NameValue(s.get().to_string(), lit_to_string(v))
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Attribute> for ast::Attribute {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Attribute {
|
2014-05-18 16:56:13 +03:00
|
|
|
self.with_desugared_doc(|a| a.node.value.clean(cx))
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:53:06 -07:00
|
|
|
// This is a rough approximation that gets us what we want.
|
2014-05-22 22:29:13 -07:00
|
|
|
impl attr::AttrMetaMethods for Attribute {
|
2014-01-08 10:35:15 -08:00
|
|
|
fn name(&self) -> InternedString {
|
2014-05-22 22:29:13 -07:00
|
|
|
match *self {
|
2014-01-08 10:35:15 -08:00
|
|
|
Word(ref n) | List(ref n, _) | NameValue(ref n, _) => {
|
2014-05-12 13:44:59 -07:00
|
|
|
token::intern_and_get_ident(n.as_slice())
|
2014-01-08 10:35:15 -08:00
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-10 14:02:36 -08:00
|
|
|
fn value_str(&self) -> Option<InternedString> {
|
2014-05-22 22:29:13 -07:00
|
|
|
match *self {
|
2014-05-12 13:44:59 -07:00
|
|
|
NameValue(_, ref v) => {
|
|
|
|
Some(token::intern_and_get_ident(v.as_slice()))
|
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2014-05-18 16:56:13 +03:00
|
|
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
2013-09-26 12:53:06 -07:00
|
|
|
}
|
2014-05-23 00:42:33 -07:00
|
|
|
impl<'a> attr::AttrMetaMethods for &'a Attribute {
|
|
|
|
fn name(&self) -> InternedString { (**self).name() }
|
|
|
|
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
|
2014-05-18 16:56:13 +03:00
|
|
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct TyParam {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-05-03 02:08:58 -07:00
|
|
|
pub did: ast::DefId,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub bounds: Vec<TyParamBound>,
|
2014-06-21 05:03:33 -07:00
|
|
|
pub default: Option<Type>
|
2014-03-28 10:27:24 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
impl Clean<TyParam> for ast::TyParam {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParam {
|
2013-08-15 16:28:54 -04:00
|
|
|
TyParam {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: self.ident.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
did: ast::DefId { krate: ast::LOCAL_CRATE, node: self.id },
|
2014-09-06 19:13:40 +03:00
|
|
|
bounds: self.bounds.clean(cx),
|
|
|
|
default: self.default.clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-03 02:08:58 -07:00
|
|
|
impl Clean<TyParam> for ty::TypeParameterDef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParam {
|
|
|
|
cx.external_typarams.borrow_mut().as_mut().unwrap()
|
2014-09-30 19:11:34 -05:00
|
|
|
.insert(self.def_id, self.name.clean(cx));
|
2014-05-03 02:08:58 -07:00
|
|
|
TyParam {
|
2014-09-30 19:11:34 -05:00
|
|
|
name: self.name.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
did: self.def_id,
|
2014-09-06 19:13:40 +03:00
|
|
|
bounds: self.bounds.clean(cx),
|
|
|
|
default: self.default.clean(cx)
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum TyParamBound {
|
2014-10-05 07:35:04 -07:00
|
|
|
RegionBound(Lifetime),
|
2013-08-15 16:28:54 -04:00
|
|
|
TraitBound(Type)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<TyParamBound> for ast::TyParamBound {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParamBound {
|
2013-08-15 16:28:54 -04:00
|
|
|
match *self {
|
2014-10-05 07:35:04 -07:00
|
|
|
ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)),
|
2014-09-06 19:13:40 +03:00
|
|
|
ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:46:52 -04:00
|
|
|
impl Clean<Vec<TyParamBound>> for ty::ExistentialBounds {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
|
2014-10-05 07:35:04 -07:00
|
|
|
let mut vec = vec![];
|
|
|
|
self.region_bound.clean(cx).map(|b| vec.push(RegionBound(b)));
|
2014-08-27 21:46:52 -04:00
|
|
|
for bb in self.builtin_bounds.iter() {
|
2014-09-06 19:13:40 +03:00
|
|
|
vec.push(bb.clean(cx));
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
vec
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn external_path(cx: &DocContext, name: &str, substs: &subst::Substs) -> Path {
|
2014-07-04 16:39:28 +02:00
|
|
|
let lifetimes = substs.regions().get_slice(subst::TypeSpace)
|
2014-05-31 18:53:13 -04:00
|
|
|
.iter()
|
2014-09-06 19:13:40 +03:00
|
|
|
.filter_map(|v| v.clean(cx))
|
2014-05-31 18:53:13 -04:00
|
|
|
.collect();
|
2014-09-17 12:56:31 -07:00
|
|
|
let types = substs.types.get_slice(subst::TypeSpace).to_vec();
|
2014-09-06 19:13:40 +03:00
|
|
|
let types = types.clean(cx);
|
2014-05-03 02:08:58 -07:00
|
|
|
Path {
|
|
|
|
global: false,
|
|
|
|
segments: vec![PathSegment {
|
2014-05-25 03:17:19 -07:00
|
|
|
name: name.to_string(),
|
2014-05-31 18:53:13 -04:00
|
|
|
lifetimes: lifetimes,
|
|
|
|
types: types,
|
2014-05-28 23:14:08 -07:00
|
|
|
}],
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<TyParamBound> for ty::BuiltinBound {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParamBound {
|
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
2014-10-06 02:22:40 -07:00
|
|
|
None => return RegionBound(Lifetime::statik())
|
2014-05-03 02:08:58 -07:00
|
|
|
};
|
2014-05-13 11:35:42 -04:00
|
|
|
let empty = subst::Substs::empty();
|
2014-05-03 02:08:58 -07:00
|
|
|
let (did, path) = match *self {
|
|
|
|
ty::BoundSend =>
|
2014-05-28 23:14:08 -07:00
|
|
|
(tcx.lang_items.send_trait().unwrap(),
|
2014-09-06 19:13:40 +03:00
|
|
|
external_path(cx, "Send", &empty)),
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::BoundSized =>
|
2014-05-28 23:14:08 -07:00
|
|
|
(tcx.lang_items.sized_trait().unwrap(),
|
2014-09-06 19:13:40 +03:00
|
|
|
external_path(cx, "Sized", &empty)),
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::BoundCopy =>
|
2014-05-28 23:14:08 -07:00
|
|
|
(tcx.lang_items.copy_trait().unwrap(),
|
2014-09-06 19:13:40 +03:00
|
|
|
external_path(cx, "Copy", &empty)),
|
2014-08-05 16:40:04 -07:00
|
|
|
ty::BoundSync =>
|
|
|
|
(tcx.lang_items.sync_trait().unwrap(),
|
2014-09-06 19:13:40 +03:00
|
|
|
external_path(cx, "Sync", &empty)),
|
2014-05-03 02:08:58 -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, TypeTrait));
|
2014-05-03 02:08:58 -07:00
|
|
|
TraitBound(ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: None,
|
|
|
|
did: did,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<TyParamBound> for ty::TraitRef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParamBound {
|
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
2014-10-06 02:22:40 -07:00
|
|
|
None => return RegionBound(Lifetime::statik())
|
2014-05-03 02:08:58 -07:00
|
|
|
};
|
|
|
|
let fqn = csearch::get_item_path(tcx, self.def_id);
|
2014-09-14 20:27:36 -07:00
|
|
|
let fqn = fqn.into_iter().map(|i| i.to_string())
|
2014-05-22 16:57:53 -07:00
|
|
|
.collect::<Vec<String>>();
|
2014-09-06 19:13:40 +03:00
|
|
|
let path = external_path(cx, fqn.last().unwrap().as_slice(),
|
2014-05-28 23:14:08 -07:00
|
|
|
&self.substs);
|
2014-08-18 17:52:38 -07:00
|
|
|
cx.external_paths.borrow_mut().as_mut().unwrap().insert(self.def_id,
|
2014-05-03 02:08:58 -07:00
|
|
|
(fqn, TypeTrait));
|
|
|
|
TraitBound(ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: None,
|
|
|
|
did: self.def_id,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Vec<TyParamBound>> for ty::ParamBounds {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
|
2014-05-03 02:08:58 -07:00
|
|
|
let mut v = Vec::new();
|
|
|
|
for b in self.builtin_bounds.iter() {
|
|
|
|
if b != ty::BoundSized {
|
2014-09-06 19:13:40 +03:00
|
|
|
v.push(b.clean(cx));
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for t in self.trait_bounds.iter() {
|
2014-09-06 19:13:40 +03:00
|
|
|
v.push(t.clean(cx));
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
2014-10-06 06:11:21 -07:00
|
|
|
for r in self.region_bounds.iter().filter_map(|r| r.clean(cx)) {
|
|
|
|
v.push(RegionBound(r));
|
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
return v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-13 11:35:42 -04:00
|
|
|
impl Clean<Option<Vec<TyParamBound>>> for subst::Substs {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
|
2014-05-03 02:08:58 -07:00
|
|
|
let mut v = Vec::new();
|
2014-10-05 07:35:04 -07:00
|
|
|
v.extend(self.regions().iter().filter_map(|r| r.clean(cx)).map(RegionBound));
|
2014-09-06 19:13:40 +03:00
|
|
|
v.extend(self.types.iter().map(|t| TraitBound(t.clean(cx))));
|
2014-05-03 02:08:58 -07:00
|
|
|
if v.len() > 0 {Some(v)} else {None}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 17:45:07 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2014-05-22 16:57:53 -07:00
|
|
|
pub struct Lifetime(String);
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2013-11-01 18:06:31 -07:00
|
|
|
impl Lifetime {
|
|
|
|
pub fn get_ref<'a>(&'a self) -> &'a str {
|
|
|
|
let Lifetime(ref s) = *self;
|
2014-05-12 13:44:59 -07:00
|
|
|
let s: &'a str = s.as_slice();
|
2013-11-01 18:06:31 -07:00
|
|
|
return s;
|
|
|
|
}
|
2014-10-05 07:35:04 -07:00
|
|
|
|
|
|
|
pub fn statik() -> Lifetime {
|
|
|
|
Lifetime("'static".to_string())
|
|
|
|
}
|
2013-11-01 18:06:31 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl Clean<Lifetime> for ast::Lifetime {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Lifetime {
|
2014-05-25 03:17:19 -07:00
|
|
|
Lifetime(token::get_name(self.name).get().to_string())
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-05 22:59:24 -04:00
|
|
|
impl Clean<Lifetime> for ast::LifetimeDef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Lifetime {
|
2014-08-05 22:59:24 -04:00
|
|
|
Lifetime(token::get_name(self.lifetime.name).get().to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-03 02:08:58 -07:00
|
|
|
impl Clean<Lifetime> for ty::RegionParameterDef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Lifetime {
|
2014-05-25 03:17:19 -07:00
|
|
|
Lifetime(token::get_name(self.name).get().to_string())
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Option<Lifetime>> for ty::Region {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Option<Lifetime> {
|
2014-05-03 02:08:58 -07:00
|
|
|
match *self {
|
2014-10-05 07:35:04 -07:00
|
|
|
ty::ReStatic => Some(Lifetime::statik()),
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::ReLateBound(_, ty::BrNamed(_, name)) =>
|
2014-05-25 03:17:19 -07:00
|
|
|
Some(Lifetime(token::get_name(name).get().to_string())),
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::ReEarlyBound(_, _, _, name) => Some(Lifetime(name.clean(cx))),
|
2014-05-03 02:08:58 -07:00
|
|
|
|
|
|
|
ty::ReLateBound(..) |
|
|
|
|
ty::ReFree(..) |
|
|
|
|
ty::ReScope(..) |
|
|
|
|
ty::ReInfer(..) |
|
|
|
|
ty::ReEmpty(..) => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 02:01:42 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
|
|
|
pub struct WherePredicate {
|
|
|
|
pub name: String,
|
|
|
|
pub bounds: Vec<TyParamBound>
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<WherePredicate> for ast::WherePredicate {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
WherePredicate {
|
|
|
|
name: self.ident.clean(cx),
|
|
|
|
bounds: self.bounds.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
// maybe use a Generic enum and use ~[Generic]?
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Generics {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub type_params: Vec<TyParam>,
|
2014-09-25 02:01:42 -07:00
|
|
|
pub where_predicates: Vec<WherePredicate>
|
2014-03-28 10:27:24 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
|
|
|
impl Clean<Generics> for ast::Generics {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Generics {
|
2013-08-15 16:28:54 -04:00
|
|
|
Generics {
|
2014-09-06 19:13:40 +03:00
|
|
|
lifetimes: self.lifetimes.clean(cx),
|
|
|
|
type_params: self.ty_params.clean(cx),
|
2014-09-25 02:01:42 -07:00
|
|
|
where_predicates: self.where_clause.predicates.clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-25 09:07:20 -07:00
|
|
|
impl<'a> Clean<Generics> for (&'a ty::Generics, subst::ParamSpace) {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Generics {
|
2014-07-25 09:07:20 -07:00
|
|
|
let (me, space) = *self;
|
2014-05-03 02:08:58 -07:00
|
|
|
Generics {
|
2014-09-17 12:56:31 -07:00
|
|
|
type_params: me.types.get_slice(space).to_vec().clean(cx),
|
|
|
|
lifetimes: me.regions.get_slice(space).to_vec().clean(cx),
|
2014-09-25 02:01:42 -07:00
|
|
|
where_predicates: vec![]
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Method {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub self_: SelfTy,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::Method {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-07-14 16:31:52 -07:00
|
|
|
let all_inputs = &self.pe_fn_decl().inputs;
|
|
|
|
let inputs = match self.pe_explicit_self().node {
|
|
|
|
ast::SelfStatic => all_inputs.as_slice(),
|
2014-09-24 23:41:09 +12:00
|
|
|
_ => all_inputs[1..]
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
2014-09-06 19:13:40 +03:00
|
|
|
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
2014-02-13 06:41:34 +11:00
|
|
|
},
|
2014-11-09 16:14:15 +01:00
|
|
|
output: self.pe_fn_decl().output.clean(cx),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.pe_ident().clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2014-06-26 11:37:39 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.pe_vis().clean(cx),
|
|
|
|
stability: get_stability(cx, ast_util::local_def(self.id)),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: MethodItem(Method {
|
2014-09-06 19:13:40 +03:00
|
|
|
generics: self.pe_generics().clean(cx),
|
|
|
|
self_: self.pe_explicit_self().node.clean(cx),
|
2014-07-14 16:31:52 -07:00
|
|
|
fn_style: self.pe_fn_style().clone(),
|
2014-01-27 14:18:36 +02:00
|
|
|
decl: decl,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct TyMethod {
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub self_: SelfTy,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for ast::TypeMethod {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-01-27 14:18:36 +02:00
|
|
|
let inputs = match self.explicit_self.node {
|
|
|
|
ast::SelfStatic => self.decl.inputs.as_slice(),
|
2014-09-24 23:41:09 +12:00
|
|
|
_ => self.decl.inputs[1..]
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
2014-09-06 19:13:40 +03:00
|
|
|
values: inputs.iter().map(|x| x.clean(cx)).collect(),
|
2014-02-13 06:41:34 +11:00
|
|
|
},
|
2014-11-09 16:14:15 +01:00
|
|
|
output: self.decl.output.clean(cx),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.ident.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2013-08-15 16:28:54 -04:00
|
|
|
visibility: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, ast_util::local_def(self.id)),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: TyMethodItem(TyMethod {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style.clone(),
|
2014-01-27 14:18:36 +02:00
|
|
|
decl: decl,
|
2014-09-06 19:13:40 +03:00
|
|
|
self_: self.explicit_self.node.clean(cx),
|
|
|
|
generics: self.generics.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 17:45:07 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum SelfTy {
|
|
|
|
SelfStatic,
|
|
|
|
SelfValue,
|
|
|
|
SelfBorrowed(Option<Lifetime>, Mutability),
|
2014-05-06 16:37:32 -07:00
|
|
|
SelfExplicit(Type),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-03 02:08:58 -07:00
|
|
|
impl Clean<SelfTy> for ast::ExplicitSelf_ {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> SelfTy {
|
2014-05-03 02:08:58 -07:00
|
|
|
match *self {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::SelfStatic => SelfStatic,
|
2014-07-06 15:10:57 -07:00
|
|
|
ast::SelfValue(_) => SelfValue,
|
2014-05-18 16:56:13 +03:00
|
|
|
ast::SelfRegion(ref lt, ref mt, _) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
SelfBorrowed(lt.clean(cx), mt.clean(cx))
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|
2014-05-18 16:56:13 +03:00
|
|
|
ast::SelfExplicit(ref typ, _) => SelfExplicit(typ.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Function {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Function {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: FunctionItem(Function {
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: self.decl.clean(cx),
|
|
|
|
generics: self.generics.clean(cx),
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct ClosureDecl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub decl: FnDecl,
|
|
|
|
pub onceness: ast::Onceness,
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub bounds: Vec<TyParamBound>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ClosureDecl> for ast::ClosureTy {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> ClosureDecl {
|
2013-08-15 16:28:54 -04:00
|
|
|
ClosureDecl {
|
2014-09-06 19:13:40 +03:00
|
|
|
lifetimes: self.lifetimes.clean(cx),
|
|
|
|
decl: self.decl.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
onceness: self.onceness,
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2014-09-06 19:13:40 +03:00
|
|
|
bounds: self.bounds.clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct FnDecl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub inputs: Arguments,
|
2014-11-09 16:14:15 +01:00
|
|
|
pub output: FunctionRetTy,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2014-02-13 06:41:34 +11:00
|
|
|
pub struct Arguments {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub values: Vec<Argument>,
|
2014-02-13 06:41:34 +11:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<FnDecl> for ast::FnDecl {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> FnDecl {
|
2013-08-15 16:28:54 -04:00
|
|
|
FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
2014-09-06 19:13:40 +03:00
|
|
|
values: self.inputs.clean(cx),
|
2014-02-13 06:41:34 +11:00
|
|
|
},
|
2014-09-06 19:13:40 +03:00
|
|
|
output: self.output.clean(cx),
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-24 21:14:37 +02:00
|
|
|
impl<'a> Clean<Type> for ty::FnOutput {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
|
|
|
match *self {
|
|
|
|
ty::FnConverging(ty) => ty.clean(cx),
|
|
|
|
ty::FnDiverging => Bottom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 18:47:01 -07:00
|
|
|
impl<'a> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig) {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> FnDecl {
|
2014-05-23 18:47:01 -07:00
|
|
|
let (did, sig) = *self;
|
|
|
|
let mut names = if did.node != 0 {
|
2014-09-14 20:27:36 -07:00
|
|
|
csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).into_iter()
|
2014-05-23 18:47:01 -07:00
|
|
|
} else {
|
2014-09-14 20:27:36 -07:00
|
|
|
Vec::new().into_iter()
|
2014-05-23 18:47:01 -07:00
|
|
|
}.peekable();
|
|
|
|
if names.peek().map(|s| s.as_slice()) == Some("self") {
|
|
|
|
let _ = names.next();
|
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
FnDecl {
|
2014-11-09 16:14:15 +01:00
|
|
|
output: Return(sig.output.clean(cx)),
|
2014-05-23 18:47:01 -07:00
|
|
|
attrs: Vec::new(),
|
2014-05-03 02:08:58 -07:00
|
|
|
inputs: Arguments {
|
2014-05-23 18:47:01 -07:00
|
|
|
values: sig.inputs.iter().map(|t| {
|
2014-05-03 02:08:58 -07:00
|
|
|
Argument {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: t.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
id: 0,
|
2014-05-25 03:17:19 -07:00
|
|
|
name: names.next().unwrap_or("".to_string()),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}).collect(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Argument {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub id: ast::NodeId,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Argument> for ast::Arg {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Argument {
|
2013-08-15 16:28:54 -04:00
|
|
|
Argument {
|
2014-05-16 10:15:33 -07:00
|
|
|
name: name_from_pat(&*self.pat),
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: (self.ty.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
id: self.id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2014-11-09 16:14:15 +01:00
|
|
|
pub enum FunctionRetTy {
|
|
|
|
Return(Type),
|
|
|
|
NoReturn
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-11-09 16:14:15 +01:00
|
|
|
impl Clean<FunctionRetTy> for ast::FunctionRetTy {
|
|
|
|
fn clean(&self, cx: &DocContext) -> FunctionRetTy {
|
2013-08-15 16:28:54 -04:00
|
|
|
match *self {
|
2014-11-09 16:14:15 +01:00
|
|
|
ast::Return(ref typ) => Return(typ.clean(cx)),
|
|
|
|
ast::NoReturn(_) => NoReturn
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Trait {
|
2014-09-11 17:07:49 +12:00
|
|
|
pub items: Vec<TraitMethod>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
2014-08-27 21:46:52 -04:00
|
|
|
pub bounds: Vec<TyParamBound>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Trait {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: TraitItem(Trait {
|
2014-09-06 19:13:40 +03:00
|
|
|
items: self.items.clean(cx),
|
|
|
|
generics: self.generics.clean(cx),
|
|
|
|
bounds: self.bounds.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Type> for ast::TraitRef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
|
|
|
resolve_type(cx, self.path.clean(cx), None, self.ref_id)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-07 06:53:45 -05:00
|
|
|
impl Clean<Type> for ast::PolyTraitRef {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
|
|
|
self.trait_ref.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
2014-09-11 17:07:49 +12:00
|
|
|
pub enum TraitMethod {
|
2014-08-04 13:56:56 -07:00
|
|
|
RequiredMethod(Item),
|
|
|
|
ProvidedMethod(Item),
|
2014-08-05 19:44:21 -07:00
|
|
|
TypeTraitItem(Item),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
impl TraitMethod {
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_req(&self) -> bool {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2014-08-04 13:56:56 -07:00
|
|
|
&RequiredMethod(..) => true,
|
2013-08-15 16:28:54 -04:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_def(&self) -> bool {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2014-08-04 13:56:56 -07:00
|
|
|
&ProvidedMethod(..) => true,
|
2013-08-15 16:28:54 -04:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn item<'a>(&'a self) -> &'a Item {
|
|
|
|
match *self {
|
2014-08-04 13:56:56 -07:00
|
|
|
RequiredMethod(ref item) => item,
|
|
|
|
ProvidedMethod(ref item) => item,
|
2014-08-05 19:44:21 -07:00
|
|
|
TypeTraitItem(ref item) => item,
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
impl Clean<TraitMethod> for ast::TraitItem {
|
|
|
|
fn clean(&self, cx: &DocContext) -> TraitMethod {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2014-09-06 19:13:40 +03:00
|
|
|
&ast::RequiredMethod(ref t) => RequiredMethod(t.clean(cx)),
|
|
|
|
&ast::ProvidedMethod(ref t) => ProvidedMethod(t.clean(cx)),
|
2014-08-05 19:44:21 -07:00
|
|
|
&ast::TypeTraitItem(ref t) => TypeTraitItem(t.clean(cx)),
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
2014-09-11 17:07:49 +12:00
|
|
|
pub enum ImplMethod {
|
2014-08-04 13:56:56 -07:00
|
|
|
MethodImplItem(Item),
|
2014-08-05 19:44:21 -07:00
|
|
|
TypeImplItem(Item),
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
impl Clean<ImplMethod> for ast::ImplItem {
|
|
|
|
fn clean(&self, cx: &DocContext) -> ImplMethod {
|
2014-08-04 13:56:56 -07:00
|
|
|
match self {
|
2014-09-06 19:13:40 +03:00
|
|
|
&ast::MethodImplItem(ref t) => MethodImplItem(t.clean(cx)),
|
2014-08-05 19:44:21 -07:00
|
|
|
&ast::TypeImplItem(ref t) => TypeImplItem(t.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-02 00:09:44 -07:00
|
|
|
impl Clean<Item> for ty::Method {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-05-03 02:08:58 -07:00
|
|
|
let (self_, sig) = match self.explicit_self {
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(cx),
|
2014-07-25 09:31:20 -07:00
|
|
|
self.fty.sig.clone()),
|
2014-05-03 02:08:58 -07:00
|
|
|
s => {
|
|
|
|
let sig = ty::FnSig {
|
2014-09-24 23:41:09 +12:00
|
|
|
inputs: self.fty.sig.inputs[1..].to_vec(),
|
2014-05-03 02:08:58 -07:00
|
|
|
..self.fty.sig.clone()
|
|
|
|
};
|
|
|
|
let s = match s {
|
2014-07-25 09:31:20 -07:00
|
|
|
ty::ByValueExplicitSelfCategory => SelfValue,
|
2014-05-06 16:37:32 -07:00
|
|
|
ty::ByReferenceExplicitSelfCategory(..) => {
|
2014-10-31 10:51:16 +02:00
|
|
|
match self.fty.sig.inputs[0].sty {
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::ty_rptr(r, mt) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
SelfBorrowed(r.clean(cx), mt.mutbl.clean(cx))
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
_ => unreachable!(),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
ty::ByBoxExplicitSelfCategory => {
|
2014-09-06 19:13:40 +03:00
|
|
|
SelfExplicit(self.fty.sig.inputs[0].clean(cx))
|
2014-05-06 16:37:32 -07:00
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
ty::StaticExplicitSelfCategory => unreachable!(),
|
2014-05-03 02:08:58 -07:00
|
|
|
};
|
|
|
|
(s, sig)
|
|
|
|
}
|
|
|
|
};
|
2014-05-23 17:13:44 -07:00
|
|
|
|
2014-06-02 00:09:44 -07:00
|
|
|
Item {
|
2014-09-30 19:11:34 -05:00
|
|
|
name: Some(self.name.clean(cx)),
|
2014-05-03 02:08:58 -07:00
|
|
|
visibility: Some(ast::Inherited),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, self.def_id),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: self.def_id,
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
|
2014-05-23 00:42:33 -07:00
|
|
|
source: Span::empty(),
|
2014-05-03 02:08:58 -07:00
|
|
|
inner: TyMethodItem(TyMethod {
|
|
|
|
fn_style: self.fty.fn_style,
|
2014-09-06 19:13:40 +03:00
|
|
|
generics: (&self.generics, subst::FnSpace).clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
self_: self_,
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: (self.def_id, &sig).clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
})
|
2014-06-02 00:09:44 -07:00
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-04 13:56:56 -07:00
|
|
|
impl Clean<Item> for ty::ImplOrTraitItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-08-04 13:56:56 -07:00
|
|
|
match *self {
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::MethodTraitItem(ref mti) => mti.clean(cx),
|
2014-08-05 19:44:21 -07:00
|
|
|
ty::TypeTraitItem(ref tti) => tti.clean(cx),
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
/// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
|
|
|
|
/// type out of the AST/ty::ctxt given one of these, if more information is needed. Most importantly
|
|
|
|
/// it does not preserve mutability or boxes.
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Type {
|
2014-01-09 15:05:33 +02:00
|
|
|
/// structs/enums/traits (anything that'd be an ast::TyPath)
|
2013-09-27 18:23:57 -07:00
|
|
|
ResolvedPath {
|
2014-11-15 17:57:54 -08:00
|
|
|
path: Path,
|
|
|
|
typarams: Option<Vec<TyParamBound>>,
|
|
|
|
did: ast::DefId,
|
2013-09-27 18:23:57 -07:00
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
// I have no idea how to usefully use this.
|
|
|
|
TyParamBinder(ast::NodeId),
|
|
|
|
/// For parameterized types, so the consumer of the JSON don't go looking
|
|
|
|
/// for types which don't exist anywhere.
|
2014-05-03 02:08:58 -07:00
|
|
|
Generic(ast::DefId),
|
2013-08-15 16:28:54 -04:00
|
|
|
/// For references to self
|
2014-05-03 02:08:58 -07:00
|
|
|
Self(ast::DefId),
|
2013-08-15 16:28:54 -04:00
|
|
|
/// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
|
2014-09-11 17:07:49 +12:00
|
|
|
Primitive(PrimitiveType),
|
2014-08-27 21:46:52 -04:00
|
|
|
Closure(Box<ClosureDecl>),
|
2014-05-05 18:56:44 -07:00
|
|
|
Proc(Box<ClosureDecl>),
|
2013-08-15 16:28:54 -04:00
|
|
|
/// extern "ABI" fn
|
2014-05-05 18:56:44 -07:00
|
|
|
BareFunction(Box<BareFunctionDecl>),
|
2014-04-19 22:24:52 -07:00
|
|
|
Tuple(Vec<Type>),
|
2014-05-05 18:56:44 -07:00
|
|
|
Vector(Box<Type>),
|
2014-05-22 16:57:53 -07:00
|
|
|
FixedVector(Box<Type>, String),
|
2014-01-09 22:25:09 +02:00
|
|
|
/// aka TyBot
|
2013-08-15 16:28:54 -04:00
|
|
|
Bottom,
|
2014-05-05 18:56:44 -07:00
|
|
|
Unique(Box<Type>),
|
|
|
|
RawPointer(Mutability, Box<Type>),
|
2014-03-28 10:27:24 -07:00
|
|
|
BorrowedRef {
|
2014-11-15 17:57:54 -08:00
|
|
|
lifetime: Option<Lifetime>,
|
|
|
|
mutability: Mutability,
|
|
|
|
type_: Box<Type>,
|
2014-03-28 10:27:24 -07:00
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
// region, raw, other boxes, mutable
|
|
|
|
}
|
|
|
|
|
2014-06-03 17:55:30 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)]
|
2014-09-11 17:07:49 +12:00
|
|
|
pub enum PrimitiveType {
|
2014-05-28 19:53:37 -07:00
|
|
|
Int, I8, I16, I32, I64,
|
|
|
|
Uint, U8, U16, U32, U64,
|
2014-06-24 16:34:46 -07:00
|
|
|
F32, F64,
|
2014-05-28 19:53:37 -07:00
|
|
|
Char,
|
|
|
|
Bool,
|
|
|
|
Str,
|
|
|
|
Slice,
|
|
|
|
PrimitiveTuple,
|
|
|
|
}
|
|
|
|
|
2013-10-02 15:39:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum TypeKind {
|
|
|
|
TypeEnum,
|
|
|
|
TypeFunction,
|
2014-05-09 13:52:17 -07:00
|
|
|
TypeModule,
|
|
|
|
TypeStatic,
|
|
|
|
TypeStruct,
|
|
|
|
TypeTrait,
|
|
|
|
TypeVariant,
|
2014-09-16 09:13:00 +12:00
|
|
|
TypeTypedef,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
impl PrimitiveType {
|
|
|
|
fn from_str(s: &str) -> Option<PrimitiveType> {
|
2014-05-28 19:53:37 -07:00
|
|
|
match s.as_slice() {
|
|
|
|
"int" => Some(Int),
|
|
|
|
"i8" => Some(I8),
|
|
|
|
"i16" => Some(I16),
|
|
|
|
"i32" => Some(I32),
|
|
|
|
"i64" => Some(I64),
|
|
|
|
"uint" => Some(Uint),
|
|
|
|
"u8" => Some(U8),
|
|
|
|
"u16" => Some(U16),
|
|
|
|
"u32" => Some(U32),
|
|
|
|
"u64" => Some(U64),
|
|
|
|
"bool" => Some(Bool),
|
|
|
|
"char" => Some(Char),
|
|
|
|
"str" => Some(Str),
|
|
|
|
"f32" => Some(F32),
|
|
|
|
"f64" => Some(F64),
|
|
|
|
"slice" => Some(Slice),
|
|
|
|
"tuple" => Some(PrimitiveTuple),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
|
2014-05-28 19:53:37 -07:00
|
|
|
for attr in attrs.iter() {
|
|
|
|
let list = match *attr {
|
|
|
|
List(ref k, ref l) if k.as_slice() == "doc" => l,
|
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
for sub_attr in list.iter() {
|
|
|
|
let value = match *sub_attr {
|
|
|
|
NameValue(ref k, ref v)
|
|
|
|
if k.as_slice() == "primitive" => v.as_slice(),
|
|
|
|
_ => continue,
|
|
|
|
};
|
2014-09-11 17:07:49 +12:00
|
|
|
match PrimitiveType::from_str(value) {
|
2014-05-28 19:53:37 -07:00
|
|
|
Some(p) => return Some(p),
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return None
|
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
pub fn to_string(&self) -> &'static str {
|
2014-05-28 19:53:37 -07:00
|
|
|
match *self {
|
|
|
|
Int => "int",
|
|
|
|
I8 => "i8",
|
|
|
|
I16 => "i16",
|
|
|
|
I32 => "i32",
|
|
|
|
I64 => "i64",
|
|
|
|
Uint => "uint",
|
|
|
|
U8 => "u8",
|
|
|
|
U16 => "u16",
|
|
|
|
U32 => "u32",
|
|
|
|
U64 => "u64",
|
|
|
|
F32 => "f32",
|
|
|
|
F64 => "f64",
|
|
|
|
Str => "str",
|
|
|
|
Bool => "bool",
|
|
|
|
Char => "char",
|
|
|
|
Slice => "slice",
|
|
|
|
PrimitiveTuple => "tuple",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_url_str(&self) -> &'static str {
|
2014-11-09 16:14:15 +01:00
|
|
|
self.to_string()
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl Clean<Type> for ast::Ty {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
2013-08-15 16:28:54 -04:00
|
|
|
use syntax::ast::*;
|
2013-09-24 13:53:09 -07:00
|
|
|
match self.node {
|
2014-09-06 19:13:40 +03:00
|
|
|
TyPtr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
|
2014-01-09 22:25:09 +02:00
|
|
|
TyRptr(ref l, ref m) =>
|
2014-09-06 19:13:40 +03:00
|
|
|
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
|
|
|
|
type_: box m.ty.clean(cx)},
|
2014-05-18 16:56:13 +03:00
|
|
|
TyVec(ref ty) => Vector(box ty.clean(cx)),
|
|
|
|
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
|
|
|
|
e.span.to_src(cx)),
|
2014-09-06 19:13:40 +03:00
|
|
|
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
2014-02-28 17:46:09 -08:00
|
|
|
TyPath(ref p, ref tpbs, id) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
resolve_type(cx, p.clean(cx), tpbs.clean(cx), id)
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
TyClosure(ref c) => Closure(box c.clean(cx)),
|
|
|
|
TyProc(ref c) => Proc(box c.clean(cx)),
|
|
|
|
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
|
|
|
|
TyParen(ref ty) => ty.clean(cx),
|
2014-10-09 15:17:22 -04:00
|
|
|
ref x => panic!("Unimplemented type {}", x),
|
2013-09-24 13:53:09 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-13 21:09:25 +03:00
|
|
|
impl Clean<Type> for Ty {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
2014-10-31 10:51:16 +02:00
|
|
|
match self.sty {
|
2014-05-28 19:53:37 -07:00
|
|
|
ty::ty_bool => Primitive(Bool),
|
|
|
|
ty::ty_char => Primitive(Char),
|
|
|
|
ty::ty_int(ast::TyI) => Primitive(Int),
|
|
|
|
ty::ty_int(ast::TyI8) => Primitive(I8),
|
|
|
|
ty::ty_int(ast::TyI16) => Primitive(I16),
|
|
|
|
ty::ty_int(ast::TyI32) => Primitive(I32),
|
|
|
|
ty::ty_int(ast::TyI64) => Primitive(I64),
|
|
|
|
ty::ty_uint(ast::TyU) => Primitive(Uint),
|
|
|
|
ty::ty_uint(ast::TyU8) => Primitive(U8),
|
|
|
|
ty::ty_uint(ast::TyU16) => Primitive(U16),
|
|
|
|
ty::ty_uint(ast::TyU32) => Primitive(U32),
|
|
|
|
ty::ty_uint(ast::TyU64) => Primitive(U64),
|
|
|
|
ty::ty_float(ast::TyF32) => Primitive(F32),
|
|
|
|
ty::ty_float(ast::TyF64) => Primitive(F64),
|
|
|
|
ty::ty_str => Primitive(Str),
|
2014-07-25 09:31:20 -07:00
|
|
|
ty::ty_uniq(t) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
let box_did = cx.tcx_opt().and_then(|tcx| {
|
2014-07-25 09:31:20 -07:00
|
|
|
tcx.lang_items.owned_box()
|
|
|
|
});
|
2014-09-06 19:13:40 +03:00
|
|
|
lang_struct(cx, box_did, t, "Box", Unique)
|
2014-07-25 09:31:20 -07:00
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::ty_vec(ty, None) => Vector(box ty.clean(cx)),
|
|
|
|
ty::ty_vec(ty, Some(i)) => FixedVector(box ty.clean(cx),
|
2014-05-27 20:44:58 -07:00
|
|
|
format!("{}", i)),
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::ty_ptr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::ty_rptr(r, mt) => BorrowedRef {
|
2014-09-06 19:13:40 +03:00
|
|
|
lifetime: r.clean(cx),
|
|
|
|
mutability: mt.mutbl.clean(cx),
|
|
|
|
type_: box mt.ty.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
},
|
|
|
|
ty::ty_bare_fn(ref fty) => BareFunction(box BareFunctionDecl {
|
|
|
|
fn_style: fty.fn_style,
|
|
|
|
generics: Generics {
|
2014-09-25 02:01:42 -07:00
|
|
|
lifetimes: Vec::new(),
|
|
|
|
type_params: Vec::new(),
|
|
|
|
where_predicates: Vec::new()
|
2014-05-03 02:08:58 -07:00
|
|
|
},
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: (ast_util::local_def(0), &fty.sig).clean(cx),
|
2014-06-21 03:39:03 -07:00
|
|
|
abi: fty.abi.to_string(),
|
2014-05-03 02:08:58 -07:00
|
|
|
}),
|
|
|
|
ty::ty_closure(ref fty) => {
|
|
|
|
let decl = box ClosureDecl {
|
|
|
|
lifetimes: Vec::new(), // FIXME: this looks wrong...
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: (ast_util::local_def(0), &fty.sig).clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
onceness: fty.onceness,
|
|
|
|
fn_style: fty.fn_style,
|
2014-09-06 19:13:40 +03:00
|
|
|
bounds: fty.bounds.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
};
|
|
|
|
match fty.store {
|
|
|
|
ty::UniqTraitStore => Proc(decl),
|
2014-08-27 21:46:52 -04:00
|
|
|
ty::RegionTraitStore(..) => Closure(decl),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ty::ty_struct(did, ref substs) |
|
|
|
|
ty::ty_enum(did, ref substs) |
|
2014-11-07 06:53:45 -05:00
|
|
|
ty::ty_trait(box ty::TyTrait { principal: ty::TraitRef { def_id: did, ref substs },
|
|
|
|
.. }) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
let fqn = csearch::get_item_path(cx.tcx(), did);
|
2014-09-14 20:27:36 -07:00
|
|
|
let fqn: Vec<String> = fqn.into_iter().map(|i| {
|
2014-06-21 03:39:03 -07:00
|
|
|
i.to_string()
|
2014-05-03 02:08:58 -07:00
|
|
|
}).collect();
|
2014-10-31 10:51:16 +02:00
|
|
|
let kind = match self.sty {
|
2014-05-03 02:08:58 -07:00
|
|
|
ty::ty_struct(..) => TypeStruct,
|
|
|
|
ty::ty_trait(..) => TypeTrait,
|
|
|
|
_ => TypeEnum,
|
|
|
|
};
|
2014-09-06 19:13:40 +03:00
|
|
|
let path = external_path(cx, fqn.last().unwrap().to_string().as_slice(),
|
2014-05-28 19:53:37 -07:00
|
|
|
substs);
|
2014-09-06 19:13:40 +03:00
|
|
|
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, kind));
|
2014-05-03 02:08:58 -07:00
|
|
|
ResolvedPath {
|
2014-05-28 19:53:37 -07:00
|
|
|
path: path,
|
2014-05-03 02:08:58 -07:00
|
|
|
typarams: None,
|
|
|
|
did: did,
|
|
|
|
}
|
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
ty::ty_tup(ref t) => Tuple(t.clean(cx)),
|
2014-05-03 02:08:58 -07:00
|
|
|
|
2014-05-31 18:53:13 -04:00
|
|
|
ty::ty_param(ref p) => {
|
|
|
|
if p.space == subst::SelfSpace {
|
|
|
|
Self(p.def_id)
|
|
|
|
} else {
|
|
|
|
Generic(p.def_id)
|
|
|
|
}
|
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
|
2014-11-09 16:14:15 +01:00
|
|
|
ty::ty_unboxed_closure(..) => Tuple(vec![]), // FIXME(pcwalton)
|
2014-05-28 22:26:56 -07:00
|
|
|
|
2014-10-09 15:17:22 -04:00
|
|
|
ty::ty_infer(..) => panic!("ty_infer"),
|
|
|
|
ty::ty_open(..) => panic!("ty_open"),
|
|
|
|
ty::ty_err => panic!("ty_err"),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
2014-04-19 22:24:52 -07:00
|
|
|
pub enum StructField {
|
2014-04-29 03:59:48 +09:00
|
|
|
HiddenStructField, // inserted later by strip passes
|
2014-04-19 22:24:52 -07:00
|
|
|
TypedStructField(Type),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::StructField {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
let (name, vis) = match self.node.kind {
|
2014-04-19 22:24:52 -07:00
|
|
|
ast::NamedField(id, vis) => (Some(id), vis),
|
|
|
|
ast::UnnamedField(vis) => (None, vis)
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: name.clean(cx),
|
|
|
|
attrs: self.node.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2014-04-19 22:24:52 -07:00
|
|
|
visibility: Some(vis),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, ast_util::local_def(self.node.id)),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.node.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
inner: StructFieldItem(TypedStructField(self.node.ty.clean(cx))),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
impl Clean<Item> for ty::field_ty {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-05-23 00:42:33 -07:00
|
|
|
use syntax::parse::token::special_idents::unnamed_field;
|
2014-07-26 13:21:36 -07:00
|
|
|
use rustc::metadata::csearch;
|
|
|
|
|
|
|
|
let attr_map = csearch::get_struct_field_attrs(&cx.tcx().sess.cstore, self.id);
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
let (name, attrs) = if self.name == unnamed_field.name {
|
|
|
|
(None, None)
|
2014-05-23 00:42:33 -07:00
|
|
|
} else {
|
2014-11-06 12:25:16 -05:00
|
|
|
(Some(self.name), Some(attr_map.get(&self.id.node).unwrap()))
|
2014-05-23 00:42:33 -07:00
|
|
|
};
|
2014-07-26 13:21:36 -07:00
|
|
|
|
2014-06-26 11:37:39 -07:00
|
|
|
let ty = ty::lookup_item_type(cx.tcx(), self.id);
|
2014-07-26 13:21:36 -07:00
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: name.clean(cx),
|
|
|
|
attrs: attrs.unwrap_or(&Vec::new()).clean(cx),
|
2014-05-23 00:42:33 -07:00
|
|
|
source: Span::empty(),
|
|
|
|
visibility: Some(self.vis),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, self.id),
|
2014-05-23 00:42:33 -07:00
|
|
|
def_id: self.id,
|
2014-09-06 19:13:40 +03:00
|
|
|
inner: StructFieldItem(TypedStructField(ty.ty.clean(cx))),
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
pub type Visibility = ast::Visibility;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Option<Visibility>> for ast::Visibility {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
2013-08-15 16:28:54 -04:00
|
|
|
Some(*self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Struct {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub struct_type: doctree::StructType,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub fields: Vec<Item>,
|
|
|
|
pub fields_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Struct {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: StructItem(Struct {
|
|
|
|
struct_type: self.struct_type,
|
2014-09-06 19:13:40 +03:00
|
|
|
generics: self.generics.clean(cx),
|
|
|
|
fields: self.fields.clean(cx),
|
2013-10-13 20:37:43 -07:00
|
|
|
fields_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-06 16:35:12 +09:00
|
|
|
/// This is a more limited form of the standard Struct, different in that
|
2013-08-15 16:28:54 -04:00
|
|
|
/// it lacks the things most items have (name, id, parameterization). Found
|
|
|
|
/// only as a variant in an enum.
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct VariantStruct {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub struct_type: doctree::StructType,
|
|
|
|
pub fields: Vec<Item>,
|
|
|
|
pub fields_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<VariantStruct> for syntax::ast::StructDef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> VariantStruct {
|
2013-08-15 16:28:54 -04:00
|
|
|
VariantStruct {
|
|
|
|
struct_type: doctree::struct_type_from_def(self),
|
2014-09-06 19:13:40 +03:00
|
|
|
fields: self.fields.clean(cx),
|
2013-10-13 20:37:43 -07:00
|
|
|
fields_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Enum {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub variants: Vec<Item>,
|
|
|
|
pub generics: Generics,
|
|
|
|
pub variants_stripped: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Enum {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: EnumItem(Enum {
|
2014-09-06 19:13:40 +03:00
|
|
|
variants: self.variants.clean(cx),
|
|
|
|
generics: self.generics.clean(cx),
|
2013-10-13 20:37:43 -07:00
|
|
|
variants_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Variant {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub kind: VariantKind,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Variant {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: VariantItem(Variant {
|
2014-09-06 19:13:40 +03:00
|
|
|
kind: self.kind.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-23 16:14:54 -07:00
|
|
|
impl Clean<Item> for ty::VariantInfo {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-05-23 16:14:54 -07:00
|
|
|
// use syntax::parse::token::special_idents::unnamed_field;
|
|
|
|
let kind = match self.arg_names.as_ref().map(|s| s.as_slice()) {
|
|
|
|
None | Some([]) if self.args.len() == 0 => CLikeVariant,
|
|
|
|
None | Some([]) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
TupleVariant(self.args.clean(cx))
|
2014-05-23 16:14:54 -07:00
|
|
|
}
|
|
|
|
Some(s) => {
|
|
|
|
StructVariant(VariantStruct {
|
|
|
|
struct_type: doctree::Plain,
|
|
|
|
fields_stripped: false,
|
|
|
|
fields: s.iter().zip(self.args.iter()).map(|(name, ty)| {
|
|
|
|
Item {
|
|
|
|
source: Span::empty(),
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(name.clean(cx)),
|
2014-05-23 16:14:54 -07:00
|
|
|
attrs: Vec::new(),
|
|
|
|
visibility: Some(ast::Public),
|
2014-05-24 11:56:38 -07:00
|
|
|
// FIXME: this is not accurate, we need an id for
|
|
|
|
// the specific field but we're using the id
|
2014-07-10 11:17:40 -07:00
|
|
|
// for the whole variant. Thus we read the
|
|
|
|
// stability from the whole variant as well.
|
|
|
|
// Struct variants are experimental and need
|
|
|
|
// more infrastructure work before we can get
|
|
|
|
// at the needed information here.
|
2014-05-24 11:56:38 -07:00
|
|
|
def_id: self.id,
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, self.id),
|
2014-05-23 16:14:54 -07:00
|
|
|
inner: StructFieldItem(
|
2014-09-06 19:13:40 +03:00
|
|
|
TypedStructField(ty.clean(cx))
|
2014-05-23 16:14:54 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}).collect()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: inline::load_attrs(cx, cx.tcx(), self.id),
|
2014-05-23 16:14:54 -07:00
|
|
|
source: Span::empty(),
|
|
|
|
visibility: Some(ast::Public),
|
|
|
|
def_id: self.id,
|
|
|
|
inner: VariantItem(Variant { kind: kind }),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, self.id),
|
2014-05-23 16:14:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum VariantKind {
|
|
|
|
CLikeVariant,
|
2014-04-19 22:24:52 -07:00
|
|
|
TupleVariant(Vec<Type>),
|
2013-08-15 16:28:54 -04:00
|
|
|
StructVariant(VariantStruct),
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<VariantKind> for ast::VariantKind {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> VariantKind {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2014-01-09 15:05:33 +02:00
|
|
|
&ast::TupleVariantKind(ref args) => {
|
2013-08-15 16:28:54 -04:00
|
|
|
if args.len() == 0 {
|
|
|
|
CLikeVariant
|
|
|
|
} else {
|
2014-09-06 19:13:40 +03:00
|
|
|
TupleVariant(args.iter().map(|x| x.ty.clean(cx)).collect())
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
},
|
2014-09-06 19:13:40 +03:00
|
|
|
&ast::StructVariantKind(ref sd) => StructVariant(sd.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 03:20:39 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable, Show)]
|
2013-09-27 15:12:23 -07:00
|
|
|
pub struct Span {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub filename: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub loline: uint,
|
|
|
|
pub locol: uint,
|
|
|
|
pub hiline: uint,
|
|
|
|
pub hicol: uint,
|
2013-09-27 15:12:23 -07:00
|
|
|
}
|
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
impl Span {
|
|
|
|
fn empty() -> Span {
|
|
|
|
Span {
|
2014-05-25 03:17:19 -07:00
|
|
|
filename: "".to_string(),
|
2014-05-23 00:42:33 -07:00
|
|
|
loline: 0, locol: 0,
|
|
|
|
hiline: 0, hicol: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 15:12:23 -07:00
|
|
|
impl Clean<Span> for syntax::codemap::Span {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Span {
|
|
|
|
let cm = cx.sess().codemap();
|
2013-09-27 15:12:23 -07:00
|
|
|
let filename = cm.span_to_filename(*self);
|
|
|
|
let lo = cm.lookup_char_pos(self.lo);
|
|
|
|
let hi = cm.lookup_char_pos(self.hi);
|
|
|
|
Span {
|
2014-05-25 03:17:19 -07:00
|
|
|
filename: filename.to_string(),
|
2013-09-27 15:12:23 -07:00
|
|
|
loline: lo.line,
|
2013-11-01 18:06:31 -07:00
|
|
|
locol: lo.col.to_uint(),
|
2013-09-27 15:12:23 -07:00
|
|
|
hiline: hi.line,
|
2013-11-01 18:06:31 -07:00
|
|
|
hicol: hi.col.to_uint(),
|
2013-09-27 15:12:23 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Path {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub global: bool,
|
|
|
|
pub segments: Vec<PathSegment>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Path> for ast::Path {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Path {
|
2013-08-15 16:28:54 -04:00
|
|
|
Path {
|
2013-09-12 15:11:06 -04:00
|
|
|
global: self.global,
|
2014-09-06 19:13:40 +03:00
|
|
|
segments: self.segments.clean(cx),
|
2013-09-12 15:11:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-09-12 15:11:06 -04:00
|
|
|
pub struct PathSegment {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub lifetimes: Vec<Lifetime>,
|
|
|
|
pub types: Vec<Type>,
|
2013-09-12 15:11:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<PathSegment> for ast::PathSegment {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> PathSegment {
|
2014-11-03 21:52:52 -05:00
|
|
|
let (lifetimes, types) = match self.parameters {
|
|
|
|
ast::AngleBracketedParameters(ref data) => {
|
|
|
|
(data.lifetimes.clean(cx), data.types.clean(cx))
|
|
|
|
}
|
|
|
|
|
|
|
|
ast::ParenthesizedParameters(ref data) => {
|
|
|
|
// FIXME -- rustdoc should be taught about Foo() notation
|
|
|
|
let inputs = Tuple(data.inputs.clean(cx));
|
|
|
|
let output = data.output.as_ref().map(|t| t.clean(cx)).unwrap_or(Tuple(Vec::new()));
|
|
|
|
(Vec::new(), vec![inputs, output])
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-12 15:11:06 -04:00
|
|
|
PathSegment {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: self.identifier.clean(cx),
|
2014-11-03 21:52:52 -05:00
|
|
|
lifetimes: lifetimes,
|
|
|
|
types: types,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
fn path_to_string(p: &ast::Path) -> String {
|
2014-05-22 16:57:53 -07:00
|
|
|
let mut s = String::new();
|
2013-08-15 16:28:54 -04:00
|
|
|
let mut first = true;
|
2014-02-14 07:07:09 +02:00
|
|
|
for i in p.segments.iter().map(|x| token::get_ident(x.identifier)) {
|
2013-08-15 16:28:54 -04:00
|
|
|
if !first || p.global {
|
|
|
|
s.push_str("::");
|
|
|
|
} else {
|
|
|
|
first = false;
|
|
|
|
}
|
2014-02-02 02:53:26 +11:00
|
|
|
s.push_str(i.get());
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-05-12 13:44:59 -07:00
|
|
|
s
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
impl Clean<String> for ast::Ident {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> String {
|
2014-05-25 03:17:19 -07:00
|
|
|
token::get_ident(*self).get().to_string()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-24 11:56:38 -07:00
|
|
|
impl Clean<String> for ast::Name {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> String {
|
2014-05-25 03:17:19 -07:00
|
|
|
token::get_name(*self).get().to_string()
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Typedef {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
|
|
|
pub generics: Generics,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Typedef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id.clone()),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: TypedefItem(Typedef {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: self.ty.clean(cx),
|
|
|
|
generics: self.gen.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:37:32 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct BareFunctionDecl {
|
2014-04-06 18:04:40 -07:00
|
|
|
pub fn_style: ast::FnStyle,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub decl: FnDecl,
|
2014-05-22 16:57:53 -07:00
|
|
|
pub abi: String,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<BareFunctionDecl> for ast::BareFnTy {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> BareFunctionDecl {
|
2013-08-15 16:28:54 -04:00
|
|
|
BareFunctionDecl {
|
2014-04-06 18:04:40 -07:00
|
|
|
fn_style: self.fn_style,
|
2013-08-15 16:28:54 -04:00
|
|
|
generics: Generics {
|
2014-09-06 19:13:40 +03:00
|
|
|
lifetimes: self.lifetimes.clean(cx),
|
2014-03-05 15:28:08 -08:00
|
|
|
type_params: Vec::new(),
|
2014-09-25 02:01:42 -07:00
|
|
|
where_predicates: Vec::new()
|
2013-08-15 16:28:54 -04:00
|
|
|
},
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: self.decl.clean(cx),
|
2014-06-21 03:39:03 -07:00
|
|
|
abi: self.abi.to_string(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 03:20:39 -04:00
|
|
|
#[deriving(Clone, Encodable, Decodable, Show)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Static {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub type_: Type,
|
|
|
|
pub mutability: Mutability,
|
2013-08-15 16:28:54 -04:00
|
|
|
/// It's useful to have the value of a static documented, but I have no
|
|
|
|
/// desire to represent expressions (that'd basically be all of the AST,
|
|
|
|
/// which is huge!). So, have a string.
|
2014-05-22 16:57:53 -07:00
|
|
|
pub expr: String,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Static {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-10-15 03:20:39 -04:00
|
|
|
debug!("claning static {}: {}", self.name.clean(cx), self);
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: StaticItem(Static {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: self.type_.clean(cx),
|
|
|
|
mutability: self.mutability.clean(cx),
|
|
|
|
expr: self.expr.span.to_src(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-06 17:41:15 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Constant {
|
|
|
|
pub type_: Type,
|
|
|
|
pub expr: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Constant {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
|
|
|
def_id: ast_util::local_def(self.id),
|
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
|
|
|
inner: ConstantItem(Constant {
|
|
|
|
type_: self.type_.clean(cx),
|
|
|
|
expr: self.expr.span.to_src(cx),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 17:45:07 -07:00
|
|
|
#[deriving(Show, Clone, Encodable, Decodable, PartialEq)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Mutability {
|
|
|
|
Mutable,
|
|
|
|
Immutable,
|
|
|
|
}
|
|
|
|
|
2013-09-05 10:14:35 -04:00
|
|
|
impl Clean<Mutability> for ast::Mutability {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Mutability {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2013-09-05 10:14:35 -04:00
|
|
|
&ast::MutMutable => Mutable,
|
|
|
|
&ast::MutImmutable => Immutable,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Impl {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub trait_: Option<Type>,
|
|
|
|
pub for_: Type,
|
2014-08-04 13:56:56 -07:00
|
|
|
pub items: Vec<Item>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub derived: bool,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-23 00:42:33 -07:00
|
|
|
fn detect_derived<M: AttrMetaMethods>(attrs: &[M]) -> bool {
|
2014-05-24 11:56:38 -07:00
|
|
|
attr::contains_name(attrs, "automatically_derived")
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
impl Clean<Item> for doctree::Impl {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
|
|
|
name: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: ImplItem(Impl {
|
2014-09-06 19:13:40 +03:00
|
|
|
generics: self.generics.clean(cx),
|
|
|
|
trait_: self.trait_.clean(cx),
|
|
|
|
for_: self.for_.clean(cx),
|
2014-09-14 20:27:36 -07:00
|
|
|
items: self.items.clean(cx).into_iter().map(|ti| {
|
2014-08-04 13:56:56 -07:00
|
|
|
match ti {
|
|
|
|
MethodImplItem(i) => i,
|
2014-08-05 19:44:21 -07:00
|
|
|
TypeImplItem(i) => i,
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
|
|
|
}).collect(),
|
2014-05-23 00:42:33 -07:00
|
|
|
derived: detect_derived(self.attrs.as_slice()),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ViewItem {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub inner: ViewItemInner,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-05-22 22:00:18 -07:00
|
|
|
impl Clean<Vec<Item>> for ast::ViewItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<Item> {
|
2014-07-02 21:27:07 -04:00
|
|
|
// We consider inlining the documentation of `pub use` statements, but we
|
2014-05-24 11:56:38 -07:00
|
|
|
// forcefully don't inline if this is not public or if the
|
|
|
|
// #[doc(no_inline)] attribute is present.
|
2014-05-22 22:00:18 -07:00
|
|
|
let denied = self.vis != ast::Public || self.attrs.iter().any(|a| {
|
|
|
|
a.name().get() == "doc" && match a.meta_item_list() {
|
2014-05-24 11:56:38 -07:00
|
|
|
Some(l) => attr::contains_name(l, "no_inline"),
|
2014-05-22 22:00:18 -07:00
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let convert = |node: &ast::ViewItem_| {
|
|
|
|
Item {
|
|
|
|
name: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2014-05-22 22:00:18 -07:00
|
|
|
def_id: ast_util::local_def(0),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
2014-06-26 11:37:39 -07:00
|
|
|
stability: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
inner: ViewItemItem(ViewItem { inner: node.clean(cx) }),
|
2014-05-22 22:00:18 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
match self.node {
|
|
|
|
ast::ViewItemUse(ref path) if !denied => {
|
|
|
|
match path.node {
|
|
|
|
ast::ViewPathGlob(..) => ret.push(convert(&self.node)),
|
|
|
|
ast::ViewPathList(ref a, ref list, ref b) => {
|
2014-05-24 11:56:38 -07:00
|
|
|
// Attempt to inline all reexported items, but be sure
|
|
|
|
// to keep any non-inlineable reexports so they can be
|
|
|
|
// listed in the documentation.
|
2014-05-22 22:00:18 -07:00
|
|
|
let remaining = list.iter().filter(|path| {
|
2014-09-06 19:13:40 +03:00
|
|
|
match inline::try_inline(cx, path.node.id(), None) {
|
2014-05-23 00:42:33 -07:00
|
|
|
Some(items) => {
|
2014-09-14 20:27:36 -07:00
|
|
|
ret.extend(items.into_iter()); false
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
2014-05-22 22:00:18 -07:00
|
|
|
None => true,
|
|
|
|
}
|
2014-07-18 00:56:56 +02:00
|
|
|
}).map(|a| a.clone()).collect::<Vec<ast::PathListItem>>();
|
2014-05-22 22:00:18 -07:00
|
|
|
if remaining.len() > 0 {
|
|
|
|
let path = ast::ViewPathList(a.clone(),
|
|
|
|
remaining,
|
|
|
|
b.clone());
|
|
|
|
let path = syntax::codemap::dummy_spanned(path);
|
2014-05-18 16:56:13 +03:00
|
|
|
ret.push(convert(&ast::ViewItemUse(P(path))));
|
2014-05-22 22:00:18 -07:00
|
|
|
}
|
|
|
|
}
|
2014-07-25 10:16:41 -07:00
|
|
|
ast::ViewPathSimple(ident, _, id) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
match inline::try_inline(cx, id, Some(ident)) {
|
2014-09-14 20:27:36 -07:00
|
|
|
Some(items) => ret.extend(items.into_iter()),
|
2014-05-22 22:00:18 -07:00
|
|
|
None => ret.push(convert(&self.node)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ref n => ret.push(convert(n)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2014-05-22 22:00:18 -07:00
|
|
|
return ret;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ViewItemInner {
|
2014-05-22 16:57:53 -07:00
|
|
|
ExternCrate(String, Option<String>, ast::NodeId),
|
2014-04-26 22:33:45 +09:00
|
|
|
Import(ViewPath)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ViewItemInner> for ast::ViewItem_ {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> ViewItemInner {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2014-03-07 15:57:45 +08:00
|
|
|
&ast::ViewItemExternCrate(ref i, ref p, ref id) => {
|
2014-01-21 10:08:10 -08:00
|
|
|
let string = match *p {
|
|
|
|
None => None,
|
2014-05-25 03:17:19 -07:00
|
|
|
Some((ref x, _)) => Some(x.get().to_string()),
|
2014-01-21 10:08:10 -08:00
|
|
|
};
|
2014-09-06 19:13:40 +03:00
|
|
|
ExternCrate(i.clean(cx), string, *id)
|
2014-01-21 10:08:10 -08:00
|
|
|
}
|
2014-02-28 17:46:09 -08:00
|
|
|
&ast::ViewItemUse(ref vp) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
Import(vp.clean(cx))
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub enum ViewPath {
|
2013-09-24 13:56:52 -07:00
|
|
|
// use str = source;
|
2014-05-22 16:57:53 -07:00
|
|
|
SimpleImport(String, ImportSource),
|
2013-09-24 13:56:52 -07:00
|
|
|
// use source::*;
|
|
|
|
GlobImport(ImportSource),
|
|
|
|
// use source::{a, b, c};
|
2014-05-09 13:52:17 -07:00
|
|
|
ImportList(ImportSource, Vec<ViewListIdent>),
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ImportSource {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub path: Path,
|
|
|
|
pub did: Option<ast::DefId>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<ViewPath> for ast::ViewPath {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> ViewPath {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self.node {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ViewPathSimple(ref i, ref p, id) =>
|
2014-09-06 19:13:40 +03:00
|
|
|
SimpleImport(i.clean(cx), resolve_use_source(cx, p.clean(cx), id)),
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ViewPathGlob(ref p, id) =>
|
2014-09-06 19:13:40 +03:00
|
|
|
GlobImport(resolve_use_source(cx, p.clean(cx), id)),
|
2014-02-28 17:46:09 -08:00
|
|
|
ast::ViewPathList(ref p, ref pl, id) => {
|
2014-09-06 19:13:40 +03:00
|
|
|
ImportList(resolve_use_source(cx, p.clean(cx), id),
|
|
|
|
pl.clean(cx))
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-24 13:56:52 -07:00
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct ViewListIdent {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub source: Option<ast::DefId>,
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-07-18 00:56:56 +02:00
|
|
|
impl Clean<ViewListIdent> for ast::PathListItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> ViewListIdent {
|
2014-07-18 00:56:56 +02:00
|
|
|
match self.node {
|
|
|
|
ast::PathListIdent { id, name } => ViewListIdent {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: name.clean(cx),
|
|
|
|
source: resolve_def(cx, id)
|
2014-07-18 00:56:56 +02:00
|
|
|
},
|
|
|
|
ast::PathListMod { id } => ViewListIdent {
|
|
|
|
name: "mod".to_string(),
|
2014-09-06 19:13:40 +03:00
|
|
|
source: resolve_def(cx, id)
|
2014-07-18 00:56:56 +02:00
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 17:46:09 -08:00
|
|
|
impl Clean<Vec<Item>> for ast::ForeignMod {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<Item> {
|
|
|
|
self.items.clean(cx)
|
2013-09-26 11:57:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-09 15:05:33 +02:00
|
|
|
impl Clean<Item> for ast::ForeignItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-09-26 11:57:25 -07:00
|
|
|
let inner = match self.node {
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ForeignItemFn(ref decl, ref generics) => {
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignFunctionItem(Function {
|
2014-09-06 19:13:40 +03:00
|
|
|
decl: decl.clean(cx),
|
|
|
|
generics: generics.clean(cx),
|
2014-05-14 16:33:15 -07:00
|
|
|
fn_style: ast::UnsafeFn,
|
2013-09-26 11:57:25 -07:00
|
|
|
})
|
|
|
|
}
|
2014-01-09 15:05:33 +02:00
|
|
|
ast::ForeignItemStatic(ref ty, mutbl) => {
|
2013-09-26 11:57:25 -07:00
|
|
|
ForeignStaticItem(Static {
|
2014-09-06 19:13:40 +03:00
|
|
|
type_: ty.clean(cx),
|
2013-09-26 11:57:25 -07:00
|
|
|
mutability: if mutbl {Mutable} else {Immutable},
|
2014-05-25 03:17:19 -07:00
|
|
|
expr: "".to_string(),
|
2013-09-26 11:57:25 -07:00
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(self.ident.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: get_stability(cx, ast_util::local_def(self.id)),
|
2013-09-26 11:57:25 -07:00
|
|
|
inner: inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
// Utilities
|
|
|
|
|
|
|
|
trait ToSource {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn to_src(&self, cx: &DocContext) -> String;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2013-09-05 10:14:35 -04:00
|
|
|
impl ToSource for syntax::codemap::Span {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn to_src(&self, cx: &DocContext) -> String {
|
2014-10-15 03:20:39 -04:00
|
|
|
debug!("converting span {} to snippet", self.clean(cx));
|
2014-09-06 19:13:40 +03:00
|
|
|
let sn = match cx.sess().codemap().span_to_snippet(*self) {
|
2014-05-25 03:17:19 -07:00
|
|
|
Some(x) => x.to_string(),
|
|
|
|
None => "".to_string()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2013-10-21 13:08:31 -07:00
|
|
|
debug!("got snippet {}", sn);
|
2013-08-15 16:28:54 -04:00
|
|
|
sn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-21 03:39:03 -07:00
|
|
|
fn lit_to_string(lit: &ast::Lit) -> String {
|
2013-08-15 16:28:54 -04:00
|
|
|
match lit.node {
|
2014-05-25 03:17:19 -07:00
|
|
|
ast::LitStr(ref st, _) => st.get().to_string(),
|
2014-10-15 03:20:39 -04:00
|
|
|
ast::LitBinary(ref data) => format!("{}", data),
|
2014-06-06 16:04:04 +01:00
|
|
|
ast::LitByte(b) => {
|
|
|
|
let mut res = String::from_str("b'");
|
|
|
|
(b as char).escape_default(|c| {
|
2014-09-22 08:28:35 -07:00
|
|
|
res.push(c);
|
2014-06-06 16:04:04 +01:00
|
|
|
});
|
2014-09-22 08:28:35 -07:00
|
|
|
res.push('\'');
|
2014-06-06 16:04:04 +01:00
|
|
|
res
|
|
|
|
},
|
2014-05-27 20:44:58 -07:00
|
|
|
ast::LitChar(c) => format!("'{}'", c),
|
2014-06-21 03:39:03 -07:00
|
|
|
ast::LitInt(i, _t) => i.to_string(),
|
2014-05-25 03:17:19 -07:00
|
|
|
ast::LitFloat(ref f, _t) => f.get().to_string(),
|
|
|
|
ast::LitFloatUnsuffixed(ref f) => f.get().to_string(),
|
2014-06-21 03:39:03 -07:00
|
|
|
ast::LitBool(b) => b.to_string(),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 16:57:53 -07:00
|
|
|
fn name_from_pat(p: &ast::Pat) -> String {
|
2013-08-15 16:28:54 -04:00
|
|
|
use syntax::ast::*;
|
2014-10-15 03:20:39 -04:00
|
|
|
debug!("Trying to get a name from pattern: {}", p);
|
2013-12-29 00:13:29 -05:00
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
match p.node {
|
2014-08-06 17:04:44 +02:00
|
|
|
PatWild(PatWildSingle) => "_".to_string(),
|
|
|
|
PatWild(PatWildMulti) => "..".to_string(),
|
2014-06-30 18:02:14 -07:00
|
|
|
PatIdent(_, ref p, _) => token::get_ident(p.node).get().to_string(),
|
2014-06-21 03:39:03 -07:00
|
|
|
PatEnum(ref p, _) => path_to_string(p),
|
2014-07-11 11:59:18 -07:00
|
|
|
PatStruct(ref name, ref fields, etc) => {
|
|
|
|
format!("{} {{ {}{} }}", path_to_string(name),
|
2014-10-06 13:36:53 +13:00
|
|
|
fields.iter().map(|&Spanned { node: ref fp, .. }|
|
2014-07-11 11:59:18 -07:00
|
|
|
format!("{}: {}", fp.ident.as_str(), name_from_pat(&*fp.pat)))
|
|
|
|
.collect::<Vec<String>>().connect(", "),
|
|
|
|
if etc { ", ..." } else { "" }
|
|
|
|
)
|
|
|
|
},
|
|
|
|
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
|
|
|
|
.collect::<Vec<String>>().connect(", ")),
|
2014-05-18 16:56:13 +03:00
|
|
|
PatBox(ref p) => name_from_pat(&**p),
|
|
|
|
PatRegion(ref p) => name_from_pat(&**p),
|
2013-12-29 00:13:29 -05:00
|
|
|
PatLit(..) => {
|
|
|
|
warn!("tried to get argument name from PatLit, \
|
|
|
|
which is silly in function arguments");
|
2014-05-25 03:17:19 -07:00
|
|
|
"()".to_string()
|
2013-12-29 00:13:29 -05:00
|
|
|
},
|
2014-10-09 15:17:22 -04:00
|
|
|
PatRange(..) => panic!("tried to get argument name from PatRange, \
|
2013-09-05 10:14:35 -04:00
|
|
|
which is not allowed in function arguments"),
|
2014-10-09 15:17:22 -04:00
|
|
|
PatVec(..) => panic!("tried to get argument name from pat_vec, \
|
2014-05-19 13:29:41 -07:00
|
|
|
which is not allowed in function arguments"),
|
|
|
|
PatMac(..) => {
|
|
|
|
warn!("can't document the name of a function argument \
|
|
|
|
produced by a pattern macro");
|
|
|
|
"(argument produced by macro)".to_string()
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a Type, resolve it using the def_map
|
2014-09-06 19:13:40 +03:00
|
|
|
fn resolve_type(cx: &DocContext, path: Path,
|
|
|
|
tpbs: Option<Vec<TyParamBound>>,
|
2013-09-24 13:53:09 -07:00
|
|
|
id: ast::NodeId) -> Type {
|
2014-09-06 19:13:40 +03:00
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
2013-12-22 11:23:04 -08:00
|
|
|
// If we're extracting tests, this return value doesn't matter.
|
2014-09-06 19:13:40 +03:00
|
|
|
None => return Primitive(Bool),
|
2013-12-22 11:23:04 -08:00
|
|
|
};
|
2014-10-15 03:20:39 -04:00
|
|
|
debug!("searching for {} in defmap", id);
|
2014-11-06 12:25:16 -05:00
|
|
|
let def = match tcx.def_map.borrow().get(&id) {
|
2014-03-20 21:52:59 -07:00
|
|
|
Some(&k) => k,
|
2014-10-09 15:17:22 -04:00
|
|
|
None => panic!("unresolved id not in defmap")
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
|
|
|
|
2014-05-09 13:52:17 -07:00
|
|
|
match def {
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefSelfTy(i) => return Self(ast_util::local_def(i)),
|
|
|
|
def::DefPrimTy(p) => match p {
|
2014-05-28 19:53:37 -07:00
|
|
|
ast::TyStr => return Primitive(Str),
|
|
|
|
ast::TyBool => return Primitive(Bool),
|
|
|
|
ast::TyChar => return Primitive(Char),
|
|
|
|
ast::TyInt(ast::TyI) => return Primitive(Int),
|
|
|
|
ast::TyInt(ast::TyI8) => return Primitive(I8),
|
|
|
|
ast::TyInt(ast::TyI16) => return Primitive(I16),
|
|
|
|
ast::TyInt(ast::TyI32) => return Primitive(I32),
|
|
|
|
ast::TyInt(ast::TyI64) => return Primitive(I64),
|
|
|
|
ast::TyUint(ast::TyU) => return Primitive(Uint),
|
|
|
|
ast::TyUint(ast::TyU8) => return Primitive(U8),
|
|
|
|
ast::TyUint(ast::TyU16) => return Primitive(U16),
|
|
|
|
ast::TyUint(ast::TyU32) => return Primitive(U32),
|
|
|
|
ast::TyUint(ast::TyU64) => return Primitive(U64),
|
|
|
|
ast::TyFloat(ast::TyF32) => return Primitive(F32),
|
|
|
|
ast::TyFloat(ast::TyF64) => return Primitive(F64),
|
2013-08-15 16:28:54 -04:00
|
|
|
},
|
2014-05-31 18:53:13 -04:00
|
|
|
def::DefTyParam(_, i, _) => return Generic(i),
|
2014-05-14 15:31:30 -04:00
|
|
|
def::DefTyParamBinder(i) => return TyParamBinder(i),
|
2014-05-09 13:52:17 -07:00
|
|
|
_ => {}
|
|
|
|
};
|
2014-06-26 11:37:39 -07:00
|
|
|
let did = register_def(&*cx, def);
|
2014-05-09 13:52:17 -07:00
|
|
|
ResolvedPath { path: path, typarams: tpbs, did: did }
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn register_def(cx: &DocContext, def: def::Def) -> ast::DefId {
|
2014-05-09 13:52:17 -07:00
|
|
|
let (did, kind) = match def {
|
2014-10-31 15:00:35 +13:00
|
|
|
def::DefFn(i, _) => (i, TypeFunction),
|
2014-09-16 09:13:00 +12:00
|
|
|
def::DefTy(i, false) => (i, TypeTypedef),
|
|
|
|
def::DefTy(i, true) => (i, TypeEnum),
|
2014-05-14 15:31:30 -04:00
|
|
|
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()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2014-05-09 13:52:17 -07:00
|
|
|
if ast_util::is_local(did) { return did }
|
2014-09-06 19:13:40 +03:00
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
|
|
|
None => return did
|
2014-05-09 13:52:17 -07:00
|
|
|
};
|
2014-05-24 11:56:38 -07:00
|
|
|
inline::record_extern_fqn(cx, did, kind);
|
2014-05-03 02:08:58 -07:00
|
|
|
match kind {
|
|
|
|
TypeTrait => {
|
2014-09-06 19:13:40 +03:00
|
|
|
let t = inline::build_external_trait(cx, tcx, did);
|
2014-08-18 17:52:38 -07:00
|
|
|
cx.external_traits.borrow_mut().as_mut().unwrap().insert(did, t);
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2014-05-09 13:52:17 -07:00
|
|
|
return did;
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
2013-09-24 13:56:52 -07:00
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn resolve_use_source(cx: &DocContext, path: Path, id: ast::NodeId) -> ImportSource {
|
2013-09-24 13:56:52 -07:00
|
|
|
ImportSource {
|
|
|
|
path: path,
|
2014-09-06 19:13:40 +03:00
|
|
|
did: resolve_def(cx, id),
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option<ast::DefId> {
|
|
|
|
cx.tcx_opt().and_then(|tcx| {
|
2014-11-06 12:25:16 -05:00
|
|
|
tcx.def_map.borrow().get(&id).map(|&def| register_def(cx, def))
|
2014-06-26 11:37:39 -07:00
|
|
|
})
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2014-02-16 21:40:26 -08:00
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Macro {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub source: String,
|
2014-02-16 21:40:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::Macro {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-02-16 21:40:26 -08:00
|
|
|
Item {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: Some(format!("{}!", self.name.clean(cx))),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
|
|
|
visibility: ast::Public.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
def_id: ast_util::local_def(self.id),
|
2014-02-16 21:40:26 -08:00
|
|
|
inner: MacroItem(Macro {
|
2014-09-06 19:13:40 +03:00
|
|
|
source: self.whence.to_src(cx),
|
2014-02-16 21:40:26 -08:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 11:37:39 -07:00
|
|
|
|
|
|
|
#[deriving(Clone, Encodable, Decodable)]
|
|
|
|
pub struct Stability {
|
|
|
|
pub level: attr::StabilityLevel,
|
|
|
|
pub text: String
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Stability> for attr::Stability {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Stability {
|
2014-06-26 11:37:39 -07:00
|
|
|
Stability {
|
|
|
|
level: self.level,
|
|
|
|
text: self.text.as_ref().map_or("".to_string(),
|
|
|
|
|interned| interned.get().to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
|
2014-08-05 19:44:21 -07:00
|
|
|
impl Clean<Item> for ast::AssociatedType {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
2014-10-29 05:58:31 -04:00
|
|
|
source: self.ty_param.span.clean(cx),
|
|
|
|
name: Some(self.ty_param.ident.clean(cx)),
|
2014-08-05 19:44:21 -07:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
inner: AssociatedTypeItem,
|
|
|
|
visibility: None,
|
2014-10-29 05:58:31 -04:00
|
|
|
def_id: ast_util::local_def(self.ty_param.id),
|
2014-08-05 19:44:21 -07:00
|
|
|
stability: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for ty::AssociatedType {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
source: DUMMY_SP.clean(cx),
|
2014-09-30 19:11:34 -05:00
|
|
|
name: Some(self.name.clean(cx)),
|
2014-08-05 19:44:21 -07:00
|
|
|
attrs: Vec::new(),
|
|
|
|
inner: AssociatedTypeItem,
|
|
|
|
visibility: None,
|
|
|
|
def_id: self.def_id,
|
|
|
|
stability: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for ast::Typedef {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
source: self.span.clean(cx),
|
|
|
|
name: Some(self.ident.clean(cx)),
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
inner: TypedefItem(Typedef {
|
|
|
|
type_: self.typ.clean(cx),
|
|
|
|
generics: Generics {
|
|
|
|
lifetimes: Vec::new(),
|
|
|
|
type_params: Vec::new(),
|
2014-09-25 02:01:42 -07:00
|
|
|
where_predicates: Vec::new()
|
2014-08-05 19:44:21 -07:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
visibility: None,
|
|
|
|
def_id: ast_util::local_def(self.id),
|
|
|
|
stability: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
|
2014-09-13 21:09:25 +03:00
|
|
|
t: Ty, name: &str,
|
2014-07-25 09:31:20 -07:00
|
|
|
fallback: fn(Box<Type>) -> Type) -> Type {
|
|
|
|
let did = match did {
|
|
|
|
Some(did) => did,
|
2014-09-06 19:13:40 +03:00
|
|
|
None => return fallback(box t.clean(cx)),
|
2014-07-25 09:31:20 -07:00
|
|
|
};
|
2014-09-06 19:13:40 +03:00
|
|
|
let fqn = csearch::get_item_path(cx.tcx(), did);
|
2014-09-14 20:27:36 -07:00
|
|
|
let fqn: Vec<String> = fqn.into_iter().map(|i| {
|
2014-07-25 09:31:20 -07:00
|
|
|
i.to_string()
|
|
|
|
}).collect();
|
2014-09-06 19:13:40 +03:00
|
|
|
cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, TypeStruct));
|
2014-07-25 09:31:20 -07:00
|
|
|
ResolvedPath {
|
|
|
|
typarams: None,
|
|
|
|
did: did,
|
|
|
|
path: Path {
|
|
|
|
global: false,
|
|
|
|
segments: vec![PathSegment {
|
|
|
|
name: name.to_string(),
|
|
|
|
lifetimes: vec![],
|
2014-09-06 19:13:40 +03:00
|
|
|
types: vec![t.clean(cx)],
|
2014-07-25 09:31:20 -07:00
|
|
|
}],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|