Skip to content

Commit fcf97a0

Browse files
committed
Fix: associated methods missing in output
1 parent c3ff3da commit fcf97a0

File tree

3 files changed

+32
-30
lines changed

3 files changed

+32
-30
lines changed

src/librustdoc/json/mod.rs

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,8 @@ pub struct JsonRenderer {
3232
}
3333

3434
impl JsonRenderer {
35-
/// Inserts an item into the index. This should be used rather than directly calling insert on
36-
/// the hashmap because certain items (traits and types) need to have their mappings for trait
37-
/// implementations filled out before they're inserted.
38-
fn insert(&self, item: clean::Item, cache: &Cache) {
39-
let id = item.def_id;
40-
let mut new_item: types::Item = item.into();
41-
if let types::ItemEnum::TraitItem(ref mut t) = new_item.inner {
42-
t.implementors = self.get_trait_implementors(id, cache)
43-
} else if let types::ItemEnum::StructItem(ref mut s) = new_item.inner {
44-
s.impls = self.get_impls(id, cache)
45-
} else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
46-
e.impls = self.get_impls(id, cache)
47-
}
48-
self.index.borrow_mut().insert(id.into(), new_item);
49-
}
50-
5135
fn get_trait_implementors(
52-
&self,
36+
&mut self,
5337
id: rustc_span::def_id::DefId,
5438
cache: &Cache,
5539
) -> Vec<types::Id> {
@@ -61,15 +45,15 @@ impl JsonRenderer {
6145
.iter()
6246
.map(|i| {
6347
let item = &i.impl_item;
64-
self.insert(item.clone(), cache);
48+
self.item(item.clone(), cache).unwrap();
6549
item.def_id.into()
6650
})
6751
.collect()
6852
})
6953
.unwrap_or_default()
7054
}
7155

72-
fn get_impls(&self, id: rustc_span::def_id::DefId, cache: &Cache) -> Vec<types::Id> {
56+
fn get_impls(&mut self, id: rustc_span::def_id::DefId, cache: &Cache) -> Vec<types::Id> {
7357
cache
7458
.impls
7559
.get(&id)
@@ -79,7 +63,7 @@ impl JsonRenderer {
7963
.filter_map(|i| {
8064
let item = &i.impl_item;
8165
if item.def_id.is_local() {
82-
self.insert(item.clone(), cache);
66+
self.item(item.clone(), cache).unwrap();
8367
Some(item.def_id.into())
8468
} else {
8569
None
@@ -90,14 +74,14 @@ impl JsonRenderer {
9074
.unwrap_or_default()
9175
}
9276

93-
fn get_trait_items(&self, cache: &Cache) -> Vec<(types::Id, types::Item)> {
77+
fn get_trait_items(&mut self, cache: &Cache) -> Vec<(types::Id, types::Item)> {
9478
cache
9579
.traits
9680
.iter()
9781
.filter_map(|(id, trait_item)| {
9882
// only need to synthesize items for external traits
9983
if !id.is_local() {
100-
trait_item.items.clone().into_iter().for_each(|i| self.insert(i, cache));
84+
trait_item.items.clone().into_iter().for_each(|i| self.item(i, cache).unwrap());
10185
Some((
10286
(*id).into(),
10387
types::Item {
@@ -150,10 +134,24 @@ impl FormatRenderer for JsonRenderer {
150134
))
151135
}
152136

137+
/// Inserts an item into the index. This should be used rather than directly calling insert on
138+
/// the hashmap because certain items (traits and types) need to have their mappings for trait
139+
/// implementations filled out before they're inserted.
153140
fn item(&mut self, item: clean::Item, cache: &Cache) -> Result<(), Error> {
154-
// Flatten items that recursively store other items by inserting them into the index
141+
// Flatten items that recursively store other items
155142
item.inner.inner_items().for_each(|i| self.item(i.clone(), cache).unwrap());
156-
self.insert(item.clone(), cache);
143+
144+
let id = item.def_id;
145+
let mut new_item: types::Item = item.into();
146+
if let types::ItemEnum::TraitItem(ref mut t) = new_item.inner {
147+
t.implementors = self.get_trait_implementors(id, cache)
148+
} else if let types::ItemEnum::StructItem(ref mut s) = new_item.inner {
149+
s.impls = self.get_impls(id, cache)
150+
} else if let types::ItemEnum::EnumItem(ref mut e) = new_item.inner {
151+
e.impls = self.get_impls(id, cache)
152+
}
153+
154+
self.index.borrow_mut().insert(id.into(), new_item);
157155
Ok(())
158156
}
159157

@@ -166,15 +164,18 @@ impl FormatRenderer for JsonRenderer {
166164
use clean::types::ItemEnum::*;
167165
if let ModuleItem(m) = &item.inner {
168166
for item in &m.items {
169-
match item.inner {
167+
match &item.inner {
170168
// These don't have names so they don't get added to the output by default
171-
ImportItem(_) => self.insert(item.clone(), cache),
172-
ExternCrateItem(_, _) => self.insert(item.clone(), cache),
169+
ImportItem(_) => self.item(item.clone(), cache).unwrap(),
170+
ExternCrateItem(_, _) => self.item(item.clone(), cache).unwrap(),
171+
ImplItem(i) => {
172+
i.items.iter().for_each(|i| self.item(i.clone(), cache).unwrap())
173+
}
173174
_ => {}
174175
}
175176
}
176177
}
177-
self.insert(item.clone(), cache);
178+
self.item(item.clone(), cache).unwrap();
178179
Ok(())
179180
}
180181

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ def check_type(ty):
7171
if ty["kind"] == "resolved_path":
7272
for bound in ty["inner"]["param_names"]:
7373
check_generic_bound(bound)
74-
if args := ty["inner"]["args"]:
74+
args = ty["inner"]["args"]
75+
if args:
7576
if "angle_bracketed" in args:
7677
for arg in args["angle_bracketed"]["args"]:
7778
if "type" in arg:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _check_subset(expected, actual, trace):
6868
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.
71-
if "id" in obj:
71+
if "id" in obj and obj["id"]:
7272
obj["id"] = ID(id)
7373
if "root" in obj:
7474
obj["root"] = ID(id)

0 commit comments

Comments
 (0)