Skip to content

Commit 350e4d7

Browse files
committed
[WIP] add statics and unions
1 parent 4b22097 commit 350e4d7

File tree

1 file changed

+13
-90
lines changed

1 file changed

+13
-90
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,26 @@ enum MaybeInlined {
237237
impl Clean<Vec<Item>> for hir::Item<'_> {
238238
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
239239
use hir::ItemKind;
240+
use MaybeInlined::NotInlined;
240241

241242
let def_id = cx.tcx.hir().local_def_id(self.hir_id).to_def_id();
242243
let name = cx.tcx.item_name(def_id).clean(cx);
243244
let maybe_inlined = match self.kind {
244245
// TODO: should store Symbol, not String
245246
ItemKind::ExternCrate(renamed) => clean_extern_crate(self, renamed, cx),
246247
ItemKind::Use(path, kind) => clean_import(self, path, kind, cx),
248+
ItemKind::Static(ty, mutability, body_id) => NotInlined(StaticItem(Static {
249+
type_: ty.clean(cx),
250+
mutability,
251+
expr: print_const_expr(cx, body_id),
252+
})),
253+
ItemKind::Const(ty, body_id) => unimplemented!(),
254+
ItemKind::Union(ref variant_data, ref generics) => NotInlined(UnionItem(Union {
255+
struct_type: doctree::struct_type_from_def(&variant_data),
256+
generics: generics.clean(cx),
257+
fields: variant_data.fields().clean(cx),
258+
fields_stripped: false,
259+
})),
247260
_ => unimplemented!(),
248261
};
249262

@@ -334,64 +347,6 @@ impl Clean<Vec<Item>> for hir::ModuleItems {
334347
}
335348
}
336349

337-
/*
338-
impl Clean<Item> for doctree::Module<'_> {
339-
fn clean(&self, cx: &DocContext<'_>) -> Item {
340-
// maintain a stack of mod ids, for doc comment path resolution
341-
// but we also need to resolve the module's own docs based on whether its docs were written
342-
// inside or outside the module, so check for that
343-
let attrs = self.attrs.clean(cx);
344-
345-
let mut items: Vec<Item> = vec![];
346-
items.extend(self.extern_crates.iter().flat_map(|x| x.clean(cx)));
347-
items.extend(self.imports.iter().flat_map(|x| x.clean(cx)));
348-
items.extend(self.structs.iter().map(|x| x.clean(cx)));
349-
items.extend(self.unions.iter().map(|x| x.clean(cx)));
350-
items.extend(self.enums.iter().map(|x| x.clean(cx)));
351-
items.extend(self.fns.iter().map(|x| x.clean(cx)));
352-
items.extend(self.foreigns.iter().map(|x| x.clean(cx)));
353-
items.extend(self.mods.iter().map(|x| x.clean(cx)));
354-
items.extend(self.typedefs.iter().map(|x| x.clean(cx)));
355-
items.extend(self.opaque_tys.iter().map(|x| x.clean(cx)));
356-
items.extend(self.statics.iter().map(|x| x.clean(cx)));
357-
items.extend(self.constants.iter().map(|x| x.clean(cx)));
358-
items.extend(self.traits.iter().map(|x| x.clean(cx)));
359-
items.extend(self.impls.iter().flat_map(|x| x.clean(cx)));
360-
items.extend(self.macros.iter().map(|x| x.clean(cx)));
361-
items.extend(self.proc_macros.iter().map(|x| x.clean(cx)));
362-
items.extend(self.trait_aliases.iter().map(|x| x.clean(cx)));
363-
364-
// determine if we should display the inner contents or
365-
// the outer `mod` item for the source code.
366-
let span = {
367-
let sm = cx.sess().source_map();
368-
let outer = sm.lookup_char_pos(self.where_outer.lo());
369-
let inner = sm.lookup_char_pos(self.where_inner.lo());
370-
if outer.file.start_pos == inner.file.start_pos {
371-
// mod foo { ... }
372-
self.where_outer
373-
} else {
374-
// mod foo; (and a separate SourceFile for the contents)
375-
self.where_inner
376-
}
377-
};
378-
379-
let what_rustc_thinks = Item::from_hir_id_and_parts(
380-
self.id,
381-
self.name,
382-
ModuleItem(Module { is_crate: self.is_crate, items }),
383-
cx,
384-
);
385-
Item {
386-
name: Some(what_rustc_thinks.name.unwrap_or_default()),
387-
attrs,
388-
source: span.clean(cx),
389-
..what_rustc_thinks
390-
}
391-
}
392-
}
393-
*/
394-
395350
impl Clean<Attributes> for [ast::Attribute] {
396351
fn clean(&self, cx: &DocContext<'_>) -> Attributes {
397352
Attributes::from_ast(cx.sess().diagnostic(), self, None)
@@ -1907,22 +1862,6 @@ impl Clean<Item> for doctree::Struct<'_> {
19071862
}
19081863
}
19091864

1910-
impl Clean<Item> for doctree::Union<'_> {
1911-
fn clean(&self, cx: &DocContext<'_>) -> Item {
1912-
Item::from_hir_id_and_parts(
1913-
self.id,
1914-
Some(self.name),
1915-
UnionItem(Union {
1916-
struct_type: self.struct_type,
1917-
generics: self.generics.clean(cx),
1918-
fields: self.fields.clean(cx),
1919-
fields_stripped: false,
1920-
}),
1921-
cx,
1922-
)
1923-
}
1924-
}
1925-
19261865
impl Clean<VariantStruct> for rustc_hir::VariantData<'_> {
19271866
fn clean(&self, cx: &DocContext<'_>) -> VariantStruct {
19281867
VariantStruct {
@@ -2131,22 +2070,6 @@ impl Clean<BareFunctionDecl> for hir::BareFnTy<'_> {
21312070
}
21322071
}
21332072

2134-
impl Clean<Item> for doctree::Static<'_> {
2135-
fn clean(&self, cx: &DocContext<'_>) -> Item {
2136-
debug!("cleaning static {}: {:?}", self.name.clean(cx), self);
2137-
Item::from_hir_id_and_parts(
2138-
self.id,
2139-
Some(self.name),
2140-
StaticItem(Static {
2141-
type_: self.type_.clean(cx),
2142-
mutability: self.mutability,
2143-
expr: print_const_expr(cx, self.expr),
2144-
}),
2145-
cx,
2146-
)
2147-
}
2148-
}
2149-
21502073
impl Clean<Item> for doctree::Constant<'_> {
21512074
fn clean(&self, cx: &DocContext<'_>) -> Item {
21522075
let def_id = cx.tcx.hir().local_def_id(self.id).to_def_id();

0 commit comments

Comments
 (0)