1
Fork 0

Address review comments.

Go back to CRATE_DEF_INDEX

Minor niceness improvements

Don't output hidden items

Remove striped items from fields

Add $TEST_BASE_DIR

Small catch
This commit is contained in:
Nixon Enraght-Moony 2020-11-30 20:24:48 +00:00
parent 1098cce27a
commit 40b5470b0d
9 changed files with 80 additions and 103 deletions

View file

@ -2281,7 +2281,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
name: None, name: None,
attrs: self.attrs.clean(cx), attrs: self.attrs.clean(cx),
source: self.span.clean(cx), source: self.span.clean(cx),
def_id: cx.tcx.hir().local_def_id(self.id).to_def_id(), def_id: DefId::local(CRATE_DEF_INDEX),
visibility: self.vis.clean(cx), visibility: self.vis.clean(cx),
stability: None, stability: None,
const_stability: None, const_stability: None,

View file

@ -12,34 +12,34 @@ use crate::doctree;
use crate::formats::item_type::ItemType; use crate::formats::item_type::ItemType;
use crate::json::types::*; use crate::json::types::*;
impl From<clean::Item> for Item { impl From<clean::Item> for Option<Item> {
fn from(item: clean::Item) -> Self { fn from(item: clean::Item) -> Self {
let item_type = ItemType::from(&item); let item_type = ItemType::from(&item);
let clean::Item { let clean::Item {
source, source,
name, name,
attrs, attrs,
kind: inner, kind,
visibility, visibility,
def_id, def_id,
stability: _, stability: _,
deprecation, deprecation,
} = item; } = item;
Item { match kind {
clean::StrippedItem(_) => None,
_ => Some(Item {
id: def_id.into(), id: def_id.into(),
crate_id: def_id.krate.as_u32(), crate_id: def_id.krate.as_u32(),
name, name,
stripped: match inner {
clean::StrippedItem(_) => true,
_ => false,
},
source: source.into(), source: source.into(),
visibility: visibility.into(), visibility: visibility.into(),
docs: attrs.collapsed_doc_value().unwrap_or_default(), docs: attrs.collapsed_doc_value().unwrap_or_default(),
links: attrs links: attrs
.links .links
.into_iter() .into_iter()
.filter_map(|clean::ItemLink { link, did, .. }| did.map(|did| (link, did.into()))) .filter_map(|clean::ItemLink { link, did, .. }| {
did.map(|did| (link, did.into()))
})
.collect(), .collect(),
attrs: attrs attrs: attrs
.other_attrs .other_attrs
@ -48,7 +48,8 @@ impl From<clean::Item> for Item {
.collect(), .collect(),
deprecation: deprecation.map(Into::into), deprecation: deprecation.map(Into::into),
kind: item_type.into(), kind: item_type.into(),
inner: inner.into(), inner: kind.into(),
}),
} }
} }
} }
@ -194,10 +195,7 @@ impl From<clean::ItemKind> for ItemEnum {
impl From<clean::Module> for Module { impl From<clean::Module> for Module {
fn from(module: clean::Module) -> Self { fn from(module: clean::Module) -> Self {
Module { Module { is_crate: module.is_crate, items: ids(module.items) }
is_crate: module.is_crate,
items: module.items.into_iter().map(|i| i.def_id.into()).collect(),
}
} }
} }
@ -208,7 +206,7 @@ impl From<clean::Struct> for Struct {
struct_type: struct_type.into(), struct_type: struct_type.into(),
generics: generics.into(), generics: generics.into(),
fields_stripped, fields_stripped,
fields: fields.into_iter().map(|i| i.def_id.into()).collect(), fields: ids(fields),
impls: Vec::new(), // Added in JsonRenderer::item impls: Vec::new(), // Added in JsonRenderer::item
} }
} }
@ -221,7 +219,7 @@ impl From<clean::Union> for Struct {
struct_type: struct_type.into(), struct_type: struct_type.into(),
generics: generics.into(), generics: generics.into(),
fields_stripped, fields_stripped,
fields: fields.into_iter().map(|i| i.def_id.into()).collect(), fields: ids(fields),
impls: Vec::new(), // Added in JsonRenderer::item impls: Vec::new(), // Added in JsonRenderer::item
} }
} }
@ -407,7 +405,7 @@ impl From<clean::Trait> for Trait {
Trait { Trait {
is_auto, is_auto,
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe, is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
items: items.into_iter().map(|i| i.def_id.into()).collect(), items: ids(items),
generics: generics.into(), generics: generics.into(),
bounds: bounds.into_iter().map(Into::into).collect(), bounds: bounds.into_iter().map(Into::into).collect(),
implementors: Vec::new(), // Added in JsonRenderer::item implementors: Vec::new(), // Added in JsonRenderer::item
@ -434,7 +432,7 @@ impl From<clean::Impl> for Impl {
provided_trait_methods: provided_trait_methods.into_iter().collect(), provided_trait_methods: provided_trait_methods.into_iter().collect(),
trait_: trait_.map(Into::into), trait_: trait_.map(Into::into),
for_: for_.into(), for_: for_.into(),
items: items.into_iter().map(|i| i.def_id.into()).collect(), items: ids(items),
negative: polarity == Some(clean::ImplPolarity::Negative), negative: polarity == Some(clean::ImplPolarity::Negative),
synthetic, synthetic,
blanket_impl: blanket_impl.map(Into::into), blanket_impl: blanket_impl.map(Into::into),
@ -460,7 +458,7 @@ impl From<clean::Enum> for Enum {
Enum { Enum {
generics: generics.into(), generics: generics.into(),
variants_stripped, variants_stripped,
variants: variants.into_iter().map(|i| i.def_id.into()).collect(), variants: ids(variants),
impls: Vec::new(), // Added in JsonRenderer::item impls: Vec::new(), // Added in JsonRenderer::item
} }
} }
@ -473,7 +471,7 @@ impl From<clean::VariantStruct> for Struct {
struct_type: struct_type.into(), struct_type: struct_type.into(),
generics: Default::default(), generics: Default::default(),
fields_stripped, fields_stripped,
fields: fields.into_iter().map(|i| i.def_id.into()).collect(), fields: ids(fields),
impls: Vec::new(), impls: Vec::new(),
} }
} }
@ -485,7 +483,7 @@ impl From<clean::Variant> for Variant {
match variant.kind { match variant.kind {
CLike => Variant::Plain, CLike => Variant::Plain,
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()), Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
Struct(s) => Variant::Struct(s.fields.into_iter().map(|i| i.def_id.into()).collect()), Struct(s) => Variant::Struct(ids(s.fields)),
} }
} }
} }
@ -594,3 +592,7 @@ impl From<ItemType> for ItemKind {
} }
} }
} }
fn ids(items: impl IntoIterator<Item = clean::Item>) -> Vec<Id> {
items.into_iter().filter(|x| !x.is_stripped()).map(|i| i.def_id.into()).collect()
}

View file

@ -99,7 +99,6 @@ impl JsonRenderer {
.0 .0
.last() .last()
.map(Clone::clone), .map(Clone::clone),
stripped: false,
visibility: types::Visibility::Public, visibility: types::Visibility::Public,
kind: types::ItemKind::Trait, kind: types::ItemKind::Trait,
inner: types::ItemEnum::TraitItem(trait_item.clone().into()), inner: types::ItemEnum::TraitItem(trait_item.clone().into()),
@ -144,7 +143,7 @@ impl FormatRenderer for JsonRenderer {
item.kind.inner_items().for_each(|i| self.item(i.clone(), cache).unwrap()); item.kind.inner_items().for_each(|i| self.item(i.clone(), cache).unwrap());
let id = item.def_id; let id = item.def_id;
let mut new_item: types::Item = item.into(); if let Some(mut new_item) = item.into(): Option<types::Item> {
if let types::ItemEnum::TraitItem(ref mut t) = new_item.inner { if let types::ItemEnum::TraitItem(ref mut t) = new_item.inner {
t.implementors = self.get_trait_implementors(id, cache) t.implementors = self.get_trait_implementors(id, cache)
} else if let types::ItemEnum::StructItem(ref mut s) = new_item.inner { } else if let types::ItemEnum::StructItem(ref mut s) = new_item.inner {
@ -152,8 +151,9 @@ impl FormatRenderer for JsonRenderer {
} else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner { } else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
e.impls = self.get_impls(id, cache) e.impls = self.get_impls(id, cache)
} }
self.index.borrow_mut().insert(id.into(), new_item); self.index.borrow_mut().insert(id.into(), new_item);
}
Ok(()) Ok(())
} }

View file

@ -62,9 +62,6 @@ pub struct Item {
pub crate_id: u32, pub crate_id: u32,
/// Some items such as impls don't have names. /// Some items such as impls don't have names.
pub name: Option<String>, pub name: Option<String>,
/// Whether this item is meant to be omitted from the generated documentation due to `#doc(hidden)`,
/// because it is private, or because it was inlined.
pub stripped: bool,
/// The source location of this item (absent if it came from a macro expansion or inline /// The source location of this item (absent if it came from a macro expansion or inline
/// assembly). /// assembly).
pub source: Option<Span>, pub source: Option<Span>,

View file

@ -14,6 +14,7 @@
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(never_type)] #![feature(never_type)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(type_ascription)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#[macro_use] #[macro_use]

View file

@ -1,6 +0,0 @@
-include ../tools.mk
tests: *.rs
$(RUSTDOC) $< -o $(TMPDIR) --output-format json
$(PYTHON) check_missing_items.py $(TMPDIR)/$(basename $<).json
$(PYTHON) compare.py $(basename $<).expected $(TMPDIR)/$(basename $<).json

View file

@ -34,23 +34,18 @@ def check_subset(expected_main, actual_main, base_dir):
def _check_subset(expected, actual, trace): def _check_subset(expected, actual, trace):
expected_type = type(expected) expected_type = type(expected)
actual_type = type(actual) actual_type = type(actual)
if actual_type is str:
actual = actual.replace(base_dir, "$TEST_BASE_DIR")
if expected_type is not actual_type: if expected_type is not actual_type:
raise SubsetException( raise SubsetException(
"expected type `{}`, got `{}`".format(expected_type, actual_type), trace "expected type `{}`, got `{}`".format(expected_type, actual_type), trace
) )
if expected_type in (str, int, bool) and expected != actual:
if expected_type == str and actual.startswith(base_dir):
if actual.replace(base_dir + "/", "") != expected: if expected_type in (int, bool, str) and expected != actual:
raise SubsetException( raise SubsetException("expected `{}`, got: `{}`".format(expected, actual), trace)
"expected `{}`, got: `{}`".format(
expected, actual.replace(base_dir + "/", "")
),
trace,
)
else:
raise SubsetException(
"expected `{}`, got: `{}`".format(expected, actual), trace
)
if expected_type is dict: if expected_type is dict:
for key in expected: for key in expected:
if key not in actual: if key not in actual:

View file

@ -7,7 +7,7 @@
"crate_id": 0, "crate_id": 0,
"name": "Unit", "name": "Unit",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
7, 7,
0 0
@ -37,7 +37,7 @@
"crate_id": 0, "crate_id": 0,
"name": "1", "name": "1",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
5, 5,
22 22
@ -72,7 +72,7 @@
"crate_id": 0, "crate_id": 0,
"name": "stuff", "name": "stuff",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
15, 15,
4 4
@ -114,7 +114,7 @@
"crate_id": 0, "crate_id": 0,
"name": "WithPrimitives", "name": "WithPrimitives",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
9, 9,
0 0
@ -141,18 +141,14 @@
], ],
"where_predicates": [] "where_predicates": []
}, },
"fields_stripped": true, "fields_stripped": true
"fields": [
"0:13",
"0:14"
]
} }
}, },
"0:14": { "0:14": {
"crate_id": 0, "crate_id": 0,
"name": "s", "name": "s",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
11, 11,
4 4
@ -184,7 +180,7 @@
"crate_id": 0, "crate_id": 0,
"name": "things", "name": "things",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
16, 16,
4 4
@ -232,7 +228,7 @@
"crate_id": 0, "crate_id": 0,
"name": "WithGenerics", "name": "WithGenerics",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
14, 14,
0 0
@ -273,18 +269,14 @@
], ],
"where_predicates": [] "where_predicates": []
}, },
"fields_stripped": true, "fields_stripped": true
"fields": [
"0:18",
"0:19"
]
} }
}, },
"0:0": { "0:0": {
"crate_id": 0, "crate_id": 0,
"name": "structs", "name": "structs",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
1, 1,
0 0
@ -315,7 +307,7 @@
"crate_id": 0, "crate_id": 0,
"name": "num", "name": "num",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
10, 10,
4 4
@ -340,7 +332,7 @@
"crate_id": 0, "crate_id": 0,
"name": "Tuple", "name": "Tuple",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
5, 5,
0 0
@ -362,18 +354,14 @@
"params": [], "params": [],
"where_predicates": [] "where_predicates": []
}, },
"fields_stripped": true, "fields_stripped": true
"fields": [
"0:7",
"0:8"
]
} }
}, },
"0:4": { "0:4": {
"crate_id": 0, "crate_id": 0,
"name": "PlainEmpty", "name": "PlainEmpty",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
3, 3,
0 0
@ -403,7 +391,7 @@
"crate_id": 0, "crate_id": 0,
"name": "0", "name": "0",
"source": { "source": {
"filename": "structs.rs", "filename": "$TEST_BASE_DIR/structs.rs",
"begin": [ "begin": [
5, 5,
17 17

View file

@ -1565,7 +1565,7 @@ impl<'test> TestCx<'test> {
self.compose_and_run_compiler(rustc, None) self.compose_and_run_compiler(rustc, None)
} }
fn document(&self, out_dir: &Path, json: bool) -> ProcRes { fn document(&self, out_dir: &Path) -> ProcRes {
if self.props.build_aux_docs { if self.props.build_aux_docs {
for rel_ab in &self.props.aux_builds { for rel_ab in &self.props.aux_builds {
let aux_testpaths = self.compute_aux_test_paths(rel_ab); let aux_testpaths = self.compute_aux_test_paths(rel_ab);
@ -1579,7 +1579,7 @@ impl<'test> TestCx<'test> {
}; };
// Create the directory for the stdout/stderr files. // Create the directory for the stdout/stderr files.
create_dir_all(aux_cx.output_base_dir()).unwrap(); create_dir_all(aux_cx.output_base_dir()).unwrap();
let auxres = aux_cx.document(out_dir, json); let auxres = aux_cx.document(out_dir);
if !auxres.status.success() { if !auxres.status.success() {
return auxres; return auxres;
} }
@ -1601,7 +1601,7 @@ impl<'test> TestCx<'test> {
.arg(&self.testpaths.file) .arg(&self.testpaths.file)
.args(&self.props.compile_flags); .args(&self.props.compile_flags);
if json { if self.config.mode == RustdocJson {
rustdoc.arg("--output-format").arg("json"); rustdoc.arg("--output-format").arg("json");
} }
@ -2336,7 +2336,7 @@ impl<'test> TestCx<'test> {
let _ = fs::remove_dir_all(&out_dir); let _ = fs::remove_dir_all(&out_dir);
create_dir_all(&out_dir).unwrap(); create_dir_all(&out_dir).unwrap();
let proc_res = self.document(&out_dir, false); let proc_res = self.document(&out_dir);
if !proc_res.status.success() { if !proc_res.status.success() {
self.fatal_proc_rec("rustdoc failed!", &proc_res); self.fatal_proc_rec("rustdoc failed!", &proc_res);
} }
@ -2392,7 +2392,7 @@ impl<'test> TestCx<'test> {
rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name()); rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name());
new_rustdoc.build_all_auxiliary(&mut rustc); new_rustdoc.build_all_auxiliary(&mut rustc);
let proc_res = new_rustdoc.document(&compare_dir, false); let proc_res = new_rustdoc.document(&compare_dir);
if !proc_res.status.success() { if !proc_res.status.success() {
proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); proc_res.fatal(Some("failed to run nightly rustdoc"), || ());
} }
@ -2482,7 +2482,7 @@ impl<'test> TestCx<'test> {
let _ = fs::remove_dir_all(&out_dir); let _ = fs::remove_dir_all(&out_dir);
create_dir_all(&out_dir).unwrap(); create_dir_all(&out_dir).unwrap();
let proc_res = self.document(&out_dir, true); let proc_res = self.document(&out_dir);
if !proc_res.status.success() { if !proc_res.status.success() {
self.fatal_proc_rec("rustdoc failed!", &proc_res); self.fatal_proc_rec("rustdoc failed!", &proc_res);
} }
@ -3052,7 +3052,7 @@ impl<'test> TestCx<'test> {
if let Some(nodejs) = &self.config.nodejs { if let Some(nodejs) = &self.config.nodejs {
let out_dir = self.output_base_dir(); let out_dir = self.output_base_dir();
self.document(&out_dir, false); self.document(&out_dir);
let root = self.config.find_rust_src_root().unwrap(); let root = self.config.find_rust_src_root().unwrap();
let file_stem = let file_stem =