Skip to content

Commit 2f955c7

Browse files
committed
rustdoc: Correctly name lifetimes in bounds
Fix #16518
1 parent dfbe9eb commit 2f955c7

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/librustdoc/clean/inline.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ fn build_impl(cx: &DocContext, tcx: &ty::ctxt,
324324
trait_: associated_trait.clean(cx).map(|bound| {
325325
match bound {
326326
clean::TraitBound(ty) => ty,
327-
clean::RegionBound => unreachable!(),
327+
clean::UnboxedFnBound => unimplemented!(),
328+
clean::RegionBound(..) |
329+
clean::UnknownBound => unreachable!(),
328330
}
329331
}),
330332
for_: ty.ty.clean(cx),

src/librustdoc/clean/mod.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -473,26 +473,29 @@ impl Clean<TyParam> for ty::TypeParameterDef {
473473

474474
#[deriving(Clone, Encodable, Decodable, PartialEq)]
475475
pub enum TyParamBound {
476-
RegionBound, // FIXME(#16518) -- need to include name of actual region
476+
RegionBound(Lifetime),
477+
UnboxedFnBound, // FIXME
478+
UnknownBound,
477479
TraitBound(Type)
478480
}
479481

480482
impl Clean<TyParamBound> for ast::TyParamBound {
481483
fn clean(&self, cx: &DocContext) -> TyParamBound {
482484
match *self {
483-
ast::RegionTyParamBound(_) => RegionBound,
485+
ast::RegionTyParamBound(lt) => RegionBound(lt.clean(cx)),
484486
ast::UnboxedFnTyParamBound(_) => {
485487
// FIXME(pcwalton): Wrong.
486-
RegionBound
487-
}
488+
UnboxedFnBound
489+
},
488490
ast::TraitTyParamBound(ref t) => TraitBound(t.clean(cx)),
489491
}
490492
}
491493
}
492494

493495
impl Clean<Vec<TyParamBound>> for ty::ExistentialBounds {
494496
fn clean(&self, cx: &DocContext) -> Vec<TyParamBound> {
495-
let mut vec = vec!(RegionBound);
497+
let mut vec = vec![];
498+
self.region_bound.clean(cx).map(|b| vec.push(RegionBound(b)));
496499
for bb in self.builtin_bounds.iter() {
497500
vec.push(bb.clean(cx));
498501
}
@@ -521,7 +524,7 @@ impl Clean<TyParamBound> for ty::BuiltinBound {
521524
fn clean(&self, cx: &DocContext) -> TyParamBound {
522525
let tcx = match cx.tcx_opt() {
523526
Some(tcx) => tcx,
524-
None => return RegionBound,
527+
None => return UnknownBound
525528
};
526529
let empty = subst::Substs::empty();
527530
let (did, path) = match *self {
@@ -554,7 +557,7 @@ impl Clean<TyParamBound> for ty::TraitRef {
554557
fn clean(&self, cx: &DocContext) -> TyParamBound {
555558
let tcx = match cx.tcx_opt() {
556559
Some(tcx) => tcx,
557-
None => return RegionBound,
560+
None => return UnknownBound
558561
};
559562
let fqn = csearch::get_item_path(tcx, self.def_id);
560563
let fqn = fqn.into_iter().map(|i| i.to_string())
@@ -589,7 +592,7 @@ impl Clean<Vec<TyParamBound>> for ty::ParamBounds {
589592
impl Clean<Option<Vec<TyParamBound>>> for subst::Substs {
590593
fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
591594
let mut v = Vec::new();
592-
v.extend(self.regions().iter().map(|_| RegionBound));
595+
v.extend(self.regions().iter().filter_map(|r| r.clean(cx)).map(RegionBound));
593596
v.extend(self.types.iter().map(|t| TraitBound(t.clean(cx))));
594597
if v.len() > 0 {Some(v)} else {None}
595598
}
@@ -604,6 +607,10 @@ impl Lifetime {
604607
let s: &'a str = s.as_slice();
605608
return s;
606609
}
610+
611+
pub fn statik() -> Lifetime {
612+
Lifetime("'static".to_string())
613+
}
607614
}
608615

609616
impl Clean<Lifetime> for ast::Lifetime {
@@ -627,7 +634,7 @@ impl Clean<Lifetime> for ty::RegionParameterDef {
627634
impl Clean<Option<Lifetime>> for ty::Region {
628635
fn clean(&self, cx: &DocContext) -> Option<Lifetime> {
629636
match *self {
630-
ty::ReStatic => Some(Lifetime("'static".to_string())),
637+
ty::ReStatic => Some(Lifetime::statik()),
631638
ty::ReLateBound(_, ty::BrNamed(_, name)) =>
632639
Some(Lifetime(token::get_name(name).get().to_string())),
633640
ty::ReEarlyBound(_, _, _, name) => Some(Lifetime(name.clean(cx))),

src/librustdoc/html/format.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,14 @@ impl fmt::Show for clean::Lifetime {
140140
impl fmt::Show for clean::TyParamBound {
141141
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
142142
match *self {
143-
clean::RegionBound => {
144-
f.write("'static".as_bytes())
143+
clean::RegionBound(ref lt) => {
144+
write!(f, "{}", *lt)
145+
}
146+
clean::UnboxedFnBound(..) => {
147+
write!(f, "Fn(???)") // FIXME
148+
}
149+
clean::UnknownBound => {
150+
write!(f, "'static")
145151
}
146152
clean::TraitBound(ref ty) => {
147153
write!(f, "{}", *ty)
@@ -401,7 +407,9 @@ impl fmt::Show for clean::Type {
401407
let mut ret = String::new();
402408
for bound in decl.bounds.iter() {
403409
match *bound {
404-
clean::RegionBound => {}
410+
clean::RegionBound(..) |
411+
clean::UnboxedFnBound |
412+
clean::UnknownBound => {}
405413
clean::TraitBound(ref t) => {
406414
if ret.len() == 0 {
407415
ret.push_str(": ");

0 commit comments

Comments
 (0)