Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustdoc: Don't crash on crate references in blocks #108988

Merged
merged 1 commit into from
Mar 11, 2023
Merged
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
12 changes: 2 additions & 10 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,20 +1849,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
&mut self,
path_str: &str,
ns: Namespace,
mut parent_scope: ParentScope<'a>,
parent_scope: ParentScope<'a>,
) -> Option<Res> {
let mut segments =
Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident));
if let Some(segment) = segments.first_mut() {
if segment.ident.name == kw::Crate {
// 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 {
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
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
fn main() {
/// [](crate)
struct X;
}
Empty file.