Skip to content

Commit c4640a2

Browse files
committed
Changes to RustDoc
1 parent 4688aad commit c4640a2

File tree

7 files changed

+34
-56
lines changed

7 files changed

+34
-56
lines changed

src/librustdoc/clean/inline.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,12 @@ pub fn build_external_trait(cx: &DocContext, tcx: &ty::ctxt,
163163
}
164164
});
165165
let trait_def = ty::lookup_trait_def(tcx, did);
166-
let (bounds, default_unbound) = trait_def.bounds.clean(cx);
166+
let bounds = trait_def.bounds.clean(cx);
167167
clean::Trait {
168168
unsafety: def.unsafety,
169169
generics: (&def.generics, subst::TypeSpace).clean(cx),
170170
items: items.collect(),
171171
bounds: bounds,
172-
default_unbound: default_unbound
173172
}
174173
}
175174

@@ -328,7 +327,7 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
328327
derived: clean::detect_derived(attrs.as_slice()),
329328
trait_: associated_trait.clean(cx).map(|bound| {
330329
match bound {
331-
clean::TraitBound(polyt) => polyt.trait_,
330+
clean::TraitBound(polyt, _) => polyt.trait_,
332331
clean::RegionBound(..) => unreachable!(),
333332
}
334333
}),

src/librustdoc/clean/mod.rs

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,6 @@ pub struct TyParam {
458458
pub did: ast::DefId,
459459
pub bounds: Vec<TyParamBound>,
460460
pub default: Option<Type>,
461-
/// An optional default bound on the parameter which is unbound, like `Sized?`
462-
pub default_unbound: Option<Type>
463461
}
464462

465463
impl Clean<TyParam> for ast::TyParam {
@@ -469,7 +467,6 @@ impl Clean<TyParam> for ast::TyParam {
469467
did: ast::DefId { krate: ast::LOCAL_CRATE, node: self.id },
470468
bounds: self.bounds.clean(cx),
471469
default: self.default.clean(cx),
472-
default_unbound: self.unbound.clean(cx)
473470
}
474471
}
475472
}
@@ -478,28 +475,27 @@ impl<'tcx> Clean<TyParam> for ty::TypeParameterDef<'tcx> {
478475
fn clean(&self, cx: &DocContext) -> TyParam {
479476
cx.external_typarams.borrow_mut().as_mut().unwrap()
480477
.insert(self.def_id, self.name.clean(cx));
481-
let (bounds, default_unbound) = self.bounds.clean(cx);
478+
let bounds = self.bounds.clean(cx);
482479
TyParam {
483480
name: self.name.clean(cx),
484481
did: self.def_id,
485482
bounds: bounds,
486483
default: self.default.clean(cx),
487-
default_unbound: default_unbound
488484
}
489485
}
490486
}
491487

492488
#[deriving(Clone, RustcEncodable, RustcDecodable, PartialEq)]
493489
pub enum TyParamBound {
494490
RegionBound(Lifetime),
495-
TraitBound(PolyTrait)
491+
TraitBound(PolyTrait, ast::TraitBoundModifier)
496492
}
497493

498494
impl Clean<TyParamBound> for ast::TyParamBound {
499495
fn clean(&self, cx: &DocContext) -> TyParamBound {
500496
match *self {
501497
ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)),
502-
ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)),
498+
ast::TraitTyParamBound(ref t, modifier) => TraitBound(t.clean(cx), modifier),
503499
}
504500
}
505501
}
@@ -600,7 +596,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
600596
did: did,
601597
},
602598
lifetimes: vec![]
603-
})
599+
}, ast::TraitBoundModifier::None)
604600
}
605601
}
606602

@@ -648,37 +644,20 @@ impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
648644
TraitBound(PolyTrait {
649645
trait_: ResolvedPath { path: path, typarams: None, did: self.def_id, },
650646
lifetimes: late_bounds
651-
})
647+
}, ast::TraitBoundModifier::None)
652648
}
653649
}
654650

655-
// Returns (bounds, default_unbound)
656-
impl<'tcx> Clean<(Vec<TyParamBound>, Option<Type>)> for ty::ParamBounds<'tcx> {
657-
fn clean(&self, cx: &DocContext) -> (Vec<TyParamBound>, Option<Type>) {
651+
impl<'tcx> Clean<Vec<TyParamBound>> for ty::ParamBounds<'tcx> {
652+
fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
658653
let mut v = Vec::new();
659-
let mut has_sized_bound = false;
660-
for b in self.builtin_bounds.iter() {
661-
if b != ty::BoundSized {
662-
v.push(b.clean(cx));
663-
} else {
664-
has_sized_bound = true;
665-
}
666-
}
667654
for t in self.trait_bounds.iter() {
668655
v.push(t.clean(cx));
669656
}
670657
for r in self.region_bounds.iter().filter_map(|r| r.clean(cx)) {
671658
v.push(RegionBound(r));
672659
}
673-
if has_sized_bound {
674-
(v, None)
675-
} else {
676-
let ty = match ty::BoundSized.clean(cx) {
677-
TraitBound(polyt) => polyt.trait_,
678-
_ => unreachable!()
679-
};
680-
(v, Some(ty))
681-
}
660+
v
682661
}
683662
}
684663

@@ -689,7 +668,7 @@ impl<'tcx> Clean<Option<Vec<TyParamBound>>> for subst::Substs<'tcx> {
689668
v.extend(self.types.iter().map(|t| TraitBound(PolyTrait {
690669
trait_: t.clean(cx),
691670
lifetimes: vec![]
692-
})));
671+
}, ast::TraitBoundModifier::None)));
693672
if v.len() > 0 {Some(v)} else {None}
694673
}
695674
}
@@ -1047,8 +1026,6 @@ pub struct Trait {
10471026
pub items: Vec<TraitMethod>,
10481027
pub generics: Generics,
10491028
pub bounds: Vec<TyParamBound>,
1050-
/// An optional default bound not required for `Self`, like `Sized?`
1051-
pub default_unbound: Option<Type>
10521029
}
10531030

10541031
impl Clean<Item> for doctree::Trait {
@@ -1065,7 +1042,6 @@ impl Clean<Item> for doctree::Trait {
10651042
items: self.items.clean(cx),
10661043
generics: self.generics.clean(cx),
10671044
bounds: self.bounds.clean(cx),
1068-
default_unbound: self.default_unbound.clean(cx)
10691045
}),
10701046
}
10711047
}
@@ -2412,7 +2388,6 @@ impl Clean<Item> for ty::AssociatedType {
24122388
},
24132389
bounds: vec![],
24142390
default: None,
2415-
default_unbound: None
24162391
}),
24172392
visibility: None,
24182393
def_id: self.def_id,

src/librustdoc/doctree.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ pub struct Trait {
178178
pub whence: Span,
179179
pub vis: ast::Visibility,
180180
pub stab: Option<attr::Stability>,
181-
pub default_unbound: Option<ast::TraitRef> // FIXME(tomjakubowski)
182181
}
183182

184183
pub struct Impl {

src/librustdoc/html/format.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ impl fmt::Show for clean::Generics {
9797
if i > 0 {
9898
try!(f.write(", ".as_bytes()))
9999
}
100-
if let Some(ref unbound) = tp.default_unbound {
101-
try!(write!(f, "{}? ", unbound));
102-
};
103100
try!(f.write(tp.name.as_bytes()));
104101

105102
if tp.bounds.len() > 0 {
@@ -182,8 +179,12 @@ impl fmt::Show for clean::TyParamBound {
182179
clean::RegionBound(ref lt) => {
183180
write!(f, "{}", *lt)
184181
}
185-
clean::TraitBound(ref ty) => {
186-
write!(f, "{}", *ty)
182+
clean::TraitBound(ref ty, modifier) => {
183+
let modifier_str = match modifier {
184+
ast::TraitBoundModifier::None => "",
185+
ast::TraitBoundModifier::Maybe => "?",
186+
};
187+
write!(f, "{}{}", modifier_str, *ty)
187188
}
188189
}
189190
}
@@ -458,12 +459,15 @@ impl fmt::Show for clean::Type {
458459
for bound in decl.bounds.iter() {
459460
match *bound {
460461
clean::RegionBound(..) => {}
461-
clean::TraitBound(ref t) => {
462+
clean::TraitBound(ref t, modifier) => {
462463
if ret.len() == 0 {
463464
ret.push_str(": ");
464465
} else {
465466
ret.push_str(" + ");
466467
}
468+
if modifier == ast::TraitBoundModifier::Maybe {
469+
ret.push_str("?");
470+
}
467471
ret.push_str(format!("{}",
468472
*t).as_slice());
469473
}

src/librustdoc/html/render.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,9 +1679,6 @@ fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
16791679
fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
16801680
t: &clean::Trait) -> fmt::Result {
16811681
let mut bounds = String::new();
1682-
if let Some(ref ty) = t.default_unbound {
1683-
bounds.push_str(format!(" for {}?", ty).as_slice());
1684-
}
16851682
if t.bounds.len() > 0 {
16861683
if bounds.len() > 0 {
16871684
bounds.push(' ');

src/librustdoc/visit_ast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
322322
};
323323
om.constants.push(s);
324324
},
325-
ast::ItemTrait(unsafety, ref gen, ref def_ub, ref b, ref items) => {
325+
ast::ItemTrait(unsafety, ref gen, ref b, ref items) => {
326326
let t = Trait {
327327
unsafety: unsafety,
328328
name: name,
@@ -334,7 +334,6 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
334334
whence: item.span,
335335
vis: item.vis,
336336
stab: self.stability(item.id),
337-
default_unbound: def_ub.clone()
338337
};
339338
om.traits.push(t);
340339
},

src/libsyntax/print/pprust.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -965,13 +965,18 @@ impl<'a> State<'a> {
965965
try!(self.word_nbsp("trait"));
966966
try!(self.print_ident(item.ident));
967967
try!(self.print_generics(generics));
968-
// TODO find and print the unbound, remove it from bounds
969-
/*if let &Some(ref tref) = unbound {
970-
try!(space(&mut self.s));
971-
try!(self.word_space("for ?"));
972-
try!(self.print_trait_ref(tref));
973-
}*/
974-
try!(self.print_bounds(":", bounds[]));
968+
let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect();
969+
let mut real_bounds = Vec::with_capacity(bounds.len());
970+
for b in bounds.into_iter() {
971+
if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b {
972+
try!(space(&mut self.s));
973+
try!(self.word_space("for ?"));
974+
try!(self.print_trait_ref(&ptr.trait_ref));
975+
} else {
976+
real_bounds.push(b);
977+
}
978+
}
979+
try!(self.print_bounds(":", real_bounds[]));
975980
try!(self.print_where_clause(generics));
976981
try!(word(&mut self.s, " "));
977982
try!(self.bopen());

0 commit comments

Comments
 (0)