Skip to content

Commit 530c884

Browse files
authored
Rollup merge of #92860 - CraftSpider:rustdoc-json-impl-ice, r=jsha
Fix errors on blanket impls by ignoring the children of generated impls Related to #83718 We can safely skip the children, as they don't contain any new info, and may be subtly different for reasons hard to track down, in ways that are consistently worse than the actual generic impl.
2 parents 10a7204 + 474e091 commit 530c884

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Diff for: src/librustdoc/json/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,21 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
171171
/// the hashmap because certain items (traits and types) need to have their mappings for trait
172172
/// implementations filled out before they're inserted.
173173
fn item(&mut self, item: clean::Item) -> Result<(), Error> {
174+
let local_blanket_impl = match item.def_id {
175+
clean::ItemId::Blanket { impl_id, .. } => impl_id.is_local(),
176+
clean::ItemId::Auto { .. }
177+
| clean::ItemId::DefId(_)
178+
| clean::ItemId::Primitive(_, _) => false,
179+
};
180+
174181
// Flatten items that recursively store other items
175-
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
182+
// FIXME(CraftSpider): We skip children of local blanket implementations, as we'll have
183+
// already seen the actual generic impl, and the generated ones don't need documenting.
184+
// This is necessary due to the visibility, return type, and self arg of the generated
185+
// impls not quite matching, and will no longer be necessary when the mismatch is fixed.
186+
if !local_blanket_impl {
187+
item.kind.inner_items().for_each(|i| self.item(i.clone()).unwrap());
188+
}
176189

177190
let id = item.def_id;
178191
if let Some(mut new_item) = self.convert_item(item) {

Diff for: src/test/rustdoc-json/impls/blanket_with_local.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Test for the ICE in rust/83718
2+
// A blanket impl plus a local type together shouldn't result in mismatched ID issues
3+
4+
// @has blanket_with_local.json "$.index[*][?(@.name=='Load')]"
5+
pub trait Load {
6+
fn load() {}
7+
}
8+
9+
impl<P> Load for P {
10+
fn load() {}
11+
}
12+
13+
// @has - "$.index[*][?(@.name=='Wrapper')]"
14+
pub struct Wrapper {}

0 commit comments

Comments
 (0)