diff options
| author | bors <bors@rust-lang.org> | 2014-10-06 16:47:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-06 16:47:13 +0000 |
| commit | 3a38797f495e30dec8117aa33032bbc7b6e5f17b (patch) | |
| tree | 1edf99997972328e0a5d119622cbd439980434bf | |
| parent | 3edcdbb0c01187a0cc6456ca29cd858579459b18 (diff) | |
| parent | 7a6eaea720a7e878f52c03b3298e782e50f1a074 (diff) | |
| download | rust-3a38797f495e30dec8117aa33032bbc7b6e5f17b.tar.gz rust-3a38797f495e30dec8117aa33032bbc7b6e5f17b.zip | |
auto merge of #17798 : tomjakubowski/rust/rustdoc-fix-bounds, r=alexcrichton
This PR adds support in rustdoc for properly naming lifetimes in bounds, instead of just showing `'static` for everything. It also adds support for unboxed function sugar bounds, which were also previously rendered as `'static`.
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 3 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 44 | ||||
| -rw-r--r-- | src/librustdoc/html/format.rs | 10 |
3 files changed, 42 insertions, 15 deletions
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index b86f4d8cfb5..4ef72361701 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -324,7 +324,8 @@ 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(..) | + clean::RegionBound(..) => unreachable!(), } }), for_: ty.ty.clean(cx), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2bbd7952776..8eab436a354 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -462,6 +462,7 @@ impl Clean<TyParam> 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, @@ -473,18 +474,16 @@ impl Clean<TyParam> for ty::TypeParameterDef { #[deriving(Clone, Encodable, Decodable, PartialEq)] pub enum TyParamBound { - RegionBound, // FIXME(#16518) -- need to include name of actual region + RegionBound(Lifetime), + UnboxedFnBound(UnboxedFnType), TraitBound(Type) } impl Clean<TyParamBound> for ast::TyParamBound { fn clean(&self, cx: &DocContext) -> TyParamBound { match *self { - ast::RegionTyParamBound(_) => RegionBound, - ast::UnboxedFnTyParamBound(_) => { - // FIXME(pcwalton): Wrong. - RegionBound - } + ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)), + ast::UnboxedFnTyParamBound(ref ty) => { UnboxedFnBound(ty.clean(cx)) }, ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)), } } @@ -492,7 +491,8 @@ impl Clean<TyParamBound> for ast::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 +521,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 RegionBound(Lifetime::statik()) }; let empty = subst::Substs::empty(); let (did, path) = match *self { @@ -554,7 +554,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 RegionBound(Lifetime::statik()) }; let fqn = csearch::get_item_path(tcx, self.def_id); let fqn = fqn.into_iter().map(|i| i.to_string()) @@ -582,6 +582,9 @@ impl Clean<Vec<TyParamBound>> 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; } } @@ -589,13 +592,28 @@ impl Clean<Vec<TyParamBound>> for ty::ParamBounds { 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} } } #[deriving(Clone, Encodable, Decodable, PartialEq)] +pub struct UnboxedFnType { + pub path: Path, + pub decl: FnDecl +} + +impl Clean<UnboxedFnType> 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); impl Lifetime { @@ -604,6 +622,10 @@ impl Lifetime { 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 +649,7 @@ impl Clean<Lifetime> for ty::RegionParameterDef { 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))), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 417e1610212..6f1feb6e1cd 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -140,8 +140,11 @@ 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(ref ty) => { + write!(f, "{}{}", ty.path, ty.decl) } clean::TraitBound(ref ty) => { write!(f, "{}", *ty) @@ -401,7 +404,8 @@ 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::TraitBound(ref t) => { if ret.len() == 0 { ret.push_str(": "); |
