Skip to content

Commit 677126c

Browse files
authored
Rollup merge of #93169 - CraftSpider:rustdoc-clean-inconsistency, r=GuillaumeGomez
Fix inconsistency of local blanket impls When a blanket impl is local, go through HIR instead of middle. This fixes inconsistencies with data detected during JSON generation. Expected this change to take longer. I also tried doing the whole item through existing clean architecture, but it didn't work out trivially, and felt like it would have added more complexity than it removed. Properly fixes #83718
2 parents 8dddc86 + 9220631 commit 677126c

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed

src/librustdoc/clean/blanket_impl.rs

+22-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,27 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
101101

102102
cx.generated_synthetics.insert((ty, trait_def_id));
103103

104+
let hir_imp = impl_def_id.as_local()
105+
.map(|local| cx.tcx.hir().expect_item(local))
106+
.and_then(|item| if let hir::ItemKind::Impl(i) = &item.kind {
107+
Some(i)
108+
} else {
109+
None
110+
});
111+
112+
let items = match hir_imp {
113+
Some(imp) => imp
114+
.items
115+
.iter()
116+
.map(|ii| cx.tcx.hir().impl_item(ii.id).clean(cx))
117+
.collect::<Vec<_>>(),
118+
None => cx.tcx
119+
.associated_items(impl_def_id)
120+
.in_definition_order()
121+
.map(|x| x.clean(cx))
122+
.collect::<Vec<_>>(),
123+
};
124+
104125
impls.push(Item {
105126
name: None,
106127
attrs: Default::default(),
@@ -117,12 +138,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
117138
// the post-inference `trait_ref`, as it's more accurate.
118139
trait_: Some(trait_ref.clean(cx)),
119140
for_: ty.clean(cx),
120-
items: cx
121-
.tcx
122-
.associated_items(impl_def_id)
123-
.in_definition_order()
124-
.map(|x| x.clean(cx))
125-
.collect::<Vec<_>>(),
141+
items,
126142
polarity: ty::ImplPolarity::Positive,
127143
kind: ImplKind::Blanket(box trait_ref.self_ty().clean(cx)),
128144
}),

src/librustdoc/json/mod.rs

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

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

src/test/rustdoc-json/impls/blanket_with_local.rs

+4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
// @has blanket_with_local.json "$.index[*][?(@.name=='Load')]"
55
pub trait Load {
6+
// @has - "$.index[*][?(@.name=='load')]"
67
fn load() {}
8+
// @has - "$.index[*][?(@.name=='write')]"
9+
fn write(self) {}
710
}
811

912
impl<P> Load for P {
1013
fn load() {}
14+
fn write(self) {}
1115
}
1216

1317
// @has - "$.index[*][?(@.name=='Wrapper')]"

0 commit comments

Comments
 (0)