about summary refs log tree commit diff
path: root/src/librustdoc
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2014-08-27 21:46:52 -0400
committerNiko Matsakis <niko@alum.mit.edu>2014-08-27 21:46:52 -0400
commit1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f (patch)
tree552fabade603ab0d148a49ae3cf1abd3f399740a /src/librustdoc
parent3ee047ae1ffab454270bc1859b3beef3556ef8f9 (diff)
downloadrust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.tar.gz
rust-1b487a890695e7d6dfbfe5dcd7d4fa0e8ca8003f.zip
Implement generalized object and type parameter bounds (Fixes #16462)
Diffstat (limited to 'src/librustdoc')
-rw-r--r--src/librustdoc/clean/inline.rs12
-rw-r--r--src/librustdoc/clean/mod.rs33
-rw-r--r--src/librustdoc/doctree.rs2
-rw-r--r--src/librustdoc/html/format.rs9
-rw-r--r--src/librustdoc/html/render.rs14
-rw-r--r--src/librustdoc/visit_ast.rs4
6 files changed, 33 insertions, 41 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 445672fcdc4..ee1b51683c2 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -159,18 +159,12 @@ pub fn build_external_trait(tcx: &ty::ctxt, did: ast::DefId) -> clean::Trait {
             clean::RequiredMethod(trait_item)
         }
     });
-    let supertraits = ty::trait_supertraits(tcx, did);
-    let mut parents = supertraits.iter().map(|i| {
-        match i.clean() {
-            clean::TraitBound(ty) => ty,
-            clean::RegionBound => unreachable!()
-        }
-    });
-
+    let trait_def = ty::lookup_trait_def(tcx, did);
+    let bounds = trait_def.bounds.clean();
     clean::Trait {
         generics: (&def.generics, subst::TypeSpace).clean(),
         items: items.collect(),
-        parents: parents.collect()
+        bounds: bounds,
     }
 }
 
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index dc2c0d1d083..af4df81f996 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -481,15 +481,14 @@ impl Clean<TyParam> for ty::TypeParameterDef {
 
 #[deriving(Clone, Encodable, Decodable, PartialEq)]
 pub enum TyParamBound {
-    RegionBound,
+    RegionBound, // FIXME(#16518) -- need to include name of actual region
     TraitBound(Type)
 }
 
 impl Clean<TyParamBound> for ast::TyParamBound {
     fn clean(&self) -> TyParamBound {
         match *self {
-            ast::StaticRegionTyParamBound => RegionBound,
-            ast::OtherRegionTyParamBound(_) => RegionBound,
+            ast::RegionTyParamBound(_) => RegionBound,
             ast::UnboxedFnTyParamBound(_) => {
                 // FIXME(pcwalton): Wrong.
                 RegionBound
@@ -499,6 +498,16 @@ impl Clean<TyParamBound> for ast::TyParamBound {
     }
 }
 
+impl Clean<Vec<TyParamBound>> for ty::ExistentialBounds {
+    fn clean(&self) -> Vec<TyParamBound> {
+        let mut vec = vec!(RegionBound);
+        for bb in self.builtin_bounds.iter() {
+            vec.push(bb.clean());
+        }
+        vec
+    }
+}
+
 fn external_path(name: &str, substs: &subst::Substs) -> Path {
     let lifetimes = substs.regions().get_slice(subst::TypeSpace)
                     .iter()
@@ -525,7 +534,6 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
         };
         let empty = subst::Substs::empty();
         let (did, path) = match *self {
-            ty::BoundStatic => return RegionBound,
             ty::BoundSend =>
                 (tcx.lang_items.send_trait().unwrap(),
                  external_path("Send", &empty)),
@@ -810,10 +818,7 @@ impl Clean<ClosureDecl> for ast::ClosureTy {
             decl: self.decl.clean(),
             onceness: self.onceness,
             fn_style: self.fn_style,
-            bounds: match self.bounds {
-                Some(ref x) => x.clean(),
-                None        => Vec::new()
-            },
+            bounds: self.bounds.clean()
         }
     }
 }
@@ -909,7 +914,7 @@ impl Clean<RetStyle> for ast::RetStyle {
 pub struct Trait {
     pub items: Vec<TraitItem>,
     pub generics: Generics,
-    pub parents: Vec<Type>,
+    pub bounds: Vec<TyParamBound>,
 }
 
 impl Clean<Item> for doctree::Trait {
@@ -924,7 +929,7 @@ impl Clean<Item> for doctree::Trait {
             inner: TraitItem(Trait {
                 items: self.items.clean(),
                 generics: self.generics.clean(),
-                parents: self.parents.clean(),
+                bounds: self.bounds.clean(),
             }),
         }
     }
@@ -1060,7 +1065,7 @@ pub enum Type {
     Self(ast::DefId),
     /// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
     Primitive(Primitive),
-    Closure(Box<ClosureDecl>, Option<Lifetime>),
+    Closure(Box<ClosureDecl>),
     Proc(Box<ClosureDecl>),
     /// extern "ABI" fn
     BareFunction(Box<BareFunctionDecl>),
@@ -1208,7 +1213,7 @@ impl Clean<Type> for ast::Ty {
                              tpbs.clean().map(|x| x),
                              id)
             }
-            TyClosure(ref c, region) => Closure(box c.clean(), region.clean()),
+            TyClosure(ref c) => Closure(box c.clean()),
             TyProc(ref c) => Proc(box c.clean()),
             TyBareFn(ref barefn) => BareFunction(box barefn.clean()),
             TyParen(ref ty) => ty.clean(),
@@ -1273,11 +1278,11 @@ impl Clean<Type> for ty::t {
                     decl: (ast_util::local_def(0), &fty.sig).clean(),
                     onceness: fty.onceness,
                     fn_style: fty.fn_style,
-                    bounds: fty.bounds.iter().map(|i| i.clean()).collect(),
+                    bounds: fty.bounds.clean(),
                 };
                 match fty.store {
                     ty::UniqTraitStore => Proc(decl),
-                    ty::RegionTraitStore(ref r, _) => Closure(decl, r.clean()),
+                    ty::RegionTraitStore(..) => Closure(decl),
                 }
             }
             ty::ty_struct(did, ref substs) |
diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs
index da45321e7fd..4d2cf852b8a 100644
--- a/src/librustdoc/doctree.rs
+++ b/src/librustdoc/doctree.rs
@@ -156,7 +156,7 @@ pub struct Trait {
     pub name: Ident,
     pub items: Vec<ast::TraitItem>, //should be TraitItem
     pub generics: ast::Generics,
-    pub parents: Vec<ast::TraitRef>,
+    pub bounds: Vec<ast::TyParamBound>,
     pub attrs: Vec<ast::Attribute>,
     pub id: ast::NodeId,
     pub whence: Span,
diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs
index 37349388588..e526286ef46 100644
--- a/src/librustdoc/html/format.rs
+++ b/src/librustdoc/html/format.rs
@@ -355,7 +355,7 @@ impl fmt::Show for clean::Type {
             }
             clean::Self(..) => f.write("Self".as_bytes()),
             clean::Primitive(prim) => primitive_link(f, prim, prim.to_string()),
-            clean::Closure(ref decl, ref region) => {
+            clean::Closure(ref decl) => {
                 write!(f, "{style}{lifetimes}|{args}|{bounds}{arrow}",
                        style = FnStyleSpace(decl.fn_style),
                        lifetimes = if decl.lifetimes.len() == 0 {
@@ -370,13 +370,6 @@ impl fmt::Show for clean::Type {
                        },
                        bounds = {
                            let mut ret = String::new();
-                           match *region {
-                               Some(ref lt) => {
-                                   ret.push_str(format!(": {}",
-                                                        *lt).as_slice());
-                               }
-                               None => {}
-                           }
                            for bound in decl.bounds.iter() {
                                 match *bound {
                                     clean::RegionBound => {}
diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs
index 6415ee85f57..8342b6bd675 100644
--- a/src/librustdoc/html/render.rs
+++ b/src/librustdoc/html/render.rs
@@ -1610,12 +1610,12 @@ fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
 
 fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
               t: &clean::Trait) -> fmt::Result {
-    let mut parents = String::new();
-    if t.parents.len() > 0 {
-        parents.push_str(": ");
-        for (i, p) in t.parents.iter().enumerate() {
-            if i > 0 { parents.push_str(" + "); }
-            parents.push_str(format!("{}", *p).as_slice());
+    let mut bounds = String::new();
+    if t.bounds.len() > 0 {
+        bounds.push_str(": ");
+        for (i, p) in t.bounds.iter().enumerate() {
+            if i > 0 { bounds.push_str(" + "); }
+            bounds.push_str(format!("{}", *p).as_slice());
         }
     }
 
@@ -1624,7 +1624,7 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
                   VisSpace(it.visibility),
                   it.name.get_ref().as_slice(),
                   t.generics,
-                  parents));
+                  bounds));
     let required = t.items.iter()
                           .filter(|m| {
                               match **m {
diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs
index b67b3c394d6..1706ebfbcf4 100644
--- a/src/librustdoc/visit_ast.rs
+++ b/src/librustdoc/visit_ast.rs
@@ -317,12 +317,12 @@ impl<'a> RustdocVisitor<'a> {
                 };
                 om.statics.push(s);
             },
-            ast::ItemTrait(ref gen, _, ref tr, ref items) => {
+            ast::ItemTrait(ref gen, _, ref b, ref items) => {
                 let t = Trait {
                     name: item.ident,
                     items: items.iter().map(|x| (*x).clone()).collect(),
                     generics: gen.clone(),
-                    parents: tr.iter().map(|x| (*x).clone()).collect(),
+                    bounds: b.iter().map(|x| (*x).clone()).collect(),
                     id: item.id,
                     attrs: item.attrs.iter().map(|x| *x).collect(),
                     whence: item.span,