Skip to content

Commit 5d428ca

Browse files
authored
Rollup merge of #79182 - lochsh:78777-fix-extern-types-ref, r=jyn514
Fix links to extern types in rustdoc (fixes #78777) r? `@jyn514` Fixes #78777. The initial fix we tried was: ```diff diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 8be9482..c4b7086fdb1 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs `@@` -433,8 +433,9 `@@` impl<'a, 'tcx> LinkCollector<'a, 'tcx> { Res::PrimTy(prim) => Some( self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str), ), - Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => { + Res::Def(kind, did) if kind.ns() == Some(Namespace::TypeNS) => { debug!("looking for associated item named {} for item {:?}", item_name, did); + // Checks if item_name belongs to `impl SomeItem` let assoc_item = cx .tcx ``` However, this caused traits to be matched, resulting in a panic when `resolve_associated_trait_item` is called further down in this function. This PR also adds an error message for that panic. Currently it will look something like: ```rust thread 'rustc' panicked at 'Not a type: DefIndex(8624)', compiler/rustc_metadata/src/rmeta/decoder.rs:951:32 ``` I wasn't sure how to get a better debug output than `DefIndex(...)`, and am open to suggestions.
2 parents 4268357 + 32cd4bc commit 5d428ca

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
947947
}
948948

949949
fn get_type(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
950-
self.root.tables.ty.get(self, id).unwrap().decode((self, tcx))
950+
self.root
951+
.tables
952+
.ty
953+
.get(self, id)
954+
.unwrap_or_else(|| panic!("Not a type: {:?}", id))
955+
.decode((self, tcx))
951956
}
952957

953958
fn get_stability(&self, id: DefIndex) -> Option<attr::Stability> {

src/librustdoc/passes/collect_intra_doc_links.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
492492
Res::PrimTy(prim) => Some(
493493
self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str),
494494
),
495-
Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => {
495+
Res::Def(
496+
DefKind::Struct
497+
| DefKind::Union
498+
| DefKind::Enum
499+
| DefKind::TyAlias
500+
| DefKind::ForeignTy,
501+
did,
502+
) => {
496503
debug!("looking for associated item named {} for item {:?}", item_name, did);
497504
// Checks if item_name belongs to `impl SomeItem`
498505
let assoc_item = cx
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(extern_types)]
2+
3+
extern {
4+
pub type ExternType;
5+
}
6+
7+
impl ExternType {
8+
pub fn f(&self) {
9+
10+
}
11+
}
12+
13+
// @has 'intra_link_extern_type/foreigntype.ExternType.html'
14+
// @has 'intra_link_extern_type/fn.links_to_extern_type.html' \
15+
// 'href="../intra_link_extern_type/foreigntype.ExternType.html#method.f"'
16+
/// See also [ExternType::f]
17+
pub fn links_to_extern_type() {
18+
}

0 commit comments

Comments
 (0)