Skip to content

Commit 66884e3

Browse files
P1n3appl3aDotInTheVoid
authored andcommitted
Add json backend
Respond to comments and start adding tests Fix re-exports and extern-crate Add expected output tests Add restricted paths Format Fix: associated methods missing in output Ignore stripped items Mark stripped items removing them creates dangling references Fix tests and update conversions Don't panic if JSON backend fails to create a file Fix attribute error in JSON testsuite Move rustdoc-json to rustdoc/ This way it doesn't have to build rustc twice. Eventually it should probably get its own suite, like rustdoc-js, but that can be fixed in a follow-up. Small cleanups Don't prettify json before printing This fully halves the size of the emitted JSON. Add comments [BREAKING CHANGE] rename version -> crate_version [BREAKING CHANGE] rename source -> span Use exhaustive matches Don't qualify imports for DefId Rename clean::{ItemEnum -> ItemKind}, clean::Item::{inner -> kind} Fix Visibility conversion clean::Visability was changed here: https://github.com/rust-lang/rust/pull/77820/files#diff-df9f90aae0b7769e1eb6ea6f1d73c1c3f649e1ac48a20e169662a8930eb427beL1467-R1509 More churn catchup Format
1 parent 4cbda82 commit 66884e3

File tree

10 files changed

+2117
-17
lines changed

10 files changed

+2117
-17
lines changed

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22812281
name: None,
22822282
attrs: self.attrs.clean(cx),
22832283
source: self.span.clean(cx),
2284-
def_id: DefId::local(CRATE_DEF_INDEX),
2284+
def_id: cx.tcx.hir().local_def_id(self.id).to_def_id(),
22852285
visibility: self.vis.clean(cx),
22862286
stability: None,
22872287
const_stability: None,

src/librustdoc/clean/types.rs

+41
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,42 @@ crate enum ItemKind {
337337
}
338338

339339
impl ItemKind {
340+
/// Some items contain others such as structs (for their fields) and Enums
341+
/// (for their variants). This method returns those contained items.
342+
crate fn inner_items(&self) -> impl Iterator<Item = &Item> {
343+
match self {
344+
StructItem(s) => s.fields.iter(),
345+
UnionItem(u) => u.fields.iter(),
346+
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
347+
EnumItem(e) => e.variants.iter(),
348+
TraitItem(t) => t.items.iter(),
349+
ImplItem(i) => i.items.iter(),
350+
ModuleItem(m) => m.items.iter(),
351+
ExternCrateItem(_, _)
352+
| ImportItem(_)
353+
| FunctionItem(_)
354+
| TypedefItem(_, _)
355+
| OpaqueTyItem(_)
356+
| StaticItem(_)
357+
| ConstantItem(_)
358+
| TraitAliasItem(_)
359+
| TyMethodItem(_)
360+
| MethodItem(_, _)
361+
| StructFieldItem(_)
362+
| VariantItem(_)
363+
| ForeignFunctionItem(_)
364+
| ForeignStaticItem(_)
365+
| ForeignTypeItem
366+
| MacroItem(_)
367+
| ProcMacroItem(_)
368+
| PrimitiveItem(_)
369+
| AssocConstItem(_, _)
370+
| AssocTypeItem(_, _)
371+
| StrippedItem(_)
372+
| KeywordItem(_) => [].iter(),
373+
}
374+
}
375+
340376
crate fn is_type_alias(&self) -> bool {
341377
match *self {
342378
ItemKind::TypedefItem(_, _) | ItemKind::AssocTypeItem(_, _) => true,
@@ -1613,6 +1649,11 @@ impl Path {
16131649
crate fn last_name(&self) -> &str {
16141650
self.segments.last().expect("segments were empty").name.as_str()
16151651
}
1652+
1653+
crate fn whole_name(&self) -> String {
1654+
String::from(if self.global { "::" } else { "" })
1655+
+ &self.segments.iter().map(|s| s.name.clone()).collect::<Vec<_>>().join("::")
1656+
}
16161657
}
16171658

16181659
#[derive(Clone, PartialEq, Eq, Debug, Hash)]

0 commit comments

Comments
 (0)