rustdoc: Fix links to Box/Gc

These are lang items now, so the internal representations need to be
re-translated back to the original structures manually.

Closes #15185
Closes #15800
This commit is contained in:
Alex Crichton 2014-07-25 09:31:20 -07:00
parent 15a727bba1
commit 431622e1e2
2 changed files with 48 additions and 14 deletions

View File

@ -747,7 +747,6 @@ pub enum SelfTy {
SelfStatic,
SelfValue,
SelfBorrowed(Option<Lifetime>, Mutability),
SelfOwned,
SelfExplicit(Type),
}
@ -971,28 +970,27 @@ impl Clean<Item> for ty::Method {
fn clean(&self) -> Item {
let cx = get_cx();
let (self_, sig) = match self.explicit_self {
ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(), self.fty.sig.clone()),
ty::StaticExplicitSelfCategory => (ast::SelfStatic.clean(),
self.fty.sig.clone()),
s => {
let sig = ty::FnSig {
inputs: Vec::from_slice(self.fty.sig.inputs.slice_from(1)),
..self.fty.sig.clone()
};
let s = match s {
ty::ByValueExplicitSelfCategory => SelfValue,
ty::ByReferenceExplicitSelfCategory(..) => {
match ty::get(self.fty.sig.inputs[0]).sty {
ty::ty_rptr(r, mt) => {
SelfBorrowed(r.clean(), mt.mutbl.clean())
}
_ => {
// FIXME(pcwalton): This is wrong.
SelfStatic
}
_ => unreachable!(),
}
}
_ => {
// FIXME(pcwalton): This is wrong.
SelfStatic
ty::ByBoxExplicitSelfCategory => {
SelfExplicit(self.fty.sig.inputs[0].clean())
}
ty::StaticExplicitSelfCategory => unreachable!(),
};
(s, sig)
}
@ -1213,8 +1211,18 @@ impl Clean<Type> for ty::t {
ty::ty_float(ast::TyF32) => Primitive(F32),
ty::ty_float(ast::TyF64) => Primitive(F64),
ty::ty_str => Primitive(Str),
ty::ty_box(t) => Managed(box t.clean()),
ty::ty_uniq(t) => Unique(box t.clean()),
ty::ty_box(t) => {
let gc_did = get_cx().tcx_opt().and_then(|tcx| {
tcx.lang_items.gc()
});
lang_struct(gc_did, t, "Gc", Managed)
}
ty::ty_uniq(t) => {
let box_did = get_cx().tcx_opt().and_then(|tcx| {
tcx.lang_items.owned_box()
});
lang_struct(box_did, t, "Box", Unique)
}
ty::ty_vec(mt, None) => Vector(box mt.ty.clean()),
ty::ty_vec(mt, Some(i)) => FixedVector(box mt.ty.clean(),
format!("{}", i)),
@ -2094,3 +2102,29 @@ impl Clean<Stability> for attr::Stability {
}
}
}
fn lang_struct(did: Option<ast::DefId>, t: ty::t, name: &str,
fallback: fn(Box<Type>) -> Type) -> Type {
let did = match did {
Some(did) => did,
None => return fallback(box t.clean()),
};
let fqn = csearch::get_item_path(get_cx().tcx(), did);
let fqn: Vec<String> = fqn.move_iter().map(|i| {
i.to_string()
}).collect();
get_cx().external_paths.borrow_mut().get_mut_ref()
.insert(did, (fqn, TypeStruct));
ResolvedPath {
typarams: None,
did: did,
path: Path {
global: false,
segments: vec![PathSegment {
name: name.to_string(),
lifetimes: vec![],
types: vec![t.clean()],
}],
},
}
}

View File

@ -444,8 +444,6 @@ impl fmt::Show for clean::Type {
format!("[{}, ..{}]", **t, *s).as_slice())
}
clean::Bottom => f.write("!".as_bytes()),
clean::Unique(ref t) => write!(f, "Box<{}>", **t),
clean::Managed(ref t) => write!(f, "Gc<{}>", **t),
clean::RawPointer(m, ref t) => {
write!(f, "*{}{}", RawMutableSpace(m), **t)
}
@ -456,6 +454,9 @@ impl fmt::Show for clean::Type {
};
write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
}
clean::Unique(..) | clean::Managed(..) => {
fail!("should have been cleaned")
}
}
}
}
@ -491,7 +492,6 @@ impl<'a> fmt::Show for Method<'a> {
match *selfty {
clean::SelfStatic => {},
clean::SelfValue => args.push_str("self"),
clean::SelfOwned => args.push_str("self: Box<Self>"),
clean::SelfBorrowed(Some(ref lt), mtbl) => {
args.push_str(format!("&amp;{} {}self", *lt,
MutableSpace(mtbl)).as_slice());