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::Type::*;
|
|
|
|
pub use self::PrimitiveType::*;
|
|
|
|
pub use self::TypeKind::*;
|
|
|
|
pub use self::VariantKind::*;
|
|
|
|
pub use self::Mutability::*;
|
2014-12-26 10:55:16 +02:00
|
|
|
pub use self::Import::*;
|
2014-11-06 00:05:53 -08:00
|
|
|
pub use self::ItemEnum::*;
|
|
|
|
pub use self::Attribute::*;
|
|
|
|
pub use self::TyParamBound::*;
|
|
|
|
pub use self::SelfTy::*;
|
|
|
|
pub use self::FunctionRetTy::*;
|
2016-04-11 08:15:14 +00:00
|
|
|
pub use self::Visibility::*;
|
2014-11-06 00:05:53 -08:00
|
|
|
|
2016-02-05 13:13:36 +01:00
|
|
|
use syntax::abi::Abi;
|
2013-08-15 16:28:54 -04:00
|
|
|
use syntax::ast;
|
2015-09-14 21:58:20 +12:00
|
|
|
use syntax::attr;
|
|
|
|
use syntax::attr::{AttributeMethods, AttrMetaMethods};
|
2016-06-21 19:57:03 -04:00
|
|
|
use syntax::codemap::Spanned;
|
2016-04-16 18:05:06 +03:00
|
|
|
use syntax::parse::token::{self, InternedString, keywords};
|
2014-05-18 16:56:13 +03:00
|
|
|
use syntax::ptr::P;
|
2016-06-21 18:08:13 -04:00
|
|
|
use syntax_pos::{self, DUMMY_SP, Pos};
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2014-11-15 20:30:33 -05:00
|
|
|
use rustc_trans::back::link;
|
2016-04-19 22:40:21 +09:00
|
|
|
use rustc::middle::cstore;
|
2016-04-07 05:59:02 +02:00
|
|
|
use rustc::middle::privacy::AccessLevels;
|
2016-07-07 18:20:26 +03:00
|
|
|
use rustc::middle::resolve_lifetime::DefRegion::*;
|
2016-03-29 12:54:26 +03:00
|
|
|
use rustc::hir::def::Def;
|
2016-04-25 08:24:50 +02:00
|
|
|
use rustc::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
|
2016-07-07 18:20:26 +03:00
|
|
|
use rustc::hir::fold::Folder;
|
2016-05-03 13:09:42 +02:00
|
|
|
use rustc::hir::print as pprust;
|
2016-03-22 17:30:57 +02:00
|
|
|
use rustc::ty::subst::{self, ParamSpace, VecPerParamSpace};
|
|
|
|
use rustc::ty;
|
2014-06-26 11:37:39 -07:00
|
|
|
use rustc::middle::stability;
|
2013-10-02 15:39:32 -07:00
|
|
|
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir;
|
2015-07-31 00:04:06 -07:00
|
|
|
|
2016-03-24 06:10:52 +01:00
|
|
|
use std::collections::{HashMap, HashSet};
|
2015-04-06 15:10:55 -07:00
|
|
|
use std::path::PathBuf;
|
2014-05-23 00:42:33 -07:00
|
|
|
use std::rc::Rc;
|
2016-04-07 05:59:02 +02:00
|
|
|
use std::sync::Arc;
|
2014-05-28 19:53:37 -07:00
|
|
|
use std::u32;
|
2016-02-23 07:52:43 +01:00
|
|
|
use std::env::current_dir;
|
2016-04-07 05:59:02 +02:00
|
|
|
use std::mem;
|
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;
|
2016-03-31 18:15:54 +02:00
|
|
|
use html::item_type::ItemType;
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2016-04-15 16:34:48 +02:00
|
|
|
pub mod inline;
|
2015-04-06 21:17:51 -07:00
|
|
|
mod simplify;
|
2014-05-24 11:56:38 -07:00
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
// extract the stability index for a node from tcx, if possible
|
2015-08-16 06:32:28 -04:00
|
|
|
fn get_stability(cx: &DocContext, def_id: DefId) -> Option<Stability> {
|
2016-03-17 00:15:31 +02:00
|
|
|
cx.tcx_opt().and_then(|tcx| tcx.lookup_stability(def_id)).clean(cx)
|
2014-06-26 11:37:39 -07:00
|
|
|
}
|
|
|
|
|
2015-12-12 23:01:27 +03:00
|
|
|
fn get_deprecation(cx: &DocContext, def_id: DefId) -> Option<Deprecation> {
|
2016-03-17 00:15:31 +02:00
|
|
|
cx.tcx_opt().and_then(|tcx| tcx.lookup_deprecation(def_id)).clean(cx)
|
2015-12-12 23:01:27 +03: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
|
|
|
}
|
|
|
|
|
2015-03-10 12:28:44 +02:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for [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> {
|
2016-02-28 12:11:13 +01:00
|
|
|
self.as_ref().map(|v| v.clean(cx))
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 23:50:46 -08:00
|
|
|
impl<T, U> Clean<U> for ty::Binder<T> where T: Clean<U> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> U {
|
|
|
|
self.0.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-16 21:44:33 +03:00
|
|
|
impl<T: Clean<U>, U> Clean<Vec<U>> for P<[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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 05:59:02 +02:00
|
|
|
#[derive(Clone, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Crate {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2015-02-26 21:00:43 -08:00
|
|
|
pub src: PathBuf,
|
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>,
|
2016-04-07 05:59:02 +02:00
|
|
|
pub access_levels: Arc<AccessLevels<DefId>>,
|
|
|
|
// These are later on moved into `CACHEKEY`, leaving the map empty.
|
|
|
|
// Only here so that they can be filtered through the rustdoc passes.
|
2015-08-16 06:32:28 -04:00
|
|
|
pub external_traits: HashMap<DefId, Trait>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-11-22 21:02:04 +02:00
|
|
|
struct CrateNum(ast::CrateNum);
|
|
|
|
|
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 {
|
2015-01-17 21:02:31 -08:00
|
|
|
use rustc::session::config::Input;
|
2016-04-17 08:54:48 +02:00
|
|
|
use ::visit_lib::LibEmbargoVisitor;
|
2015-01-17 21:02:31 -08:00
|
|
|
|
2015-04-13 16:23:32 -07:00
|
|
|
if let Some(t) = cx.tcx_opt() {
|
|
|
|
cx.deref_trait_did.set(t.lang_items.deref_trait());
|
2016-04-07 05:59:02 +02:00
|
|
|
cx.renderinfo.borrow_mut().deref_trait_did = cx.deref_trait_did.get();
|
2015-04-13 16:23:32 -07:00
|
|
|
}
|
|
|
|
|
2014-03-05 15:28:08 -08:00
|
|
|
let mut externs = Vec::new();
|
2015-11-22 21:02:04 +02:00
|
|
|
for cnum in cx.sess().cstore.crates() {
|
|
|
|
externs.push((cnum, CrateNum(cnum).clean(cx)));
|
2016-04-17 08:54:48 +02:00
|
|
|
if cx.tcx_opt().is_some() {
|
|
|
|
// Analyze doc-reachability for extern items
|
|
|
|
LibEmbargoVisitor::new(cx).visit_lib(cnum);
|
|
|
|
}
|
2015-11-22 21:02:04 +02: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
|
2015-01-17 21:02:31 -08:00
|
|
|
let input = &cx.input;
|
2015-09-14 21:58:20 +12:00
|
|
|
let name = link::find_crate_name(None, &self.attrs, 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
|
2015-10-07 23:11:25 +01:00
|
|
|
// item tagged with `#[doc(primitive)]` then we would also have to
|
2014-05-29 13:50:47 -07:00
|
|
|
// 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();
|
2015-01-31 20:02:00 -05:00
|
|
|
for child in &mut m.items {
|
2016-02-28 12:23:07 +01:00
|
|
|
if !child.is_mod() {
|
|
|
|
continue;
|
2014-12-18 19:13:32 -08:00
|
|
|
}
|
2015-02-01 21:53:25 -05:00
|
|
|
let prim = match PrimitiveType::find(&child.attrs) {
|
2014-05-28 19:53:37 -07:00
|
|
|
Some(prim) => prim,
|
|
|
|
None => continue,
|
|
|
|
};
|
|
|
|
primitives.push(prim);
|
2014-12-18 19:13:32 -08:00
|
|
|
tmp.push(Item {
|
2014-05-28 19:53:37 -07:00
|
|
|
source: Span::empty(),
|
|
|
|
name: Some(prim.to_url_str().to_string()),
|
2014-12-18 19:13:32 -08:00
|
|
|
attrs: child.attrs.clone(),
|
2016-04-11 08:15:14 +00:00
|
|
|
visibility: Some(Public),
|
2014-06-26 11:37:39 -07:00
|
|
|
stability: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: None,
|
2015-09-17 14:29:59 -04:00
|
|
|
def_id: DefId::local(prim.to_def_index()),
|
2014-05-28 19:53:37 -07:00
|
|
|
inner: PrimitiveItem(prim),
|
2014-12-18 19:13:32 -08:00
|
|
|
});
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
2015-06-10 17:22:20 +01:00
|
|
|
m.items.extend(tmp);
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
|
2015-01-17 21:02:31 -08:00
|
|
|
let src = match cx.input {
|
2016-02-23 07:52:43 +01:00
|
|
|
Input::File(ref path) => {
|
|
|
|
if path.is_absolute() {
|
|
|
|
path.clone()
|
|
|
|
} else {
|
|
|
|
current_dir().unwrap().join(path)
|
|
|
|
}
|
|
|
|
},
|
2016-03-10 04:49:40 +01:00
|
|
|
Input::Str { ref name, .. } => PathBuf::from(name.clone()),
|
2015-01-17 21:02:31 -08:00
|
|
|
};
|
|
|
|
|
2016-04-07 05:59:02 +02:00
|
|
|
let mut access_levels = cx.access_levels.borrow_mut();
|
|
|
|
let mut external_traits = cx.external_traits.borrow_mut();
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
Crate {
|
2014-06-06 13:21:18 -07:00
|
|
|
name: name.to_string(),
|
2015-01-17 21:02:31 -08:00
|
|
|
src: src,
|
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,
|
2016-04-07 05:59:02 +02:00
|
|
|
access_levels: Arc::new(mem::replace(&mut access_levels, Default::default())),
|
|
|
|
external_traits: mem::replace(&mut external_traits, Default::default()),
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-10-02 15:39:32 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-11-22 21:02:04 +02:00
|
|
|
impl Clean<ExternalCrate> for CrateNum {
|
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| {
|
2015-11-22 21:02:04 +02:00
|
|
|
for item in tcx.sess.cstore.crate_top_level_items(self.0) {
|
|
|
|
let did = match item.def {
|
2016-01-20 22:31:10 +03:00
|
|
|
cstore::DlDef(Def::Mod(did)) => did,
|
2015-11-22 21:02:04 +02:00
|
|
|
_ => continue
|
2014-06-26 11:37:39 -07:00
|
|
|
};
|
2014-09-06 19:13:40 +03:00
|
|
|
let attrs = inline::load_attrs(cx, tcx, did);
|
2015-02-01 21:53:25 -05:00
|
|
|
PrimitiveType::find(&attrs).map(|prim| primitives.push(prim));
|
2015-11-22 21:02:04 +02:00
|
|
|
}
|
2014-06-26 11:37:39 -07:00
|
|
|
});
|
2013-10-02 15:39:32 -07:00
|
|
|
ExternalCrate {
|
2016-02-12 12:43:13 -05:00
|
|
|
name: (&cx.sess().cstore.crate_name(self.0)[..]).to_owned(),
|
2015-11-22 21:02:04 +02:00
|
|
|
attrs: cx.sess().cstore.crate_attrs(self.0).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.
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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>,
|
2016-02-28 10:12:41 +01:00
|
|
|
pub attrs: Vec<Attribute>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub inner: ItemEnum,
|
|
|
|
pub visibility: Option<Visibility>,
|
2015-08-16 06:32:28 -04:00
|
|
|
pub def_id: DefId,
|
2014-06-26 11:37:39 -07:00
|
|
|
pub stability: Option<Stability>,
|
2015-12-12 23:01:27 +03:00
|
|
|
pub deprecation: Option<Deprecation>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2013-09-18 22:18:38 -07:00
|
|
|
impl Item {
|
|
|
|
/// Finds the `doc` attribute as a NameValue and returns the corresponding
|
|
|
|
/// value found.
|
|
|
|
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
|
2016-02-28 10:12:41 +01:00
|
|
|
self.attrs.value("doc")
|
2014-04-29 03:59:48 +09:00
|
|
|
}
|
2016-02-28 12:23:07 +01:00
|
|
|
pub fn is_crate(&self) -> bool {
|
|
|
|
match self.inner {
|
2016-03-31 18:15:54 +02:00
|
|
|
StrippedItem(box ModuleItem(Module { is_crate: true, ..})) |
|
|
|
|
ModuleItem(Module { is_crate: true, ..}) => true,
|
|
|
|
_ => false,
|
2016-02-28 12:23:07 +01:00
|
|
|
}
|
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
pub fn is_mod(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Module
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_trait(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Trait
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_struct(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Struct
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_enum(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Module
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
pub fn is_fn(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Function
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
2016-02-28 12:23:07 +01:00
|
|
|
pub fn is_associated_type(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::AssociatedType
|
2016-02-28 12:23:07 +01:00
|
|
|
}
|
|
|
|
pub fn is_associated_const(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::AssociatedConst
|
2016-02-28 12:23:07 +01:00
|
|
|
}
|
|
|
|
pub fn is_method(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::Method
|
2016-02-28 12:23:07 +01:00
|
|
|
}
|
|
|
|
pub fn is_ty_method(&self) -> bool {
|
2016-03-31 18:15:54 +02:00
|
|
|
ItemType::from_item(self) == ItemType::TyMethod
|
|
|
|
}
|
2016-06-30 23:16:44 +01:00
|
|
|
pub fn is_primitive(&self) -> bool {
|
|
|
|
ItemType::from_item(self) == ItemType::Primitive
|
|
|
|
}
|
2016-03-31 18:15:54 +02:00
|
|
|
pub fn is_stripped(&self) -> bool {
|
|
|
|
match self.inner { StrippedItem(..) => true, _ => false }
|
2016-02-28 12:23:07 +01:00
|
|
|
}
|
2016-04-02 08:17:59 +02:00
|
|
|
pub fn has_stripped_fields(&self) -> Option<bool> {
|
|
|
|
match self.inner {
|
|
|
|
StructItem(ref _struct) => Some(_struct.fields_stripped),
|
|
|
|
VariantItem(Variant { kind: StructVariant(ref vstruct)} ) => {
|
|
|
|
Some(vstruct.fields_stripped)
|
|
|
|
},
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2015-04-13 11:55:00 -07:00
|
|
|
|
|
|
|
pub fn stability_class(&self) -> String {
|
2016-02-28 12:11:13 +01:00
|
|
|
self.stability.as_ref().map(|ref s| {
|
|
|
|
let mut base = match s.level {
|
|
|
|
stability::Unstable => "unstable".to_string(),
|
|
|
|
stability::Stable => String::new(),
|
|
|
|
};
|
|
|
|
if !s.deprecated_since.is_empty() {
|
|
|
|
base.push_str(" deprecated");
|
2015-04-13 11:55:00 -07:00
|
|
|
}
|
2016-02-28 12:11:13 +01:00
|
|
|
base
|
|
|
|
}).unwrap_or(String::new())
|
2015-04-13 11:55:00 -07:00
|
|
|
}
|
2016-02-09 21:15:29 -05:00
|
|
|
|
|
|
|
pub fn stable_since(&self) -> Option<&str> {
|
2016-02-28 12:11:13 +01:00
|
|
|
self.stability.as_ref().map(|s| &s.since[..])
|
2016-02-09 21:15:29 -05:00
|
|
|
}
|
2013-09-18 22:18:38 -07:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum ItemEnum {
|
2014-12-26 10:55:16 +02:00
|
|
|
ExternCrateItem(String, Option<String>),
|
|
|
|
ImportItem(Import),
|
2013-08-15 16:28:54 -04:00
|
|
|
StructItem(Struct),
|
|
|
|
EnumItem(Enum),
|
|
|
|
FunctionItem(Function),
|
|
|
|
ModuleItem(Module),
|
2015-05-21 14:17:37 +02:00
|
|
|
TypedefItem(Typedef, bool /* is associated type */),
|
2013-08-15 16:28:54 -04:00
|
|
|
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
|
|
|
/// 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),
|
2016-04-02 08:17:59 +02:00
|
|
|
StructFieldItem(Type),
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
2015-03-14 12:05:00 -06:00
|
|
|
AssociatedConstItem(Type, Option<String>),
|
2015-03-10 12:28:44 +02:00
|
|
|
AssociatedTypeItem(Vec<TyParamBound>, Option<Type>),
|
2015-03-12 19:15:52 -07:00
|
|
|
DefaultImplItem(DefaultImpl),
|
2016-03-31 18:15:54 +02:00
|
|
|
/// An item that has been stripped by a rustdoc pass
|
|
|
|
StrippedItem(Box<ItemEnum>),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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
|
|
|
};
|
2015-02-02 18:33:24 +09:00
|
|
|
|
|
|
|
let mut items: Vec<Item> = vec![];
|
|
|
|
items.extend(self.extern_crates.iter().map(|x| x.clean(cx)));
|
2015-06-10 17:22:20 +01:00
|
|
|
items.extend(self.imports.iter().flat_map(|x| x.clean(cx)));
|
2015-02-02 18:33:24 +09:00
|
|
|
items.extend(self.structs.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.enums.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.fns.iter().map(|x| x.clean(cx)));
|
2015-06-10 17:22:20 +01:00
|
|
|
items.extend(self.foreigns.iter().flat_map(|x| x.clean(cx)));
|
2015-02-02 18:33:24 +09:00
|
|
|
items.extend(self.mods.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.typedefs.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.statics.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.constants.iter().map(|x| x.clean(cx)));
|
|
|
|
items.extend(self.traits.iter().map(|x| x.clean(cx)));
|
2015-06-10 17:22:20 +01:00
|
|
|
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
|
2015-02-02 18:33:24 +09:00
|
|
|
items.extend(self.macros.iter().map(|x| x.clean(cx)));
|
2015-03-12 19:15:52 -07:00
|
|
|
items.extend(self.def_traits.iter().map(|x| x.clean(cx)));
|
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),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(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-12-26 10:55:16 +02:00
|
|
|
items: items
|
2013-08-15 16:28:54 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-28 10:12:41 +01:00
|
|
|
pub trait Attributes {
|
|
|
|
fn has_word(&self, &str) -> bool;
|
|
|
|
fn value<'a>(&'a self, &str) -> Option<&'a str>;
|
2016-03-22 20:26:33 +01:00
|
|
|
fn list<'a>(&'a self, &str) -> &'a [Attribute];
|
2016-02-28 10:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Attributes for [Attribute] {
|
|
|
|
/// Returns whether the attribute list contains a specific `Word`
|
|
|
|
fn has_word(&self, word: &str) -> bool {
|
|
|
|
for attr in self {
|
|
|
|
if let Word(ref w) = *attr {
|
|
|
|
if word == *w {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finds an attribute as NameValue and returns the corresponding value found.
|
|
|
|
fn value<'a>(&'a self, name: &str) -> Option<&'a str> {
|
|
|
|
for attr in self {
|
|
|
|
if let NameValue(ref x, ref v) = *attr {
|
|
|
|
if name == *x {
|
|
|
|
return Some(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Finds an attribute as List and returns the list of attributes nested inside.
|
2016-03-22 20:26:33 +01:00
|
|
|
fn list<'a>(&'a self, name: &str) -> &'a [Attribute] {
|
2016-02-28 10:12:41 +01:00
|
|
|
for attr in self {
|
|
|
|
if let List(ref x, ref list) = *attr {
|
|
|
|
if name == *x {
|
|
|
|
return &list[..];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
&[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Attribute {
|
2014-05-22 16:57:53 -07:00
|
|
|
Word(String),
|
2016-02-28 10:12:41 +01:00
|
|
|
List(String, Vec<Attribute>),
|
2014-05-22 16:57:53 -07:00
|
|
|
NameValue(String, String)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-09-14 21:58:20 +12:00
|
|
|
impl Clean<Attribute> for ast::MetaItem {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Attribute {
|
2016-07-15 13:13:17 -07:00
|
|
|
if self.is_word() {
|
|
|
|
Word(self.name().to_string())
|
|
|
|
} else if let Some(v) = self.value_str() {
|
|
|
|
NameValue(self.name().to_string(), v.to_string())
|
|
|
|
} else { // must be a list
|
|
|
|
let l = self.meta_item_list().unwrap();
|
2016-07-17 21:45:06 -07:00
|
|
|
List(self.name().to_string(), l.clean(cx))
|
2016-07-15 13:13:17 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 21:58:20 +12:00
|
|
|
impl Clean<Attribute> for ast::Attribute {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Attribute {
|
2016-07-15 13:13:17 -07:00
|
|
|
self.with_desugared_doc(|a| a.meta().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, _) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
token::intern_and_get_ident(n)
|
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) => {
|
2015-02-01 21:53:25 -05:00
|
|
|
Some(token::intern_and_get_ident(v))
|
2014-05-12 13:44:59 -07:00
|
|
|
}
|
2013-09-26 12:53:06 -07:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2015-09-14 21:58:20 +12:00
|
|
|
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
|
2016-07-15 13:13:17 -07:00
|
|
|
|
|
|
|
fn is_word(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
Word(_) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_value_str(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
NameValue(..) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_meta_item_list(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
List(..) => true,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:08:13 -04:00
|
|
|
fn span(&self) -> syntax_pos::Span { unimplemented!() }
|
2013-09-26 12:53:06 -07:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct TyParam {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2015-08-16 06:32:28 -04:00
|
|
|
pub did: DefId,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub bounds: Vec<TyParamBound>,
|
2014-11-24 10:14:46 -08:00
|
|
|
pub default: Option<Type>,
|
2014-03-28 10:27:24 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<TyParam> for hir::TyParam {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParam {
|
2013-08-15 16:28:54 -04:00
|
|
|
TyParam {
|
2015-09-20 16:47:24 +03:00
|
|
|
name: self.name.clean(cx),
|
2015-09-04 13:52:28 -04:00
|
|
|
did: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
bounds: self.bounds.clean(cx),
|
2014-11-24 10:14:46 -08:00
|
|
|
default: self.default.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyParam {
|
2016-04-07 05:59:02 +02:00
|
|
|
cx.renderinfo.borrow_mut().external_typarams.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,
|
2015-02-18 11:50:51 -05:00
|
|
|
bounds: vec![], // these are filled in from the where-clauses
|
2014-11-24 10:14:46 -08:00
|
|
|
default: self.default.clean(cx),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum TyParamBound {
|
2014-10-05 07:35:04 -07:00
|
|
|
RegionBound(Lifetime),
|
2015-07-31 00:04:06 -07:00
|
|
|
TraitBound(PolyTrait, hir::TraitBoundModifier)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-04-07 00:16:35 -07:00
|
|
|
impl TyParamBound {
|
|
|
|
fn maybe_sized(cx: &DocContext) -> TyParamBound {
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir::TraitBoundModifier as TBM;
|
2015-06-18 08:51:23 +03:00
|
|
|
let mut sized_bound = ty::BoundSized.clean(cx);
|
2015-04-07 00:16:35 -07:00
|
|
|
if let TyParamBound::TraitBound(_, ref mut tbm) = sized_bound {
|
|
|
|
*tbm = TBM::Maybe
|
|
|
|
};
|
|
|
|
sized_bound
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_sized_bound(&self, cx: &DocContext) -> bool {
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir::TraitBoundModifier as TBM;
|
2015-04-07 00:16:35 -07:00
|
|
|
if let Some(tcx) = cx.tcx_opt() {
|
2016-03-24 06:10:52 +01:00
|
|
|
if let TyParamBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
|
|
|
|
if trait_.def_id() == tcx.lang_items.sized_trait() {
|
|
|
|
return true;
|
2015-04-07 00:16:35 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<TyParamBound> for hir::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 {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)),
|
|
|
|
hir::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-12 09:43:24 -08:00
|
|
|
impl<'tcx> Clean<(Vec<TyParamBound>, Vec<TypeBinding>)> for ty::ExistentialBounds<'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> (Vec<TyParamBound>, Vec<TypeBinding>) {
|
|
|
|
let mut tp_bounds = vec![];
|
|
|
|
self.region_bound.clean(cx).map(|b| tp_bounds.push(RegionBound(b)));
|
2015-01-31 12:20:46 -05:00
|
|
|
for bb in &self.builtin_bounds {
|
2015-01-12 09:43:24 -08:00
|
|
|
tp_bounds.push(bb.clean(cx));
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
2014-12-29 11:02:24 -05:00
|
|
|
|
2015-01-12 09:43:24 -08:00
|
|
|
let mut bindings = vec![];
|
2015-01-31 12:20:46 -05:00
|
|
|
for &ty::Binder(ref pb) in &self.projection_bounds {
|
2015-01-12 09:43:24 -08:00
|
|
|
bindings.push(TypeBinding {
|
|
|
|
name: pb.projection_ty.item_name.clean(cx),
|
|
|
|
ty: pb.ty.clean(cx)
|
|
|
|
});
|
|
|
|
}
|
2014-12-29 11:02:24 -05:00
|
|
|
|
2015-01-12 09:43:24 -08:00
|
|
|
(tp_bounds, bindings)
|
2014-08-27 21:46:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:32:28 -04:00
|
|
|
fn external_path_params(cx: &DocContext, trait_did: Option<DefId>,
|
2015-01-12 09:43:24 -08:00
|
|
|
bindings: Vec<TypeBinding>, substs: &subst::Substs) -> PathParameters {
|
2016-03-09 18:22:05 -05: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-12-17 02:39:10 -08:00
|
|
|
|
|
|
|
match (trait_did, cx.tcx_opt()) {
|
|
|
|
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
|
|
|
|
(Some(did), Some(ref tcx)) if tcx.lang_items.fn_trait_kind(did).is_some() => {
|
2015-01-12 10:24:19 -05:00
|
|
|
assert_eq!(types.len(), 1);
|
2014-12-17 02:39:10 -08:00
|
|
|
let inputs = match types[0].sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyTuple(ref tys) => tys.iter().map(|t| t.clean(cx)).collect(),
|
2014-12-17 02:39:10 -08:00
|
|
|
_ => {
|
|
|
|
return PathParameters::AngleBracketed {
|
|
|
|
lifetimes: lifetimes,
|
2015-01-07 16:10:40 -08:00
|
|
|
types: types.clean(cx),
|
2015-01-12 09:43:24 -08:00
|
|
|
bindings: bindings
|
2014-12-17 02:39:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-01-12 10:24:19 -05:00
|
|
|
let output = None;
|
|
|
|
// FIXME(#20299) return type comes from a projection now
|
|
|
|
// match types[1].sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
// ty::TyTuple(ref v) if v.is_empty() => None, // -> ()
|
2015-01-12 10:24:19 -05:00
|
|
|
// _ => Some(types[1].clean(cx))
|
|
|
|
// };
|
2014-12-17 02:39:10 -08:00
|
|
|
PathParameters::Parenthesized {
|
|
|
|
inputs: inputs,
|
|
|
|
output: output
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(_, _) => {
|
|
|
|
PathParameters::AngleBracketed {
|
|
|
|
lifetimes: lifetimes,
|
|
|
|
types: types.clean(cx),
|
2015-01-12 09:43:24 -08:00
|
|
|
bindings: bindings
|
2014-12-17 02:39:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar
|
|
|
|
// from Fn<(A, B,), C> to Fn(A, B) -> C
|
2015-08-16 06:32:28 -04:00
|
|
|
fn external_path(cx: &DocContext, name: &str, trait_did: Option<DefId>,
|
2015-01-12 09:43:24 -08:00
|
|
|
bindings: Vec<TypeBinding>, substs: &subst::Substs) -> Path {
|
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(),
|
2015-01-12 09:43:24 -08:00
|
|
|
params: external_path_params(cx, trait_did, bindings, substs)
|
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(),
|
2015-01-12 09:43:24 -08:00
|
|
|
external_path(cx, "Send", None, vec![], &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(),
|
2015-01-12 09:43:24 -08:00
|
|
|
external_path(cx, "Sized", None, vec![], &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(),
|
2015-01-12 09:43:24 -08:00
|
|
|
external_path(cx, "Copy", None, vec![], &empty)),
|
2014-08-05 16:40:04 -07:00
|
|
|
ty::BoundSync =>
|
|
|
|
(tcx.lang_items.sync_trait().unwrap(),
|
2015-01-12 09:43:24 -08:00
|
|
|
external_path(cx, "Sync", None, vec![], &empty)),
|
2014-05-03 02:08:58 -07:00
|
|
|
};
|
2015-12-05 11:58:04 +01:00
|
|
|
inline::record_extern_fqn(cx, did, TypeTrait);
|
2014-12-16 08:50:52 -08:00
|
|
|
TraitBound(PolyTrait {
|
|
|
|
trait_: ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: None,
|
|
|
|
did: did,
|
2015-05-25 15:06:38 +02:00
|
|
|
is_generic: false,
|
2014-12-16 08:50:52 -08:00
|
|
|
},
|
|
|
|
lifetimes: vec![]
|
2015-07-31 00:04:06 -07:00
|
|
|
}, hir::TraitBoundModifier::None)
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
|
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
|
|
|
};
|
2015-12-05 11:58:04 +01:00
|
|
|
inline::record_extern_fqn(cx, self.def_id, TypeTrait);
|
|
|
|
let path = external_path(cx, &tcx.item_name(self.def_id).as_str(),
|
2015-01-12 09:43:24 -08:00
|
|
|
Some(self.def_id), vec![], self.substs);
|
2014-12-16 08:50:52 -08:00
|
|
|
|
2014-12-20 00:09:35 -08:00
|
|
|
debug!("ty::TraitRef\n substs.types(TypeSpace): {:?}\n",
|
2014-12-16 08:50:52 -08:00
|
|
|
self.substs.types.get_slice(ParamSpace::TypeSpace));
|
|
|
|
|
|
|
|
// collect any late bound regions
|
|
|
|
let mut late_bounds = vec![];
|
2015-01-31 12:20:46 -05:00
|
|
|
for &ty_s in self.substs.types.get_slice(ParamSpace::TypeSpace) {
|
2016-04-29 08:30:54 +03:00
|
|
|
if let ty::TyTuple(ts) = ty_s.sty {
|
2015-01-31 12:20:46 -05:00
|
|
|
for &ty_s in ts {
|
2015-06-11 16:21:46 -07:00
|
|
|
if let ty::TyRef(ref reg, _) = ty_s.sty {
|
|
|
|
if let &ty::Region::ReLateBound(_, _) = *reg {
|
2014-12-20 00:09:35 -08:00
|
|
|
debug!(" hit an ReLateBound {:?}", reg);
|
2014-12-16 08:50:52 -08:00
|
|
|
if let Some(lt) = reg.clean(cx) {
|
2016-02-28 12:11:13 +01:00
|
|
|
late_bounds.push(lt);
|
2014-12-16 08:50:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-24 06:10:52 +01:00
|
|
|
TraitBound(
|
|
|
|
PolyTrait {
|
|
|
|
trait_: ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: None,
|
|
|
|
did: self.def_id,
|
|
|
|
is_generic: false,
|
|
|
|
},
|
|
|
|
lifetimes: late_bounds,
|
2015-05-25 15:06:38 +02:00
|
|
|
},
|
2016-03-24 06:10:52 +01:00
|
|
|
hir::TraitBoundModifier::None
|
|
|
|
)
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<Option<Vec<TyParamBound>>> for subst::Substs<'tcx> {
|
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();
|
2016-06-13 20:46:08 +03:00
|
|
|
v.extend(self.regions.as_full_slice().iter().filter_map(|r| r.clean(cx))
|
|
|
|
.map(RegionBound));
|
|
|
|
v.extend(self.types.as_full_slice().iter().map(|t| TraitBound(PolyTrait {
|
2014-12-16 08:50:52 -08:00
|
|
|
trait_: t.clean(cx),
|
|
|
|
lifetimes: vec![]
|
2015-07-31 00:04:06 -07:00
|
|
|
}, hir::TraitBoundModifier::None)));
|
2015-03-24 16:54:09 -07:00
|
|
|
if !v.is_empty() {Some(v)} else {None}
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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;
|
2015-02-01 21:53:25 -05:00
|
|
|
let s: &'a str = s;
|
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
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Lifetime> for hir::Lifetime {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Lifetime {
|
2015-07-28 18:07:20 +02:00
|
|
|
Lifetime(self.name.to_string())
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Lifetime> for hir::LifetimeDef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Lifetime {
|
2016-05-15 15:29:44 +02:00
|
|
|
if self.bounds.len() > 0 {
|
|
|
|
let mut s = format!("{}: {}",
|
|
|
|
self.lifetime.name.to_string(),
|
|
|
|
self.bounds[0].name.to_string());
|
|
|
|
for bound in self.bounds.iter().skip(1) {
|
|
|
|
s.push_str(&format!(" + {}", bound.name.to_string()));
|
|
|
|
}
|
|
|
|
Lifetime(s)
|
|
|
|
} else {
|
|
|
|
Lifetime(self.lifetime.name.to_string())
|
|
|
|
}
|
2014-08-05 22:59:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 {
|
2015-07-28 18:07:20 +02:00
|
|
|
Lifetime(self.name.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()),
|
2016-04-21 05:10:10 -04:00
|
|
|
ty::ReLateBound(_, ty::BrNamed(_, name, _)) => Some(Lifetime(name.to_string())),
|
2015-04-17 10:05:25 -04:00
|
|
|
ty::ReEarlyBound(ref data) => Some(Lifetime(data.name.clean(cx))),
|
2014-05-03 02:08:58 -07:00
|
|
|
|
|
|
|
ty::ReLateBound(..) |
|
|
|
|
ty::ReFree(..) |
|
|
|
|
ty::ReScope(..) |
|
2015-08-18 23:21:29 +03:00
|
|
|
ty::ReVar(..) |
|
|
|
|
ty::ReSkolemized(..) |
|
2016-06-01 15:10:44 +03:00
|
|
|
ty::ReEmpty |
|
|
|
|
ty::ReErased => None
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2014-12-23 01:08:00 -08:00
|
|
|
pub enum WherePredicate {
|
|
|
|
BoundPredicate { ty: Type, bounds: Vec<TyParamBound> },
|
|
|
|
RegionPredicate { lifetime: Lifetime, bounds: Vec<Lifetime>},
|
2015-01-10 23:50:46 -08:00
|
|
|
EqPredicate { lhs: Type, rhs: Type }
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<WherePredicate> for hir::WherePredicate {
|
2014-09-25 02:01:42 -07:00
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
2014-12-02 15:03:02 -08:00
|
|
|
match *self {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::WherePredicate::BoundPredicate(ref wbp) => {
|
2014-12-23 01:08:00 -08:00
|
|
|
WherePredicate::BoundPredicate {
|
2014-12-20 02:29:19 -08:00
|
|
|
ty: wbp.bounded_ty.clean(cx),
|
2014-12-02 15:03:02 -08:00
|
|
|
bounds: wbp.bounds.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
2014-12-23 01:08:00 -08:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::WherePredicate::RegionPredicate(ref wrp) => {
|
2014-12-23 01:08:00 -08:00
|
|
|
WherePredicate::RegionPredicate {
|
|
|
|
lifetime: wrp.lifetime.clean(cx),
|
|
|
|
bounds: wrp.bounds.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::WherePredicate::EqPredicate(_) => {
|
2015-01-10 23:50:46 -08:00
|
|
|
unimplemented!() // FIXME(#20041)
|
2014-12-02 15:03:02 -08:00
|
|
|
}
|
2014-09-25 02:01:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 23:50:46 -08:00
|
|
|
impl<'a> Clean<WherePredicate> for ty::Predicate<'a> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
2016-03-22 17:30:57 +02:00
|
|
|
use rustc::ty::Predicate;
|
2015-01-10 23:50:46 -08:00
|
|
|
|
|
|
|
match *self {
|
|
|
|
Predicate::Trait(ref pred) => pred.clean(cx),
|
|
|
|
Predicate::Equate(ref pred) => pred.clean(cx),
|
|
|
|
Predicate::RegionOutlives(ref pred) => pred.clean(cx),
|
|
|
|
Predicate::TypeOutlives(ref pred) => pred.clean(cx),
|
2015-08-07 09:30:19 -04:00
|
|
|
Predicate::Projection(ref pred) => pred.clean(cx),
|
|
|
|
Predicate::WellFormed(_) => panic!("not user writable"),
|
|
|
|
Predicate::ObjectSafe(_) => panic!("not user writable"),
|
2016-04-06 00:20:59 -07:00
|
|
|
Predicate::ClosureKind(..) => panic!("not user writable"),
|
2016-05-02 17:18:05 +03:00
|
|
|
Predicate::Rfc1592(..) => panic!("not user writable"),
|
2015-01-10 23:50:46 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Clean<WherePredicate> for ty::TraitPredicate<'a> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
WherePredicate::BoundPredicate {
|
|
|
|
ty: self.trait_ref.substs.self_ty().clean(cx).unwrap(),
|
|
|
|
bounds: vec![self.trait_ref.clean(cx)]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> Clean<WherePredicate> for ty::EquatePredicate<'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
let ty::EquatePredicate(ref lhs, ref rhs) = *self;
|
|
|
|
WherePredicate::EqPredicate {
|
|
|
|
lhs: lhs.clean(cx),
|
|
|
|
rhs: rhs.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<WherePredicate> for ty::OutlivesPredicate<ty::Region, ty::Region> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
let ty::OutlivesPredicate(ref a, ref b) = *self;
|
|
|
|
WherePredicate::RegionPredicate {
|
|
|
|
lifetime: a.clean(cx).unwrap(),
|
|
|
|
bounds: vec![b.clean(cx).unwrap()]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> Clean<WherePredicate> for ty::OutlivesPredicate<ty::Ty<'tcx>, ty::Region> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
let ty::OutlivesPredicate(ref ty, ref lt) = *self;
|
|
|
|
|
|
|
|
WherePredicate::BoundPredicate {
|
|
|
|
ty: ty.clean(cx),
|
|
|
|
bounds: vec![TyParamBound::RegionBound(lt.clean(cx).unwrap())]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> Clean<WherePredicate> for ty::ProjectionPredicate<'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> WherePredicate {
|
|
|
|
WherePredicate::EqPredicate {
|
|
|
|
lhs: self.projection_ty.clean(cx),
|
|
|
|
rhs: self.ty.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
|
|
|
let trait_ = match self.trait_ref.clean(cx) {
|
|
|
|
TyParamBound::TraitBound(t, _) => t.trait_,
|
2015-04-07 00:16:35 -07:00
|
|
|
TyParamBound::RegionBound(_) => {
|
|
|
|
panic!("cleaning a trait got a region")
|
|
|
|
}
|
2015-01-10 23:50:46 -08:00
|
|
|
};
|
|
|
|
Type::QPath {
|
|
|
|
name: self.item_name.clean(cx),
|
|
|
|
self_type: box self.trait_ref.self_ty().clean(cx),
|
|
|
|
trait_: box trait_
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-02 16:25:49 -04:00
|
|
|
// maybe use a Generic enum and use Vec<Generic>?
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Generics> for hir::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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-11 10:28:52 -05:00
|
|
|
impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics<'tcx>,
|
|
|
|
&'a ty::GenericPredicates<'tcx>,
|
|
|
|
subst::ParamSpace) {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Generics {
|
2015-01-10 23:50:46 -08:00
|
|
|
use self::WherePredicate as WP;
|
|
|
|
|
2015-02-11 10:28:52 -05:00
|
|
|
let (gens, preds, space) = *self;
|
|
|
|
|
2015-04-06 21:17:51 -07:00
|
|
|
// Bounds in the type_params and lifetimes fields are repeated in the
|
|
|
|
// predicates field (see rustc_typeck::collect::ty_generics), so remove
|
|
|
|
// them.
|
2015-01-10 23:50:46 -08:00
|
|
|
let stripped_typarams = gens.types.get_slice(space).iter().map(|tp| {
|
2015-02-18 11:50:51 -05:00
|
|
|
tp.clean(cx)
|
2015-01-10 23:50:46 -08:00
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
let stripped_lifetimes = gens.regions.get_slice(space).iter().map(|rp| {
|
|
|
|
let mut srp = rp.clone();
|
|
|
|
srp.bounds = Vec::new();
|
|
|
|
srp.clean(cx)
|
|
|
|
}).collect::<Vec<_>>();
|
|
|
|
|
2016-06-13 20:10:32 +03:00
|
|
|
let mut where_predicates = preds.predicates.to_vec().clean(cx);
|
2015-02-11 10:28:52 -05:00
|
|
|
|
2015-04-07 00:16:35 -07:00
|
|
|
// Type parameters and have a Sized bound by default unless removed with
|
2015-04-06 21:17:51 -07:00
|
|
|
// ?Sized. Scan through the predicates and mark any type parameter with
|
|
|
|
// a Sized bound, removing the bounds as we find them.
|
2015-04-07 00:16:35 -07:00
|
|
|
//
|
|
|
|
// Note that associated types also have a sized bound by default, but we
|
2015-05-06 01:49:07 +02:00
|
|
|
// don't actually know the set of associated types right here so that's
|
2015-04-07 00:16:35 -07:00
|
|
|
// handled in cleaning associated types
|
2015-01-10 23:50:46 -08:00
|
|
|
let mut sized_params = HashSet::new();
|
2015-04-07 00:16:35 -07:00
|
|
|
where_predicates.retain(|pred| {
|
|
|
|
match *pred {
|
|
|
|
WP::BoundPredicate { ty: Generic(ref g), ref bounds } => {
|
|
|
|
if bounds.iter().any(|b| b.is_sized_bound(cx)) {
|
|
|
|
sized_params.insert(g.clone());
|
|
|
|
false
|
|
|
|
} else {
|
|
|
|
true
|
|
|
|
}
|
2015-01-10 23:50:46 -08:00
|
|
|
}
|
2015-04-07 00:16:35 -07:00
|
|
|
_ => true,
|
2015-01-10 23:50:46 -08:00
|
|
|
}
|
2015-04-07 00:16:35 -07:00
|
|
|
});
|
2015-02-11 10:28:52 -05:00
|
|
|
|
2015-04-07 00:16:35 -07:00
|
|
|
// Run through the type parameters again and insert a ?Sized
|
2015-04-06 21:17:51 -07:00
|
|
|
// unbound for any we didn't find to be Sized.
|
2015-01-31 12:20:46 -05:00
|
|
|
for tp in &stripped_typarams {
|
2015-01-10 23:50:46 -08:00
|
|
|
if !sized_params.contains(&tp.name) {
|
|
|
|
where_predicates.push(WP::BoundPredicate {
|
|
|
|
ty: Type::Generic(tp.name.clone()),
|
2015-04-07 00:16:35 -07:00
|
|
|
bounds: vec![TyParamBound::maybe_sized(cx)],
|
2015-01-10 23:50:46 -08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// It would be nice to collect all of the bounds on a type and recombine
|
|
|
|
// them if possible, to avoid e.g. `where T: Foo, T: Bar, T: Sized, T: 'a`
|
|
|
|
// and instead see `where T: Foo + Bar + Sized + 'a`
|
|
|
|
|
2014-05-03 02:08:58 -07:00
|
|
|
Generics {
|
2015-04-06 21:17:51 -07:00
|
|
|
type_params: simplify::ty_params(stripped_typarams),
|
2015-01-10 23:50:46 -08:00
|
|
|
lifetimes: stripped_lifetimes,
|
2015-04-07 12:20:24 -07:00
|
|
|
where_predicates: simplify::where_clauses(cx, where_predicates),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Method {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
|
|
|
pub constness: hir::Constness,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
2016-02-05 13:13:36 +01:00
|
|
|
pub abi: Abi,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Method> for hir::MethodSig {
|
2015-03-10 12:28:44 +02:00
|
|
|
fn clean(&self, cx: &DocContext) -> Method {
|
2014-01-27 14:18:36 +02:00
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
2016-05-08 21:19:29 +03:00
|
|
|
values: self.decl.inputs.clean(cx),
|
2014-02-13 06:41:34 +11:00
|
|
|
},
|
2015-03-11 23:38:58 +02:00
|
|
|
output: self.decl.output.clean(cx),
|
2015-08-20 18:27:53 +01:00
|
|
|
variadic: false,
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2015-03-10 12:28:44 +02:00
|
|
|
Method {
|
2015-03-11 23:38:58 +02:00
|
|
|
generics: self.generics.clean(cx),
|
2015-02-25 22:05:07 +02:00
|
|
|
unsafety: self.unsafety,
|
|
|
|
constness: self.constness,
|
2015-03-10 12:28:44 +02:00
|
|
|
decl: decl,
|
2015-03-11 23:38:58 +02:00
|
|
|
abi: self.abi
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct TyMethod {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
2016-02-05 13:13:36 +01:00
|
|
|
pub abi: Abi,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<TyMethod> for hir::MethodSig {
|
2015-03-10 12:28:44 +02:00
|
|
|
fn clean(&self, cx: &DocContext) -> TyMethod {
|
2014-01-27 14:18:36 +02:00
|
|
|
let decl = FnDecl {
|
2014-02-13 06:41:34 +11:00
|
|
|
inputs: Arguments {
|
2016-05-08 21:19:29 +03:00
|
|
|
values: self.decl.inputs.clean(cx),
|
2014-02-13 06:41:34 +11:00
|
|
|
},
|
2014-11-09 16:14:15 +01:00
|
|
|
output: self.decl.output.clean(cx),
|
2015-08-20 18:27:53 +01:00
|
|
|
variadic: false,
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2014-01-27 14:18:36 +02:00
|
|
|
};
|
2015-03-10 12:28:44 +02:00
|
|
|
TyMethod {
|
|
|
|
unsafety: self.unsafety.clone(),
|
|
|
|
decl: decl,
|
|
|
|
generics: self.generics.clean(cx),
|
|
|
|
abi: self.abi
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Function {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub decl: FnDecl,
|
|
|
|
pub generics: Generics,
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
|
|
|
pub constness: hir::Constness,
|
2016-02-05 13:13:36 +01:00
|
|
|
pub abi: Abi,
|
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),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(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-12-09 10:36:46 -05:00
|
|
|
unsafety: self.unsafety,
|
2015-02-25 22:05:07 +02:00
|
|
|
constness: self.constness,
|
2015-04-07 14:22:55 -07:00
|
|
|
abi: self.abi,
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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,
|
2015-08-20 18:27:53 +01:00
|
|
|
pub variadic: bool,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub attrs: Vec<Attribute>,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2016-05-08 21:19:29 +03:00
|
|
|
impl FnDecl {
|
|
|
|
pub fn has_self(&self) -> bool {
|
|
|
|
return self.inputs.values.len() > 0 && self.inputs.values[0].name == "self";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<FnDecl> for hir::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),
|
2015-08-20 18:27:53 +01:00
|
|
|
variadic: self.variadic,
|
2014-03-05 15:28:08 -08:00
|
|
|
attrs: Vec::new()
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:32:28 -04:00
|
|
|
impl<'a, 'tcx> Clean<FnDecl> for (DefId, &'a ty::PolyFnSig<'tcx>) {
|
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;
|
2016-02-28 12:11:13 +01:00
|
|
|
let mut names = if cx.map.as_local_node_id(did).is_some() {
|
2015-09-04 13:52:28 -04:00
|
|
|
vec![].into_iter()
|
2014-05-23 18:47:01 -07:00
|
|
|
} else {
|
2015-11-22 21:02:04 +02:00
|
|
|
cx.tcx().sess.cstore.method_arg_names(did).into_iter()
|
2014-05-23 18:47:01 -07:00
|
|
|
}.peekable();
|
2014-05-03 02:08:58 -07:00
|
|
|
FnDecl {
|
2014-12-12 11:28:35 -05:00
|
|
|
output: Return(sig.0.output.clean(cx)),
|
2014-05-23 18:47:01 -07:00
|
|
|
attrs: Vec::new(),
|
2015-08-20 18:27:53 +01:00
|
|
|
variadic: sig.0.variadic,
|
2014-05-03 02:08:58 -07:00
|
|
|
inputs: Arguments {
|
2014-12-12 11:28:35 -05:00
|
|
|
values: sig.0.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(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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
|
|
|
}
|
|
|
|
|
2016-05-08 21:19:29 +03:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
|
|
|
pub enum SelfTy {
|
|
|
|
SelfValue,
|
|
|
|
SelfBorrowed(Option<Lifetime>, Mutability),
|
|
|
|
SelfExplicit(Type),
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Argument {
|
|
|
|
pub fn to_self(&self) -> Option<SelfTy> {
|
|
|
|
if self.name == "self" {
|
|
|
|
match self.type_ {
|
|
|
|
Infer => Some(SelfValue),
|
|
|
|
BorrowedRef{ref lifetime, mutability, ref type_} if **type_ == Infer => {
|
|
|
|
Some(SelfBorrowed(lifetime.clone(), mutability))
|
|
|
|
}
|
|
|
|
_ => Some(SelfExplicit(self.type_.clone()))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Argument> for hir::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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2014-11-09 16:14:15 +01:00
|
|
|
pub enum FunctionRetTy {
|
|
|
|
Return(Type),
|
2015-01-18 22:49:19 +09:00
|
|
|
DefaultReturn,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<FunctionRetTy> for hir::FunctionRetTy {
|
2014-11-09 16:14:15 +01:00
|
|
|
fn clean(&self, cx: &DocContext) -> FunctionRetTy {
|
2013-08-15 16:28:54 -04:00
|
|
|
match *self {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::Return(ref typ) => Return(typ.clean(cx)),
|
|
|
|
hir::DefaultReturn(..) => DefaultReturn,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Trait {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2015-03-10 12:28:44 +02:00
|
|
|
pub items: Vec<Item>,
|
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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: TraitItem(Trait {
|
2014-12-09 19:59:20 -05:00
|
|
|
unsafety: self.unsafety,
|
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
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Type> for hir::TraitRef {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
2014-11-20 19:44:49 -05:00
|
|
|
resolve_type(cx, self.path.clean(cx), self.ref_id)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<PolyTrait> for hir::PolyTraitRef {
|
2014-12-16 08:50:52 -08:00
|
|
|
fn clean(&self, cx: &DocContext) -> PolyTrait {
|
|
|
|
PolyTrait {
|
|
|
|
trait_: self.trait_ref.clean(cx),
|
|
|
|
lifetimes: self.bound_lifetimes.clean(cx)
|
|
|
|
}
|
2014-11-07 06:53:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Item> for hir::TraitItem {
|
2015-03-10 12:28:44 +02:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
let inner = match self.node {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::ConstTraitItem(ref ty, ref default) => {
|
2015-03-14 12:05:00 -06:00
|
|
|
AssociatedConstItem(ty.clean(cx),
|
2016-05-03 13:09:42 +02:00
|
|
|
default.as_ref().map(|e| pprust::expr_to_string(&e)))
|
2015-03-14 12:05:00 -06:00
|
|
|
}
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::MethodTraitItem(ref sig, Some(_)) => {
|
2015-03-11 23:38:58 +02:00
|
|
|
MethodItem(sig.clean(cx))
|
|
|
|
}
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::MethodTraitItem(ref sig, None) => {
|
2015-03-11 23:38:58 +02:00
|
|
|
TyMethodItem(sig.clean(cx))
|
|
|
|
}
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::TypeTraitItem(ref bounds, ref default) => {
|
2015-03-10 12:28:44 +02:00
|
|
|
AssociatedTypeItem(bounds.clean(cx), default.clean(cx))
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Item {
|
2015-09-20 04:50:30 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
2015-03-10 12:28:44 +02:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2015-03-10 12:28:44 +02:00
|
|
|
visibility: None,
|
2015-09-02 16:11:32 -04:00
|
|
|
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
|
2015-03-10 12:28:44 +02:00
|
|
|
inner: inner
|
2014-08-04 13:56:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Item> for hir::ImplItem {
|
2015-03-10 12:28:44 +02:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
let inner = match self.node {
|
2015-11-12 15:57:51 +01:00
|
|
|
hir::ImplItemKind::Const(ref ty, ref expr) => {
|
2016-02-12 09:34:00 +01:00
|
|
|
AssociatedConstItem(ty.clean(cx),
|
2016-05-03 13:09:42 +02:00
|
|
|
Some(pprust::expr_to_string(expr)))
|
2015-03-14 12:05:00 -06:00
|
|
|
}
|
2015-11-12 15:57:51 +01:00
|
|
|
hir::ImplItemKind::Method(ref sig, _) => {
|
2015-03-11 23:38:58 +02:00
|
|
|
MethodItem(sig.clean(cx))
|
|
|
|
}
|
2015-11-12 15:57:51 +01:00
|
|
|
hir::ImplItemKind::Type(ref ty) => TypedefItem(Typedef {
|
2015-03-10 12:28:44 +02:00
|
|
|
type_: ty.clean(cx),
|
|
|
|
generics: Generics {
|
|
|
|
lifetimes: Vec::new(),
|
|
|
|
type_params: Vec::new(),
|
|
|
|
where_predicates: Vec::new()
|
|
|
|
},
|
2015-05-21 14:17:37 +02:00
|
|
|
}, true),
|
2015-03-10 12:28:44 +02:00
|
|
|
};
|
|
|
|
Item {
|
2015-09-20 04:50:30 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
2015-03-10 12:28:44 +02:00
|
|
|
source: self.span.clean(cx),
|
|
|
|
attrs: self.attrs.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2015-03-10 12:28:44 +02:00
|
|
|
visibility: self.vis.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
|
2015-03-10 12:28:44 +02:00
|
|
|
inner: inner
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<Item> for ty::Method<'tcx> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2016-06-13 20:10:32 +03:00
|
|
|
// Depend on trait/impl predicates always being before method's own predicates,
|
|
|
|
// to be able to split method predicates into "inherited" and method-specific.
|
|
|
|
let outer_predicates = cx.tcx().lookup_predicates(self.container_id()).predicates;
|
|
|
|
let method_start = outer_predicates.len();
|
|
|
|
assert_eq!(&outer_predicates[..], &self.predicates.predicates[..method_start]);
|
|
|
|
|
|
|
|
let method_predicates = ty::GenericPredicates {
|
|
|
|
predicates: self.predicates.predicates[method_start..].to_vec()
|
|
|
|
};
|
|
|
|
|
|
|
|
let generics = (&self.generics, &method_predicates,
|
2015-04-07 11:50:14 -07:00
|
|
|
subst::FnSpace).clean(cx);
|
2016-05-08 21:19:29 +03:00
|
|
|
let mut decl = (self.def_id, &self.fty.sig).clean(cx);
|
|
|
|
match self.explicit_self {
|
|
|
|
ty::ExplicitSelfCategory::ByValue => {
|
|
|
|
decl.inputs.values[0].type_ = Infer;
|
|
|
|
}
|
|
|
|
ty::ExplicitSelfCategory::ByReference(..) => {
|
|
|
|
match decl.inputs.values[0].type_ {
|
|
|
|
BorrowedRef{ref mut type_, ..} => **type_ = Infer,
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2015-04-07 11:50:14 -07:00
|
|
|
let provided = match self.container {
|
|
|
|
ty::ImplContainer(..) => false,
|
|
|
|
ty::TraitContainer(did) => {
|
2015-06-25 23:42:17 +03:00
|
|
|
cx.tcx().provided_trait_methods(did).iter().any(|m| {
|
2015-04-07 11:50:14 -07:00
|
|
|
m.def_id == self.def_id
|
|
|
|
})
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let inner = if provided {
|
|
|
|
MethodItem(Method {
|
|
|
|
unsafety: self.fty.unsafety,
|
|
|
|
generics: generics,
|
|
|
|
decl: decl,
|
2015-05-05 08:47:04 -04:00
|
|
|
abi: self.fty.abi,
|
|
|
|
|
|
|
|
// trait methods canot (currently, at least) be const
|
2015-07-31 00:04:06 -07:00
|
|
|
constness: hir::Constness::NotConst,
|
2015-04-07 11:50:14 -07:00
|
|
|
})
|
|
|
|
} else {
|
|
|
|
TyMethodItem(TyMethod {
|
|
|
|
unsafety: self.fty.unsafety,
|
|
|
|
generics: generics,
|
|
|
|
decl: decl,
|
2015-05-05 08:47:04 -04:00
|
|
|
abi: self.fty.abi,
|
2015-04-07 11:50:14 -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)),
|
2016-04-11 08:15:14 +00:00
|
|
|
visibility: Some(Inherited),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: get_stability(cx, self.def_id),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(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(),
|
2015-04-07 11:50:14 -07:00
|
|
|
inner: inner,
|
2014-06-02 00:09:44 -07:00
|
|
|
}
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<Item> for ty::ImplOrTraitItem<'tcx> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2014-08-04 13:56:56 -07:00
|
|
|
match *self {
|
2015-03-14 12:05:00 -06:00
|
|
|
ty::ConstTraitItem(ref cti) => cti.clean(cx),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 08:50:52 -08:00
|
|
|
/// A trait reference, which may have higher ranked lifetimes.
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2014-12-16 08:50:52 -08:00
|
|
|
pub struct PolyTrait {
|
|
|
|
pub trait_: Type,
|
|
|
|
pub lifetimes: Vec<Lifetime>
|
|
|
|
}
|
|
|
|
|
2013-08-15 16:28:54 -04:00
|
|
|
/// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original
|
2016-02-29 23:36:51 +00:00
|
|
|
/// type out of the AST/TyCtxt given one of these, if more information is needed. Most importantly
|
2013-08-15 16:28:54 -04:00
|
|
|
/// it does not preserve mutability or boxes.
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Type {
|
2015-07-31 00:04:06 -07:00
|
|
|
/// structs/enums/traits (most that'd be an hir::TyPath)
|
2013-09-27 18:23:57 -07:00
|
|
|
ResolvedPath {
|
2014-11-15 17:57:54 -08:00
|
|
|
path: Path,
|
|
|
|
typarams: Option<Vec<TyParamBound>>,
|
2015-08-16 06:32:28 -04:00
|
|
|
did: DefId,
|
2015-05-25 15:06:38 +02:00
|
|
|
/// true if is a `T::Name` path for associated types
|
|
|
|
is_generic: bool,
|
2013-09-27 18:23:57 -07:00
|
|
|
},
|
2014-12-27 19:42:27 -05:00
|
|
|
/// For parameterized types, so the consumer of the JSON don't go
|
|
|
|
/// looking for types which don't exist anywhere.
|
|
|
|
Generic(String),
|
2015-03-25 17:06:52 -07:00
|
|
|
/// Primitives are the fixed-size numeric types (plus int/usize/float), char,
|
2015-03-23 14:01:28 -07:00
|
|
|
/// arrays, slices, and tuples.
|
2014-09-11 17:07:49 +12:00
|
|
|
Primitive(PrimitiveType),
|
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),
|
2016-08-02 15:56:20 +08:00
|
|
|
Never,
|
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
|
|
|
},
|
2014-11-26 10:11:27 -05:00
|
|
|
|
|
|
|
// <Type as Trait>::Name
|
2014-11-20 21:45:05 -08:00
|
|
|
QPath {
|
|
|
|
name: String,
|
|
|
|
self_type: Box<Type>,
|
|
|
|
trait_: Box<Type>
|
|
|
|
},
|
2014-11-26 10:11:27 -05:00
|
|
|
|
|
|
|
// _
|
|
|
|
Infer,
|
|
|
|
|
|
|
|
// for<'a> Foo(&'a)
|
|
|
|
PolyTraitRef(Vec<TyParamBound>),
|
2016-08-01 04:25:32 +03:00
|
|
|
|
|
|
|
// impl TraitA+TraitB
|
|
|
|
ImplTrait(Vec<TyParamBound>),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Copy, Debug)]
|
2014-09-11 17:07:49 +12:00
|
|
|
pub enum PrimitiveType {
|
2014-12-05 18:11:46 -08:00
|
|
|
Isize, I8, I16, I32, I64,
|
|
|
|
Usize, 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,
|
2015-03-23 14:01:28 -07:00
|
|
|
Array,
|
2014-05-28 19:53:37 -07:00
|
|
|
PrimitiveTuple,
|
2015-04-06 15:58:23 -07:00
|
|
|
PrimitiveRawPointer,
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)]
|
2013-10-02 15:39:32 -07:00
|
|
|
pub enum TypeKind {
|
|
|
|
TypeEnum,
|
|
|
|
TypeFunction,
|
2014-05-09 13:52:17 -07:00
|
|
|
TypeModule,
|
2014-12-12 04:13:36 -08:00
|
|
|
TypeConst,
|
2014-05-09 13:52:17 -07:00
|
|
|
TypeStatic,
|
|
|
|
TypeStruct,
|
|
|
|
TypeTrait,
|
|
|
|
TypeVariant,
|
2014-09-16 09:13:00 +12:00
|
|
|
TypeTypedef,
|
2013-10-02 15:39:32 -07:00
|
|
|
}
|
|
|
|
|
2016-03-24 06:10:52 +01:00
|
|
|
pub trait GetDefId {
|
|
|
|
fn def_id(&self) -> Option<DefId>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: GetDefId> GetDefId for Option<T> {
|
|
|
|
fn def_id(&self) -> Option<DefId> {
|
|
|
|
self.as_ref().and_then(|d| d.def_id())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-07 17:35:23 -07:00
|
|
|
impl Type {
|
|
|
|
pub fn primitive_type(&self) -> Option<PrimitiveType> {
|
|
|
|
match *self {
|
|
|
|
Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p),
|
|
|
|
Vector(..) | BorrowedRef{ type_: box Vector(..), .. } => Some(Slice),
|
|
|
|
FixedVector(..) | BorrowedRef { type_: box FixedVector(..), .. } => {
|
|
|
|
Some(Array)
|
|
|
|
}
|
|
|
|
Tuple(..) => Some(PrimitiveTuple),
|
|
|
|
RawPointer(..) => Some(PrimitiveRawPointer),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 01:11:08 +09:00
|
|
|
|
2016-05-09 16:48:02 +02:00
|
|
|
pub fn is_generic(&self) -> bool {
|
|
|
|
match *self {
|
|
|
|
ResolvedPath { is_generic, .. } => is_generic,
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2016-03-24 06:10:52 +01:00
|
|
|
}
|
2016-03-08 11:20:16 -08:00
|
|
|
|
2016-03-24 06:10:52 +01:00
|
|
|
impl GetDefId for Type {
|
2016-03-08 11:20:16 -08:00
|
|
|
fn def_id(&self) -> Option<DefId> {
|
|
|
|
match *self {
|
|
|
|
ResolvedPath { did, .. } => Some(did),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
2015-04-07 17:35:23 -07:00
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
impl PrimitiveType {
|
|
|
|
fn from_str(s: &str) -> Option<PrimitiveType> {
|
2015-02-01 21:53:25 -05:00
|
|
|
match s {
|
2015-03-25 17:06:52 -07:00
|
|
|
"isize" => Some(Isize),
|
2014-05-28 19:53:37 -07:00
|
|
|
"i8" => Some(I8),
|
|
|
|
"i16" => Some(I16),
|
|
|
|
"i32" => Some(I32),
|
|
|
|
"i64" => Some(I64),
|
2015-03-25 17:06:52 -07:00
|
|
|
"usize" => Some(Usize),
|
2014-05-28 19:53:37 -07:00
|
|
|
"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),
|
2015-03-23 14:01:28 -07:00
|
|
|
"array" => Some(Array),
|
2014-05-28 19:53:37 -07:00
|
|
|
"slice" => Some(Slice),
|
|
|
|
"tuple" => Some(PrimitiveTuple),
|
2015-04-06 15:58:23 -07:00
|
|
|
"pointer" => Some(PrimitiveRawPointer),
|
2014-05-28 19:53:37 -07:00
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-11 17:07:49 +12:00
|
|
|
fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
|
2016-03-22 20:26:33 +01:00
|
|
|
for attr in attrs.list("doc") {
|
2016-02-28 10:12:41 +01:00
|
|
|
if let NameValue(ref k, ref v) = *attr {
|
|
|
|
if "primitive" == *k {
|
|
|
|
if let ret@Some(..) = PrimitiveType::from_str(v) {
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-28 10:12:41 +01:00
|
|
|
None
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
|
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 {
|
2014-12-05 18:11:46 -08:00
|
|
|
Isize => "isize",
|
2014-05-28 19:53:37 -07:00
|
|
|
I8 => "i8",
|
|
|
|
I16 => "i16",
|
|
|
|
I32 => "i32",
|
|
|
|
I64 => "i64",
|
2014-12-05 18:11:46 -08:00
|
|
|
Usize => "usize",
|
2014-05-28 19:53:37 -07:00
|
|
|
U8 => "u8",
|
|
|
|
U16 => "u16",
|
|
|
|
U32 => "u32",
|
|
|
|
U64 => "u64",
|
|
|
|
F32 => "f32",
|
|
|
|
F64 => "f64",
|
|
|
|
Str => "str",
|
|
|
|
Bool => "bool",
|
|
|
|
Char => "char",
|
2015-03-23 14:01:28 -07:00
|
|
|
Array => "array",
|
2014-05-28 19:53:37 -07:00
|
|
|
Slice => "slice",
|
|
|
|
PrimitiveTuple => "tuple",
|
2015-04-06 15:58:23 -07:00
|
|
|
PrimitiveRawPointer => "pointer",
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2015-09-17 14:29:59 -04:00
|
|
|
pub fn to_def_index(&self) -> DefIndex {
|
|
|
|
let x = u32::MAX - 1 - (*self as u32);
|
|
|
|
DefIndex::new(x as usize)
|
2014-05-28 19:53:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-07 18:20:26 +03:00
|
|
|
|
|
|
|
// Poor man's type parameter substitution at HIR level.
|
|
|
|
// Used to replace private type aliases in public signatures with their aliased types.
|
|
|
|
struct SubstAlias<'a, 'tcx: 'a> {
|
|
|
|
tcx: &'a ty::TyCtxt<'a, 'tcx, 'tcx>,
|
|
|
|
// Table type parameter definition -> substituted type
|
|
|
|
ty_substs: HashMap<Def, hir::Ty>,
|
|
|
|
// Table node id of lifetime parameter definition -> substituted lifetime
|
|
|
|
lt_substs: HashMap<ast::NodeId, hir::Lifetime>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a, 'tcx: 'a, 'b: 'tcx> Folder for SubstAlias<'a, 'tcx> {
|
|
|
|
fn fold_ty(&mut self, ty: P<hir::Ty>) -> P<hir::Ty> {
|
|
|
|
if let hir::TyPath(..) = ty.node {
|
|
|
|
let def = self.tcx.expect_def(ty.id);
|
|
|
|
if let Some(new_ty) = self.ty_substs.get(&def).cloned() {
|
|
|
|
return P(new_ty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hir::fold::noop_fold_ty(ty, self)
|
|
|
|
}
|
|
|
|
fn fold_lifetime(&mut self, lt: hir::Lifetime) -> hir::Lifetime {
|
|
|
|
let def = self.tcx.named_region_map.defs.get(<.id).cloned();
|
|
|
|
match def {
|
|
|
|
Some(DefEarlyBoundRegion(_, _, node_id)) |
|
|
|
|
Some(DefLateBoundRegion(_, node_id)) |
|
|
|
|
Some(DefFreeRegion(_, node_id)) => {
|
|
|
|
if let Some(lt) = self.lt_substs.get(&node_id).cloned() {
|
|
|
|
return lt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
hir::fold::noop_fold_lifetime(lt, self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Type> for hir::Ty {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Type {
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir::*;
|
2013-09-24 13:53:09 -07:00
|
|
|
match self.node {
|
2016-08-02 15:56:20 +08:00
|
|
|
TyNever => Never,
|
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)),
|
2016-07-13 10:35:58 +02:00
|
|
|
TyFixedLengthVec(ref ty, ref e) => {
|
|
|
|
let n = if let Some(tcx) = cx.tcx_opt() {
|
|
|
|
use rustc_const_math::{ConstInt, ConstUsize};
|
|
|
|
use rustc_const_eval::eval_const_expr;
|
|
|
|
use rustc::middle::const_val::ConstVal;
|
|
|
|
match eval_const_expr(tcx, e) {
|
|
|
|
ConstVal::Integral(ConstInt::Usize(u)) => match u {
|
|
|
|
ConstUsize::Us16(u) => u.to_string(),
|
|
|
|
ConstUsize::Us32(u) => u.to_string(),
|
|
|
|
ConstUsize::Us64(u) => u.to_string(),
|
|
|
|
},
|
|
|
|
// after type checking this can't fail
|
|
|
|
_ => unreachable!(),
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pprust::expr_to_string(e)
|
|
|
|
};
|
|
|
|
FixedVector(box ty.clean(cx), n)
|
|
|
|
},
|
2014-09-06 19:13:40 +03:00
|
|
|
TyTup(ref tys) => Tuple(tys.clean(cx)),
|
2016-07-07 18:20:26 +03:00
|
|
|
TyPath(None, ref path) => {
|
|
|
|
if let Some(tcx) = cx.tcx_opt() {
|
|
|
|
// Substitute private type aliases
|
|
|
|
let def = tcx.expect_def(self.id);
|
|
|
|
if let Def::TyAlias(def_id) = def {
|
|
|
|
if let Some(node_id) = tcx.map.as_local_node_id(def_id) {
|
|
|
|
if !cx.access_levels.borrow().is_exported(def_id) {
|
|
|
|
let item = tcx.map.expect_item(node_id);
|
|
|
|
if let hir::ItemTy(ref ty, ref generics) = item.node {
|
|
|
|
let provided_params = &path.segments.last().unwrap().parameters;
|
|
|
|
let mut ty_substs = HashMap::new();
|
|
|
|
let mut lt_substs = HashMap::new();
|
|
|
|
for (i, ty_param) in generics.ty_params.iter().enumerate() {
|
|
|
|
let ty_param_def = tcx.expect_def(ty_param.id);
|
|
|
|
if let Some(ty) = provided_params.types().get(i).cloned()
|
|
|
|
.cloned() {
|
|
|
|
ty_substs.insert(ty_param_def, ty.unwrap());
|
|
|
|
} else if let Some(default) = ty_param.default.clone() {
|
|
|
|
ty_substs.insert(ty_param_def, default.unwrap());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i, lt_param) in generics.lifetimes.iter().enumerate() {
|
|
|
|
if let Some(lt) = provided_params.lifetimes().get(i)
|
|
|
|
.cloned()
|
|
|
|
.cloned() {
|
|
|
|
lt_substs.insert(lt_param.lifetime.id, lt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let mut subst_alias = SubstAlias {
|
|
|
|
tcx: &tcx,
|
|
|
|
ty_substs: ty_substs,
|
|
|
|
lt_substs: lt_substs
|
|
|
|
};
|
|
|
|
return subst_alias.fold_ty(ty.clone()).clean(cx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resolve_type(cx, path.clean(cx), self.id)
|
2014-11-20 19:44:49 -05:00
|
|
|
}
|
2015-02-17 19:29:13 +02:00
|
|
|
TyPath(Some(ref qself), ref p) => {
|
2015-12-17 20:41:28 +03:00
|
|
|
let mut segments: Vec<_> = p.segments.clone().into();
|
|
|
|
segments.pop();
|
|
|
|
let trait_path = hir::Path {
|
|
|
|
span: p.span,
|
|
|
|
global: p.global,
|
|
|
|
segments: segments.into(),
|
|
|
|
};
|
2015-01-31 05:51:21 +02:00
|
|
|
Type::QPath {
|
2016-03-06 15:54:44 +03:00
|
|
|
name: p.segments.last().unwrap().name.clean(cx),
|
2015-02-17 19:29:13 +02:00
|
|
|
self_type: box qself.ty.clean(cx),
|
2015-01-31 21:20:24 +02:00
|
|
|
trait_: box resolve_type(cx, trait_path.clean(cx), self.id)
|
2015-01-31 05:51:21 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 19:44:49 -05:00
|
|
|
TyObjectSum(ref lhs, ref bounds) => {
|
|
|
|
let lhs_ty = lhs.clean(cx);
|
|
|
|
match lhs_ty {
|
2015-05-25 15:06:38 +02:00
|
|
|
ResolvedPath { path, typarams: None, did, is_generic } => {
|
|
|
|
ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: Some(bounds.clean(cx)),
|
|
|
|
did: did,
|
|
|
|
is_generic: is_generic,
|
|
|
|
}
|
2014-11-20 19:44:49 -05:00
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
lhs_ty // shouldn't happen
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2014-09-06 19:13:40 +03:00
|
|
|
TyBareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
|
2016-02-28 12:11:13 +01:00
|
|
|
TyPolyTraitRef(ref bounds) => PolyTraitRef(bounds.clean(cx)),
|
2016-08-01 04:25:32 +03:00
|
|
|
TyImplTrait(ref bounds) => ImplTrait(bounds.clean(cx)),
|
2016-02-28 12:11:13 +01:00
|
|
|
TyInfer => Infer,
|
|
|
|
TyTypeof(..) => panic!("Unimplemented type {:?}", self.node),
|
2013-09-24 13:53:09 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-06 09:20:16 +02:00
|
|
|
impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
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 {
|
2016-08-02 15:56:20 +08:00
|
|
|
ty::TyNever => Never,
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyBool => Primitive(Bool),
|
|
|
|
ty::TyChar => Primitive(Char),
|
2016-02-08 16:20:57 +01:00
|
|
|
ty::TyInt(ast::IntTy::Is) => Primitive(Isize),
|
|
|
|
ty::TyInt(ast::IntTy::I8) => Primitive(I8),
|
|
|
|
ty::TyInt(ast::IntTy::I16) => Primitive(I16),
|
|
|
|
ty::TyInt(ast::IntTy::I32) => Primitive(I32),
|
|
|
|
ty::TyInt(ast::IntTy::I64) => Primitive(I64),
|
|
|
|
ty::TyUint(ast::UintTy::Us) => Primitive(Usize),
|
|
|
|
ty::TyUint(ast::UintTy::U8) => Primitive(U8),
|
|
|
|
ty::TyUint(ast::UintTy::U16) => Primitive(U16),
|
|
|
|
ty::TyUint(ast::UintTy::U32) => Primitive(U32),
|
|
|
|
ty::TyUint(ast::UintTy::U64) => Primitive(U64),
|
2016-02-08 16:09:01 +01:00
|
|
|
ty::TyFloat(ast::FloatTy::F32) => Primitive(F32),
|
|
|
|
ty::TyFloat(ast::FloatTy::F64) => Primitive(F64),
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyStr => Primitive(Str),
|
|
|
|
ty::TyBox(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
|
|
|
}
|
2015-06-12 16:50:13 -07:00
|
|
|
ty::TySlice(ty) => Vector(box ty.clean(cx)),
|
|
|
|
ty::TyArray(ty, i) => FixedVector(box ty.clean(cx),
|
|
|
|
format!("{}", i)),
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyRawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
|
|
|
|
ty::TyRef(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
|
|
|
},
|
2016-02-16 18:36:41 +02:00
|
|
|
ty::TyFnDef(_, _, ref fty) |
|
2015-06-13 13:15:03 -07:00
|
|
|
ty::TyFnPtr(ref fty) => BareFunction(box BareFunctionDecl {
|
2014-12-09 10:36:46 -05:00
|
|
|
unsafety: fty.unsafety,
|
2014-05-03 02:08:58 -07:00
|
|
|
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
|
|
|
},
|
2015-09-02 16:11:32 -04:00
|
|
|
decl: (cx.map.local_def_id(0), &fty.sig).clean(cx),
|
2016-04-22 11:48:46 +01:00
|
|
|
abi: fty.abi,
|
2014-05-03 02:08:58 -07:00
|
|
|
}),
|
2015-07-20 22:13:36 +03:00
|
|
|
ty::TyStruct(def, substs) |
|
|
|
|
ty::TyEnum(def, substs) => {
|
|
|
|
let did = def.did;
|
2014-10-31 10:51:16 +02:00
|
|
|
let kind = match self.sty {
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyStruct(..) => TypeStruct,
|
2014-05-03 02:08:58 -07:00
|
|
|
_ => TypeEnum,
|
|
|
|
};
|
2015-12-05 11:58:04 +01:00
|
|
|
inline::record_extern_fqn(cx, did, kind);
|
|
|
|
let path = external_path(cx, &cx.tcx().item_name(did).as_str(),
|
2015-01-12 09:43:24 -08:00
|
|
|
None, vec![], substs);
|
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,
|
2015-05-25 15:06:38 +02:00
|
|
|
is_generic: false,
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyTrait(box ty::TraitTy { ref principal, ref bounds }) => {
|
2014-12-26 04:36:04 -05:00
|
|
|
let did = principal.def_id();
|
2015-12-05 11:58:04 +01:00
|
|
|
inline::record_extern_fqn(cx, did, TypeTrait);
|
2015-01-12 09:43:24 -08:00
|
|
|
let (typarams, bindings) = bounds.clean(cx);
|
2015-12-05 11:58:04 +01:00
|
|
|
let path = external_path(cx, &cx.tcx().item_name(did).as_str(),
|
2015-01-12 09:43:24 -08:00
|
|
|
Some(did), bindings, principal.substs());
|
2014-12-26 04:36:04 -05:00
|
|
|
ResolvedPath {
|
|
|
|
path: path,
|
2015-01-12 09:43:24 -08:00
|
|
|
typarams: Some(typarams),
|
2014-12-26 04:36:04 -05:00
|
|
|
did: did,
|
2015-05-25 15:06:38 +02:00
|
|
|
is_generic: false,
|
2014-12-26 04:36:04 -05:00
|
|
|
}
|
|
|
|
}
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyTuple(ref t) => Tuple(t.clean(cx)),
|
2014-05-03 02:08:58 -07:00
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyProjection(ref data) => data.clean(cx),
|
2014-12-17 14:16:28 -05:00
|
|
|
|
2015-07-28 18:07:20 +02:00
|
|
|
ty::TyParam(ref p) => Generic(p.name.to_string()),
|
2014-05-03 02:08:58 -07:00
|
|
|
|
2016-07-22 18:56:22 +03:00
|
|
|
ty::TyAnon(def_id, substs) => {
|
|
|
|
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
|
|
|
|
// by looking up the projections associated with the def_id.
|
|
|
|
let item_predicates = cx.tcx().lookup_predicates(def_id);
|
|
|
|
let substs = cx.tcx().lift(&substs).unwrap();
|
|
|
|
let bounds = item_predicates.instantiate(cx.tcx(), substs);
|
2016-06-13 20:10:32 +03:00
|
|
|
ImplTrait(bounds.predicates.into_iter().filter_map(|predicate| {
|
2016-07-22 18:56:22 +03:00
|
|
|
predicate.to_opt_poly_trait_ref().clean(cx)
|
|
|
|
}).collect())
|
|
|
|
}
|
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyClosure(..) => Tuple(vec![]), // FIXME(pcwalton)
|
2014-05-28 22:26:56 -07:00
|
|
|
|
2015-06-11 16:21:46 -07:00
|
|
|
ty::TyInfer(..) => panic!("TyInfer"),
|
|
|
|
ty::TyError => panic!("TyError"),
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Item> for hir::StructField {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
Item {
|
2016-02-27 11:34:29 +03:00
|
|
|
name: Some(self.name).clean(cx),
|
|
|
|
attrs: self.attrs.clean(cx),
|
2014-09-06 19:13:40 +03:00
|
|
|
source: self.span.clean(cx),
|
2016-03-25 06:08:11 +00:00
|
|
|
visibility: self.vis.clean(cx),
|
2016-02-27 11:34:29 +03:00
|
|
|
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
|
|
|
deprecation: get_deprecation(cx, cx.map.local_def_id(self.id)),
|
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2016-04-02 08:17:59 +02:00
|
|
|
inner: StructFieldItem(self.ty.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 14:41:33 +03:00
|
|
|
impl<'tcx> Clean<Item> for ty::FieldDefData<'tcx, 'static> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2015-11-22 21:02:04 +02:00
|
|
|
// FIXME: possible O(n^2)-ness! Not my fault.
|
2016-02-27 11:34:29 +03:00
|
|
|
let attr_map = cx.tcx().sess.cstore.crate_struct_field_attrs(self.did.krate);
|
2014-05-23 00:42:33 -07:00
|
|
|
Item {
|
2016-02-27 11:34:29 +03:00
|
|
|
name: Some(self.name).clean(cx),
|
|
|
|
attrs: attr_map.get(&self.did).unwrap_or(&Vec::new()).clean(cx),
|
2014-05-23 00:42:33 -07:00
|
|
|
source: Span::empty(),
|
2016-03-25 06:08:11 +00:00
|
|
|
visibility: self.vis.clean(cx),
|
2015-08-02 22:52:50 +03:00
|
|
|
stability: get_stability(cx, self.did),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(cx, self.did),
|
2015-08-02 22:52:50 +03:00
|
|
|
def_id: self.did,
|
2016-04-02 08:17:59 +02:00
|
|
|
inner: StructFieldItem(self.unsubst_ty().clean(cx)),
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-11 08:15:14 +00:00
|
|
|
#[derive(Clone, PartialEq, Eq, RustcDecodable, RustcEncodable, Debug)]
|
|
|
|
pub enum Visibility {
|
|
|
|
Public,
|
|
|
|
Inherited,
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Option<Visibility>> for hir::Visibility {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
2016-04-11 08:15:14 +00:00
|
|
|
Some(if *self == hir::Visibility::Public { Public } else { Inherited })
|
2016-03-25 06:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Option<Visibility>> for ty::Visibility {
|
|
|
|
fn clean(&self, _: &DocContext) -> Option<Visibility> {
|
2016-04-11 08:15:14 +00:00
|
|
|
Some(if *self == ty::Visibility::Public { Public } else { Inherited })
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.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.
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-29 08:50:44 +03:00
|
|
|
impl Clean<VariantStruct> for ::rustc::hir::VariantData {
|
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),
|
2015-10-25 18:33:51 +03:00
|
|
|
fields: self.fields().iter().map(|x| x.clean(cx)).collect(),
|
2013-10-13 20:37:43 -07:00
|
|
|
fields_stripped: false,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.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
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
2015-09-16 20:01:15 +03:00
|
|
|
visibility: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2015-10-10 03:28:40 +03:00
|
|
|
def_id: cx.map.local_def_id(self.def.id()),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: VariantItem(Variant {
|
2015-10-02 00:03:22 +03:00
|
|
|
kind: struct_def_to_variant_kind(&self.def, cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-07 14:41:33 +03:00
|
|
|
impl<'tcx> Clean<Item> for ty::VariantDefData<'tcx, 'static> {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2016-06-11 18:47:47 +03:00
|
|
|
let kind = match self.kind {
|
2015-08-02 22:52:50 +03:00
|
|
|
ty::VariantKind::Unit => CLikeVariant,
|
|
|
|
ty::VariantKind::Tuple => {
|
|
|
|
TupleVariant(
|
|
|
|
self.fields.iter().map(|f| f.unsubst_ty().clean(cx)).collect()
|
|
|
|
)
|
2014-05-23 16:14:54 -07:00
|
|
|
}
|
2015-10-08 03:20:57 +03:00
|
|
|
ty::VariantKind::Struct => {
|
2014-05-23 16:14:54 -07:00
|
|
|
StructVariant(VariantStruct {
|
|
|
|
struct_type: doctree::Plain,
|
|
|
|
fields_stripped: false,
|
2015-08-02 22:52:50 +03:00
|
|
|
fields: self.fields.iter().map(|field| {
|
2014-05-23 16:14:54 -07:00
|
|
|
Item {
|
|
|
|
source: Span::empty(),
|
2015-08-02 22:52:50 +03:00
|
|
|
name: Some(field.name.clean(cx)),
|
2016-03-25 02:18:57 +01:00
|
|
|
attrs: cx.tcx().get_attrs(field.did).clean(cx),
|
2016-03-25 06:08:11 +00:00
|
|
|
visibility: field.vis.clean(cx),
|
2016-03-25 02:18:57 +01:00
|
|
|
def_id: field.did,
|
|
|
|
stability: get_stability(cx, field.did),
|
|
|
|
deprecation: get_deprecation(cx, field.did),
|
2016-04-02 08:17:59 +02:00
|
|
|
inner: StructFieldItem(field.unsubst_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)),
|
2015-08-02 22:52:50 +03:00
|
|
|
attrs: inline::load_attrs(cx, cx.tcx(), self.did),
|
2014-05-23 16:14:54 -07:00
|
|
|
source: Span::empty(),
|
2016-04-11 08:15:14 +00:00
|
|
|
visibility: Some(Inherited),
|
2015-08-02 22:52:50 +03:00
|
|
|
def_id: self.did,
|
2014-05-23 16:14:54 -07:00
|
|
|
inner: VariantItem(Variant { kind: kind }),
|
2015-08-02 22:52:50 +03:00
|
|
|
stability: get_stability(cx, self.did),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(cx, self.did),
|
2014-05-23 16:14:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
|
|
|
}
|
|
|
|
|
2015-10-08 03:20:57 +03:00
|
|
|
fn struct_def_to_variant_kind(struct_def: &hir::VariantData, cx: &DocContext) -> VariantKind {
|
2015-10-08 23:45:46 +03:00
|
|
|
if struct_def.is_struct() {
|
2015-10-02 00:03:22 +03:00
|
|
|
StructVariant(struct_def.clean(cx))
|
2015-10-08 23:45:46 +03:00
|
|
|
} else if struct_def.is_unit() {
|
2015-10-02 00:03:22 +03:00
|
|
|
CLikeVariant
|
|
|
|
} else {
|
2016-02-27 11:34:29 +03:00
|
|
|
TupleVariant(struct_def.fields().iter().map(|x| x.ty.clean(cx)).collect())
|
2015-10-02 00:03:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-09-27 15:12:23 -07:00
|
|
|
pub struct Span {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub filename: String,
|
2015-03-25 17:06:52 -07:00
|
|
|
pub loline: usize,
|
|
|
|
pub locol: usize,
|
|
|
|
pub hiline: usize,
|
|
|
|
pub hicol: usize,
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 18:08:13 -04:00
|
|
|
impl Clean<Span> for syntax_pos::Span {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Span {
|
2015-07-06 14:13:19 +12:00
|
|
|
if *self == DUMMY_SP {
|
|
|
|
return Span::empty();
|
|
|
|
}
|
|
|
|
|
2014-09-06 19:13:40 +03:00
|
|
|
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,
|
2015-01-17 23:49:08 +00:00
|
|
|
locol: lo.col.to_usize(),
|
2013-09-27 15:12:23 -07:00
|
|
|
hiline: hi.line,
|
2015-01-17 23:49:08 +00:00
|
|
|
hicol: hi.col.to_usize(),
|
2013-09-27 15:12:23 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
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
|
|
|
}
|
|
|
|
|
2015-04-07 00:16:35 -07:00
|
|
|
impl Path {
|
|
|
|
pub fn singleton(name: String) -> Path {
|
|
|
|
Path {
|
|
|
|
global: false,
|
|
|
|
segments: vec![PathSegment {
|
|
|
|
name: name,
|
|
|
|
params: PathParameters::AngleBracketed {
|
|
|
|
lifetimes: Vec::new(),
|
|
|
|
types: Vec::new(),
|
|
|
|
bindings: Vec::new()
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 01:11:08 +09:00
|
|
|
|
|
|
|
pub fn last_name(&self) -> String {
|
|
|
|
self.segments.last().unwrap().name.clone()
|
|
|
|
}
|
2015-04-07 00:16:35 -07:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Path> for hir::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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2014-12-16 12:40:43 -08:00
|
|
|
pub enum PathParameters {
|
|
|
|
AngleBracketed {
|
|
|
|
lifetimes: Vec<Lifetime>,
|
|
|
|
types: Vec<Type>,
|
2015-01-07 16:10:40 -08:00
|
|
|
bindings: Vec<TypeBinding>
|
2014-12-16 12:40:43 -08:00
|
|
|
},
|
|
|
|
Parenthesized {
|
|
|
|
inputs: Vec<Type>,
|
|
|
|
output: Option<Type>
|
|
|
|
}
|
2013-09-12 15:11:06 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<PathParameters> for hir::PathParameters {
|
2014-12-16 12:40:43 -08:00
|
|
|
fn clean(&self, cx: &DocContext) -> PathParameters {
|
|
|
|
match *self {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::AngleBracketedParameters(ref data) => {
|
2014-12-16 12:40:43 -08:00
|
|
|
PathParameters::AngleBracketed {
|
|
|
|
lifetimes: data.lifetimes.clean(cx),
|
2015-01-07 16:10:40 -08:00
|
|
|
types: data.types.clean(cx),
|
|
|
|
bindings: data.bindings.clean(cx)
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
2014-11-03 21:52:52 -05:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::ParenthesizedParameters(ref data) => {
|
2014-12-16 12:40:43 -08:00
|
|
|
PathParameters::Parenthesized {
|
|
|
|
inputs: data.inputs.clean(cx),
|
|
|
|
output: data.output.clean(cx)
|
|
|
|
}
|
2014-11-03 21:52:52 -05:00
|
|
|
}
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-03 21:52:52 -05:00
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2014-12-16 12:40:43 -08:00
|
|
|
pub struct PathSegment {
|
|
|
|
pub name: String,
|
|
|
|
pub params: PathParameters
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<PathSegment> for hir::PathSegment {
|
2014-12-16 12:40:43 -08:00
|
|
|
fn clean(&self, cx: &DocContext) -> PathSegment {
|
2013-09-12 15:11:06 -04:00
|
|
|
PathSegment {
|
2016-03-06 15:54:44 +03:00
|
|
|
name: self.name.clean(cx),
|
2014-12-16 12:40:43 -08:00
|
|
|
params: self.parameters.clean(cx)
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
fn path_to_string(p: &hir::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;
|
2016-03-06 15:54:44 +03:00
|
|
|
for i in p.segments.iter().map(|x| x.name.as_str()) {
|
2013-08-15 16:28:54 -04:00
|
|
|
if !first || p.global {
|
|
|
|
s.push_str("::");
|
|
|
|
} else {
|
|
|
|
first = false;
|
|
|
|
}
|
2015-02-05 15:19:23 +01:00
|
|
|
s.push_str(&i);
|
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-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 {
|
2015-07-28 18:07:20 +02:00
|
|
|
self.to_string()
|
2014-05-23 00:42:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id.clone()),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.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),
|
2015-05-21 14:17:37 +02:00
|
|
|
}, false),
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct BareFunctionDecl {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
|
|
|
pub decl: FnDecl,
|
2016-04-22 11:48:46 +01:00
|
|
|
pub abi: Abi,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<BareFunctionDecl> for hir::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-12-09 10:36:46 -05:00
|
|
|
unsafety: self.unsafety,
|
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),
|
2016-04-22 11:48:46 +01:00
|
|
|
abi: self.abi,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
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-12-20 00:09:35 -08:00
|
|
|
debug!("cleaning 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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.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),
|
2016-05-03 13:09:42 +02:00
|
|
|
expr: pprust::expr_to_string(&self.expr),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2014-10-06 17:41:15 -07:00
|
|
|
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),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-10-06 17:41:15 -07:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2014-10-06 17:41:15 -07:00
|
|
|
inner: ConstantItem(Constant {
|
|
|
|
type_: self.type_.clean(cx),
|
2016-05-03 13:09:42 +02:00
|
|
|
expr: pprust::expr_to_string(&self.expr),
|
2014-10-06 17:41:15 -07:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Debug, Clone, RustcEncodable, RustcDecodable, PartialEq, Copy)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub enum Mutability {
|
|
|
|
Mutable,
|
|
|
|
Immutable,
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Mutability> for hir::Mutability {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Mutability {
|
2013-08-15 16:28:54 -04:00
|
|
|
match self {
|
2015-07-31 00:04:06 -07:00
|
|
|
&hir::MutMutable => Mutable,
|
|
|
|
&hir::MutImmutable => Immutable,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Copy, Debug)]
|
2015-01-21 04:35:57 +00:00
|
|
|
pub enum ImplPolarity {
|
|
|
|
Positive,
|
|
|
|
Negative,
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<ImplPolarity> for hir::ImplPolarity {
|
2015-01-21 04:35:57 +00:00
|
|
|
fn clean(&self, _: &DocContext) -> ImplPolarity {
|
|
|
|
match self {
|
2015-07-31 00:04:06 -07:00
|
|
|
&hir::ImplPolarity::Positive => ImplPolarity::Positive,
|
|
|
|
&hir::ImplPolarity::Negative => ImplPolarity::Negative,
|
2015-01-21 04:35:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-08-15 16:28:54 -04:00
|
|
|
pub struct Impl {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub generics: Generics,
|
2016-03-24 06:10:52 +01:00
|
|
|
pub provided_trait_methods: HashSet<String>,
|
2014-03-28 10:27:24 -07:00
|
|
|
pub trait_: Option<Type>,
|
|
|
|
pub for_: Type,
|
2014-08-04 13:56:56 -07:00
|
|
|
pub items: Vec<Item>,
|
2015-01-21 04:35:57 +00:00
|
|
|
pub polarity: Option<ImplPolarity>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-04-13 16:23:32 -07:00
|
|
|
impl Clean<Vec<Item>> for doctree::Impl {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<Item> {
|
|
|
|
let mut ret = Vec::new();
|
|
|
|
let trait_ = self.trait_.clean(cx);
|
|
|
|
let items = self.items.clean(cx);
|
|
|
|
|
|
|
|
// If this impl block is an implementation of the Deref trait, then we
|
|
|
|
// need to try inlining the target's inherent impl blocks as well.
|
2016-03-24 06:10:52 +01:00
|
|
|
if trait_.def_id() == cx.deref_trait_did.get() {
|
|
|
|
build_deref_target_impls(cx, &items, &mut ret);
|
2015-04-13 16:23:32 -07:00
|
|
|
}
|
|
|
|
|
2016-03-24 06:10:52 +01:00
|
|
|
let provided = trait_.def_id().and_then(|did| {
|
|
|
|
cx.tcx_opt().map(|tcx| {
|
|
|
|
tcx.provided_trait_methods(did)
|
|
|
|
.into_iter()
|
|
|
|
.map(|meth| meth.name.to_string())
|
|
|
|
.collect()
|
|
|
|
})
|
|
|
|
}).unwrap_or(HashSet::new());
|
|
|
|
|
2015-04-13 16:23:32 -07:00
|
|
|
ret.push(Item {
|
2013-08-15 16:28:54 -04:00
|
|
|
name: None,
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2013-08-15 16:28:54 -04:00
|
|
|
inner: ImplItem(Impl {
|
2015-03-12 19:15:52 -07:00
|
|
|
unsafety: self.unsafety,
|
2014-09-06 19:13:40 +03:00
|
|
|
generics: self.generics.clean(cx),
|
2016-03-24 06:10:52 +01:00
|
|
|
provided_trait_methods: provided,
|
2015-04-13 16:23:32 -07:00
|
|
|
trait_: trait_,
|
2014-09-06 19:13:40 +03:00
|
|
|
for_: self.for_.clean(cx),
|
2015-04-13 16:23:32 -07:00
|
|
|
items: items,
|
2015-01-21 04:35:57 +00:00
|
|
|
polarity: Some(self.polarity.clean(cx)),
|
2013-08-15 16:28:54 -04:00
|
|
|
}),
|
2015-04-13 16:23:32 -07:00
|
|
|
});
|
2016-02-28 12:11:13 +01:00
|
|
|
ret
|
2015-04-13 16:23:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn build_deref_target_impls(cx: &DocContext,
|
|
|
|
items: &[Item],
|
|
|
|
ret: &mut Vec<Item>) {
|
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(t) => t,
|
|
|
|
None => return,
|
|
|
|
};
|
|
|
|
|
|
|
|
for item in items {
|
|
|
|
let target = match item.inner {
|
2015-05-21 14:17:37 +02:00
|
|
|
TypedefItem(ref t, true) => &t.type_,
|
2015-04-13 16:23:32 -07:00
|
|
|
_ => continue,
|
|
|
|
};
|
|
|
|
let primitive = match *target {
|
2015-08-16 06:32:28 -04:00
|
|
|
ResolvedPath { did, .. } if did.is_local() => continue,
|
2015-04-13 16:23:32 -07:00
|
|
|
ResolvedPath { did, .. } => {
|
|
|
|
ret.extend(inline::build_impls(cx, tcx, did));
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
_ => match target.primitive_type() {
|
|
|
|
Some(prim) => prim,
|
|
|
|
None => continue,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let did = match primitive {
|
|
|
|
Isize => tcx.lang_items.isize_impl(),
|
|
|
|
I8 => tcx.lang_items.i8_impl(),
|
|
|
|
I16 => tcx.lang_items.i16_impl(),
|
|
|
|
I32 => tcx.lang_items.i32_impl(),
|
|
|
|
I64 => tcx.lang_items.i64_impl(),
|
|
|
|
Usize => tcx.lang_items.usize_impl(),
|
|
|
|
U8 => tcx.lang_items.u8_impl(),
|
|
|
|
U16 => tcx.lang_items.u16_impl(),
|
|
|
|
U32 => tcx.lang_items.u32_impl(),
|
|
|
|
U64 => tcx.lang_items.u64_impl(),
|
|
|
|
F32 => tcx.lang_items.f32_impl(),
|
|
|
|
F64 => tcx.lang_items.f64_impl(),
|
|
|
|
Char => tcx.lang_items.char_impl(),
|
|
|
|
Bool => None,
|
|
|
|
Str => tcx.lang_items.str_impl(),
|
|
|
|
Slice => tcx.lang_items.slice_impl(),
|
|
|
|
Array => tcx.lang_items.slice_impl(),
|
|
|
|
PrimitiveTuple => None,
|
|
|
|
PrimitiveRawPointer => tcx.lang_items.const_ptr_impl(),
|
|
|
|
};
|
|
|
|
if let Some(did) = did {
|
2015-08-16 06:32:28 -04:00
|
|
|
if !did.is_local() {
|
2015-04-13 16:23:32 -07:00
|
|
|
inline::build_impl(cx, tcx, did, ret);
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 19:15:52 -07:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
|
|
|
pub struct DefaultImpl {
|
2015-07-31 00:04:06 -07:00
|
|
|
pub unsafety: hir::Unsafety,
|
2015-03-12 19:15:52 -07:00
|
|
|
pub trait_: Type,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Clean<Item> for doctree::DefaultImpl {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
name: None,
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2016-04-11 08:15:14 +00:00
|
|
|
visibility: Some(Public),
|
2015-03-12 19:15:52 -07:00
|
|
|
stability: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: None,
|
2015-03-12 19:15:52 -07:00
|
|
|
inner: DefaultImplItem(DefaultImpl {
|
|
|
|
unsafety: self.unsafety,
|
|
|
|
trait_: self.trait_.clean(cx),
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-26 10:55:16 +02:00
|
|
|
impl Clean<Item> for doctree::ExternCrate {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
name: None,
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2016-04-25 08:24:50 +02:00
|
|
|
def_id: DefId { krate: self.cnum, index: CRATE_DEF_INDEX },
|
2014-12-26 10:55:16 +02:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: None,
|
2014-12-26 10:55:16 +02:00
|
|
|
inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
|
|
|
|
}
|
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2014-12-26 10:55:16 +02:00
|
|
|
impl Clean<Vec<Item>> for doctree::Import {
|
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.
|
2016-06-07 01:20:12 +01:00
|
|
|
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
|
2015-07-31 00:04:06 -07:00
|
|
|
let denied = self.vis != hir::Public || self.attrs.iter().any(|a| {
|
2015-02-20 14:08:14 -05:00
|
|
|
&a.name()[..] == "doc" && match a.meta_item_list() {
|
2016-06-07 01:20:12 +01:00
|
|
|
Some(l) => attr::contains_name(l, "no_inline") ||
|
|
|
|
attr::contains_name(l, "hidden"),
|
2014-05-22 22:00:18 -07:00
|
|
|
None => false,
|
|
|
|
}
|
|
|
|
});
|
2014-12-26 10:55:16 +02:00
|
|
|
let (mut ret, inner) = match self.node {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::ViewPathGlob(ref p) => {
|
2014-12-26 10:55:16 +02:00
|
|
|
(vec![], GlobImport(resolve_use_source(cx, p.clean(cx), self.id)))
|
2014-05-22 22:00:18 -07:00
|
|
|
}
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::ViewPathList(ref p, ref list) => {
|
2014-12-26 10:55:16 +02:00
|
|
|
// Attempt to inline all reexported items, but be sure
|
|
|
|
// to keep any non-inlineable reexports so they can be
|
|
|
|
// listed in the documentation.
|
|
|
|
let mut ret = vec![];
|
|
|
|
let remaining = if !denied {
|
|
|
|
let mut remaining = vec![];
|
2015-01-31 12:20:46 -05:00
|
|
|
for path in list {
|
2015-07-31 22:20:25 -07:00
|
|
|
match inline::try_inline(cx, path.node.id(), path.node.rename()) {
|
2014-12-26 10:55:16 +02:00
|
|
|
Some(items) => {
|
2015-06-10 17:22:20 +01:00
|
|
|
ret.extend(items);
|
2014-12-26 10:55:16 +02:00
|
|
|
}
|
|
|
|
None => {
|
|
|
|
remaining.push(path.clean(cx));
|
2014-05-22 22:00:18 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-12-26 10:55:16 +02:00
|
|
|
remaining
|
|
|
|
} else {
|
|
|
|
list.clean(cx)
|
2014-01-21 10:08:10 -08:00
|
|
|
};
|
2014-12-26 10:55:16 +02:00
|
|
|
if remaining.is_empty() {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
(ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id),
|
|
|
|
remaining))
|
2014-01-21 10:08:10 -08:00
|
|
|
}
|
2015-09-20 14:51:40 +03:00
|
|
|
hir::ViewPathSimple(name, ref p) => {
|
2014-12-26 10:55:16 +02:00
|
|
|
if !denied {
|
2016-02-28 12:11:13 +01:00
|
|
|
if let Some(items) = inline::try_inline(cx, self.id, Some(name)) {
|
|
|
|
return items;
|
2014-12-26 10:55:16 +02:00
|
|
|
}
|
|
|
|
}
|
2015-09-20 14:51:40 +03:00
|
|
|
(vec![], SimpleImport(name.clean(cx),
|
2014-12-26 10:55:16 +02:00
|
|
|
resolve_use_source(cx, p.clean(cx), self.id)))
|
2014-02-28 17:46:09 -08:00
|
|
|
}
|
2014-12-26 10:55:16 +02:00
|
|
|
};
|
|
|
|
ret.push(Item {
|
|
|
|
name: None,
|
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(0),
|
2014-12-26 10:55:16 +02:00
|
|
|
visibility: self.vis.clean(cx),
|
|
|
|
stability: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: None,
|
2014-12-26 10:55:16 +02:00
|
|
|
inner: ImportItem(inner)
|
|
|
|
});
|
|
|
|
ret
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2014-12-26 10:55:16 +02:00
|
|
|
pub enum Import {
|
2014-11-22 19:07:54 +13:00
|
|
|
// use source as str;
|
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
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-09-24 13:56:52 -07:00
|
|
|
pub struct ImportSource {
|
2014-03-28 10:27:24 -07:00
|
|
|
pub path: Path,
|
2015-08-16 06:32:28 -04:00
|
|
|
pub did: Option<DefId>,
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2013-09-24 13:56:52 -07:00
|
|
|
pub struct ViewListIdent {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub name: String,
|
2015-07-31 22:20:25 -07:00
|
|
|
pub rename: Option<String>,
|
2015-08-16 06:32:28 -04:00
|
|
|
pub source: Option<DefId>,
|
2013-09-24 13:56:52 -07:00
|
|
|
}
|
2013-08-15 16:28:54 -04:00
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<ViewListIdent> for hir::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 {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::PathListIdent { id, name, rename } => ViewListIdent {
|
2014-09-06 19:13:40 +03:00
|
|
|
name: name.clean(cx),
|
2015-07-31 22:20:25 -07:00
|
|
|
rename: rename.map(|r| r.clean(cx)),
|
2014-09-06 19:13:40 +03:00
|
|
|
source: resolve_def(cx, id)
|
2014-07-18 00:56:56 +02:00
|
|
|
},
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::PathListMod { id, rename } => ViewListIdent {
|
2015-01-27 09:26:52 -08:00
|
|
|
name: "self".to_string(),
|
2015-07-31 22:20:25 -07:00
|
|
|
rename: rename.map(|r| r.clean(cx)),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Vec<Item>> for hir::ForeignMod {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn clean(&self, cx: &DocContext) -> Vec<Item> {
|
2015-04-07 14:22:55 -07:00
|
|
|
let mut items = self.items.clean(cx);
|
|
|
|
for item in &mut items {
|
2016-02-28 12:11:13 +01:00
|
|
|
if let ForeignFunctionItem(ref mut f) = item.inner {
|
|
|
|
f.abi = self.abi;
|
2015-04-07 14:22:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
items
|
2013-09-26 11:57:25 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<Item> for hir::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 {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::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),
|
2015-07-31 00:04:06 -07:00
|
|
|
unsafety: hir::Unsafety::Unsafe,
|
2016-02-05 13:13:36 +01:00
|
|
|
abi: Abi::Rust,
|
2015-07-31 00:04:06 -07:00
|
|
|
constness: hir::Constness::NotConst,
|
2013-09-26 11:57:25 -07:00
|
|
|
})
|
|
|
|
}
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::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 {
|
2015-09-20 04:50:30 +03:00
|
|
|
name: Some(self.name.clean(cx)),
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.span.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-09-06 19:13:40 +03:00
|
|
|
visibility: self.vis.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
stability: get_stability(cx, cx.map.local_def_id(self.id)),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: get_deprecation(cx, cx.map.local_def_id(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
|
|
|
}
|
|
|
|
|
2016-06-21 18:08:13 -04:00
|
|
|
impl ToSource for syntax_pos::Span {
|
2014-09-06 19:13:40 +03:00
|
|
|
fn to_src(&self, cx: &DocContext) -> String {
|
2014-12-20 00:09:35 -08: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) {
|
2015-02-05 16:02:22 +01:00
|
|
|
Ok(x) => x.to_string(),
|
|
|
|
Err(_) => "".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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
fn name_from_pat(p: &hir::Pat) -> String {
|
2016-03-29 08:50:44 +03:00
|
|
|
use rustc::hir::*;
|
2014-12-20 00:09:35 -08: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 {
|
2016-02-14 15:25:12 +03:00
|
|
|
PatKind::Wild => "_".to_string(),
|
2016-03-06 15:54:44 +03:00
|
|
|
PatKind::Binding(_, ref p, _) => p.node.to_string(),
|
2016-06-11 18:47:47 +03:00
|
|
|
PatKind::TupleStruct(ref p, _, _) | PatKind::Path(None, ref p) => path_to_string(p),
|
|
|
|
PatKind::Path(..) => panic!("tried to get argument name from qualified PatKind::Path, \
|
|
|
|
which is not allowed in function arguments"),
|
2016-02-14 15:25:12 +03:00
|
|
|
PatKind::Struct(ref name, ref fields, etc) => {
|
2014-07-11 11:59:18 -07:00
|
|
|
format!("{} {{ {}{} }}", path_to_string(name),
|
2014-10-06 13:36:53 +13:00
|
|
|
fields.iter().map(|&Spanned { node: ref fp, .. }|
|
2015-09-20 16:47:24 +03:00
|
|
|
format!("{}: {}", fp.name, name_from_pat(&*fp.pat)))
|
2015-07-10 08:19:21 -04:00
|
|
|
.collect::<Vec<String>>().join(", "),
|
2014-07-11 11:59:18 -07:00
|
|
|
if etc { ", ..." } else { "" }
|
|
|
|
)
|
|
|
|
},
|
2016-03-06 15:54:44 +03:00
|
|
|
PatKind::Tuple(ref elts, _) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
|
2015-07-10 08:19:21 -04:00
|
|
|
.collect::<Vec<String>>().join(", ")),
|
2016-02-14 15:25:12 +03:00
|
|
|
PatKind::Box(ref p) => name_from_pat(&**p),
|
|
|
|
PatKind::Ref(ref p, _) => name_from_pat(&**p),
|
|
|
|
PatKind::Lit(..) => {
|
|
|
|
warn!("tried to get argument name from PatKind::Lit, \
|
2013-12-29 00:13:29 -05:00
|
|
|
which is silly in function arguments");
|
2014-05-25 03:17:19 -07:00
|
|
|
"()".to_string()
|
2013-12-29 00:13:29 -05:00
|
|
|
},
|
2016-02-14 15:25:12 +03:00
|
|
|
PatKind::Range(..) => panic!("tried to get argument name from PatKind::Range, \
|
2013-09-05 10:14:35 -04:00
|
|
|
which is not allowed in function arguments"),
|
2016-02-14 15:25:12 +03:00
|
|
|
PatKind::Vec(ref begin, ref mid, ref end) => {
|
2015-01-04 17:52:08 +11:00
|
|
|
let begin = begin.iter().map(|p| name_from_pat(&**p));
|
|
|
|
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
|
|
|
|
let end = end.iter().map(|p| name_from_pat(&**p));
|
2015-07-10 08:19:21 -04:00
|
|
|
format!("[{}]", begin.chain(mid).chain(end).collect::<Vec<_>>().join(", "))
|
2015-01-04 17:52:08 +11:00
|
|
|
},
|
2013-08-15 16:28:54 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Given a Type, resolve it using the def_map
|
2014-11-20 19:44:49 -05:00
|
|
|
fn resolve_type(cx: &DocContext,
|
|
|
|
path: Path,
|
2013-09-24 13:53:09 -07:00
|
|
|
id: ast::NodeId) -> Type {
|
2015-09-08 10:08:30 -04:00
|
|
|
debug!("resolve_type({:?},{:?})", path, id);
|
2014-09-06 19:13:40 +03:00
|
|
|
let tcx = match cx.tcx_opt() {
|
|
|
|
Some(tcx) => tcx,
|
2015-11-04 23:41:33 +00:00
|
|
|
// If we're extracting tests, this return value's accuracy is not
|
|
|
|
// important, all we want is a string representation to help people
|
|
|
|
// figure out what doctests are failing.
|
|
|
|
None => {
|
|
|
|
let did = DefId::local(DefIndex::from_u32(0));
|
|
|
|
return ResolvedPath {
|
|
|
|
path: path,
|
|
|
|
typarams: None,
|
|
|
|
did: did,
|
|
|
|
is_generic: false
|
|
|
|
};
|
|
|
|
}
|
2013-12-22 11:23:04 -08:00
|
|
|
};
|
2016-06-03 23:15:00 +03:00
|
|
|
let def = tcx.expect_def(id);
|
2015-09-08 10:08:30 -04:00
|
|
|
debug!("resolve_type: def={:?}", def);
|
|
|
|
|
2015-05-25 15:06:38 +02:00
|
|
|
let is_generic = match def {
|
2016-01-20 22:31:10 +03:00
|
|
|
Def::PrimTy(p) => match p {
|
2015-07-31 00:04:06 -07:00
|
|
|
hir::TyStr => return Primitive(Str),
|
|
|
|
hir::TyBool => return Primitive(Bool),
|
|
|
|
hir::TyChar => return Primitive(Char),
|
2016-02-08 16:20:57 +01:00
|
|
|
hir::TyInt(ast::IntTy::Is) => return Primitive(Isize),
|
|
|
|
hir::TyInt(ast::IntTy::I8) => return Primitive(I8),
|
|
|
|
hir::TyInt(ast::IntTy::I16) => return Primitive(I16),
|
|
|
|
hir::TyInt(ast::IntTy::I32) => return Primitive(I32),
|
|
|
|
hir::TyInt(ast::IntTy::I64) => return Primitive(I64),
|
|
|
|
hir::TyUint(ast::UintTy::Us) => return Primitive(Usize),
|
|
|
|
hir::TyUint(ast::UintTy::U8) => return Primitive(U8),
|
|
|
|
hir::TyUint(ast::UintTy::U16) => return Primitive(U16),
|
|
|
|
hir::TyUint(ast::UintTy::U32) => return Primitive(U32),
|
|
|
|
hir::TyUint(ast::UintTy::U64) => return Primitive(U64),
|
2016-02-08 16:09:01 +01:00
|
|
|
hir::TyFloat(ast::FloatTy::F32) => return Primitive(F32),
|
|
|
|
hir::TyFloat(ast::FloatTy::F64) => return Primitive(F64),
|
2013-08-15 16:28:54 -04:00
|
|
|
},
|
2016-01-20 22:31:10 +03:00
|
|
|
Def::SelfTy(..) if path.segments.len() == 1 => {
|
2016-04-18 22:53:50 +03:00
|
|
|
return Generic(keywords::SelfType.name().to_string());
|
2015-04-01 14:04:20 -07:00
|
|
|
}
|
2016-06-11 18:47:47 +03:00
|
|
|
Def::SelfTy(..) | Def::TyParam(..) | Def::AssociatedTy(..) => true,
|
2015-05-25 15:06:38 +02:00
|
|
|
_ => false,
|
2014-05-09 13:52:17 -07:00
|
|
|
};
|
2014-06-26 11:37:39 -07:00
|
|
|
let did = register_def(&*cx, def);
|
2015-05-25 15:06:38 +02:00
|
|
|
ResolvedPath { path: path, typarams: None, did: did, is_generic: is_generic }
|
2014-05-09 13:52:17 -07:00
|
|
|
}
|
|
|
|
|
2016-01-20 22:31:10 +03:00
|
|
|
fn register_def(cx: &DocContext, def: Def) -> DefId {
|
2015-09-08 10:08:30 -04:00
|
|
|
debug!("register_def({:?})", def);
|
|
|
|
|
2014-05-09 13:52:17 -07:00
|
|
|
let (did, kind) = match def {
|
2016-01-20 22:31:10 +03:00
|
|
|
Def::Fn(i) => (i, TypeFunction),
|
|
|
|
Def::TyAlias(i) => (i, TypeTypedef),
|
|
|
|
Def::Enum(i) => (i, TypeEnum),
|
|
|
|
Def::Trait(i) => (i, TypeTrait),
|
|
|
|
Def::Struct(i) => (i, TypeStruct),
|
|
|
|
Def::Mod(i) => (i, TypeModule),
|
|
|
|
Def::Static(i, _) => (i, TypeStatic),
|
|
|
|
Def::Variant(i, _) => (i, TypeEnum),
|
|
|
|
Def::SelfTy(Some(def_id), _) => (def_id, TypeTrait),
|
2016-07-26 10:58:35 -04:00
|
|
|
Def::SelfTy(_, Some(impl_id)) => {
|
|
|
|
// For Def::SelfTy() values inlined from another crate, the
|
|
|
|
// impl_id will be DUMMY_NODE_ID, which would cause problems.
|
|
|
|
// But we should never run into an impl from another crate here.
|
|
|
|
return cx.map.local_def_id(impl_id)
|
|
|
|
}
|
2014-05-14 15:31:30 -04:00
|
|
|
_ => return def.def_id()
|
2013-08-15 16:28:54 -04:00
|
|
|
};
|
2015-08-16 06:32:28 -04:00
|
|
|
if did.is_local() { 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-11-29 16:41:21 -05:00
|
|
|
if let TypeTrait = kind {
|
|
|
|
let t = inline::build_external_trait(cx, tcx, did);
|
2016-04-07 05:59:02 +02:00
|
|
|
cx.external_traits.borrow_mut().insert(did, t);
|
2014-05-03 02:08:58 -07:00
|
|
|
}
|
2016-02-28 12:11:13 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:32:28 -04:00
|
|
|
fn resolve_def(cx: &DocContext, id: ast::NodeId) -> Option<DefId> {
|
2014-09-06 19:13:40 +03:00
|
|
|
cx.tcx_opt().and_then(|tcx| {
|
2016-06-03 23:15:00 +03:00
|
|
|
tcx.expect_def_or_none(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
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2014-02-16 21:40:26 -08:00
|
|
|
pub struct Macro {
|
2014-05-22 16:57:53 -07:00
|
|
|
pub source: String,
|
2015-04-13 15:25:40 -07:00
|
|
|
pub imported_from: Option<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 {
|
2015-11-26 19:14:36 +01:00
|
|
|
let name = format!("{}!", self.name.clean(cx));
|
2014-02-16 21:40:26 -08:00
|
|
|
Item {
|
2015-11-26 19:14:36 +01:00
|
|
|
name: Some(name.clone()),
|
2014-09-06 19:13:40 +03:00
|
|
|
attrs: self.attrs.clean(cx),
|
|
|
|
source: self.whence.clean(cx),
|
2016-04-11 08:15:14 +00:00
|
|
|
visibility: Some(Public),
|
2014-09-06 19:13:40 +03:00
|
|
|
stability: self.stab.clean(cx),
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: self.depr.clean(cx),
|
2015-09-02 16:11:32 -04:00
|
|
|
def_id: cx.map.local_def_id(self.id),
|
2014-02-16 21:40:26 -08:00
|
|
|
inner: MacroItem(Macro {
|
2015-11-26 19:14:36 +01:00
|
|
|
source: format!("macro_rules! {} {{\n{}}}",
|
|
|
|
name.trim_right_matches('!'), self.matchers.iter().map(|span|
|
2015-11-26 21:10:04 +01:00
|
|
|
format!(" {} => {{ ... }};\n", span.to_src(cx))).collect::<String>()),
|
2015-04-13 15:25:40 -07:00
|
|
|
imported_from: self.imported_from.clean(cx),
|
2014-02-16 21:40:26 -08:00
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 11:37:39 -07:00
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
2014-06-26 11:37:39 -07:00
|
|
|
pub struct Stability {
|
2015-10-13 06:01:31 +03:00
|
|
|
pub level: stability::StabilityLevel,
|
2015-01-12 18:40:19 -08:00
|
|
|
pub feature: String,
|
|
|
|
pub since: String,
|
2015-02-13 16:36:56 +02:00
|
|
|
pub deprecated_since: String,
|
2015-08-16 15:53:18 +02:00
|
|
|
pub reason: String,
|
|
|
|
pub issue: Option<u32>
|
2014-06-26 11:37:39 -07:00
|
|
|
}
|
|
|
|
|
2015-12-12 23:01:27 +03:00
|
|
|
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
|
|
|
|
pub struct Deprecation {
|
|
|
|
pub since: String,
|
|
|
|
pub note: String,
|
|
|
|
}
|
|
|
|
|
2014-06-26 11:37:39 -07:00
|
|
|
impl Clean<Stability> for attr::Stability {
|
2015-05-26 00:41:27 +03:00
|
|
|
fn clean(&self, _: &DocContext) -> Stability {
|
|
|
|
Stability {
|
2015-10-13 06:01:31 +03:00
|
|
|
level: stability::StabilityLevel::from_attr_level(&self.level),
|
2015-05-26 00:41:27 +03:00
|
|
|
feature: self.feature.to_string(),
|
2015-10-13 06:01:31 +03:00
|
|
|
since: match self.level {
|
|
|
|
attr::Stable {ref since} => since.to_string(),
|
|
|
|
_ => "".to_string(),
|
|
|
|
},
|
2015-12-04 19:34:28 +03:00
|
|
|
deprecated_since: match self.rustc_depr {
|
|
|
|
Some(attr::RustcDeprecation {ref since, ..}) => since.to_string(),
|
2015-10-13 06:01:31 +03:00
|
|
|
_=> "".to_string(),
|
|
|
|
},
|
2015-10-15 01:28:38 +03:00
|
|
|
reason: {
|
2016-02-28 12:11:13 +01:00
|
|
|
match (&self.rustc_depr, &self.level) {
|
|
|
|
(&Some(ref depr), _) => depr.reason.to_string(),
|
|
|
|
(&None, &attr::Unstable {reason: Some(ref reason), ..}) => reason.to_string(),
|
|
|
|
_ => "".to_string(),
|
2015-10-15 01:28:38 +03:00
|
|
|
}
|
2015-10-13 06:01:31 +03:00
|
|
|
},
|
|
|
|
issue: match self.level {
|
|
|
|
attr::Unstable {issue, ..} => Some(issue),
|
|
|
|
_ => None,
|
|
|
|
}
|
2015-05-26 00:41:27 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Clean<Stability> for &'a attr::Stability {
|
2015-10-13 06:01:31 +03:00
|
|
|
fn clean(&self, dc: &DocContext) -> Stability {
|
|
|
|
(**self).clean(dc)
|
2014-06-26 11:37:39 -07:00
|
|
|
}
|
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
|
2015-12-12 23:01:27 +03:00
|
|
|
impl Clean<Deprecation> for attr::Deprecation {
|
|
|
|
fn clean(&self, _: &DocContext) -> Deprecation {
|
|
|
|
Deprecation {
|
|
|
|
since: self.since.as_ref().map_or("".to_string(), |s| s.to_string()),
|
|
|
|
note: self.note.as_ref().map_or("".to_string(), |s| s.to_string()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-14 12:05:00 -06:00
|
|
|
impl<'tcx> Clean<Item> for ty::AssociatedConst<'tcx> {
|
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
|
|
|
Item {
|
|
|
|
source: DUMMY_SP.clean(cx),
|
|
|
|
name: Some(self.name.clean(cx)),
|
|
|
|
attrs: Vec::new(),
|
|
|
|
inner: AssociatedConstItem(self.ty.clean(cx), None),
|
|
|
|
visibility: None,
|
|
|
|
def_id: self.def_id,
|
|
|
|
stability: None,
|
2015-12-12 23:01:27 +03:00
|
|
|
deprecation: None,
|
2015-03-14 12:05:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 17:12:39 +03:00
|
|
|
impl<'tcx> Clean<Item> for ty::AssociatedType<'tcx> {
|
2014-08-05 19:44:21 -07:00
|
|
|
fn clean(&self, cx: &DocContext) -> Item {
|
2015-04-07 00:16:35 -07:00
|
|
|
let my_name = self.name.clean(cx);
|
2015-05-26 17:12:39 +03:00
|
|
|
|
|
|
|
let mut bounds = if let ty::TraitContainer(did) = self.container {
|
|
|
|
// When loading a cross-crate associated type, the bounds for this type
|
|
|
|
// are actually located on the trait/impl itself, so we need to load
|
|
|
|
// all of the generics from there and then look for bounds that are
|
|
|
|
// applied to this associated type in question.
|
2015-06-25 23:42:17 +03:00
|
|
|
let def = cx.tcx().lookup_trait_def(did);
|
|
|
|
let predicates = cx.tcx().lookup_predicates(did);
|
2015-05-26 17:12:39 +03:00
|
|
|
let generics = (&def.generics, &predicates, subst::TypeSpace).clean(cx);
|
|
|
|
generics.where_predicates.iter().filter_map(|pred| {
|
|
|
|
let (name, self_type, trait_, bounds) = match *pred {
|
|
|
|
WherePredicate::BoundPredicate {
|
|
|
|
ty: QPath { ref name, ref self_type, ref trait_ },
|
|
|
|
ref bounds
|
|
|
|
} => (name, self_type, trait_, bounds),
|
|
|
|
_ => return None,
|
|
|
|
};
|
|
|
|
if *name != my_name { return None }
|
|
|
|
match **trait_ {
|
|
|
|
ResolvedPath { did, .. } if did == self.container.id() => {}
|
|
|
|
_ => return None,
|
|
|
|
}
|
|
|
|
match **self_type {
|
|
|
|
Generic(ref s) if *s == "Self" => {}
|
|
|
|
_ => return None,
|
|
|
|
}
|
|
|
|
Some(bounds)
|
|
|
|
}).flat_map(|i| i.iter().cloned()).collect::<Vec<_>>()
|
|
|
|
} else {
|
|
|
|
vec![]
|
|
|
|
};
|
2015-04-07 00:16:35 -07:00
|
|
|
|
|
|
|
// Our Sized/?Sized bound didn't get handled when creating the generics
|
|
|
|
// because we didn't actually get our whole set of bounds until just now
|
|
|
|
// (some of them may have come from the trait). If we do have a sized
|
|
|
|
// bound, we remove it, and if we don't then we add the `?Sized` bound
|
|
|
|
// at the end.
|
|
|
|
match bounds.iter().position(|b| b.is_sized_bound(cx)) {
|
|
|
|
Some(i) => { bounds.remove(i); }
|
|
|
|
None => bounds.push(TyParamBound::maybe_sized(cx)),
|
|
|
|
}
|
|
|
|
|
2014-08-05 19:44:21 -07:00
|
|
|
Item {
|
|
|
|
source: DUMMY_SP.clean(cx),
|
2014-09-30 19:11:34 -05:00
|
|
|
name: Some(self.name.clean(cx)),
|
2015-04-07 00:16:35 -07:00
|
|
|
attrs: inline::load_attrs(cx, cx.tcx(), self.def_id),
|
2015-05-26 17:12:39 +03:00
|
|
|
inner: AssociatedTypeItem(bounds, self.ty.clean(cx)),
|
2015-04-07 00:16:35 -07:00
|
|
|
visibility: self.vis.clean(cx),
|
2014-08-05 19:44:21 -07:00
|
|
|
def_id: self.def_id,
|
2016-03-17 00:15:31 +02:00
|
|
|
stability: cx.tcx().lookup_stability(self.def_id).clean(cx),
|
|
|
|
deprecation: cx.tcx().lookup_deprecation(self.def_id).clean(cx),
|
2014-08-05 19:44:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-16 06:32:28 -04:00
|
|
|
fn lang_struct(cx: &DocContext, did: Option<DefId>,
|
2014-11-06 09:20:16 +02:00
|
|
|
t: ty::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
|
|
|
};
|
2015-12-05 11:58:04 +01:00
|
|
|
inline::record_extern_fqn(cx, did, 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(),
|
2014-12-16 12:40:43 -08:00
|
|
|
params: PathParameters::AngleBracketed {
|
|
|
|
lifetimes: vec![],
|
|
|
|
types: vec![t.clean(cx)],
|
2015-01-07 16:10:40 -08:00
|
|
|
bindings: vec![]
|
2014-12-16 12:40:43 -08:00
|
|
|
}
|
2014-07-25 09:31:20 -07:00
|
|
|
}],
|
|
|
|
},
|
2015-05-25 15:06:38 +02:00
|
|
|
is_generic: false,
|
2014-07-25 09:31:20 -07:00
|
|
|
}
|
|
|
|
}
|
2015-01-07 16:10:40 -08:00
|
|
|
|
|
|
|
/// An equality constraint on an associated type, e.g. `A=Bar` in `Foo<A=Bar>`
|
2015-01-28 08:34:18 -05:00
|
|
|
#[derive(Clone, PartialEq, RustcDecodable, RustcEncodable, Debug)]
|
2015-01-07 16:10:40 -08:00
|
|
|
pub struct TypeBinding {
|
|
|
|
pub name: String,
|
|
|
|
pub ty: Type
|
|
|
|
}
|
|
|
|
|
2015-07-31 00:04:06 -07:00
|
|
|
impl Clean<TypeBinding> for hir::TypeBinding {
|
2015-01-07 16:10:40 -08:00
|
|
|
fn clean(&self, cx: &DocContext) -> TypeBinding {
|
|
|
|
TypeBinding {
|
2015-09-20 16:47:24 +03:00
|
|
|
name: self.name.clean(cx),
|
2015-01-07 16:10:40 -08:00
|
|
|
ty: self.ty.clean(cx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|