Skip to content

Fix "kind" for associated types in trait implementations in rustdoc JSON #98577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My nightly regression test job for cargo public-api found a regression with this change (job)

Reported as #98658

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)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparing with the HTML rendering code I think this line should be something like

default: t.item_type.unwrap_or(t.type_).map(|ty| ty.into_tcx(tcx))

I will maybe have time later today to try that fix.

},
// `convert_item` early returns `None` for striped items and keywords.
StrippedItem(_) | KeywordItem(_) => unreachable!(),
ExternCrateItem { ref src } => ItemEnum::ExternCrate {
Expand Down
29 changes: 29 additions & 0 deletions src/test/rustdoc-json/assoc_items.rs
Original file line number Diff line number Diff line change
@@ -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;
}