Skip to content
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

RustDoc: Fix bounds linking trait.Foo instead of traitalias.Foo #84811

Merged
merged 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType)
if did.is_local() {
cx.cache.exact_paths.insert(did, fqn);
} else {
cx.cache.external_paths.insert(did, (fqn, ItemType::from(kind)));
cx.cache.external_paths.insert(did, (fqn, kind));
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
fn clean(&self, cx: &mut DocContext<'_>) -> Type {
let (trait_ref, bounds) = *self;
inline::record_extern_fqn(cx, trait_ref.def_id, ItemType::Trait);
let kind = match cx.tcx.def_kind(trait_ref.def_id) {
DefKind::Trait => ItemType::Trait,
DefKind::TraitAlias => ItemType::TraitAlias,
other => bug!("`TraitRef` had unexpected kind {:?}", other),
};
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
let path = external_path(
cx,
cx.tcx.item_name(trait_ref.def_id),
Expand Down
46 changes: 32 additions & 14 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::EnumItem(..)
| clean::TypedefItem(..)
| clean::TraitItem(..)
| clean::TraitAliasItem(..)
| clean::FunctionItem(..)
| clean::ModuleItem(..)
| clean::ForeignFunctionItem(..)
Expand All @@ -350,26 +351,43 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
| clean::ForeignTypeItem
| clean::MacroItem(..)
| clean::ProcMacroItem(..)
| clean::VariantItem(..)
if !self.cache.stripped_mod =>
{
// Re-exported items mean that the same id can show up twice
// in the rustdoc ast that we're looking at. We know,
// however, that a re-exported item doesn't show up in the
// `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're
// not a public item.
if !self.cache.paths.contains_key(&item.def_id)
|| self.cache.access_levels.is_public(item.def_id)
{
self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
| clean::VariantItem(..) => {
if !self.cache.stripped_mod {
// Re-exported items mean that the same id can show up twice
// in the rustdoc ast that we're looking at. We know,
// however, that a re-exported item doesn't show up in the
// `public_items` map, so we can skip inserting into the
// paths map if there was already an entry present and we're
// not a public item.
if !self.cache.paths.contains_key(&item.def_id)
|| self.cache.access_levels.is_public(item.def_id)
{
self.cache
.paths
.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
}
}
}
clean::PrimitiveItem(..) => {
self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
}

_ => {}
clean::ExternCrateItem { .. }
Copy link
Member

Choose a reason for hiding this comment

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

This seems to work ok as a re-export:
image
I don't think extern crates can show up anywhere else, so this seems fine for now.

| clean::ImportItem(..)
| clean::OpaqueTyItem(..)
Copy link
Member

Choose a reason for hiding this comment

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

This seems to work ok:
image
image

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, is this one TAIT? I would have guessed https://doc.rust-lang.org/nightly/unstable-book/language-features/extern-types.html

But overall, I'd like to leave the match as-is for this PR, if that's ok. Then someone else can audit them later and move them to different sections with comments about why they're ok to be skipped, or whatever.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, that seems good to me.

| clean::ImplItem(..)
| clean::TyMethodItem(..)
| clean::MethodItem(..)
| clean::StructFieldItem(..)
| clean::AssocConstItem(..)
| clean::AssocTypeItem(..)
| clean::StrippedItem(..)
| clean::KeywordItem(..) => {
// FIXME: Do these need handling?
// The person writing this comment doesn't know.
// So would rather leave them to an expert,
// as at least the list is better than `_ => {}`.
}
}

// Maintain the parent stack
Expand Down
9 changes: 9 additions & 0 deletions src/test/rustdoc/trait-alias-mention.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(trait_alias)]
#![feature(ptr_metadata)]

#![crate_name = "foo"]

// @has foo/fn.this_never_panics.html '//a[@title="traitalias core::ptr::metadata::Thin"]' 'Thin'
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
pub fn this_never_panics<T: std::ptr::Thin>() {
assert_eq!(std::mem::size_of::<&T>(), std::mem::size_of::<usize>())
}
2 changes: 2 additions & 0 deletions src/test/rustdoc/trait_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ pub trait CopyAlias = Copy;
pub trait Alias2 = Copy + Debug;
// @has foo/traitalias.Foo.html '//section[@id="main"]/pre' 'trait Foo<T> = Into<T> + Debug;'
pub trait Foo<T> = Into<T> + Debug;
// @has foo/fn.bar.html '//a[@href="traitalias.Alias2.html"]' 'Alias2'
pub fn bar<T>() where T: Alias2 {}