Skip to content

Commit 36154e5

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 760430e commit 36154e5

File tree

10 files changed

+2117
-17
lines changed

10 files changed

+2117
-17
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2276,7 +2276,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
22762276
name: None,
22772277
attrs: self.attrs.clean(cx),
22782278
source: self.span.clean(cx),
2279-
def_id: DefId::local(CRATE_DEF_INDEX),
2279+
def_id: cx.tcx.hir().local_def_id(self.id).to_def_id(),
22802280
visibility: self.vis.clean(cx),
22812281
stability: None,
22822282
deprecation: None,

src/librustdoc/clean/types.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,42 @@ crate enum ItemKind {
328328
}
329329

330330
impl ItemKind {
331+
/// Some items contain others such as structs (for their fields) and Enums
332+
/// (for their variants). This method returns those contained items.
333+
crate fn inner_items(&self) -> impl Iterator<Item = &Item> {
334+
match self {
335+
StructItem(s) => s.fields.iter(),
336+
UnionItem(u) => u.fields.iter(),
337+
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
338+
EnumItem(e) => e.variants.iter(),
339+
TraitItem(t) => t.items.iter(),
340+
ImplItem(i) => i.items.iter(),
341+
ModuleItem(m) => m.items.iter(),
342+
ExternCrateItem(_, _)
343+
| ImportItem(_)
344+
| FunctionItem(_)
345+
| TypedefItem(_, _)
346+
| OpaqueTyItem(_)
347+
| StaticItem(_)
348+
| ConstantItem(_)
349+
| TraitAliasItem(_)
350+
| TyMethodItem(_)
351+
| MethodItem(_, _)
352+
| StructFieldItem(_)
353+
| VariantItem(_)
354+
| ForeignFunctionItem(_)
355+
| ForeignStaticItem(_)
356+
| ForeignTypeItem
357+
| MacroItem(_)
358+
| ProcMacroItem(_)
359+
| PrimitiveItem(_)
360+
| AssocConstItem(_, _)
361+
| AssocTypeItem(_, _)
362+
| StrippedItem(_)
363+
| KeywordItem(_) => [].iter(),
364+
}
365+
}
366+
331367
crate fn is_type_alias(&self) -> bool {
332368
match *self {
333369
ItemKind::TypedefItem(_, _) | ItemKind::AssocTypeItem(_, _) => true,
@@ -1604,6 +1640,11 @@ impl Path {
16041640
crate fn last_name(&self) -> &str {
16051641
self.segments.last().expect("segments were empty").name.as_str()
16061642
}
1643+
1644+
crate fn whole_name(&self) -> String {
1645+
String::from(if self.global { "::" } else { "" })
1646+
+ &self.segments.iter().map(|s| s.name.clone()).collect::<Vec<_>>().join("::")
1647+
}
16071648
}
16081649

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

0 commit comments

Comments
 (0)