about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-06-27 22:35:11 +0200
committerGitHub <noreply@github.com>2022-06-27 22:35:11 +0200
commitd0ae6ebe63913b56ddcb557e836e36b49136944a (patch)
tree698e6f09404603453c315889769462b85b5cf186
parent950934801ee6480e47973dc99a8c9e5eb8e884f0 (diff)
parent9277f959dda23b3a4129b28cc5b059788f6653af (diff)
downloadrust-d0ae6ebe63913b56ddcb557e836e36b49136944a.tar.gz
rust-d0ae6ebe63913b56ddcb557e836e36b49136944a.zip
Rollup merge of #98577 - GuillaumeGomez:associated-items, r=notriddle
Fix "kind" for associated types in trait implementations in rustdoc JSON

Fixes https://github.com/rust-lang/rust/issues/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`
-rw-r--r--src/librustdoc/json/conversions.rs7
-rw-r--r--src/test/rustdoc-json/assoc_items.rs29
2 files changed, 34 insertions, 2 deletions
diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs
index c627dcc30d6..428519dbc16 100644
--- a/src/librustdoc/json/conversions.rs
+++ b/src/librustdoc/json/conversions.rs
@@ -252,8 +252,11 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum {
             bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
             default: None,
         },
-        // FIXME: do not map to Typedef but to a custom variant
-        AssocTypeItem(t, _) => ItemEnum::Typedef(t.into_tcx(tcx)),
+        AssocTypeItem(t, b) => ItemEnum::AssocType {
+            generics: t.generics.into_tcx(tcx),
+            bounds: b.into_iter().map(|x| x.into_tcx(tcx)).collect(),
+            default: t.item_type.map(|ty| ty.into_tcx(tcx)),
+        },
         // `convert_item` early returns `None` for striped items and keywords.
         StrippedItem(_) | KeywordItem(_) => unreachable!(),
         ExternCrateItem { ref src } => ItemEnum::ExternCrate {
diff --git a/src/test/rustdoc-json/assoc_items.rs b/src/test/rustdoc-json/assoc_items.rs
new file mode 100644
index 00000000000..2ee64c9f6eb
--- /dev/null
+++ b/src/test/rustdoc-json/assoc_items.rs
@@ -0,0 +1,29 @@
+#![no_std]
+
+// @has assoc_items.json
+
+pub struct Simple;
+
+impl Simple {
+    // @has - "$.index[*][?(@.name=='CONSTANT')].kind" \"assoc_const\"
+    pub const CONSTANT: usize = 0;
+}
+
+pub trait EasyToImpl {
+    // @has - "$.index[*][?(@.name=='ToDeclare')].kind" \"assoc_type\"
+    // @has - "$.index[*][?(@.name=='ToDeclare')].inner.default" null
+    type ToDeclare;
+    // @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].kind" \"assoc_const\"
+    // @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.default" null
+    const AN_ATTRIBUTE: usize;
+}
+
+impl EasyToImpl for Simple {
+    // @has - "$.index[*][?(@.name=='ToDeclare')].inner.default.kind" \"primitive\"
+    // @has - "$.index[*][?(@.name=='ToDeclare')].inner.default.inner" \"usize\"
+    type ToDeclare = usize;
+    // @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.type.kind" \"primitive\"
+    // @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.type.inner" \"usize\"
+    // @has - "$.index[*][?(@.name=='AN_ATTRIBUTE')].inner.default" \"12\"
+    const AN_ATTRIBUTE: usize = 12;
+}