diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-03-26 02:50:00 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-03-31 10:58:36 +0300 |
| commit | f5ee822098580f4e99bc0c710427727fe9df802c (patch) | |
| tree | 10242b1e15a3988b6cee4f073607f4b0c6bd8238 /compiler/rustc_resolve/src | |
| parent | ffaf6f0d0ccfbc76da00baded073d10f05ffcbd1 (diff) | |
| download | rust-f5ee822098580f4e99bc0c710427727fe9df802c.tar.gz rust-f5ee822098580f4e99bc0c710427727fe9df802c.zip | |
rustdoc: Fix resolution of `crate`-relative paths in doc links
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 48675fa8827..082da70be39 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -3285,12 +3285,21 @@ impl<'a> Resolver<'a> { &mut self, path_str: &str, ns: Namespace, - module_id: DefId, + mut module_id: DefId, ) -> Option<Res> { let mut segments = Vec::from_iter(path_str.split("::").map(Ident::from_str).map(Segment::from_ident)); - if path_str.starts_with("::") { - segments[0].ident.name = kw::PathRoot; + 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 `module_id`'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; + module_id = module_id.krate.as_def_id(); + } else if segment.ident.name == kw::Empty { + segment.ident.name = kw::PathRoot; + } } let module = self.expect_module(module_id); |
