]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
formatting
[rust.git] / src / librustdoc / clean / mod.rs
index defdeb52186cbf5bff37cef866f4f2853a04385e..20a5a6c54984d0bed6dd310df67780dbdd35cc8e 100644 (file)
@@ -9,9 +9,6 @@
 pub mod types;
 pub mod utils;
 
-use rustc::hir;
-use rustc::hir::def::{CtorKind, DefKind, Res};
-use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX};
 use rustc::infer::region_constraints::{Constraint, RegionConstraintData};
 use rustc::middle::lang_items;
 use rustc::middle::resolve_lifetime as rl;
 use rustc::ty::fold::TypeFolder;
 use rustc::ty::subst::InternalSubsts;
 use rustc::ty::{self, AdtKind, Lift, Ty, TyCtxt};
-use rustc::util::nodemap::{FxHashMap, FxHashSet};
+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::hygiene::MacroKind;
-use syntax_pos::symbol::{kw, sym};
-use syntax_pos::{self, Pos};
 
 use std::collections::hash_map::Entry;
 use std::default::Default;
@@ -895,7 +896,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
             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
@@ -1003,8 +1004,8 @@ fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
 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,
         }
     }
 }
@@ -1121,7 +1122,9 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
                 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)
+                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() },
@@ -1187,7 +1190,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
                 };
                 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
@@ -1281,10 +1284,13 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
 
                     AssocTypeItem(bounds, ty.clean(cx))
                 } else {
+                    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_: cx.tcx.type_of(self.def_id).clean(cx),
+                            type_,
                             generics: Generics { params: Vec::new(), where_predicates: Vec::new() },
+                            item_type,
                         },
                         true,
                     )
@@ -1313,7 +1319,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
 
 impl Clean<Type> for hir::Ty<'_> {
     fn clean(&self, cx: &DocContext<'_>) -> Type {
-        use rustc::hir::*;
+        use rustc_hir::*;
 
         match self.kind {
             TyKind::Never => Never,
@@ -1808,7 +1814,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
     }
 }
 
-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),
@@ -1903,7 +1909,7 @@ fn clean(&self, cx: &DocContext<'_>) -> VariantKind {
     }
 }
 
-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();
@@ -1988,6 +1994,8 @@ fn clean(&self, _: &DocContext<'_>) -> String {
 
 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),
@@ -1996,10 +2004,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
             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),
         }
     }
 }
@@ -2100,7 +2105,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
             build_deref_target_impls(cx, &items, &mut ret);
         }
 
-        let provided = trait_
+        let provided: FxHashSet<String> = trait_
             .def_id()
             .map(|did| {
                 cx.tcx
@@ -2111,7 +2116,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
             })
             .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),
@@ -2122,15 +2132,19 @@ fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
             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
     }
 }