Skip to content

Commit fe540ae

Browse files
committed
RustDoc: Fix bounds linking trait.Foo instead of traitalias.Foo
1 parent 4ae0a8e commit fe540ae

File tree

5 files changed

+50
-16
lines changed

5 files changed

+50
-16
lines changed

src/librustdoc/clean/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: ItemType)
188188
if did.is_local() {
189189
cx.cache.exact_paths.insert(did, fqn);
190190
} else {
191-
cx.cache.external_paths.insert(did, (fqn, ItemType::from(kind)));
191+
cx.cache.external_paths.insert(did, (fqn, kind));
192192
}
193193
}
194194

src/librustdoc/clean/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ impl Clean<GenericBound> for hir::GenericBound<'_> {
157157
impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
158158
fn clean(&self, cx: &mut DocContext<'_>) -> Type {
159159
let (trait_ref, bounds) = *self;
160-
inline::record_extern_fqn(cx, trait_ref.def_id, ItemType::Trait);
160+
let kind = match cx.tcx.def_kind(trait_ref.def_id) {
161+
DefKind::Trait => ItemType::Trait,
162+
DefKind::TraitAlias => ItemType::TraitAlias,
163+
other => bug!("`TraitRef` had unexpected kind {:?}", other),
164+
};
165+
inline::record_extern_fqn(cx, trait_ref.def_id, kind);
161166
let path = external_path(
162167
cx,
163168
cx.tcx.item_name(trait_ref.def_id),

src/librustdoc/formats/cache.rs

+32-14
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
340340
| clean::EnumItem(..)
341341
| clean::TypedefItem(..)
342342
| clean::TraitItem(..)
343+
| clean::TraitAliasItem(..)
343344
| clean::FunctionItem(..)
344345
| clean::ModuleItem(..)
345346
| clean::ForeignFunctionItem(..)
@@ -350,26 +351,43 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
350351
| clean::ForeignTypeItem
351352
| clean::MacroItem(..)
352353
| clean::ProcMacroItem(..)
353-
| clean::VariantItem(..)
354-
if !self.cache.stripped_mod =>
355-
{
356-
// Re-exported items mean that the same id can show up twice
357-
// in the rustdoc ast that we're looking at. We know,
358-
// however, that a re-exported item doesn't show up in the
359-
// `public_items` map, so we can skip inserting into the
360-
// paths map if there was already an entry present and we're
361-
// not a public item.
362-
if !self.cache.paths.contains_key(&item.def_id)
363-
|| self.cache.access_levels.is_public(item.def_id)
364-
{
365-
self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
354+
| clean::VariantItem(..) => {
355+
if !self.cache.stripped_mod {
356+
// Re-exported items mean that the same id can show up twice
357+
// in the rustdoc ast that we're looking at. We know,
358+
// however, that a re-exported item doesn't show up in the
359+
// `public_items` map, so we can skip inserting into the
360+
// paths map if there was already an entry present and we're
361+
// not a public item.
362+
if !self.cache.paths.contains_key(&item.def_id)
363+
|| self.cache.access_levels.is_public(item.def_id)
364+
{
365+
self.cache
366+
.paths
367+
.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
368+
}
366369
}
367370
}
368371
clean::PrimitiveItem(..) => {
369372
self.cache.paths.insert(item.def_id, (self.cache.stack.clone(), item.type_()));
370373
}
371374

372-
_ => {}
375+
clean::ExternCrateItem { .. }
376+
| clean::ImportItem(..)
377+
| clean::OpaqueTyItem(..)
378+
| clean::ImplItem(..)
379+
| clean::TyMethodItem(..)
380+
| clean::MethodItem(..)
381+
| clean::StructFieldItem(..)
382+
| clean::AssocConstItem(..)
383+
| clean::AssocTypeItem(..)
384+
| clean::StrippedItem(..)
385+
| clean::KeywordItem(..) => {
386+
// FIXME: Do these need handling?
387+
// The person writing this comment doesn't know.
388+
// So would rather leave them to an expert,
389+
// as at least the list is better than `_ => {}`.
390+
}
373391
}
374392

375393
// Maintain the parent stack
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(trait_alias)]
2+
#![feature(ptr_metadata)]
3+
4+
#![crate_name = "foo"]
5+
6+
// @has foo/fn.this_never_panics.html '//a[@title="traitalias core::ptr::metadata::Thin"]' 'Thin'
7+
pub fn this_never_panics<T: std::ptr::Thin>() {
8+
assert_eq!(std::mem::size_of::<&T>(), std::mem::size_of::<usize>())
9+
}

src/test/rustdoc/trait_alias.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ pub trait CopyAlias = Copy;
1919
pub trait Alias2 = Copy + Debug;
2020
// @has foo/traitalias.Foo.html '//section[@id="main"]/pre' 'trait Foo<T> = Into<T> + Debug;'
2121
pub trait Foo<T> = Into<T> + Debug;
22+
// @has foo/fn.bar.html '//a[@href="traitalias.Alias2.html"]' 'Alias2'
23+
pub fn bar<T>() where T: Alias2 {}

0 commit comments

Comments
 (0)