Skip to content

Commit

Permalink
Rollup merge of rust-lang#79539 - aDotInTheVoid:json-mvp, r=jyn514,Gu…
Browse files Browse the repository at this point in the history
…illaumeGomez

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`
  • Loading branch information
m-ou-se authored Dec 1, 2020
2 parents d6c3d16 + 97011eb commit f401e9e
Show file tree
Hide file tree
Showing 14 changed files with 2,188 additions and 21 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ impl<'a> Builder<'a> {
test::RustdocJSNotStd,
test::RustdocTheme,
test::RustdocUi,
test::RustdocJson,
// Run bootstrap close to the end as it's unlikely to fail
test::Bootstrap,
// Run run-make last, since these won't pass without make on Windows
Expand Down
7 changes: 7 additions & 0 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,12 @@ host_test!(UiFullDeps { path: "src/test/ui-fulldeps", mode: "ui", suite: "ui-ful
host_test!(Rustdoc { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" });
host_test!(RustdocUi { path: "src/test/rustdoc-ui", mode: "ui", suite: "rustdoc-ui" });

host_test!(RustdocJson {
path: "src/test/rustdoc-json",
mode: "rustdoc-json",
suite: "rustdoc-json"
});

host_test!(Pretty { path: "src/test/pretty", mode: "pretty", suite: "pretty" });

default_test!(RunMake { path: "src/test/run-make", mode: "run-make", suite: "run-make" });
Expand Down Expand Up @@ -1001,6 +1007,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the
|| (mode == "run-make" && suite.ends_with("fulldeps"))
|| (mode == "ui" && is_rustdoc)
|| mode == "js-doc-test"
|| mode == "rustdoc-json"
{
cmd.arg("--rustdoc-path").arg(builder.rustdoc(compiler));
}
Expand Down
41 changes: 41 additions & 0 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,42 @@ crate enum ItemKind {
}

impl ItemKind {
/// Some items contain others such as structs (for their fields) and Enums
/// (for their variants). This method returns those contained items.
crate fn inner_items(&self) -> impl Iterator<Item = &Item> {
match self {
StructItem(s) => s.fields.iter(),
UnionItem(u) => u.fields.iter(),
VariantItem(Variant { kind: VariantKind::Struct(v) }) => v.fields.iter(),
EnumItem(e) => e.variants.iter(),
TraitItem(t) => t.items.iter(),
ImplItem(i) => i.items.iter(),
ModuleItem(m) => m.items.iter(),
ExternCrateItem(_, _)
| ImportItem(_)
| FunctionItem(_)
| TypedefItem(_, _)
| OpaqueTyItem(_)
| StaticItem(_)
| ConstantItem(_)
| TraitAliasItem(_)
| TyMethodItem(_)
| MethodItem(_, _)
| StructFieldItem(_)
| VariantItem(_)
| ForeignFunctionItem(_)
| ForeignStaticItem(_)
| ForeignTypeItem
| MacroItem(_)
| ProcMacroItem(_)
| PrimitiveItem(_)
| AssocConstItem(_, _)
| AssocTypeItem(_, _)
| StrippedItem(_)
| KeywordItem(_) => [].iter(),
}
}

crate fn is_type_alias(&self) -> bool {
match *self {
ItemKind::TypedefItem(_, _) | ItemKind::AssocTypeItem(_, _) => true,
Expand Down Expand Up @@ -1604,6 +1640,11 @@ impl Path {
crate fn last_name(&self) -> &str {
self.segments.last().expect("segments were empty").name.as_str()
}

crate fn whole_name(&self) -> String {
String::from(if self.global { "::" } else { "" })
+ &self.segments.iter().map(|s| s.name.clone()).collect::<Vec<_>>().join("::")
}
}

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
Expand Down
Loading

0 comments on commit f401e9e

Please sign in to comment.