]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / librustdoc / clean / mod.rs
index c1a91f26dbf802c9e725cc8e533aebd33fa5f8e1..b4d44aab239214b1d068c74c6be8fea4efb4a00a 100644 (file)
 use syntax::ast_util::PostExpansionMethod;
 use syntax::attr;
 use syntax::attr::{AttributeMethods, AttrMetaMethods};
-use syntax::codemap::Pos;
+use syntax::codemap::{DUMMY_SP, Pos};
 use syntax::parse::token::InternedString;
 use syntax::parse::token;
+use syntax::ptr::P;
 
 use rustc::back::link;
 use rustc::driver::driver;
@@ -34,7 +35,6 @@
 
 use std::rc::Rc;
 use std::u32;
-use std::gc::{Gc, GC};
 
 use core::DocContext;
 use doctree;
@@ -67,7 +67,7 @@ fn clean(&self, cx: &DocContext) -> VecPerParamSpace<U> {
     }
 }
 
-impl<T: 'static + Clean<U>, U> Clean<U> for Gc<T> {
+impl<T: Clean<U>, U> Clean<U> for P<T> {
     fn clean(&self, cx: &DocContext) -> U {
         (**self).clean(cx)
     }
@@ -99,7 +99,7 @@ pub struct Crate {
     pub name: String,
     pub module: Option<Item>,
     pub externs: Vec<(ast::CrateNum, ExternalCrate)>,
-    pub primitives: Vec<Primitive>,
+    pub primitives: Vec<PrimitiveType>,
 }
 
 impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
@@ -142,12 +142,12 @@ fn clean(&self, cx: &DocContext) -> Crate {
                 _ => unreachable!(),
             };
             let mut tmp = Vec::new();
-            for child in m.items.mut_iter() {
+            for child in m.items.iter_mut() {
                 let inner = match child.inner {
                     ModuleItem(ref mut m) => m,
                     _ => continue,
                 };
-                let prim = match Primitive::find(child.attrs.as_slice()) {
+                let prim = match PrimitiveType::find(child.attrs.as_slice()) {
                     Some(prim) => prim,
                     None => continue,
                 };
@@ -171,7 +171,7 @@ fn clean(&self, cx: &DocContext) -> Crate {
                 inner.items.push(i);
 
             }
-            m.items.extend(tmp.move_iter());
+            m.items.extend(tmp.into_iter());
         }
 
         Crate {
@@ -187,7 +187,7 @@ fn clean(&self, cx: &DocContext) -> Crate {
 pub struct ExternalCrate {
     pub name: String,
     pub attrs: Vec<Attribute>,
-    pub primitives: Vec<Primitive>,
+    pub primitives: Vec<PrimitiveType>,
 }
 
 impl Clean<ExternalCrate> for cstore::crate_metadata {
@@ -202,7 +202,7 @@ fn clean(&self, cx: &DocContext) -> ExternalCrate {
                     _ => return
                 };
                 let attrs = inline::load_attrs(cx, tcx, did);
-                Primitive::find(attrs.as_slice()).map(|prim| primitives.push(prim));
+                PrimitiveType::find(attrs.as_slice()).map(|prim| primitives.push(prim));
             })
         });
         ExternalCrate {
@@ -316,7 +316,8 @@ pub enum ItemEnum {
     /// `static`s from an extern block
     ForeignStaticItem(Static),
     MacroItem(Macro),
-    PrimitiveItem(Primitive),
+    PrimitiveItem(PrimitiveType),
+    AssociatedTypeItem,
 }
 
 #[deriving(Clone, Encodable, Decodable)]
@@ -333,8 +334,8 @@ fn clean(&self, cx: &DocContext) -> Item {
             "".to_string()
         };
         let mut foreigns = Vec::new();
-        for subforeigns in self.foreigns.clean(cx).move_iter() {
-            for foreign in subforeigns.move_iter() {
+        for subforeigns in self.foreigns.clean(cx).into_iter() {
+            for foreign in subforeigns.into_iter() {
                 foreigns.push(foreign)
             }
         }
@@ -348,8 +349,8 @@ fn clean(&self, cx: &DocContext) -> Item {
             self.statics.clean(cx),
             self.traits.clean(cx),
             self.impls.clean(cx),
-            self.view_items.clean(cx).move_iter()
-                           .flat_map(|s| s.move_iter()).collect(),
+            self.view_items.clean(cx).into_iter()
+                           .flat_map(|s| s.into_iter()).collect(),
             self.macros.clean(cx),
         );
 
@@ -408,7 +409,7 @@ fn clean(&self, cx: &DocContext) -> Attribute {
 
 impl Clean<Attribute> for ast::Attribute {
     fn clean(&self, cx: &DocContext) -> Attribute {
-        self.desugar_doc().node.value.clean(cx)
+        self.with_desugared_doc(|a| a.node.value.clean(cx))
     }
 }
 
@@ -430,12 +431,12 @@ fn value_str(&self) -> Option<InternedString> {
             _ => None,
         }
     }
-    fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
+    fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
 }
 impl<'a> attr::AttrMetaMethods for &'a Attribute {
     fn name(&self) -> InternedString { (**self).name() }
     fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
-    fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
+    fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
 }
 
 #[deriving(Clone, Encodable, Decodable, PartialEq)]
@@ -538,7 +539,7 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
                  external_path(cx, "Sync", &empty)),
         };
         let fqn = csearch::get_item_path(tcx, did);
-        let fqn = fqn.move_iter().map(|i| i.to_string()).collect();
+        let fqn = fqn.into_iter().map(|i| i.to_string()).collect();
         cx.external_paths.borrow_mut().as_mut().unwrap().insert(did,
                                                                 (fqn, TypeTrait));
         TraitBound(ResolvedPath {
@@ -556,7 +557,7 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
             None => return RegionBound,
         };
         let fqn = csearch::get_item_path(tcx, self.def_id);
-        let fqn = fqn.move_iter().map(|i| i.to_string())
+        let fqn = fqn.into_iter().map(|i| i.to_string())
                      .collect::<Vec<String>>();
         let path = external_path(cx, fqn.last().unwrap().as_slice(),
                                  &self.substs);
@@ -758,10 +759,10 @@ fn clean(&self, cx: &DocContext) -> SelfTy {
         match *self {
             ast::SelfStatic => SelfStatic,
             ast::SelfValue(_) => SelfValue,
-            ast::SelfRegion(lt, mt, _) => {
+            ast::SelfRegion(ref lt, ref mt, _) => {
                 SelfBorrowed(lt.clean(cx), mt.clean(cx))
             }
-            ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean(cx)),
+            ast::SelfExplicit(ref typ, _) => SelfExplicit(typ.clean(cx)),
         }
     }
 }
@@ -842,9 +843,9 @@ impl<'a> Clean<FnDecl> for (ast::DefId, &'a ty::FnSig) {
     fn clean(&self, cx: &DocContext) -> FnDecl {
         let (did, sig) = *self;
         let mut names = if did.node != 0 {
-            csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).move_iter()
+            csearch::get_method_arg_names(&cx.tcx().sess.cstore, did).into_iter()
         } else {
-            Vec::new().move_iter()
+            Vec::new().into_iter()
         }.peekable();
         if names.peek().map(|s| s.as_slice()) == Some("self") {
             let _ = names.next();
@@ -900,7 +901,7 @@ fn clean(&self, _: &DocContext) -> RetStyle {
 
 #[deriving(Clone, Encodable, Decodable)]
 pub struct Trait {
-    pub items: Vec<TraitItem>,
+    pub items: Vec<TraitMethod>,
     pub generics: Generics,
     pub bounds: Vec<TyParamBound>,
 }
@@ -930,12 +931,13 @@ fn clean(&self, cx: &DocContext) -> Type {
 }
 
 #[deriving(Clone, Encodable, Decodable)]
-pub enum TraitItem {
+pub enum TraitMethod {
     RequiredMethod(Item),
     ProvidedMethod(Item),
+    TypeTraitItem(Item),
 }
 
-impl TraitItem {
+impl TraitMethod {
     pub fn is_req(&self) -> bool {
         match self {
             &RequiredMethod(..) => true,
@@ -952,28 +954,32 @@ pub fn item<'a>(&'a self) -> &'a Item {
         match *self {
             RequiredMethod(ref item) => item,
             ProvidedMethod(ref item) => item,
+            TypeTraitItem(ref item) => item,
         }
     }
 }
 
-impl Clean<TraitItem> for ast::TraitItem {
-    fn clean(&self, cx: &DocContext) -> TraitItem {
+impl Clean<TraitMethod> for ast::TraitItem {
+    fn clean(&self, cx: &DocContext) -> TraitMethod {
         match self {
             &ast::RequiredMethod(ref t) => RequiredMethod(t.clean(cx)),
             &ast::ProvidedMethod(ref t) => ProvidedMethod(t.clean(cx)),
+            &ast::TypeTraitItem(ref t) => TypeTraitItem(t.clean(cx)),
         }
     }
 }
 
 #[deriving(Clone, Encodable, Decodable)]
-pub enum ImplItem {
+pub enum ImplMethod {
     MethodImplItem(Item),
+    TypeImplItem(Item),
 }
 
-impl Clean<ImplItem> for ast::ImplItem {
-    fn clean(&self, cx: &DocContext) -> ImplItem {
+impl Clean<ImplMethod> for ast::ImplItem {
+    fn clean(&self, cx: &DocContext) -> ImplMethod {
         match self {
             &ast::MethodImplItem(ref t) => MethodImplItem(t.clean(cx)),
+            &ast::TypeImplItem(ref t) => TypeImplItem(t.clean(cx)),
         }
     }
 }
@@ -1028,6 +1034,7 @@ impl Clean<Item> for ty::ImplOrTraitItem {
     fn clean(&self, cx: &DocContext) -> Item {
         match *self {
             ty::MethodTraitItem(ref mti) => mti.clean(cx),
+            ty::TypeTraitItem(ref tti) => tti.clean(cx),
         }
     }
 }
@@ -1051,7 +1058,7 @@ pub enum Type {
     /// For references to self
     Self(ast::DefId),
     /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
-    Primitive(Primitive),
+    Primitive(PrimitiveType),
     Closure(Box<ClosureDecl>),
     Proc(Box<ClosureDecl>),
     /// extern "ABI" fn
@@ -1073,7 +1080,7 @@ pub enum Type {
 }
 
 #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)]
-pub enum Primitive {
+pub enum PrimitiveType {
     Int, I8, I16, I32, I64,
     Uint, U8, U16, U32, U64,
     F32, F64,
@@ -1094,10 +1101,11 @@ pub enum TypeKind {
     TypeStruct,
     TypeTrait,
     TypeVariant,
+    TypeTypedef,
 }
 
-impl Primitive {
-    fn from_str(s: &str) -> Option<Primitive> {
+impl PrimitiveType {
+    fn from_str(s: &str) -> Option<PrimitiveType> {
         match s.as_slice() {
             "int" => Some(Int),
             "i8" => Some(I8),
@@ -1121,7 +1129,7 @@ fn from_str(s: &str) -> Option<Primitive> {
         }
     }
 
-    fn find(attrs: &[Attribute]) -> Option<Primitive> {
+    fn find(attrs: &[Attribute]) -> Option<PrimitiveType> {
         for attr in attrs.iter() {
             let list = match *attr {
                 List(ref k, ref l) if k.as_slice() == "doc" => l,
@@ -1133,7 +1141,7 @@ fn find(attrs: &[Attribute]) -> Option<Primitive> {
                         if k.as_slice() == "primitive" => v.as_slice(),
                     _ => continue,
                 };
-                match Primitive::from_str(value) {
+                match PrimitiveType::from_str(value) {
                     Some(p) => return Some(p),
                     None => {}
                 }
@@ -1189,11 +1197,11 @@ fn clean(&self, cx: &DocContext) -> Type {
             TyRptr(ref l, ref m) =>
                 BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
                              type_: box m.ty.clean(cx)},
-            TyBox(ty) => Managed(box ty.clean(cx)),
-            TyUniq(ty) => Unique(box ty.clean(cx)),
-            TyVec(ty) => Vector(box ty.clean(cx)),
-            TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(cx),
-                                                       e.span.to_src(cx)),
+            TyBox(ref ty) => Managed(box ty.clean(cx)),
+            TyUniq(ref ty) => Unique(box ty.clean(cx)),
+            TyVec(ref ty) => Vector(box ty.clean(cx)),
+            TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
+                                                           e.span.to_src(cx)),
             TyTup(ref tys) => Tuple(tys.clean(cx)),
             TyPath(ref p, ref tpbs, id) => {
                 resolve_type(cx, p.clean(cx), tpbs.clean(cx), id)
@@ -1274,7 +1282,7 @@ fn clean(&self, cx: &DocContext) -> Type {
             ty::ty_enum(did, ref substs) |
             ty::ty_trait(box ty::TyTrait { def_id: did, ref substs, .. }) => {
                 let fqn = csearch::get_item_path(cx.tcx(), did);
-                let fqn: Vec<String> = fqn.move_iter().map(|i| {
+                let fqn: Vec<String> = fqn.into_iter().map(|i| {
                     i.to_string()
                 }).collect();
                 let kind = match ty::get(*self).sty {
@@ -1739,9 +1747,10 @@ fn clean(&self, cx: &DocContext) -> Item {
                 generics: self.generics.clean(cx),
                 trait_: self.trait_.clean(cx),
                 for_: self.for_.clean(cx),
-                items: self.items.clean(cx).move_iter().map(|ti| {
+                items: self.items.clean(cx).into_iter().map(|ti| {
                         match ti {
                             MethodImplItem(i) => i,
+                            TypeImplItem(i) => i,
                         }
                     }).collect(),
                 derived: detect_derived(self.attrs.as_slice()),
@@ -1789,7 +1798,7 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
                         let remaining = list.iter().filter(|path| {
                             match inline::try_inline(cx, path.node.id(), None) {
                                 Some(items) => {
-                                    ret.extend(items.move_iter()); false
+                                    ret.extend(items.into_iter()); false
                                 }
                                 None => true,
                             }
@@ -1799,12 +1808,12 @@ fn clean(&self, cx: &DocContext) -> Vec<Item> {
                                                          remaining,
                                                          b.clone());
                             let path = syntax::codemap::dummy_spanned(path);
-                            ret.push(convert(&ast::ViewItemUse(box(GC) path)));
+                            ret.push(convert(&ast::ViewItemUse(P(path))));
                         }
                     }
                     ast::ViewPathSimple(ident, _, id) => {
                         match inline::try_inline(cx, id, Some(ident)) {
-                            Some(items) => ret.extend(items.move_iter()),
+                            Some(items) => ret.extend(items.into_iter()),
                             None => ret.push(convert(&self.node)),
                         }
                     }
@@ -1985,8 +1994,8 @@ fn name_from_pat(p: &ast::Pat) -> String {
         },
         PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
                                             .collect::<Vec<String>>().connect(", ")),
-        PatBox(p) => name_from_pat(&*p),
-        PatRegion(p) => name_from_pat(&*p),
+        PatBox(ref p) => name_from_pat(&**p),
+        PatRegion(ref p) => name_from_pat(&**p),
         PatLit(..) => {
             warn!("tried to get argument name from PatLit, \
                   which is silly in function arguments");
@@ -2049,7 +2058,8 @@ fn resolve_type(cx: &DocContext, path: Path,
 fn register_def(cx: &DocContext, def: def::Def) -> ast::DefId {
     let (did, kind) = match def {
         def::DefFn(i, _) => (i, TypeFunction),
-        def::DefTy(i) => (i, TypeEnum),
+        def::DefTy(i, false) => (i, TypeTypedef),
+        def::DefTy(i, true) => (i, TypeEnum),
         def::DefTrait(i) => (i, TypeTrait),
         def::DefStruct(i) => (i, TypeStruct),
         def::DefMod(i) => (i, TypeModule),
@@ -2123,6 +2133,54 @@ fn clean(&self, _: &DocContext) -> Stability {
     }
 }
 
+impl Clean<Item> for ast::AssociatedType {
+    fn clean(&self, cx: &DocContext) -> Item {
+        Item {
+            source: self.span.clean(cx),
+            name: Some(self.ident.clean(cx)),
+            attrs: self.attrs.clean(cx),
+            inner: AssociatedTypeItem,
+            visibility: None,
+            def_id: ast_util::local_def(self.id),
+            stability: None,
+        }
+    }
+}
+
+impl Clean<Item> for ty::AssociatedType {
+    fn clean(&self, cx: &DocContext) -> Item {
+        Item {
+            source: DUMMY_SP.clean(cx),
+            name: Some(self.ident.clean(cx)),
+            attrs: Vec::new(),
+            inner: AssociatedTypeItem,
+            visibility: None,
+            def_id: self.def_id,
+            stability: None,
+        }
+    }
+}
+
+impl Clean<Item> for ast::Typedef {
+    fn clean(&self, cx: &DocContext) -> Item {
+        Item {
+            source: self.span.clean(cx),
+            name: Some(self.ident.clean(cx)),
+            attrs: self.attrs.clean(cx),
+            inner: TypedefItem(Typedef {
+                type_: self.typ.clean(cx),
+                generics: Generics {
+                    lifetimes: Vec::new(),
+                    type_params: Vec::new(),
+                },
+            }),
+            visibility: None,
+            def_id: ast_util::local_def(self.id),
+            stability: None,
+        }
+    }
+}
+
 fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
                t: ty::t, name: &str,
                fallback: fn(Box<Type>) -> Type) -> Type {
@@ -2131,7 +2189,7 @@ fn lang_struct(cx: &DocContext, did: Option<ast::DefId>,
         None => return fallback(box t.clean(cx)),
     };
     let fqn = csearch::get_item_path(cx.tcx(), did);
-    let fqn: Vec<String> = fqn.move_iter().map(|i| {
+    let fqn: Vec<String> = fqn.into_iter().map(|i| {
         i.to_string()
     }).collect();
     cx.external_paths.borrow_mut().as_mut().unwrap().insert(did, (fqn, TypeStruct));