diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index cdc51bb801c5..3eda39f54a99 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -163,13 +163,12 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt, } }); let trait_def = ty::lookup_trait_def(tcx, did); - let (bounds, default_unbound) = trait_def.bounds.clean(cx); + let bounds = trait_def.bounds.clean(cx); clean::Trait { unsafety: def.unsafety, generics: (&def.generics, subst::TypeSpace).clean(cx), items: items.collect(), bounds: bounds, - default_unbound: default_unbound } } @@ -328,7 +327,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt, derived: clean::detect_derived(attrs.as_slice()), trait_: associated_trait.clean(cx).map(|bound| { match bound { - clean::TraitBound(polyt) => polyt.trait_, + clean::TraitBound(polyt, _) => polyt.trait_, clean::RegionBound(..) => unreachable!(), } }), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2e0affe827b7..a39764f3c55f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -458,8 +458,6 @@ pub struct TyParam { pub did: ast::DefId, pub bounds: Vec, pub default: Option, - /// An optional default bound on the parameter which is unbound, like `Sized?` - pub default_unbound: Option } impl Clean for ast::TyParam { @@ -469,7 +467,6 @@ impl Clean for ast::TyParam { did: ast::DefId { krate: ast::LOCAL_CRATE, node: self.id }, bounds: self.bounds.clean(cx), default: self.default.clean(cx), - default_unbound: self.unbound.clean(cx) } } } @@ -478,13 +475,12 @@ impl<'tcx> Clean for ty::TypeParameterDef<'tcx> { fn clean(&self, cx: &DocContext) -> TyParam { cx.external_typarams.borrow_mut().as_mut().unwrap() .insert(self.def_id, self.name.clean(cx)); - let (bounds, default_unbound) = self.bounds.clean(cx); + let bounds = self.bounds.clean(cx); TyParam { name: self.name.clean(cx), did: self.def_id, bounds: bounds, default: self.default.clean(cx), - default_unbound: default_unbound } } } @@ -492,14 +488,14 @@ impl<'tcx> Clean for ty::TypeParameterDef<'tcx> { #[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)] pub enum TyParamBound { RegionBound(Lifetime), - TraitBound(PolyTrait) + TraitBound(PolyTrait, ast::TraitBoundModifier) } impl Clean for ast::TyParamBound { fn clean(&self, cx: &DocContext) -> TyParamBound { match *self { ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)), - ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)), + ast::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier), } } } @@ -600,7 +596,7 @@ impl Clean for ty::BuiltinBound { did: did, }, lifetimes: vec![] - }) + }, ast::TraitBoundModifier::None) } } @@ -648,37 +644,20 @@ impl<'tcx> Clean for ty::TraitRef<'tcx> { TraitBound(PolyTrait { trait_: ResolvedPath { path: path, typarams: None, did: self.def_id, }, lifetimes: late_bounds - }) + }, ast::TraitBoundModifier::None) } } -// Returns (bounds, default_unbound) -impl<'tcx> Clean<(Vec, Option)> for ty::ParamBounds<'tcx> { - fn clean(&self, cx: &DocContext) -> (Vec, Option) { +impl<'tcx> Clean> for ty::ParamBounds<'tcx> { + fn clean(&self, cx: &DocContext) -> Vec { let mut v = Vec::new(); - let mut has_sized_bound = false; - for b in self.builtin_bounds.iter() { - if b != ty::BoundSized { - v.push(b.clean(cx)); - } else { - has_sized_bound = true; - } - } 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)); } - if has_sized_bound { - (v, None) - } else { - let ty = match ty::BoundSized.clean(cx) { - TraitBound(polyt) => polyt.trait_, - _ => unreachable!() - }; - (v, Some(ty)) - } + v } } @@ -689,7 +668,7 @@ impl<'tcx> Clean>> for subst::Substs<'tcx> { v.extend(self.types.iter().map(|t| TraitBound(PolyTrait { trait_: t.clean(cx), lifetimes: vec![] - }))); + }, ast::TraitBoundModifier::None))); if v.len() > 0 {Some(v)} else {None} } } @@ -1047,8 +1026,6 @@ pub struct Trait { pub items: Vec, pub generics: Generics, pub bounds: Vec, - /// An optional default bound not required for `Self`, like `Sized?` - pub default_unbound: Option } impl Clean for doctree::Trait { @@ -1065,7 +1042,6 @@ impl Clean for doctree::Trait { items: self.items.clean(cx), generics: self.generics.clean(cx), bounds: self.bounds.clean(cx), - default_unbound: self.default_unbound.clean(cx) }), } } @@ -2412,7 +2388,6 @@ impl Clean for ty::AssociatedType { }, bounds: vec![], default: None, - default_unbound: None }), visibility: None, def_id: self.def_id, diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 7f7c055062aa..251ce5aefeb7 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -178,7 +178,6 @@ pub struct Trait { pub whence: Span, pub vis: ast::Visibility, pub stab: Option, - pub default_unbound: Option // FIXME(tomjakubowski) } pub struct Impl { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 25c4f4e01b62..f20a74f937b7 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -97,9 +97,6 @@ impl fmt::Show for clean::Generics { if i > 0 { try!(f.write(", ".as_bytes())) } - if let Some(ref unbound) = tp.default_unbound { - try!(write!(f, "{}? ", unbound)); - }; try!(f.write(tp.name.as_bytes())); if tp.bounds.len() > 0 { @@ -182,8 +179,12 @@ impl fmt::Show for clean::TyParamBound { clean::RegionBound(ref lt) => { write!(f, "{}", *lt) } - clean::TraitBound(ref ty) => { - write!(f, "{}", *ty) + clean::TraitBound(ref ty, modifier) => { + let modifier_str = match modifier { + ast::TraitBoundModifier::None => "", + ast::TraitBoundModifier::Maybe => "?", + }; + write!(f, "{}{}", modifier_str, *ty) } } } @@ -458,12 +459,15 @@ impl fmt::Show for clean::Type { for bound in decl.bounds.iter() { match *bound { clean::RegionBound(..) => {} - clean::TraitBound(ref t) => { + clean::TraitBound(ref t, modifier) => { if ret.len() == 0 { ret.push_str(": "); } else { ret.push_str(" + "); } + if modifier == ast::TraitBoundModifier::Maybe { + ret.push_str("?"); + } ret.push_str(format!("{}", *t).as_slice()); } diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 304dbe201e8f..bfb03cb2589c 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1679,9 +1679,6 @@ 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 bounds = String::new(); - if let Some(ref ty) = t.default_unbound { - bounds.push_str(format!(" for {}?", ty).as_slice()); - } if t.bounds.len() > 0 { if bounds.len() > 0 { bounds.push(' '); diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 4374ce5deef4..e71711aa8d6e 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -322,7 +322,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.constants.push(s); }, - ast::ItemTrait(unsafety, ref gen, ref def_ub, ref b, ref items) => { + ast::ItemTrait(unsafety, ref gen, ref b, ref items) => { let t = Trait { unsafety: unsafety, name: name, @@ -334,7 +334,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { whence: item.span, vis: item.vis, stab: self.stability(item.id), - default_unbound: def_ub.clone() }; om.traits.push(t); }, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7713a0f23d1b..1d3dc42cf08c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -965,13 +965,18 @@ impl<'a> State<'a> { try!(self.word_nbsp("trait")); try!(self.print_ident(item.ident)); try!(self.print_generics(generics)); - // TODO find and print the unbound, remove it from bounds - /*if let &Some(ref tref) = unbound { - try!(space(&mut self.s)); - try!(self.word_space("for ?")); - try!(self.print_trait_ref(tref)); - }*/ - try!(self.print_bounds(":", bounds[])); + let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect(); + let mut real_bounds = Vec::with_capacity(bounds.len()); + for b in bounds.into_iter() { + if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b { + try!(space(&mut self.s)); + try!(self.word_space("for ?")); + try!(self.print_trait_ref(&ptr.trait_ref)); + } else { + real_bounds.push(b); + } + } + try!(self.print_bounds(":", real_bounds[])); try!(self.print_where_clause(generics)); try!(word(&mut self.s, " ")); try!(self.bopen());