]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Correctly name lifetimes in bounds
authorTom Jakubowski <tom@crystae.net>
Sun, 5 Oct 2014 14:35:04 +0000 (07:35 -0700)
committerTom Jakubowski <tom@crystae.net>
Mon, 6 Oct 2014 09:23:53 +0000 (02:23 -0700)
Fix #16518

src/librustdoc/clean/inline.rs
src/librustdoc/clean/mod.rs
src/librustdoc/html/format.rs

index b86f4d8cfb54195d0771814bb438afd8497dc596..d755378366e540cade8f400fc3222c9f438c2455 100644 (file)
@@ -324,7 +324,9 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
             trait_: associated_trait.clean(cx).map(|bound| {
                 match bound {
                     clean::TraitBound(ty) => ty,
-                    clean::RegionBound => unreachable!(),
+                    clean::UnboxedFnBound => unimplemented!(),
+                    clean::RegionBound(..) |
+                    clean::UnknownBound => unreachable!(),
                 }
             }),
             for_: ty.ty.clean(cx),
index 2bbd7952776c3c69c4f0bb45c715da9a4aac054d..e6e4453c4dac176a3e333c44768622e71062cd3a 100644 (file)
@@ -473,18 +473,20 @@ fn clean(&self, cx: &DocContext) -> TyParam {
 
 #[deriving(Clone, Encodable, Decodable, PartialEq)]
 pub enum TyParamBound {
-    RegionBound, // FIXME(#16518) -- need to include name of actual region
+    RegionBound(Lifetime),
+    UnboxedFnBound, // FIXME
+    UnknownBound,
     TraitBound(Type)
 }
 
 impl Clean<TyParamBound> for ast::TyParamBound {
     fn clean(&self, cx: &DocContext) -> TyParamBound {
         match *self {
-            ast::RegionTyParamBound(_) => RegionBound,
+            ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)),
             ast::UnboxedFnTyParamBound(_) => {
                 // FIXME(pcwalton): Wrong.
-                RegionBound
-            }
+                UnboxedFnBound
+            },
             ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)),
         }
     }
@@ -492,7 +494,8 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
 
 impl Clean<Vec<TyParamBound>> for ty::ExistentialBounds {
     fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
-        let mut vec = vec!(RegionBound);
+        let mut vec = vec![];
+        self.region_bound.clean(cx).map(|b| vec.push(RegionBound(b)));
         for bb in self.builtin_bounds.iter() {
             vec.push(bb.clean(cx));
         }
@@ -521,7 +524,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
     fn clean(&self, cx: &DocContext) -> TyParamBound {
         let tcx = match cx.tcx_opt() {
             Some(tcx) => tcx,
-            None => return RegionBound,
+            None => return UnknownBound
         };
         let empty = subst::Substs::empty();
         let (did, path) = match *self {
@@ -554,7 +557,7 @@ impl Clean<TyParamBound> for ty::TraitRef {
     fn clean(&self, cx: &DocContext) -> TyParamBound {
         let tcx = match cx.tcx_opt() {
             Some(tcx) => tcx,
-            None => return RegionBound,
+            None => return UnknownBound
         };
         let fqn = csearch::get_item_path(tcx, self.def_id);
         let fqn = fqn.into_iter().map(|i| i.to_string())
@@ -589,7 +592,7 @@ fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
 impl Clean<Option<Vec<TyParamBound>>> for subst::Substs {
     fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
         let mut v = Vec::new();
-        v.extend(self.regions().iter().map(|_| RegionBound));
+        v.extend(self.regions().iter().filter_map(|r| r.clean(cx)).map(RegionBound));
         v.extend(self.types.iter().map(|t| TraitBound(t.clean(cx))));
         if v.len() > 0 {Some(v)} else {None}
     }
@@ -604,6 +607,10 @@ pub fn get_ref<'a>(&'a self) -> &'a str {
         let s: &'a str = s.as_slice();
         return s;
     }
+
+    pub fn statik() -> Lifetime {
+        Lifetime("'static".to_string())
+    }
 }
 
 impl Clean<Lifetime> for ast::Lifetime {
@@ -627,7 +634,7 @@ fn clean(&self, _: &DocContext) -> Lifetime {
 impl Clean<Option<Lifetime>> for ty::Region {
     fn clean(&self, cx: &DocContext) -> Option<Lifetime> {
         match *self {
-            ty::ReStatic => Some(Lifetime("'static".to_string())),
+            ty::ReStatic => Some(Lifetime::statik()),
             ty::ReLateBound(_, ty::BrNamed(_, name)) =>
                 Some(Lifetime(token::get_name(name).get().to_string())),
             ty::ReEarlyBound(_, _, _, name) => Some(Lifetime(name.clean(cx))),
index 417e16102125e43bee2d2a0637eb5870fce73d62..7f5be22f391633b7500e1044107bbd5132a46868 100644 (file)
@@ -140,8 +140,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 impl fmt::Show for clean::TyParamBound {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match *self {
-            clean::RegionBound => {
-                f.write("'static".as_bytes())
+            clean::RegionBound(ref lt) => {
+                write!(f, "{}", *lt)
+            }
+            clean::UnboxedFnBound(..) => {
+                write!(f, "Fn(???)") // FIXME
+            }
+            clean::UnknownBound => {
+                write!(f, "'static")
             }
             clean::TraitBound(ref ty) => {
                 write!(f, "{}", *ty)
@@ -401,7 +407,9 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
                            let mut ret = String::new();
                            for bound in decl.bounds.iter() {
                                 match *bound {
-                                    clean::RegionBound => {}
+                                    clean::RegionBound(..) |
+                                    clean::UnboxedFnBound |
+                                    clean::UnknownBound => {}
                                     clean::TraitBound(ref t) => {
                                         if ret.len() == 0 {
                                             ret.push_str(": ");