Skip to content

Commit c84c5e6

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

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Diff for: compiler/rustc_resolve/src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1849,20 +1849,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
18491849
&mut self,
18501850
path_str: &str,
18511851
ns: Namespace,
1852-
mut parent_scope: ParentScope<'a>,
1852+
parent_scope: ParentScope<'a>,
18531853
) -> Option<Res> {
18541854
let mut segments =
18551855
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
18561856
if let Some(segment) = segments.first_mut() {
1857-
if segment.ident.name == kw::Crate {
1858-
// FIXME: `resolve_path` always resolves `crate` to the current crate root, but
1859-
// rustdoc wants it to resolve to the `parent_scope`'s crate root. This trick of
1860-
// replacing `crate` with `self` and changing the current module should achieve
1861-
// the same effect.
1862-
segment.ident.name = kw::SelfLower;
1863-
parent_scope.module =
1864-
self.expect_module(parent_scope.module.def_id().krate.as_def_id());
1865-
} else if segment.ident.name == kw::Empty {
1857+
if segment.ident.name == kw::Empty {
18661858
segment.ident.name = kw::PathRoot;
18671859
}
18681860
}

Diff for: tests/rustdoc-ui/crate-reference-in-block-module.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// check-pass
2+
fn main() {
3+
/// [](crate)
4+
struct X;
5+
}

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

Whitespace-only changes.

0 commit comments

Comments
 (0)