Skip to content

Commit 3cdb0bf

Browse files
committed
Ignore stripped items
1 parent fcf97a0 commit 3cdb0bf

File tree

9 files changed

+340
-300
lines changed

9 files changed

+340
-300
lines changed

src/librustdoc/json/conversions.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ impl From<clean::Item> for Item {
2626
deprecation,
2727
} = item;
2828
Item {
29+
id: def_id.into(),
2930
crate_id: def_id.krate.as_u32(),
3031
name,
32+
stripped: inner == clean::StrippedItem(_),
3133
source: source.into(),
3234
visibility: visibility.into(),
3335
docs: attrs.collapsed_doc_value().unwrap_or_default(),
@@ -183,12 +185,21 @@ impl From<clean::ItemEnum> for ItemEnum {
183185
}
184186
}
185187

188+
fn remove_stripped(items: &[clean::Item]) -> Vec<Id> {
189+
items
190+
.into_iter()
191+
.filter_map(|i| {
192+
if let clean::StrippedItem(_) = i.inner {
193+
return None;
194+
}
195+
Some(i.def_id.into())
196+
})
197+
.collect()
198+
}
199+
186200
impl From<clean::Module> for Module {
187201
fn from(module: clean::Module) -> Self {
188-
Module {
189-
is_crate: module.is_crate,
190-
items: module.items.into_iter().map(|i| i.def_id.into()).collect(),
191-
}
202+
Module { is_crate: module.is_crate, items: remove_stripped(&module.items) }
192203
}
193204
}
194205

@@ -199,8 +210,8 @@ impl From<clean::Struct> for Struct {
199210
struct_type: struct_type.into(),
200211
generics: generics.into(),
201212
fields_stripped,
202-
fields: fields.into_iter().map(|i| i.def_id.into()).collect(),
203-
impls: Vec::new(), // Added in JsonRenderer::insert
213+
fields: remove_stripped(&fields),
214+
impls: Vec::new(), // Added in JsonRenderer::item
204215
}
205216
}
206217
}
@@ -212,8 +223,8 @@ impl From<clean::Union> for Struct {
212223
struct_type: struct_type.into(),
213224
generics: generics.into(),
214225
fields_stripped,
215-
fields: fields.into_iter().map(|i| i.def_id.into()).collect(),
216-
impls: Vec::new(), // Added in JsonRenderer::insert
226+
fields: remove_stripped(&fields),
227+
impls: Vec::new(), // Added in JsonRenderer::item
217228
}
218229
}
219230
}
@@ -399,10 +410,10 @@ impl From<clean::Trait> for Trait {
399410
Trait {
400411
is_auto: auto,
401412
is_unsafe: unsafety == rustc_hir::Unsafety::Unsafe,
402-
items: items.into_iter().map(|i| i.def_id.into()).collect(),
413+
items: remove_stripped(&items),
403414
generics: generics.into(),
404415
bounds: bounds.into_iter().map(Into::into).collect(),
405-
implementors: Vec::new(), // Added in JsonRenderer::insert
416+
implementors: Vec::new(), // Added in JsonRenderer::item
406417
}
407418
}
408419
}
@@ -426,7 +437,7 @@ impl From<clean::Impl> for Impl {
426437
provided_trait_methods: provided_trait_methods.into_iter().collect(),
427438
trait_: trait_.map(Into::into),
428439
for_: for_.into(),
429-
items: items.into_iter().map(|i| i.def_id.into()).collect(),
440+
items: remove_stripped(&items),
430441
negative: polarity == Some(clean::ImplPolarity::Negative),
431442
synthetic,
432443
blanket_impl: blanket_impl.map(Into::into),
@@ -465,8 +476,8 @@ impl From<clean::Enum> for Enum {
465476
Enum {
466477
generics: generics.into(),
467478
variants_stripped,
468-
variants: variants.into_iter().map(|i| i.def_id.into()).collect(),
469-
impls: Vec::new(), // Added in JsonRenderer::insert
479+
variants: remove_stripped(&variants.into_iter().collect::<Vec<_>>()),
480+
impls: Vec::new(), // Added in JsonRenderer::item
470481
}
471482
}
472483
}
@@ -478,7 +489,7 @@ impl From<clean::VariantStruct> for Struct {
478489
struct_type: struct_type.into(),
479490
generics: Default::default(),
480491
fields_stripped,
481-
fields: fields.into_iter().map(|i| i.def_id.into()).collect(),
492+
fields: remove_stripped(&fields),
482493
impls: Vec::new(),
483494
}
484495
}
@@ -490,7 +501,7 @@ impl From<clean::Variant> for Variant {
490501
match variant.kind {
491502
CLike => Variant::Plain,
492503
Tuple(t) => Variant::Tuple(t.into_iter().map(Into::into).collect()),
493-
Struct(s) => Variant::Struct(s.fields.into_iter().map(|i| i.def_id.into()).collect()),
504+
Struct(s) => Variant::Struct(remove_stripped(&s.fields)),
494505
}
495506
}
496507
}
@@ -562,7 +573,7 @@ impl From<clean::TraitAlias> for TraitAlias {
562573
fn from(alias: clean::TraitAlias) -> Self {
563574
TraitAlias {
564575
generics: alias.generics.into(),
565-
bounds: alias.bounds.into_iter().map(Into::into).collect(),
576+
params: alias.bounds.into_iter().map(Into::into).collect(),
566577
}
567578
}
568579
}

src/librustdoc/json/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ impl JsonRenderer {
7878
cache
7979
.traits
8080
.iter()
81-
.filter_map(|(id, trait_item)| {
81+
.filter_map(|(&id, trait_item)| {
8282
// only need to synthesize items for external traits
8383
if !id.is_local() {
8484
trait_item.items.clone().into_iter().for_each(|i| self.item(i, cache).unwrap());
8585
Some((
86-
(*id).into(),
86+
id.into(),
8787
types::Item {
88+
id: id.into(),
8889
crate_id: id.krate.as_u32(),
8990
name: cache
9091
.paths
@@ -138,8 +139,17 @@ impl FormatRenderer for JsonRenderer {
138139
/// the hashmap because certain items (traits and types) need to have their mappings for trait
139140
/// implementations filled out before they're inserted.
140141
fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> {
142+
if let clean::StrippedItem(_) = item.inner {
143+
return Ok(());
144+
}
145+
141146
// Flatten items that recursively store other items
142-
item.inner.inner_items().for_each(|i| self.item(i.clone(), cache).unwrap());
147+
item.inner.inner_items().for_each(|i| {
148+
if let clean::StrippedItem(_) = i.inner {
149+
} else {
150+
self.item(i.clone(), cache).unwrap()
151+
}
152+
});
143153

144154
let id = item.def_id;
145155
let mut new_item: types::Item = item.into();

src/librustdoc/json/types.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,16 @@ pub struct ItemSummary {
5555

5656
#[derive(Clone, Debug, Serialize, Deserialize)]
5757
pub struct Item {
58+
/// The unique identifier of this item. Can be used to find this item in various mappings.
59+
pub id: Id,
5860
/// This can be used as a key to the `external_crates` map of [`Crate`] to see which crate
5961
/// this item came from.
6062
pub crate_id: u32,
6163
/// Some items such as impls don't have names.
6264
pub name: Option<String>,
65+
/// Whether this item is meant to be omitted from the generated documentation due to `#doc(hidden)`,
66+
/// because it is private, or because it was inlined.
67+
pub stripped: bool,
6368
/// The source location of this item (absent if it came from a macro expansion or inline
6469
/// assembly).
6570
pub source: Option<Span>,
@@ -198,15 +203,15 @@ pub enum ItemEnum {
198203

199204
FunctionItem(Function),
200205

201-
TypedefItem(Typedef),
202-
OpaqueTyItem(OpaqueTy),
203-
ConstantItem(Constant),
204-
205206
TraitItem(Trait),
206207
TraitAliasItem(TraitAlias),
207208
MethodItem(Method),
208209
ImplItem(Impl),
209210

211+
TypedefItem(Typedef),
212+
OpaqueTyItem(OpaqueTy),
213+
ConstantItem(Constant),
214+
210215
StaticItem(Static),
211216

212217
/// `type`s from an extern block
@@ -225,9 +230,6 @@ pub enum ItemEnum {
225230
bounds: Vec<GenericBound>,
226231
default: Option<Type>,
227232
},
228-
229-
/// An item that has been stripped by a rustdoc pass
230-
StrippedItem(Box<ItemEnum>),
231233
}
232234

233235
#[derive(Clone, Debug, Serialize, Deserialize)]
@@ -418,7 +420,7 @@ pub struct Trait {
418420
#[derive(Clone, Debug, Serialize, Deserialize)]
419421
pub struct TraitAlias {
420422
pub generics: Generics,
421-
pub bounds: Vec<GenericBound>,
423+
pub params: Vec<GenericBound>,
422424
}
423425

424426
#[derive(Clone, Debug, Serialize, Deserialize)]

src/test/run-make-fulldeps/rustdoc-json/check_missing_items.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def check_type(ty):
8989
for ty in args["parenthesized"]["inputs"]:
9090
check_type(ty)
9191
if args["parenthesized"]["output"]:
92-
ckeck_ty(args["parenthesized"]["output"])
92+
check_type(args["parenthesized"]["output"])
9393
if not valid_id(ty["inner"]["id"]):
9494
print("Type contained an invalid ID:", ty["inner"]["id"])
9595
sys.exit(1)
@@ -150,10 +150,14 @@ def check_type(ty):
150150
elif item["kind"] == "typedef":
151151
check_type(item["inner"]["type"])
152152
check_generics(item["inner"]["generics"])
153-
elif item["kind"] in ("opaque_ty", "trait_alias"):
153+
elif item["kind"] == "opaque_ty":
154154
check_generics(item["inner"]["generics"])
155155
for bound in item["inner"]["bounds"]:
156156
check_generic_bound(bound)
157+
elif item["kind"] == "trait_alias":
158+
check_generics(item["inner"]["params"])
159+
for bound in item["inner"]["bounds"]:
160+
check_generic_bound(bound)
157161
elif item["kind"] == "trait":
158162
check_generics(item["inner"]["generics"])
159163
for bound in item["inner"]["bounds"]:

src/test/run-make-fulldeps/rustdoc-json/compare.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def rustdoc_object_hook(obj):
6969
# No need to convert paths, index and external_crates keys to ids, since
7070
# they are the target of resolution, and never a source itself.
7171
if "id" in obj and obj["id"]:
72-
obj["id"] = ID(id)
72+
obj["id"] = ID(obj["id"])
7373
if "root" in obj:
74-
obj["root"] = ID(id)
74+
obj["root"] = ID(obj["root"])
7575
if "items" in obj:
7676
obj["items"] = [ID(id) for id in obj["items"]]
7777
if "variants" in obj:
@@ -102,4 +102,5 @@ def main(expected_fpath, actual_fpath):
102102
if __name__ == "__main__":
103103
if len(sys.argv) < 3:
104104
print("Usage: `compare.py expected.json actual.json`")
105-
main(sys.argv[1], sys.argv[2])
105+
else:
106+
main(sys.argv[1], sys.argv[2])

0 commit comments

Comments
 (0)