From 2f955c73d635c987ffb6b1d9381ba0ca8f837762 Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Sun, 5 Oct 2014 07:35:04 -0700 Subject: [PATCH 1/4] rustdoc: Correctly name lifetimes in bounds Fix #16518 --- src/librustdoc/clean/inline.rs | 4 +++- src/librustdoc/clean/mod.rs | 25 ++++++++++++++++--------- src/librustdoc/html/format.rs | 14 +++++++++++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index b86f4d8cfb541..d755378366e54 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -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), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2bbd7952776c3..e6e4453c4dac1 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -473,18 +473,20 @@ impl Clean for ty::TypeParameterDef { #[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 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 @@ impl Clean for ast::TyParamBound { impl Clean> for ty::ExistentialBounds { fn clean(&self, cx: &DocContext) -> Vec { - 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 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 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 @@ impl Clean> for ty::ParamBounds { impl Clean>> for subst::Substs { fn clean(&self, cx: &DocContext) -> Option> { 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 @@ impl Lifetime { let s: &'a str = s.as_slice(); return s; } + + pub fn statik() -> Lifetime { + Lifetime("'static".to_string()) + } } impl Clean for ast::Lifetime { @@ -627,7 +634,7 @@ impl Clean for ty::RegionParameterDef { impl Clean> for ty::Region { fn clean(&self, cx: &DocContext) -> Option { 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))), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 417e16102125e..7f5be22f39163 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -140,8 +140,14 @@ impl fmt::Show for clean::Lifetime { 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 @@ impl fmt::Show for clean::Type { 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(": "); From 7be20574e06fdbaffcc6f56b9ee562ce9f81f9b9 Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Sun, 5 Oct 2014 08:09:41 -0700 Subject: [PATCH 2/4] rustdoc: Support unboxed fn sugar in bounds --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/clean/mod.rs | 22 +++++++++++++++++----- src/librustdoc/html/format.rs | 6 +++--- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d755378366e54..4bef672ea0df9 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -324,7 +324,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, trait_: associated_trait.clean(cx).map(|bound| { match bound { clean::TraitBound(ty) => ty, - clean::UnboxedFnBound => unimplemented!(), + clean::UnboxedFnBound(..) | clean::RegionBound(..) | clean::UnknownBound => unreachable!(), } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index e6e4453c4dac1..0b37a21cb0b80 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -474,7 +474,7 @@ impl Clean for ty::TypeParameterDef { #[deriving(Clone, Encodable, Decodable, PartialEq)] pub enum TyParamBound { RegionBound(Lifetime), - UnboxedFnBound, // FIXME + UnboxedFnBound(UnboxedFnType), UnknownBound, TraitBound(Type) } @@ -483,10 +483,7 @@ impl Clean for ast::TyParamBound { fn clean(&self, cx: &DocContext) -> TyParamBound { match *self { ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)), - ast::UnboxedFnTyParamBound(_) => { - // FIXME(pcwalton): Wrong. - UnboxedFnBound - }, + ast::UnboxedFnTyParamBound(ref ty) => { UnboxedFnBound(ty.clean(cx)) }, ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)), } } @@ -598,6 +595,21 @@ impl Clean>> for subst::Substs { } } +#[deriving(Clone, Encodable, Decodable, PartialEq)] +pub struct UnboxedFnType { + pub path: Path, + pub decl: FnDecl +} + +impl Clean for ast::UnboxedFnBound { + fn clean(&self, cx: &DocContext) -> UnboxedFnType { + UnboxedFnType { + path: self.path.clean(cx), + decl: self.decl.clean(cx) + } + } +} + #[deriving(Clone, Encodable, Decodable, PartialEq)] pub struct Lifetime(String); diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 7f5be22f39163..9d77b621d4aa0 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -143,8 +143,8 @@ impl fmt::Show for clean::TyParamBound { clean::RegionBound(ref lt) => { write!(f, "{}", *lt) } - clean::UnboxedFnBound(..) => { - write!(f, "Fn(???)") // FIXME + clean::UnboxedFnBound(ref ty) => { + write!(f, "{}{}", ty.path, ty.decl) } clean::UnknownBound => { write!(f, "'static") @@ -408,7 +408,7 @@ impl fmt::Show for clean::Type { for bound in decl.bounds.iter() { match *bound { clean::RegionBound(..) | - clean::UnboxedFnBound | + clean::UnboxedFnBound(..) | clean::UnknownBound => {} clean::TraitBound(ref t) => { if ret.len() == 0 { From 3bd44752788b7f27b8fbe4a9f436d65ff9dd9de2 Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Mon, 6 Oct 2014 02:22:40 -0700 Subject: [PATCH 3/4] rustdoc: Remove dummy UnknownBound variant --- src/librustdoc/clean/inline.rs | 3 +-- src/librustdoc/clean/mod.rs | 5 ++--- src/librustdoc/html/format.rs | 6 +----- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 4bef672ea0df9..4ef72361701f2 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -325,8 +325,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, match bound { clean::TraitBound(ty) => ty, clean::UnboxedFnBound(..) | - clean::RegionBound(..) | - clean::UnknownBound => unreachable!(), + clean::RegionBound(..) => unreachable!(), } }), for_: ty.ty.clean(cx), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0b37a21cb0b80..0175c95d7cb1f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -475,7 +475,6 @@ impl Clean for ty::TypeParameterDef { pub enum TyParamBound { RegionBound(Lifetime), UnboxedFnBound(UnboxedFnType), - UnknownBound, TraitBound(Type) } @@ -521,7 +520,7 @@ impl Clean for ty::BuiltinBound { fn clean(&self, cx: &DocContext) -> TyParamBound { let tcx = match cx.tcx_opt() { Some(tcx) => tcx, - None => return UnknownBound + None => return RegionBound(Lifetime::statik()) }; let empty = subst::Substs::empty(); let (did, path) = match *self { @@ -554,7 +553,7 @@ impl Clean for ty::TraitRef { fn clean(&self, cx: &DocContext) -> TyParamBound { let tcx = match cx.tcx_opt() { Some(tcx) => tcx, - None => return UnknownBound + None => return RegionBound(Lifetime::statik()) }; let fqn = csearch::get_item_path(tcx, self.def_id); let fqn = fqn.into_iter().map(|i| i.to_string()) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9d77b621d4aa0..6f1feb6e1cd86 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -146,9 +146,6 @@ impl fmt::Show for clean::TyParamBound { clean::UnboxedFnBound(ref ty) => { write!(f, "{}{}", ty.path, ty.decl) } - clean::UnknownBound => { - write!(f, "'static") - } clean::TraitBound(ref ty) => { write!(f, "{}", *ty) } @@ -408,8 +405,7 @@ impl fmt::Show for clean::Type { for bound in decl.bounds.iter() { match *bound { clean::RegionBound(..) | - clean::UnboxedFnBound(..) | - clean::UnknownBound => {} + clean::UnboxedFnBound(..) => {} clean::TraitBound(ref t) => { if ret.len() == 0 { ret.push_str(": "); From 7a6eaea720a7e878f52c03b3298e782e50f1a074 Mon Sep 17 00:00:00 2001 From: Tom Jakubowski Date: Mon, 6 Oct 2014 06:11:21 -0700 Subject: [PATCH 4/4] rustdoc: Include lifetimes in re-exported bounds Fix #17818 --- src/librustdoc/clean/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0175c95d7cb1f..8eab436a3543a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -462,6 +462,7 @@ impl Clean for ty::TypeParameterDef { fn clean(&self, cx: &DocContext) -> TyParam { cx.external_typarams.borrow_mut().as_mut().unwrap() .insert(self.def_id, self.ident.clean(cx)); + TyParam { name: self.ident.clean(cx), did: self.def_id, @@ -581,6 +582,9 @@ impl Clean> for ty::ParamBounds { for t in self.trait_bounds.iter() { v.push(t.clean(cx)); } + for r in self.region_bounds.iter().filter_map(|r| r.clean(cx)) { + v.push(RegionBound(r)); + } return v; } }