From 6948a2df318d1bc2d668d8b29a653f15db1653d8 Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Tue, 23 Dec 2014 01:08:00 -0800 Subject: [PATCH 1/2] Support all variants of WherePredicate Adds support for all variants of ast::WherePredicate in clean/mod.rs. Fixes #20048, but will need modification when EqualityPredicates are fully implemented in #20041. --- src/librustdoc/clean/mod.rs | 23 ++++++++++++++++------- src/librustdoc/html/format.rs | 22 ++++++++++++++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0dd6c2a7ce730..a0e4d0a30a0a4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -683,23 +683,32 @@ impl Clean> for ty::Region { } #[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] -pub struct WherePredicate { - pub ty: Type, - pub bounds: Vec +pub enum WherePredicate { + BoundPredicate { ty: Type, bounds: Vec }, + RegionPredicate { lifetime: Lifetime, bounds: Vec}, + // FIXME (#20041) + EqPredicate } impl Clean for ast::WherePredicate { fn clean(&self, cx: &DocContext) -> WherePredicate { match *self { ast::WherePredicate::BoundPredicate(ref wbp) => { - WherePredicate { + WherePredicate::BoundPredicate { ty: wbp.bounded_ty.clean(cx), bounds: wbp.bounds.clean(cx) } } - // FIXME(#20048) - _ => { - unimplemented!(); + + ast::WherePredicate::RegionPredicate(ref wrp) => { + WherePredicate::RegionPredicate { + lifetime: wrp.lifetime.clean(cx), + bounds: wrp.bounds.clean(cx) + } + } + + ast::WherePredicate::EqPredicate(_) => { + WherePredicate::EqPredicate } } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index a2d5530692c11..9b39b223f8e40 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -128,8 +128,26 @@ impl<'a> fmt::Show for WhereClause<'a> { if i > 0 { try!(f.write(", ".as_bytes())); } - let bounds = pred.bounds.as_slice(); - try!(write!(f, "{}: {}", pred.ty, TyParamBounds(bounds))); + match pred { + &clean::WherePredicate::BoundPredicate {ref ty, ref bounds } => { + let bounds = bounds.as_slice(); + try!(write!(f, "{}: {}", ty, TyParamBounds(bounds))); + }, + &clean::WherePredicate::RegionPredicate { ref lifetime, + ref bounds } => { + try!(write!(f, "{}: ", lifetime)); + for (i, lifetime) in bounds.iter().enumerate() { + if i > 0 { + try!(f.write(" + ".as_bytes())); + } + + try!(write!(f, "{}", lifetime)); + } + }, + &clean::WherePredicate::EqPredicate => { + unimplemented!() + } + } } Ok(()) } From 177529267dd12e698435f84557e27307034e211d Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Wed, 24 Dec 2014 00:58:21 -0800 Subject: [PATCH 2/2] Address code review nits --- src/librustdoc/html/format.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 9b39b223f8e40..5da451237b443 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -129,10 +129,10 @@ impl<'a> fmt::Show for WhereClause<'a> { try!(f.write(", ".as_bytes())); } match pred { - &clean::WherePredicate::BoundPredicate {ref ty, ref bounds } => { + &clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => { let bounds = bounds.as_slice(); try!(write!(f, "{}: {}", ty, TyParamBounds(bounds))); - }, + } &clean::WherePredicate::RegionPredicate { ref lifetime, ref bounds } => { try!(write!(f, "{}: ", lifetime)); @@ -143,7 +143,7 @@ impl<'a> fmt::Show for WhereClause<'a> { try!(write!(f, "{}", lifetime)); } - }, + } &clean::WherePredicate::EqPredicate => { unimplemented!() }