Skip to content

Commit 622c8f7

Browse files
committed
rustdoc: Inline enums across crates
1 parent c81b511 commit 622c8f7

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

src/librustdoc/clean.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,49 @@ impl Clean<Item> for doctree::Variant {
12041204
}
12051205
}
12061206

1207+
impl Clean<Item> for ty::VariantInfo {
1208+
fn clean(&self) -> Item {
1209+
// use syntax::parse::token::special_idents::unnamed_field;
1210+
let cx = super::ctxtkey.get().unwrap();
1211+
let tcx = match cx.maybe_typed {
1212+
core::Typed(ref tycx) => tycx,
1213+
core::NotTyped(_) => fail!("tcx not present"),
1214+
};
1215+
let kind = match self.arg_names.as_ref().map(|s| s.as_slice()) {
1216+
None | Some([]) if self.args.len() == 0 => CLikeVariant,
1217+
None | Some([]) => {
1218+
TupleVariant(self.args.iter().map(|t| t.clean()).collect())
1219+
}
1220+
Some(s) => {
1221+
StructVariant(VariantStruct {
1222+
struct_type: doctree::Plain,
1223+
fields_stripped: false,
1224+
fields: s.iter().zip(self.args.iter()).map(|(name, ty)| {
1225+
Item {
1226+
source: Span::empty(),
1227+
name: Some(name.clean()),
1228+
attrs: Vec::new(),
1229+
visibility: Some(ast::Public),
1230+
def_id: self.id, // FIXME: this is not accurate
1231+
inner: StructFieldItem(
1232+
TypedStructField(ty.clean())
1233+
)
1234+
}
1235+
}).collect()
1236+
})
1237+
}
1238+
};
1239+
Item {
1240+
name: Some(self.name.clean()),
1241+
attrs: load_attrs(tcx, self.id),
1242+
source: Span::empty(),
1243+
visibility: Some(ast::Public),
1244+
def_id: self.id,
1245+
inner: VariantItem(Variant { kind: kind }),
1246+
}
1247+
}
1248+
}
1249+
12071250
#[deriving(Clone, Encodable, Decodable)]
12081251
pub enum VariantKind {
12091252
CLikeVariant,
@@ -1524,6 +1567,10 @@ fn try_inline(id: ast::NodeId) -> Option<Vec<Item>> {
15241567
ret.extend(build_impls(tcx, did).move_iter());
15251568
StructItem(build_struct(tcx, did))
15261569
}
1570+
ast::DefTy(did) => {
1571+
ret.extend(build_impls(tcx, did).move_iter());
1572+
build_type(tcx, did)
1573+
}
15271574
_ => return None,
15281575
};
15291576
let fqn = csearch::get_item_path(tcx, did);
@@ -1822,6 +1869,25 @@ fn build_struct(tcx: &ty::ctxt, did: ast::DefId) -> Struct {
18221869
}
18231870
}
18241871

1872+
fn build_type(tcx: &ty::ctxt, did: ast::DefId) -> ItemEnum {
1873+
let t = ty::lookup_item_type(tcx, did);
1874+
match ty::get(t.ty).sty {
1875+
ty::ty_enum(edid, _) => {
1876+
return EnumItem(Enum {
1877+
generics: t.generics.clean(),
1878+
variants_stripped: false,
1879+
variants: ty::enum_variants(tcx, edid).clean(),
1880+
})
1881+
}
1882+
_ => {}
1883+
}
1884+
1885+
TypedefItem(Typedef {
1886+
type_: t.ty.clean(),
1887+
generics: t.generics.clean(),
1888+
})
1889+
}
1890+
18251891
fn build_impls(tcx: &ty::ctxt,
18261892
did: ast::DefId) -> Vec<Item> {
18271893
ty::populate_implementations_for_type_if_necessary(tcx, did);

0 commit comments

Comments
 (0)