Skip to content

Commit d0ae6eb

Browse files
authored
Rollup merge of #98577 - GuillaumeGomez:associated-items, r=notriddle
Fix "kind" for associated types in trait implementations in rustdoc JSON Fixes #81340. Contrary to what is suggested in the issue, I really think we should distinguish between associated items and "normal" constants and types. cc `@CraftSpider` `@SimonSapin` r? `@notriddle`
2 parents 9509348 + 9277f95 commit d0ae6eb

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/librustdoc/json/conversions.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,11 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
252252
bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
253253
default: None,
254254
},
255-
// FIXME: do not map to Typedef but to a custom variant
256-
AssocTypeItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
255+
AssocTypeItem(t, b) => ItemEnum::AssocType {
256+
generics: t.generics.into_tcx(tcx),
257+
bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
258+
default: t.item_type.map(|ty| ty.into_tcx(tcx)),
259+
},
257260
// `convert_item` early returns `None` for striped items and keywords.
258261
StrippedItem(_) | KeywordItem(_) => unreachable!(),
259262
ExternCrateItem { ref src } => ItemEnum::ExternCrate {

src/test/rustdoc-json/assoc_items.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![no_std]
2+
3+
// @has assoc_items.json
4+
5+
pub struct Simple;
6+
7+
impl Simple {
8+
// @has - "$.index[*][?(@.name=='CONSTANT')].kind" \"assoc_const\"
9+
pub const CONSTANT: usize = 0;
10+
}
11+
12+
pub trait EasyToImpl {
13+
// @has - "$.index[*][?(@.name=='ToDeclare')].kind" \"assoc_type\"
14+
// @has - "$.index[*][?(@.name=='ToDeclare')].inner.default" null
15+
type ToDeclare;
16+
// @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].kind" \"assoc_const\"
17+
// @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.default" null
18+
const AN_ATTRIBUTE: usize;
19+
}
20+
21+
impl EasyToImpl for Simple {
22+
// @has - "$.index[*][?(@.name=='ToDeclare')].inner.default.kind" \"primitive\"
23+
// @has - "$.index[*][?(@.name=='ToDeclare')].inner.default.inner" \"usize\"
24+
type ToDeclare = usize;
25+
// @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.type.kind" \"primitive\"
26+
// @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.type.inner" \"usize\"
27+
// @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.default" \"12\"
28+
const AN_ATTRIBUTE: usize = 12;
29+
}

0 commit comments

Comments
 (0)