Skip to content

Commit 652291c

Browse files
committed
rustdoc: Don't crash on crate references in blocks
This is a regression from #94857.
1 parent d583342 commit 652291c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/rustc_resolve/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18601860
// replacing `crate` with `self` and changing the current module should achieve
18611861
// the same effect.
18621862
segment.ident.name = kw::SelfLower;
1863-
parent_scope.module =
1864-
self.expect_module(parent_scope.module.def_id().krate.as_def_id());
1863+
let mut new_parent = parent_scope.module;
1864+
while matches!(new_parent.kind, ModuleKind::Block) {
1865+
new_parent = new_parent.parent.unwrap();
1866+
}
1867+
parent_scope.module = self.expect_module(new_parent.def_id().krate.as_def_id());
18651868
} else if segment.ident.name == kw::Empty {
18661869
segment.ident.name = kw::PathRoot;
18671870
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// check-pass
2+
fn main() {
3+
/// [](crate)
4+
struct X;
5+
}

tests/rustdoc-ui/crate-reference-in-block-module.stderr

Whitespace-only changes.

0 commit comments

Comments
 (0)