rustdoc: Don't crash on crate
references in blocks
This is a regression from #94857.
This commit is contained in:
parent
d5833423a0
commit
c84c5e6439
@ -1849,20 +1849,12 @@ fn resolve_rustdoc_path(
|
|||||||
&mut self,
|
&mut self,
|
||||||
path_str: &str,
|
path_str: &str,
|
||||||
ns: Namespace,
|
ns: Namespace,
|
||||||
mut parent_scope: ParentScope<'a>,
|
parent_scope: ParentScope<'a>,
|
||||||
) -> Option<Res> {
|
) -> Option<Res> {
|
||||||
let mut segments =
|
let mut segments =
|
||||||
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
|
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
|
||||||
if let Some(segment) = segments.first_mut() {
|
if let Some(segment) = segments.first_mut() {
|
||||||
if segment.ident.name == kw::Crate {
|
if segment.ident.name == kw::Empty {
|
||||||
// FIXME: `resolve_path` always resolves `crate` to the current crate root, but
|
|
||||||
// rustdoc wants it to resolve to the `parent_scope`'s crate root. This trick of
|
|
||||||
// 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());
|
|
||||||
} else if segment.ident.name == kw::Empty {
|
|
||||||
segment.ident.name = kw::PathRoot;
|
segment.ident.name = kw::PathRoot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
tests/rustdoc-ui/crate-reference-in-block-module.rs
Normal file
5
tests/rustdoc-ui/crate-reference-in-block-module.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// check-pass
|
||||||
|
fn main() {
|
||||||
|
/// [](crate)
|
||||||
|
struct X;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user