Skip to content

Commit 25e767b

Browse files
Ignore impl associated types in jump to def feature
1 parent d528a49 commit 25e767b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/librustdoc/html/render/span_map.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,13 @@ impl SpanMapVisitor<'_> {
205205
// panicking.
206206
fn hir_enclosing_body_owner(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<LocalDefId> {
207207
for (_, node) in tcx.hir_parent_iter(hir_id) {
208-
if let Some((def_id, _)) = node.associated_body() {
208+
// FIXME: associated type impl items don't have an associated body, so we don't handle
209+
// them currently.
210+
if let Node::ImplItem(impl_item) = node
211+
&& matches!(impl_item.kind, rustc_hir::ImplItemKind::Type(_))
212+
{
213+
return None;
214+
} else if let Some((def_id, _)) = node.associated_body() {
209215
return Some(def_id);
210216
}
211217
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This test ensures that associated types don't crash rustdoc jump to def.
2+
3+
//@ compile-flags: -Zunstable-options --generate-link-to-definition
4+
5+
6+
#![crate_name = "foo"]
7+
8+
//@ has 'src/foo/jump-to-def-ice-assoc-types.rs.html'
9+
10+
pub trait Trait {
11+
type Node;
12+
}
13+
14+
pub fn y<G: Trait>() {
15+
struct X<G>(G);
16+
17+
impl<G: Trait> Trait for X<G> {
18+
type Node = G::Node;
19+
}
20+
}

0 commit comments

Comments
 (0)