//! This module contains the "cleaned" pieces of the AST, and the functions
//! that clean them.
-pub mod inline;
-pub mod cfg;
-pub mod utils;
mod auto_trait;
mod blanket_impl;
+pub mod cfg;
+pub mod inline;
mod simplify;
pub mod types;
+pub mod utils;
-use rustc_index::vec::{IndexVec, Idx};
-use rustc_typeck::hir_ty_to_ty;
-use rustc::infer::region_constraints::{RegionConstraintData, Constraint};
-use rustc::middle::resolve_lifetime as rl;
+use rustc::infer::region_constraints::{Constraint, RegionConstraintData};
use rustc::middle::lang_items;
+use rustc::middle::resolve_lifetime as rl;
use rustc::middle::stability;
-use rustc::mir::interpret::GlobalId;
-use rustc::hir;
-use rustc::hir::def::{CtorKind, DefKind, Res};
-use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
-use rustc::hir::ptr::P;
-use rustc::ty::subst::InternalSubsts;
-use rustc::ty::{self, TyCtxt, Ty, AdtKind, Lift};
use rustc::ty::fold::TypeFolder;
-use rustc::util::nodemap::{FxHashMap, FxHashSet};
+use rustc::ty::subst::InternalSubsts;
+use rustc::ty::{self, AdtKind, Lift, Ty, TyCtxt};
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
+use rustc_hir as hir;
+use rustc_hir::def::{CtorKind, DefKind, Res};
+use rustc_hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
+use rustc_index::vec::{Idx, IndexVec};
+use rustc_mir::const_eval::is_min_const_fn;
+use rustc_span::hygiene::MacroKind;
+use rustc_span::symbol::{kw, sym};
+use rustc_span::{self, Pos};
+use rustc_typeck::hir_ty_to_ty;
use syntax::ast::{self, Ident};
use syntax::attr;
-use syntax_pos::symbol::{kw, sym};
-use syntax_pos::hygiene::MacroKind;
-use syntax_pos::{self, Pos};
use std::collections::hash_map::Entry;
-use std::hash::Hash;
use std::default::Default;
-use std::{mem, vec};
+use std::hash::Hash;
use std::rc::Rc;
use std::u32;
+use std::{mem, vec};
use crate::core::{self, DocContext, ImplTraitParam};
use crate::doctree;
pub use utils::{get_auto_trait_and_blanket_impls, krate, register_res};
-pub use self::types::*;
-pub use self::types::Type::*;
-pub use self::types::Mutability::*;
+pub use self::types::FunctionRetTy::*;
pub use self::types::ItemEnum::*;
pub use self::types::SelfTy::*;
-pub use self::types::FunctionRetTy::*;
-pub use self::types::Visibility::{Public, Inherited};
+pub use self::types::Type::*;
+pub use self::types::Visibility::{Inherited, Public};
+pub use self::types::*;
const FN_OUTPUT_NAME: &'static str = "Output";
}
}
-impl<T: Clean<U>, U> Clean<U> for P<T> {
+impl<T: Clean<U>, U> Clean<U> for &T {
fn clean(&self, cx: &DocContext<'_>) -> U {
(**self).clean(cx)
}
}
}
-impl<T, U> Clean<U> for ty::Binder<T> where T: Clean<U> {
+impl<T, U> Clean<U> for ty::Binder<T>
+where
+ T: Clean<U>,
+{
fn clean(&self, cx: &DocContext<'_>) -> U {
self.skip_binder().clean(cx)
}
}
-impl<T: Clean<U>, U> Clean<Vec<U>> for P<[T]> {
- fn clean(&self, cx: &DocContext<'_>) -> Vec<U> {
- self.iter().map(|x| x.clean(cx)).collect()
- }
-}
-
impl Clean<ExternalCrate> for CrateNum {
fn clean(&self, cx: &DocContext<'_>) -> ExternalCrate {
let root = DefId { krate: *self, index: CRATE_DEF_INDEX };
None
};
let primitives = if root.is_local() {
- cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| {
- let item = cx.tcx.hir().expect_item(id.id);
- match item.kind {
- hir::ItemKind::Mod(_) => {
- as_primitive(Res::Def(
- DefKind::Mod,
- cx.tcx.hir().local_def_id(id.id),
- ))
- }
- hir::ItemKind::Use(ref path, hir::UseKind::Single)
- if item.vis.node.is_pub() => {
- as_primitive(path.res).map(|(_, prim, attrs)| {
- // Pretend the primitive is local.
- (cx.tcx.hir().local_def_id(id.id), prim, attrs)
- })
+ cx.tcx
+ .hir()
+ .krate()
+ .module
+ .item_ids
+ .iter()
+ .filter_map(|&id| {
+ let item = cx.tcx.hir().expect_item(id.id);
+ match item.kind {
+ hir::ItemKind::Mod(_) => {
+ as_primitive(Res::Def(DefKind::Mod, cx.tcx.hir().local_def_id(id.id)))
+ }
+ hir::ItemKind::Use(ref path, hir::UseKind::Single)
+ if item.vis.node.is_pub() =>
+ {
+ as_primitive(path.res).map(|(_, prim, attrs)| {
+ // Pretend the primitive is local.
+ (cx.tcx.hir().local_def_id(id.id), prim, attrs)
+ })
+ }
+ _ => None,
}
- _ => None
- }
- }).collect()
+ })
+ .collect()
} else {
- cx.tcx.item_children(root).iter().map(|item| item.res)
- .filter_map(as_primitive).collect()
+ cx.tcx
+ .item_children(root)
+ .iter()
+ .map(|item| item.res)
+ .filter_map(as_primitive)
+ .collect()
};
let as_keyword = |res: Res| {
None
};
let keywords = if root.is_local() {
- cx.tcx.hir().krate().module.item_ids.iter().filter_map(|&id| {
- let item = cx.tcx.hir().expect_item(id.id);
- match item.kind {
- hir::ItemKind::Mod(_) => {
- as_keyword(Res::Def(
- DefKind::Mod,
- cx.tcx.hir().local_def_id(id.id),
- ))
- }
- hir::ItemKind::Use(ref path, hir::UseKind::Single)
- if item.vis.node.is_pub() => {
- as_keyword(path.res).map(|(_, prim, attrs)| {
- (cx.tcx.hir().local_def_id(id.id), prim, attrs)
- })
+ cx.tcx
+ .hir()
+ .krate()
+ .module
+ .item_ids
+ .iter()
+ .filter_map(|&id| {
+ let item = cx.tcx.hir().expect_item(id.id);
+ match item.kind {
+ hir::ItemKind::Mod(_) => {
+ as_keyword(Res::Def(DefKind::Mod, cx.tcx.hir().local_def_id(id.id)))
+ }
+ hir::ItemKind::Use(ref path, hir::UseKind::Single)
+ if item.vis.node.is_pub() =>
+ {
+ as_keyword(path.res).map(|(_, prim, attrs)| {
+ (cx.tcx.hir().local_def_id(id.id), prim, attrs)
+ })
+ }
+ _ => None,
}
- _ => None
- }
- }).collect()
+ })
+ .collect()
} else {
- cx.tcx.item_children(root).iter().map(|item| item.res)
- .filter_map(as_keyword).collect()
+ cx.tcx.item_children(root).iter().map(|item| item.res).filter_map(as_keyword).collect()
};
ExternalCrate {
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
- inner: ModuleItem(Module {
- is_crate: self.is_crate,
- items,
- })
+ inner: ModuleItem(Module { is_crate: self.is_crate, items }),
}
}
}
}
}
-impl Clean<GenericBound> for hir::GenericBound {
+impl Clean<GenericBound> for hir::GenericBound<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
match *self {
hir::GenericBound::Outlives(lt) => GenericBound::Outlives(lt.clean(cx)),
fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
let (trait_ref, ref bounds) = *self;
inline::record_extern_fqn(cx, trait_ref.def_id, TypeKind::Trait);
- let path = external_path(cx, cx.tcx.item_name(trait_ref.def_id),
- Some(trait_ref.def_id), true, bounds.clone(), trait_ref.substs);
+ let path = external_path(
+ cx,
+ cx.tcx.item_name(trait_ref.def_id),
+ Some(trait_ref.def_id),
+ true,
+ bounds.clone(),
+ trait_ref.substs,
+ );
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
},
generic_params: late_bounds,
},
- hir::TraitBoundModifier::None
+ hir::TraitBoundModifier::None,
)
}
}
fn clean(&self, cx: &DocContext<'_>) -> Option<Vec<GenericBound>> {
let mut v = Vec::new();
v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives));
- v.extend(self.types().map(|t| GenericBound::TraitBound(PolyTrait {
- trait_: t.clean(cx),
- generic_params: Vec::new(),
- }, hir::TraitBoundModifier::None)));
- if !v.is_empty() {Some(v)} else {None}
+ v.extend(self.types().map(|t| {
+ GenericBound::TraitBound(
+ PolyTrait { trait_: t.clean(cx), generic_params: Vec::new() },
+ hir::TraitBoundModifier::None,
+ )
+ }));
+ if !v.is_empty() { Some(v) } else { None }
}
}
if self.hir_id != hir::DUMMY_HIR_ID {
let def = cx.tcx.named_region(self.hir_id);
match def {
- Some(rl::Region::EarlyBound(_, node_id, _)) |
- Some(rl::Region::LateBound(_, node_id, _)) |
- Some(rl::Region::Free(_, node_id)) => {
+ Some(rl::Region::EarlyBound(_, node_id, _))
+ | Some(rl::Region::LateBound(_, node_id, _))
+ | Some(rl::Region::Free(_, node_id)) => {
if let Some(lt) = cx.lt_substs.borrow().get(&node_id).cloned() {
return lt;
}
}
}
-impl Clean<Lifetime> for hir::GenericParam {
+impl Clean<Lifetime> for hir::GenericParam<'_> {
fn clean(&self, _: &DocContext<'_>) -> Lifetime {
match self.kind {
hir::GenericParamKind::Lifetime { .. } => {
Constant {
type_: cx.tcx.type_of(cx.tcx.hir().body_owner_def_id(self.value.body)).clean(cx),
expr: print_const_expr(cx, self.value.body),
+ value: None,
+ is_literal: is_literal_expr(cx, self.value.body.hir_id),
}
}
}
ty::ReLateBound(_, ty::BrNamed(_, name)) => Some(Lifetime(name.to_string())),
ty::ReEarlyBound(ref data) => Some(Lifetime(data.name.clean(cx))),
- ty::ReLateBound(..) |
- ty::ReFree(..) |
- ty::ReScope(..) |
- ty::ReVar(..) |
- ty::RePlaceholder(..) |
- ty::ReEmpty |
- ty::ReClosureBound(_) |
- ty::ReErased => {
+ ty::ReLateBound(..)
+ | ty::ReFree(..)
+ | ty::ReScope(..)
+ | ty::ReVar(..)
+ | ty::RePlaceholder(..)
+ | ty::ReEmpty
+ | ty::ReClosureBound(_)
+ | ty::ReErased => {
debug!("cannot clean region {:?}", self);
None
}
}
}
-impl Clean<WherePredicate> for hir::WherePredicate {
+impl Clean<WherePredicate> for hir::WherePredicate<'_> {
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
match *self {
- hir::WherePredicate::BoundPredicate(ref wbp) => {
- WherePredicate::BoundPredicate {
- ty: wbp.bounded_ty.clean(cx),
- bounds: wbp.bounds.clean(cx)
- }
- }
+ hir::WherePredicate::BoundPredicate(ref wbp) => WherePredicate::BoundPredicate {
+ ty: wbp.bounded_ty.clean(cx),
+ bounds: wbp.bounds.clean(cx),
+ },
- hir::WherePredicate::RegionPredicate(ref wrp) => {
- WherePredicate::RegionPredicate {
- lifetime: wrp.lifetime.clean(cx),
- bounds: wrp.bounds.clean(cx)
- }
- }
+ hir::WherePredicate::RegionPredicate(ref wrp) => WherePredicate::RegionPredicate {
+ lifetime: wrp.lifetime.clean(cx),
+ bounds: wrp.bounds.clean(cx),
+ },
hir::WherePredicate::EqPredicate(ref wrp) => {
- WherePredicate::EqPredicate {
- lhs: wrp.lhs_ty.clean(cx),
- rhs: wrp.rhs_ty.clean(cx)
- }
+ WherePredicate::EqPredicate { lhs: wrp.lhs_ty.clean(cx), rhs: wrp.rhs_ty.clean(cx) }
}
}
}
Predicate::TypeOutlives(ref pred) => pred.clean(cx),
Predicate::Projection(ref pred) => Some(pred.clean(cx)),
- Predicate::WellFormed(..) |
- Predicate::ObjectSafe(..) |
- Predicate::ClosureKind(..) |
- Predicate::ConstEvaluatable(..) => panic!("not user writable"),
+ Predicate::WellFormed(..)
+ | Predicate::ObjectSafe(..)
+ | Predicate::ClosureKind(..)
+ | Predicate::ConstEvaluatable(..) => panic!("not user writable"),
}
}
}
fn clean(&self, cx: &DocContext<'_>) -> WherePredicate {
WherePredicate::BoundPredicate {
ty: self.trait_ref.self_ty().clean(cx),
- bounds: vec![self.trait_ref.clean(cx)]
+ bounds: vec![self.trait_ref.clean(cx)],
}
}
}
impl<'tcx> Clean<WherePredicate> for ty::SubtypePredicate<'tcx> {
fn clean(&self, _cx: &DocContext<'_>) -> WherePredicate {
- panic!("subtype predicates are an internal rustc artifact \
- and should not be seen by rustdoc")
+ panic!(
+ "subtype predicates are an internal rustc artifact \
+ and should not be seen by rustdoc"
+ )
}
}
-impl<'tcx> Clean<Option<WherePredicate>> for
- ty::OutlivesPredicate<ty::Region<'tcx>,ty::Region<'tcx>> {
-
+impl<'tcx> Clean<Option<WherePredicate>>
+ for ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>>
+{
fn clean(&self, cx: &DocContext<'_>) -> Option<WherePredicate> {
let ty::OutlivesPredicate(ref a, ref b) = *self;
match (a, b) {
(ty::ReEmpty, ty::ReEmpty) => {
return None;
- },
+ }
_ => {}
}
Some(WherePredicate::RegionPredicate {
lifetime: a.clean(cx).expect("failed to clean lifetime"),
- bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))]
+ bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))],
})
}
}
Some(WherePredicate::BoundPredicate {
ty: ty.clean(cx),
- bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))]
+ bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))],
})
}
}
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)
- }
+ WherePredicate::EqPredicate { lhs: self.projection_ty.clean(cx), rhs: self.ty.clean(cx) }
}
}
Type::QPath {
name: cx.tcx.associated_item(self.item_def_id).ident.name.clean(cx),
self_type: box self.self_ty().clean(cx),
- trait_: box trait_
+ trait_: box trait_,
}
}
}
(self.name.to_string(), GenericParamDefKind::Lifetime)
}
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
- let default = if has_default {
- Some(cx.tcx.type_of(self.def_id).clean(cx))
- } else {
- None
- };
- (self.name.clean(cx), GenericParamDefKind::Type {
- did: self.def_id,
- bounds: vec![], // These are filled in from the where-clauses.
- default,
- synthetic,
- })
+ let default =
+ if has_default { Some(cx.tcx.type_of(self.def_id).clean(cx)) } else { None };
+ (
+ self.name.clean(cx),
+ GenericParamDefKind::Type {
+ did: self.def_id,
+ bounds: vec![], // These are filled in from the where-clauses.
+ default,
+ synthetic,
+ },
+ )
}
- ty::GenericParamDefKind::Const { .. } => {
- (self.name.clean(cx), GenericParamDefKind::Const {
+ ty::GenericParamDefKind::Const { .. } => (
+ self.name.clean(cx),
+ GenericParamDefKind::Const {
did: self.def_id,
ty: cx.tcx.type_of(self.def_id).clean(cx),
- })
- }
+ },
+ ),
};
- GenericParamDef {
- name,
- kind,
- }
+ GenericParamDef { name, kind }
}
}
-impl Clean<GenericParamDef> for hir::GenericParam {
+impl Clean<GenericParamDef> for hir::GenericParam<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
let (name, kind) = match self.kind {
hir::GenericParamKind::Lifetime { .. } => {
};
(name, GenericParamDefKind::Lifetime)
}
- hir::GenericParamKind::Type { ref default, synthetic } => {
- (self.name.ident().name.clean(cx), GenericParamDefKind::Type {
+ hir::GenericParamKind::Type { ref default, synthetic } => (
+ self.name.ident().name.clean(cx),
+ GenericParamDefKind::Type {
did: cx.tcx.hir().local_def_id(self.hir_id),
bounds: self.bounds.clean(cx),
default: default.clean(cx),
synthetic,
- })
- }
- hir::GenericParamKind::Const { ref ty } => {
- (self.name.ident().name.clean(cx), GenericParamDefKind::Const {
+ },
+ ),
+ hir::GenericParamKind::Const { ref ty } => (
+ self.name.ident().name.clean(cx),
+ GenericParamDefKind::Const {
did: cx.tcx.hir().local_def_id(self.hir_id),
ty: ty.clean(cx),
- })
- }
+ },
+ ),
};
- GenericParamDef {
- name,
- kind,
- }
+ GenericParamDef { name, kind }
}
}
-impl Clean<Generics> for hir::Generics {
+impl Clean<Generics> for hir::Generics<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Generics {
// Synthetic type-parameters are inserted after normal ones.
// In order for normal parameters to be able to refer to synthetic ones,
// scans them first.
- fn is_impl_trait(param: &hir::GenericParam) -> bool {
+ fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool {
match param.kind {
hir::GenericParamKind::Type { synthetic, .. } => {
synthetic == Some(hir::SyntheticTyParamKind::ImplTrait)
_ => false,
}
}
- let impl_trait_params = self.params
+ let impl_trait_params = self
+ .params
.iter()
.filter(|param| is_impl_trait(param))
.map(|param| {
}
params.extend(impl_trait_params);
- let mut generics = Generics {
- params,
- where_predicates: self.where_clause.predicates.clean(cx),
- };
+ let mut generics =
+ Generics { params, where_predicates: self.where_clause.predicates.clean(cx) };
// Some duplicates are generated for ?Sized bounds between type params and where
// predicates. The point in here is to move the bounds definitions from type params
GenericParamDefKind::Type { bounds: ref mut ty_bounds, .. } => {
if ¶m.name == name {
mem::swap(bounds, ty_bounds);
- break
+ break;
}
}
GenericParamDefKind::Const { .. } => {}
// Bounds in the type_params and lifetimes fields are repeated in the
// predicates field (see rustc_typeck::collect::ty_generics), so remove
// them.
- let stripped_typarams = gens.params.iter()
+ let stripped_typarams = gens
+ .params
+ .iter()
.filter_map(|param| match param.kind {
ty::GenericParamDefKind::Lifetime => None,
ty::GenericParamDefKind::Type { synthetic, .. } => {
Some(param.clean(cx))
}
ty::GenericParamDefKind::Const { .. } => None,
- }).collect::<Vec<GenericParamDef>>();
+ })
+ .collect::<Vec<GenericParamDef>>();
// param index -> [(DefId of trait, associated type name, type)]
- let mut impl_trait_proj =
- FxHashMap::<u32, Vec<(DefId, String, Ty<'tcx>)>>::default();
+ let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, String, Ty<'tcx>)>>::default();
- let where_predicates = preds.predicates.iter()
+ let where_predicates = preds
+ .predicates
+ .iter()
.flat_map(|(p, _)| {
let mut projection = None;
let param_idx = (|| {
.into_iter()
.flatten()
.cloned()
- .filter(|b| !b.is_sized_bound(cx))
+ .filter(|b| !b.is_sized_bound(cx)),
);
let proj = projection
if let Some(((_, trait_did, name), rhs)) =
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
{
- impl_trait_proj
- .entry(param_idx)
- .or_default()
- .push((trait_did, name.to_string(), rhs));
+ impl_trait_proj.entry(param_idx).or_default().push((
+ trait_did,
+ name.to_string(),
+ rhs,
+ ));
}
return None;
for (param, mut bounds) in impl_trait {
// Move trait bounds to the front.
- bounds.sort_by_key(|b| if let GenericBound::TraitBound(..) = b {
- false
- } else {
- true
- });
+ bounds.sort_by_key(|b| if let GenericBound::TraitBound(..) = b { false } else { true });
if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
- simplify::merge_bounds(
- cx,
- &mut bounds,
- trait_did,
- &name,
- &rhs.clean(cx),
- );
+ simplify::merge_bounds(cx, &mut bounds, trait_did, &name, &rhs.clean(cx));
}
}
} else {
// Now that `cx.impl_trait_bounds` is populated, we can process
// remaining predicates which could contain `impl Trait`.
- let mut where_predicates = where_predicates
- .into_iter()
- .flat_map(|p| p.clean(cx))
- .collect::<Vec<_>>();
+ let mut where_predicates =
+ where_predicates.into_iter().flat_map(|p| p.clean(cx)).collect::<Vec<_>>();
// Type parameters and have a Sized bound by default unless removed with
// ?Sized. Scan through the predicates and mark any type parameter with
// don't actually know the set of associated types right here so that's
// handled in cleaning associated types
let mut sized_params = FxHashSet::default();
- 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
- }
+ 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
}
- _ => true,
}
+ _ => true,
});
// Run through the type parameters again and insert a ?Sized
// and instead see `where T: Foo + Bar + Sized + 'a`
Generics {
- params: gens.params
- .iter()
- .flat_map(|param| match param.kind {
- ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
- ty::GenericParamDefKind::Type { .. } => None,
- ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
- }).chain(simplify::ty_params(stripped_typarams).into_iter())
- .collect(),
+ params: gens
+ .params
+ .iter()
+ .flat_map(|param| match param.kind {
+ ty::GenericParamDefKind::Lifetime => Some(param.clean(cx)),
+ ty::GenericParamDefKind::Type { .. } => None,
+ ty::GenericParamDefKind::Const { .. } => Some(param.clean(cx)),
+ })
+ .chain(simplify::ty_params(stripped_typarams).into_iter())
+ .collect(),
where_predicates: simplify::where_clauses(cx, where_predicates),
}
}
}
-impl<'a> Clean<Method> for (&'a hir::FnSig, &'a hir::Generics, hir::BodyId,
- Option<hir::Defaultness>) {
+impl<'a> Clean<Method>
+ for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::BodyId, Option<hir::Defaultness>)
+{
fn clean(&self, cx: &DocContext<'_>) -> Method {
- let (generics, decl) = enter_impl_trait(cx, || {
- (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx))
- });
+ let (generics, decl) =
+ enter_impl_trait(cx, || (self.1.clean(cx), (&*self.0.decl, self.2).clean(cx)));
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
- Method {
- decl,
- generics,
- header: self.0.header,
- defaultness: self.3,
- all_types,
- ret_types,
- }
+ Method { decl, generics, header: self.0.header, defaultness: self.3, all_types, ret_types }
}
}
impl Clean<Item> for doctree::Function<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
- let (generics, decl) = enter_impl_trait(cx, || {
- (self.generics.clean(cx), (self.decl, self.body).clean(cx))
- });
+ let (generics, decl) =
+ enter_impl_trait(cx, || (self.generics.clean(cx), (self.decl, self.body).clean(cx)));
let did = cx.tcx.hir().local_def_id(self.id);
- let constness = if cx.tcx.is_min_const_fn(did) {
+ let constness = if is_min_const_fn(cx.tcx, did) {
hir::Constness::Const
} else {
hir::Constness::NotConst
}
}
-impl<'a> Clean<Arguments> for (&'a [hir::Ty], &'a [ast::Ident]) {
+impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], &'a [ast::Ident]) {
fn clean(&self, cx: &DocContext<'_>) -> Arguments {
Arguments {
- values: self.0.iter().enumerate().map(|(i, ty)| {
- let mut name = self.1.get(i).map(|ident| ident.to_string())
- .unwrap_or(String::new());
- if name.is_empty() {
- name = "_".to_string();
- }
- Argument {
- name,
- type_: ty.clean(cx),
- }
- }).collect()
+ values: self
+ .0
+ .iter()
+ .enumerate()
+ .map(|(i, ty)| {
+ let mut name =
+ self.1.get(i).map(|ident| ident.to_string()).unwrap_or(String::new());
+ if name.is_empty() {
+ name = "_".to_string();
+ }
+ Argument { name, type_: ty.clean(cx) }
+ })
+ .collect(),
}
}
}
-impl<'a> Clean<Arguments> for (&'a [hir::Ty], hir::BodyId) {
+impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
fn clean(&self, cx: &DocContext<'_>) -> Arguments {
let body = cx.tcx.hir().body(self.1);
Arguments {
- values: self.0.iter().enumerate().map(|(i, ty)| {
- Argument {
+ values: self
+ .0
+ .iter()
+ .enumerate()
+ .map(|(i, ty)| Argument {
name: name_from_pat(&body.params[i].pat),
type_: ty.clean(cx),
- }
- }).collect()
+ })
+ .collect(),
}
}
}
-impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl, A)
- where (&'a [hir::Ty], A): Clean<Arguments>
+impl<'a, A: Copy> Clean<FnDecl> for (&'a hir::FnDecl<'a>, A)
+where
+ (&'a [hir::Ty<'a>], A): Clean<Arguments>,
{
fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
FnDecl {
attrs: Attributes::default(),
c_variadic: sig.skip_binder().c_variadic,
inputs: Arguments {
- values: sig.skip_binder().inputs().iter().map(|t| {
- Argument {
+ values: sig
+ .skip_binder()
+ .inputs()
+ .iter()
+ .map(|t| Argument {
type_: t.clean(cx),
name: names.next().map_or(String::new(), |name| name.to_string()),
- }
- }).collect(),
+ })
+ .collect(),
},
}
}
}
-impl Clean<FunctionRetTy> for hir::FunctionRetTy {
+impl Clean<FunctionRetTy> for hir::FunctionRetTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> FunctionRetTy {
match *self {
- hir::Return(ref typ) => Return(typ.clean(cx)),
- hir::DefaultReturn(..) => DefaultReturn,
+ Self::Return(ref typ) => Return(typ.clean(cx)),
+ Self::DefaultReturn(..) => DefaultReturn,
}
}
}
}
}
-impl Clean<Type> for hir::TraitRef {
+impl Clean<Type> for hir::TraitRef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Type {
resolve_type(cx, self.path.clean(cx), self.hir_ref_id)
}
}
-impl Clean<PolyTrait> for hir::PolyTraitRef {
+impl Clean<PolyTrait> for hir::PolyTraitRef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> PolyTrait {
PolyTrait {
trait_: self.trait_ref.clean(cx),
- generic_params: self.bound_generic_params.clean(cx)
+ generic_params: self.bound_generic_params.clean(cx),
}
}
}
-impl Clean<Item> for hir::TraitItem {
+impl Clean<Item> for hir::TraitItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let inner = match self.kind {
hir::TraitItemKind::Const(ref ty, default) => {
- AssocConstItem(ty.clean(cx),
- default.map(|e| print_const_expr(cx, e)))
+ AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx, e)))
}
hir::TraitItemKind::Method(ref sig, hir::TraitMethod::Provided(body)) => {
MethodItem((sig, &self.generics, body, None).clean(cx))
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
});
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
- TyMethodItem(TyMethod {
- header: sig.header,
- decl,
- generics,
- all_types,
- ret_types,
- })
+ TyMethodItem(TyMethod { header: sig.header, decl, generics, all_types, ret_types })
}
hir::TraitItemKind::Type(ref bounds, ref default) => {
AssocTypeItem(bounds.clean(cx), default.clean(cx))
}
}
-impl Clean<Item> for hir::ImplItem {
+impl Clean<Item> for hir::ImplItem<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let inner = match self.kind {
hir::ImplItemKind::Const(ref ty, expr) => {
- AssocConstItem(ty.clean(cx),
- Some(print_const_expr(cx, expr)))
+ AssocConstItem(ty.clean(cx), Some(print_const_expr(cx, expr)))
}
hir::ImplItemKind::Method(ref sig, body) => {
MethodItem((sig, &self.generics, body, Some(self.defaultness)).clean(cx))
}
- hir::ImplItemKind::TyAlias(ref ty) => TypedefItem(Typedef {
- type_: ty.clean(cx),
- generics: Generics::default(),
- }, true),
- hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(OpaqueTy {
- bounds: bounds.clean(cx),
- generics: Generics::default(),
- }, true),
+ hir::ImplItemKind::TyAlias(ref ty) => {
+ let type_ = ty.clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
+ TypedefItem(Typedef { type_, generics: Generics::default(), item_type }, true)
+ }
+ hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(
+ OpaqueTy { bounds: bounds.clean(cx), generics: Generics::default() },
+ true,
+ ),
};
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
Item {
AssocConstItem(ty.clean(cx), default)
}
ty::AssocKind::Method => {
- let generics = (cx.tcx.generics_of(self.def_id),
- cx.tcx.explicit_predicates_of(self.def_id)).clean(cx);
+ let generics =
+ (cx.tcx.generics_of(self.def_id), cx.tcx.explicit_predicates_of(self.def_id))
+ .clean(cx);
let sig = cx.tcx.fn_sig(self.def_id);
let mut decl = (self.def_id, sig).clean(cx);
if self.method_has_self_argument {
let self_ty = match self.container {
- ty::ImplContainer(def_id) => {
- cx.tcx.type_of(def_id)
- }
+ ty::ImplContainer(def_id) => cx.tcx.type_of(def_id),
ty::TraitContainer(_) => cx.tcx.types.self_param,
};
let self_arg_ty = *sig.input(0).skip_binder();
} else if let ty::Ref(_, ty, _) = self_arg_ty.kind {
if ty == self_ty {
match decl.inputs.values[0].type_ {
- BorrowedRef{ref mut type_, ..} => {
+ BorrowedRef { ref mut type_, .. } => {
**type_ = Generic(String::from("Self"))
}
_ => unreachable!(),
let provided = match self.container {
ty::ImplContainer(_) => true,
- ty::TraitContainer(_) => self.defaultness.has_value()
+ ty::TraitContainer(_) => self.defaultness.has_value(),
};
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
if provided {
- let constness = if cx.tcx.is_min_const_fn(self.def_id) {
+ let constness = if is_min_const_fn(cx.tcx, self.def_id) {
hir::Constness::Const
} else {
hir::Constness::NotConst
// applied to this associated type in question.
let predicates = cx.tcx.explicit_predicates_of(did);
let generics = (cx.tcx.generics_of(did), predicates).clean(cx);
- let mut bounds = 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<_>>();
+ let mut bounds = 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<_>>();
// 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); }
+ Some(i) => {
+ bounds.remove(i);
+ }
None => bounds.push(GenericBound::maybe_sized(cx)),
}
AssocTypeItem(bounds, ty.clean(cx))
} else {
- TypedefItem(Typedef {
- type_: cx.tcx.type_of(self.def_id).clean(cx),
- generics: Generics {
- params: Vec::new(),
- where_predicates: Vec::new(),
+ let type_ = cx.tcx.type_of(self.def_id).clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
+ TypedefItem(
+ Typedef {
+ type_,
+ generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
+ item_type,
},
- }, true)
+ true,
+ )
}
}
ty::AssocKind::OpaqueTy => unimplemented!(),
}
}
-impl Clean<Type> for hir::Ty {
+impl Clean<Type> for hir::Ty<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Type {
- use rustc::hir::*;
+ use rustc_hir::*;
match self.kind {
TyKind::Never => Never,
- TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
+ TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
TyKind::Rptr(ref l, ref m) => {
- let lifetime = if l.is_elided() {
- None
- } else {
- Some(l.clean(cx))
- };
- BorrowedRef {lifetime, mutability: m.mutbl.clean(cx),
- type_: box m.ty.clean(cx)}
+ let lifetime = if l.is_elided() { None } else { Some(l.clean(cx)) };
+ BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
}
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
TyKind::Array(ref ty, ref length) => {
let def_id = cx.tcx.hir().local_def_id(length.hir_id);
- let param_env = cx.tcx.param_env(def_id);
- let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
- let cid = GlobalId {
- instance: ty::Instance::new(def_id, substs),
- promoted: None
- };
- let length = match cx.tcx.const_eval(param_env.and(cid)) {
+ let length = match cx.tcx.const_eval_poly(def_id) {
Ok(length) => print_const(cx, length),
- Err(_) => cx.sess()
- .source_map()
- .span_to_snippet(cx.tcx.def_span(def_id))
- .unwrap_or_else(|_| "_".to_string()),
+ Err(_) => cx
+ .sess()
+ .source_map()
+ .span_to_snippet(cx.tcx.def_span(def_id))
+ .unwrap_or_else(|_| "_".to_string()),
};
Array(box ty.clean(cx), length)
- },
+ }
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::Def(item_id, _) => {
let item = cx.tcx.hir().expect_item(item_id.id);
match param.kind {
hir::GenericParamKind::Lifetime { .. } => {
let mut j = 0;
- let lifetime = generic_args.args.iter().find_map(|arg| {
- match arg {
+ let lifetime =
+ generic_args.args.iter().find_map(|arg| match arg {
hir::GenericArg::Lifetime(lt) => {
if indices.lifetimes == j {
return Some(lt);
None
}
_ => None,
- }
- });
+ });
if let Some(lt) = lifetime.cloned() {
if !lt.is_elided() {
- let lt_def_id =
- cx.tcx.hir().local_def_id(param.hir_id);
+ let lt_def_id = cx.tcx.hir().local_def_id(param.hir_id);
lt_substs.insert(lt_def_id, lt.clean(cx));
}
}
indices.lifetimes += 1;
}
hir::GenericParamKind::Type { ref default, .. } => {
- let ty_param_def_id =
- cx.tcx.hir().local_def_id(param.hir_id);
+ let ty_param_def_id = cx.tcx.hir().local_def_id(param.hir_id);
let mut j = 0;
- let type_ = generic_args.args.iter().find_map(|arg| {
- match arg {
+ let type_ =
+ generic_args.args.iter().find_map(|arg| match arg {
hir::GenericArg::Type(ty) => {
if indices.types == j {
return Some(ty);
None
}
_ => None,
- }
- });
+ });
if let Some(ty) = type_ {
ty_substs.insert(ty_param_def_id, ty.clean(cx));
} else if let Some(default) = default.clone() {
- ty_substs.insert(ty_param_def_id,
- default.clean(cx));
+ ty_substs.insert(ty_param_def_id, default.clean(cx));
}
indices.types += 1;
}
let const_param_def_id =
cx.tcx.hir().local_def_id(param.hir_id);
let mut j = 0;
- let const_ = generic_args.args.iter().find_map(|arg| {
- match arg {
+ let const_ =
+ generic_args.args.iter().find_map(|arg| match arg {
hir::GenericArg::Const(ct) => {
if indices.consts == j {
return Some(ct);
None
}
_ => None,
- }
- });
+ });
if let Some(ct) = const_ {
ct_substs.insert(const_param_def_id, ct.clean(cx));
}
Type::QPath {
name: p.segments.last().expect("segments were empty").ident.name.clean(cx),
self_type: box qself.clean(cx),
- trait_: box resolve_type(cx, trait_path, self.hir_id)
+ trait_: box resolve_type(cx, trait_path, self.hir_id),
}
}
TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => {
if let ty::Projection(proj) = ty.kind {
res = Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id);
}
- let trait_path = hir::Path {
- span: self.span,
- res,
- segments: vec![].into(),
- };
+ let trait_path = hir::Path { span: self.span, res, segments: &[] };
Type::QPath {
name: segment.ident.name.clean(cx),
self_type: box qself.clean(cx),
- trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id)
+ trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id),
}
}
TyKind::TraitObject(ref bounds, ref lifetime) => {
match bounds[0].clean(cx).trait_ {
ResolvedPath { path, param_names: None, did, is_generic } => {
- let mut bounds: Vec<self::GenericBound> = bounds[1..].iter().map(|bound| {
- self::GenericBound::TraitBound(bound.clean(cx),
- hir::TraitBoundModifier::None)
- }).collect();
+ let mut bounds: Vec<self::GenericBound> = bounds[1..]
+ .iter()
+ .map(|bound| {
+ self::GenericBound::TraitBound(
+ bound.clean(cx),
+ hir::TraitBoundModifier::None,
+ )
+ })
+ .collect();
if !lifetime.is_elided() {
bounds.push(self::GenericBound::Outlives(lifetime.clean(cx)));
}
- ResolvedPath { path, param_names: Some(bounds), did, is_generic, }
+ ResolvedPath { path, param_names: Some(bounds), did, is_generic }
}
_ => Infer, // shouldn't happen
}
ty::Slice(ty) => Slice(box ty.clean(cx)),
ty::Array(ty, n) => {
let mut n = cx.tcx.lift(&n).expect("array lift failed");
- if let ty::ConstKind::Unevaluated(def_id, substs) = n.val {
- let param_env = cx.tcx.param_env(def_id);
- let cid = GlobalId {
- instance: ty::Instance::new(def_id, substs),
- promoted: None
- };
- if let Ok(new_n) = cx.tcx.const_eval(param_env.and(cid)) {
- n = new_n;
- }
- };
+ n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
let n = print_const(cx, n);
Array(box ty.clean(cx), n)
}
- ty::RawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
- ty::Ref(r, ty, mutbl) => BorrowedRef {
- lifetime: r.clean(cx),
- mutability: mutbl.clean(cx),
- type_: box ty.clean(cx),
- },
- ty::FnDef(..) |
- ty::FnPtr(_) => {
+ ty::RawPtr(mt) => RawPointer(mt.mutbl, box mt.ty.clean(cx)),
+ ty::Ref(r, ty, mutbl) => {
+ BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) }
+ }
+ ty::FnDef(..) | ty::FnPtr(_) => {
let ty = cx.tcx.lift(self).expect("FnPtr lift failed");
let sig = ty.fn_sig(cx.tcx);
let local_def_id = cx.tcx.hir().local_def_id_from_node_id(ast::CRATE_NODE_ID);
};
inline::record_extern_fqn(cx, did, kind);
let path = external_path(cx, cx.tcx.item_name(did), None, false, vec![], substs);
- ResolvedPath {
- path,
- param_names: None,
- did,
- is_generic: false,
- }
+ ResolvedPath { path, param_names: None, did, is_generic: false }
}
ty::Foreign(did) => {
inline::record_extern_fqn(cx, did, TypeKind::Foreign);
- let path = external_path(cx, cx.tcx.item_name(did),
- None, false, vec![], InternalSubsts::empty());
- ResolvedPath {
- path,
- param_names: None,
- did,
- is_generic: false,
- }
+ let path = external_path(
+ cx,
+ cx.tcx.item_name(did),
+ None,
+ false,
+ vec![],
+ InternalSubsts::empty(),
+ );
+ ResolvedPath { path, param_names: None, did, is_generic: false }
}
ty::Dynamic(ref obj, ref reg) => {
// HACK: pick the first `did` as the `did` of the trait object. Someone
// might want to implement "native" support for marker-trait-only
// trait objects.
let mut dids = obj.principal_def_id().into_iter().chain(obj.auto_traits());
- let did = dids.next().unwrap_or_else(|| {
- panic!("found trait object `{:?}` with no traits?", self)
- });
+ let did = dids
+ .next()
+ .unwrap_or_else(|| panic!("found trait object `{:?}` with no traits?", self));
let substs = match obj.principal() {
Some(principal) => principal.skip_binder().substs,
// marker traits have no substs.
- _ => cx.tcx.intern_substs(&[])
+ _ => cx.tcx.intern_substs(&[]),
};
inline::record_extern_fqn(cx, did, TypeKind::Trait);
reg.clean(cx).map(|b| param_names.push(GenericBound::Outlives(b)));
for did in dids {
let empty = cx.tcx.intern_substs(&[]);
- let path = external_path(cx, cx.tcx.item_name(did),
- Some(did), false, vec![], empty);
+ let path =
+ external_path(cx, cx.tcx.item_name(did), Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, TypeKind::Trait);
- let bound = GenericBound::TraitBound(PolyTrait {
- trait_: ResolvedPath {
- path,
- param_names: None,
- did,
- is_generic: false,
+ let bound = GenericBound::TraitBound(
+ PolyTrait {
+ trait_: ResolvedPath {
+ path,
+ param_names: None,
+ did,
+ is_generic: false,
+ },
+ generic_params: Vec::new(),
},
- generic_params: Vec::new(),
- }, hir::TraitBoundModifier::None);
+ hir::TraitBoundModifier::None,
+ );
param_names.push(bound);
}
for pb in obj.projection_bounds() {
bindings.push(TypeBinding {
name: cx.tcx.associated_item(pb.item_def_id()).ident.name.clean(cx),
- kind: TypeBindingKind::Equality {
- ty: pb.skip_binder().ty.clean(cx)
- },
+ kind: TypeBindingKind::Equality { ty: pb.skip_binder().ty.clean(cx) },
});
}
- let path = external_path(cx, cx.tcx.item_name(did), Some(did),
- false, bindings, substs);
- ResolvedPath {
- path,
- param_names: Some(param_names),
- did,
- is_generic: false,
- }
+ let path =
+ external_path(cx, cx.tcx.item_name(did), Some(did), false, bindings, substs);
+ ResolvedPath { path, param_names: Some(param_names), did, is_generic: false }
}
ty::Tuple(ref t) => {
Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx))
let bounds = predicates_of.instantiate(cx.tcx, substs);
let mut regions = vec![];
let mut has_sized = false;
- let mut bounds = bounds.predicates.iter().filter_map(|predicate| {
- let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() {
- tr
- } else if let ty::Predicate::TypeOutlives(pred) = *predicate {
- // these should turn up at the end
- pred.skip_binder().1.clean(cx).map(|r| {
- regions.push(GenericBound::Outlives(r))
- });
- return None;
- } else {
- return None;
- };
-
- if let Some(sized) = cx.tcx.lang_items().sized_trait() {
- if trait_ref.def_id() == sized {
- has_sized = true;
+ let mut bounds = bounds
+ .predicates
+ .iter()
+ .filter_map(|predicate| {
+ let trait_ref = if let Some(tr) = predicate.to_opt_poly_trait_ref() {
+ tr
+ } else if let ty::Predicate::TypeOutlives(pred) = *predicate {
+ // these should turn up at the end
+ pred.skip_binder()
+ .1
+ .clean(cx)
+ .map(|r| regions.push(GenericBound::Outlives(r)));
return None;
- }
- }
+ } else {
+ return None;
+ };
- let bounds = bounds.predicates.iter().filter_map(|pred|
- if let ty::Predicate::Projection(proj) = *pred {
- let proj = proj.skip_binder();
- if proj.projection_ty.trait_ref(cx.tcx) == *trait_ref.skip_binder() {
- Some(TypeBinding {
- name: cx.tcx.associated_item(proj.projection_ty.item_def_id)
- .ident.name.clean(cx),
- kind: TypeBindingKind::Equality {
- ty: proj.ty.clean(cx),
- },
- })
- } else {
- None
+ if let Some(sized) = cx.tcx.lang_items().sized_trait() {
+ if trait_ref.def_id() == sized {
+ has_sized = true;
+ return None;
}
- } else {
- None
}
- ).collect();
- Some((trait_ref.skip_binder(), bounds).clean(cx))
- }).collect::<Vec<_>>();
+ let bounds = bounds
+ .predicates
+ .iter()
+ .filter_map(|pred| {
+ if let ty::Predicate::Projection(proj) = *pred {
+ let proj = proj.skip_binder();
+ if proj.projection_ty.trait_ref(cx.tcx)
+ == *trait_ref.skip_binder()
+ {
+ Some(TypeBinding {
+ name: cx
+ .tcx
+ .associated_item(proj.projection_ty.item_def_id)
+ .ident
+ .name
+ .clean(cx),
+ kind: TypeBindingKind::Equality {
+ ty: proj.ty.clean(cx),
+ },
+ })
+ } else {
+ None
+ }
+ } else {
+ None
+ }
+ })
+ .collect();
+
+ Some((trait_ref.skip_binder(), bounds).clean(cx))
+ })
+ .collect::<Vec<_>>();
bounds.extend(regions);
if !has_sized && !bounds.is_empty() {
bounds.insert(0, GenericBound::maybe_sized(cx));
Constant {
type_: self.ty.clean(cx),
expr: format!("{}", self),
+ value: None,
+ is_literal: false,
}
}
}
-impl Clean<Item> for hir::StructField {
+impl Clean<Item> for hir::StructField<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
let local_did = cx.tcx.hir().local_def_id(self.hir_id);
}
}
-impl Clean<Visibility> for hir::Visibility {
+impl Clean<Visibility> for hir::Visibility<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Visibility {
match self.node {
hir::VisibilityKind::Public => Visibility::Public,
}
}
-impl Clean<VariantStruct> for ::rustc::hir::VariantData {
+impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
VariantStruct {
struct_type: doctree::struct_type_from_def(self),
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
- inner: VariantItem(Variant {
- kind: self.def.clean(cx),
- }),
+ inner: VariantItem(Variant { kind: self.def.clean(cx) }),
}
}
}
fn clean(&self, cx: &DocContext<'_>) -> Item {
let kind = match self.ctor_kind {
CtorKind::Const => VariantKind::CLike,
- CtorKind::Fn => {
- VariantKind::Tuple(
- self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect()
- )
- }
- CtorKind::Fictive => {
- VariantKind::Struct(VariantStruct {
- struct_type: doctree::Plain,
- fields_stripped: false,
- fields: self.fields.iter().map(|field| {
- Item {
- source: cx.tcx.def_span(field.did).clean(cx),
- name: Some(field.ident.name.clean(cx)),
- attrs: cx.tcx.get_attrs(field.did).clean(cx),
- visibility: field.vis.clean(cx),
- def_id: field.did,
- stability: get_stability(cx, field.did),
- deprecation: get_deprecation(cx, field.did),
- inner: StructFieldItem(cx.tcx.type_of(field.did).clean(cx))
- }
- }).collect()
- })
- }
+ CtorKind::Fn => VariantKind::Tuple(
+ self.fields.iter().map(|f| cx.tcx.type_of(f.did).clean(cx)).collect(),
+ ),
+ CtorKind::Fictive => VariantKind::Struct(VariantStruct {
+ struct_type: doctree::Plain,
+ fields_stripped: false,
+ fields: self
+ .fields
+ .iter()
+ .map(|field| Item {
+ source: cx.tcx.def_span(field.did).clean(cx),
+ name: Some(field.ident.name.clean(cx)),
+ attrs: cx.tcx.get_attrs(field.did).clean(cx),
+ visibility: field.vis.clean(cx),
+ def_id: field.did,
+ stability: get_stability(cx, field.did),
+ deprecation: get_deprecation(cx, field.did),
+ inner: StructFieldItem(cx.tcx.type_of(field.did).clean(cx)),
+ })
+ .collect(),
+ }),
};
Item {
name: Some(self.ident.clean(cx)),
}
}
-impl Clean<VariantKind> for hir::VariantData {
+impl Clean<VariantKind> for hir::VariantData<'_> {
fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
match self {
hir::VariantData::Struct(..) => VariantKind::Struct(self.clean(cx)),
- hir::VariantData::Tuple(..) =>
- VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect()),
+ hir::VariantData::Tuple(..) => {
+ VariantKind::Tuple(self.fields().iter().map(|x| x.ty.clean(cx)).collect())
+ }
hir::VariantData::Unit(..) => VariantKind::CLike,
}
}
}
-impl Clean<Span> for syntax_pos::Span {
+impl Clean<Span> for rustc_span::Span {
fn clean(&self, cx: &DocContext<'_>) -> Span {
if self.is_dummy() {
return Span::empty();
}
}
-impl Clean<Path> for hir::Path {
+impl Clean<Path> for hir::Path<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Path {
Path {
global: self.is_global(),
}
}
-impl Clean<GenericArgs> for hir::GenericArgs {
+impl Clean<GenericArgs> for hir::GenericArgs<'_> {
fn clean(&self, cx: &DocContext<'_>) -> GenericArgs {
if self.parenthesized {
let output = self.bindings[0].ty().clean(cx);
GenericArgs::Parenthesized {
inputs: self.inputs().clean(cx),
- output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None }
+ output: if output != Type::Tuple(Vec::new()) { Some(output) } else { None },
}
} else {
let elide_lifetimes = self.args.iter().all(|arg| match arg {
_ => true,
});
GenericArgs::AngleBracketed {
- args: self.args.iter().filter_map(|arg| match arg {
- hir::GenericArg::Lifetime(lt) if !elide_lifetimes => {
- Some(GenericArg::Lifetime(lt.clean(cx)))
- }
- hir::GenericArg::Lifetime(_) => None,
- hir::GenericArg::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
- hir::GenericArg::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
- }).collect(),
+ args: self
+ .args
+ .iter()
+ .filter_map(|arg| match arg {
+ hir::GenericArg::Lifetime(lt) if !elide_lifetimes => {
+ Some(GenericArg::Lifetime(lt.clean(cx)))
+ }
+ hir::GenericArg::Lifetime(_) => None,
+ hir::GenericArg::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
+ hir::GenericArg::Const(ct) => Some(GenericArg::Const(ct.clean(cx))),
+ })
+ .collect(),
bindings: self.bindings.clean(cx),
}
}
}
}
-impl Clean<PathSegment> for hir::PathSegment {
+impl Clean<PathSegment> for hir::PathSegment<'_> {
fn clean(&self, cx: &DocContext<'_>) -> PathSegment {
- PathSegment {
- name: self.ident.name.clean(cx),
- args: self.generic_args().clean(cx),
- }
+ PathSegment { name: self.ident.name.clean(cx), args: self.generic_args().clean(cx) }
}
}
impl Clean<Item> for doctree::Typedef<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
+ let type_ = self.ty.clean(cx);
+ let item_type = type_.def_id().and_then(|did| inline::build_ty(cx, did));
Item {
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
visibility: self.vis.clean(cx),
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
- inner: TypedefItem(Typedef {
- type_: self.ty.clean(cx),
- generics: self.gen.clean(cx),
- }, false),
+ inner: TypedefItem(Typedef { type_, generics: self.gen.clean(cx), item_type }, false),
}
}
}
visibility: self.vis.clean(cx),
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
- inner: OpaqueTyItem(OpaqueTy {
- bounds: self.opaque_ty.bounds.clean(cx),
- generics: self.opaque_ty.generics.clean(cx),
- }, false),
+ inner: OpaqueTyItem(
+ OpaqueTy {
+ bounds: self.opaque_ty.bounds.clean(cx),
+ generics: self.opaque_ty.generics.clean(cx),
+ },
+ false,
+ ),
}
}
}
-impl Clean<BareFunctionDecl> for hir::BareFnTy {
+impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
fn clean(&self, cx: &DocContext<'_>) -> BareFunctionDecl {
let (generic_params, decl) = enter_impl_trait(cx, || {
(self.generic_params.clean(cx), (&*self.decl, &self.param_names[..]).clean(cx))
});
- BareFunctionDecl {
- unsafety: self.unsafety,
- abi: self.abi,
- decl,
- generic_params,
- }
+ BareFunctionDecl { unsafety: self.unsafety, abi: self.abi, decl, generic_params }
}
}
deprecation: cx.deprecation(self.id).clean(cx),
inner: StaticItem(Static {
type_: self.type_.clean(cx),
- mutability: self.mutability.clean(cx),
+ mutability: self.mutability,
expr: print_const_expr(cx, self.expr),
}),
}
impl Clean<Item> for doctree::Constant<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Item {
+ let def_id = cx.tcx.hir().local_def_id(self.id);
+
Item {
name: Some(self.name.clean(cx)),
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
- def_id: cx.tcx.hir().local_def_id(self.id),
+ def_id,
visibility: self.vis.clean(cx),
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
inner: ConstantItem(Constant {
type_: self.type_.clean(cx),
expr: print_const_expr(cx, self.expr),
+ value: print_evaluated_const(cx, def_id),
+ is_literal: is_literal_expr(cx, self.expr.hir_id),
}),
}
}
}
-impl Clean<Mutability> for hir::Mutability {
- fn clean(&self, _: &DocContext<'_>) -> Mutability {
- match self {
- &hir::Mutability::Mut => Mutable,
- &hir::Mutability::Not => Immutable,
- }
- }
-}
-
impl Clean<ImplPolarity> for ty::ImplPolarity {
fn clean(&self, _: &DocContext<'_>) -> ImplPolarity {
match self {
build_deref_target_impls(cx, &items, &mut ret);
}
- let provided = trait_.def_id().map(|did| {
- cx.tcx.provided_trait_methods(did)
- .into_iter()
- .map(|meth| meth.ident.to_string())
- .collect()
- }).unwrap_or_default();
+ let provided: FxHashSet<String> = trait_
+ .def_id()
+ .map(|did| {
+ cx.tcx
+ .provided_trait_methods(did)
+ .into_iter()
+ .map(|meth| meth.ident.to_string())
+ .collect()
+ })
+ .unwrap_or_default();
- ret.push(Item {
+ let for_ = self.for_.clean(cx);
+ let type_alias = for_.def_id().and_then(|did| match cx.tcx.def_kind(did) {
+ Some(DefKind::TyAlias) => Some(cx.tcx.type_of(did).clean(cx)),
+ _ => None,
+ });
+ let make_item = |trait_: Option<Type>, for_: Type, items: Vec<Item>| Item {
name: None,
attrs: self.attrs.clean(cx),
source: self.whence.clean(cx),
inner: ImplItem(Impl {
unsafety: self.unsafety,
generics: self.generics.clean(cx),
- provided_trait_methods: provided,
+ provided_trait_methods: provided.clone(),
trait_,
- for_: self.for_.clean(cx),
+ for_,
items,
polarity: Some(cx.tcx.impl_polarity(def_id).clean(cx)),
synthetic: false,
blanket_impl: None,
- })
- });
+ }),
+ };
+ if let Some(type_alias) = type_alias {
+ ret.push(make_item(trait_.clone(), type_alias, items.clone()));
+ }
+ ret.push(make_item(trait_, for_, items));
ret
}
}
impl Clean<Vec<Item>> for doctree::ExternCrate<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
-
- let please_inline = self.vis.node.is_pub() && self.attrs.iter().any(|a| {
- a.check_name(sym::doc) && match a.meta_item_list() {
- Some(l) => attr::list_contains_name(&l, sym::inline),
- None => false,
- }
- });
+ let please_inline = self.vis.node.is_pub()
+ && self.attrs.iter().any(|a| {
+ a.check_name(sym::doc)
+ && match a.meta_item_list() {
+ Some(l) => attr::list_contains_name(&l, sym::inline),
+ None => false,
+ }
+ });
if please_inline {
let mut visited = FxHashSet::default();
- let res = Res::Def(
- DefKind::Mod,
- DefId {
- krate: self.cnum,
- index: CRATE_DEF_INDEX,
- },
- );
+ let res = Res::Def(DefKind::Mod, DefId { krate: self.cnum, index: CRATE_DEF_INDEX });
if let Some(items) = inline::try_inline(
- cx, res, self.name,
+ cx,
+ res,
+ self.name,
Some(rustc::ty::Attributes::Borrowed(self.attrs)),
- &mut visited
+ &mut visited,
) {
return items;
}
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
- inner: ExternCrateItem(self.name.clean(cx), self.path.clone())
+ inner: ExternCrateItem(self.name.clean(cx), self.path.clone()),
}]
}
}
// forcefully don't inline if this is not public or if the
// #[doc(no_inline)] attribute is present.
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
- let mut denied = !self.vis.node.is_pub() || self.attrs.iter().any(|a| {
- a.check_name(sym::doc) && match a.meta_item_list() {
- Some(l) => attr::list_contains_name(&l, sym::no_inline) ||
- attr::list_contains_name(&l, sym::hidden),
- None => false,
- }
- });
+ let mut denied = !self.vis.node.is_pub()
+ || self.attrs.iter().any(|a| {
+ a.check_name(sym::doc)
+ && match a.meta_item_list() {
+ Some(l) => {
+ attr::list_contains_name(&l, sym::no_inline)
+ || attr::list_contains_name(&l, sym::hidden)
+ }
+ None => false,
+ }
+ });
// Also check whether imports were asked to be inlined, in case we're trying to re-export a
// crate in Rust 2018+
let please_inline = self.attrs.lists(sym::doc).has_word(sym::inline);
if !denied {
let mut visited = FxHashSet::default();
if let Some(items) = inline::try_inline(
- cx, path.res, name,
+ cx,
+ path.res,
+ name,
Some(rustc::ty::Attributes::Borrowed(self.attrs)),
- &mut visited
+ &mut visited,
) {
return items;
}
visibility: self.vis.clean(cx),
stability: None,
deprecation: None,
- inner: ImportItem(inner)
+ inner: ImportItem(inner),
}]
}
}
let inner = match self.kind {
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
let abi = cx.tcx.hir().get_foreign_abi(self.id);
- let (generics, decl) = enter_impl_trait(cx, || {
- (generics.clean(cx), (&**decl, &names[..]).clean(cx))
- });
+ let (generics, decl) =
+ enter_impl_trait(cx, || (generics.clean(cx), (&**decl, &names[..]).clean(cx)));
let (all_types, ret_types) = get_all_types(&generics, &decl, cx);
ForeignFunctionItem(Function {
decl,
ret_types,
})
}
- hir::ForeignItemKind::Static(ref ty, mutbl) => {
- ForeignStaticItem(Static {
- type_: ty.clean(cx),
- mutability: mutbl.clean(cx),
- expr: String::new(),
- })
- }
- hir::ForeignItemKind::Type => {
- ForeignTypeItem
- }
+ hir::ForeignItemKind::Static(ref ty, mutbl) => ForeignStaticItem(Static {
+ type_: ty.clean(cx),
+ mutability: *mutbl,
+ expr: String::new(),
+ }),
+ hir::ForeignItemKind::Type => ForeignTypeItem,
};
Item {
deprecation: cx.deprecation(self.hid).clean(cx),
def_id: self.def_id,
inner: MacroItem(Macro {
- source: format!("macro_rules! {} {{\n{}}}",
- name,
- self.matchers.iter().map(|span| {
- format!(" {} => {{ ... }};\n", span.to_src(cx))
- }).collect::<String>()),
+ source: format!(
+ "macro_rules! {} {{\n{}}}",
+ name,
+ self.matchers
+ .iter()
+ .map(|span| { format!(" {} => {{ ... }};\n", span.to_src(cx)) })
+ .collect::<String>()
+ ),
imported_from: self.imported_from.clean(cx),
}),
}
stability: cx.stability(self.id).clean(cx),
deprecation: cx.deprecation(self.id).clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id),
- inner: ProcMacroItem(ProcMacro {
- kind: self.kind,
- helpers: self.helpers.clean(cx),
- }),
+ inner: ProcMacroItem(ProcMacro { kind: self.kind, helpers: self.helpers.clean(cx) }),
}
}
}
level: stability::StabilityLevel::from_attr_level(&self.level),
feature: Some(self.feature.to_string()).filter(|f| !f.is_empty()),
since: match self.level {
- attr::Stable {ref since} => since.to_string(),
+ attr::Stable { ref since } => since.to_string(),
_ => String::new(),
},
- deprecation: self.rustc_depr.as_ref().map(|d| {
- Deprecation {
- note: Some(d.reason.to_string()).filter(|r| !r.is_empty()),
- since: Some(d.since.to_string()).filter(|d| !d.is_empty()),
- }
+ deprecation: self.rustc_depr.as_ref().map(|d| Deprecation {
+ note: Some(d.reason.to_string()).filter(|r| !r.is_empty()),
+ since: Some(d.since.to_string()).filter(|d| !d.is_empty()),
}),
unstable_reason: match self.level {
attr::Unstable { reason: Some(ref reason), .. } => Some(reason.to_string()),
_ => None,
},
issue: match self.level {
- attr::Unstable {issue, ..} => issue,
+ attr::Unstable { issue, .. } => issue,
_ => None,
- }
+ },
}
}
}
-impl<'a> Clean<Stability> for &'a attr::Stability {
- fn clean(&self, dc: &DocContext<'_>) -> Stability {
- (**self).clean(dc)
- }
-}
-
impl Clean<Deprecation> for attr::Deprecation {
fn clean(&self, _: &DocContext<'_>) -> Deprecation {
Deprecation {
}
}
-impl Clean<TypeBinding> for hir::TypeBinding {
+impl Clean<TypeBinding> for hir::TypeBinding<'_> {
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
- TypeBinding {
- name: self.ident.name.clean(cx),
- kind: self.kind.clean(cx),
- }
+ TypeBinding { name: self.ident.name.clean(cx), kind: self.kind.clean(cx) }
}
}
-impl Clean<TypeBindingKind> for hir::TypeBindingKind {
+impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
fn clean(&self, cx: &DocContext<'_>) -> TypeBindingKind {
match *self {
- hir::TypeBindingKind::Equality { ref ty } =>
- TypeBindingKind::Equality {
- ty: ty.clean(cx),
- },
- hir::TypeBindingKind::Constraint { ref bounds } =>
- TypeBindingKind::Constraint {
- bounds: bounds.into_iter().map(|b| b.clean(cx)).collect(),
- },
+ hir::TypeBindingKind::Equality { ref ty } => {
+ TypeBindingKind::Equality { ty: ty.clean(cx) }
+ }
+ hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
+ bounds: bounds.into_iter().map(|b| b.clean(cx)).collect(),
+ },
}
}
}
match bound.clone() {
GenericBound::Outlives(l) => SimpleBound::Outlives(l),
GenericBound::TraitBound(t, mod_) => match t.trait_ {
- Type::ResolvedPath { path, param_names, .. } => {
- SimpleBound::TraitBound(path.segments,
- param_names
- .map_or_else(|| Vec::new(), |v| v.iter()
- .map(|p| SimpleBound::from(p.clone()))
- .collect()),
- t.generic_params,
- mod_)
- }
+ Type::ResolvedPath { path, param_names, .. } => SimpleBound::TraitBound(
+ path.segments,
+ param_names.map_or_else(
+ || Vec::new(),
+ |v| v.iter().map(|p| SimpleBound::from(p.clone())).collect(),
+ ),
+ t.generic_params,
+ mod_,
+ ),
_ => panic!("Unexpected bound {:?}", bound),
- }
+ },
}
}
}