Skip to content

Commit

Permalink
rustdoc: Don't crash on crate references in blocks
Browse files Browse the repository at this point in the history
This is a regression from #94857.
  • Loading branch information
adrianheine committed Mar 10, 2023
1 parent d583342 commit 652291c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,8 +1860,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// replacing `crate` with `self` and changing the current module should achieve
// the same effect.
segment.ident.name = kw::SelfLower;
parent_scope.module =
self.expect_module(parent_scope.module.def_id().krate.as_def_id());
let mut new_parent = parent_scope.module;
while matches!(new_parent.kind, ModuleKind::Block) {
new_parent = new_parent.parent.unwrap();
}
parent_scope.module = self.expect_module(new_parent.def_id().krate.as_def_id());
} else if segment.ident.name == kw::Empty {
segment.ident.name = kw::PathRoot;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/rustdoc-ui/crate-reference-in-block-module.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// check-pass
fn main() {
/// [](crate)
struct X;
}
Empty file.

0 comments on commit 652291c

Please sign in to comment.