Skip to content

Commit 7dc1e85

Browse files
committed
Auto merge of rust-lang#79539 - aDotInTheVoid:json-mvp, r=jyn514
Rustdoc: JSON backend experimental impl, with new tests. Based on rust-lang#75114 by `@P1n3appl3` The first commit is all of rust-lang#75114, but squased to 1 commit, as that was much easier to rebase onto master. The git history is a mess, but I think I'll edit it after review, so it's obvious whats new. ## Still to do - [ ] Update docs. - [ ] Add bless option to tests. - [ ] Add test option for multiple files in same crate. - [ ] Decide if the tests should check for json to be equal or subset. - [ ] Go through the rest of the review for the original pr. (This is open because the test system is done(ish), but stuff like [not using a hashmap](rust-lang#75114 (comment)) and [using `CRATE_DEF_INDEX` ](rust-lang#75114 (comment)) hasn't) I'm also sure how many of these we need to do before landing on nightly, as it would be nice to get this in tree, so it isn't effected by churn like rust-lang#79125, rust-lang#79041, rust-lang#79061 r? `@jyn514`
2 parents f4db9ff + d619271 commit 7dc1e85

File tree

14 files changed

+2192
-21
lines changed

14 files changed

+2192
-21
lines changed

src/bootstrap/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ impl<'a> Builder<'a> {
425425
test::RustdocJSNotStd,
426426
test::RustdocTheme,
427427
test::RustdocUi,
428+
test::RustdocJson,
428429
// Run bootstrap close to the end as it's unlikely to fail
429430
test::Bootstrap,
430431
// Run run-make last, since these won't pass without make on Windows

src/bootstrap/test.rs

+7
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,12 @@ host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-ful
904904
host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
905905
host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });
906906

907+
host_test!(RustdocJson {
908+
path: "src/test/rustdoc-json",
909+
mode: "rustdoc-json",
910+
suite: "rustdoc-json"
911+
});
912+
907913
host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });
908914

909915
default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
@@ -1001,6 +1007,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
10011007
|| (mode == "run-make" && suite.ends_with("fulldeps"))
10021008
|| (mode == "ui" && is_rustdoc)
10031009
|| mode == "js-doc-test"
1010+
|| mode == "rustdoc-json"
10041011
{
10051012
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
10061013
}

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)