Skip to content
Open
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: 7 additions & 0 deletions src/librustdoc/html/render/span_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ fn hir_enclosing_body_owner(tcx: TyCtxt<'_>, hir_id: HirId) -> Option<LocalDefId
return None;
} else if let Some((def_id, _)) = node.associated_body() {
return Some(def_id);
// Items don't have enclosing bodies.
// If we go any further, we might encounter an enclosing function
// (e.g. if we're inside an impl that's inside of a function).
// This would cause us to erroneously consider this function to be the owner
// of the node and produce invalid `HirId`s later.
} else if matches!(node, Node::Item(_)) {
return None;
}
}
None
Expand Down
22 changes: 22 additions & 0 deletions tests/rustdoc/nested-fn-impl-147882.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ compile-flags: -Zunstable-options --generate-link-to-definition

// See: https://github.com/rust-lang/rust/issues/147882

#![crate_name = "foo"]

trait Fun {
fn fun();
}

trait Other {}

impl Fun for () {
fn fun() {
impl<E> Other for E
where
E: std::str::FromStr,
E::Err: Send,
{
}
}
}
Loading