From b7bf22bb582b3ea3f94cc93f6e3536d7fa4a1d15 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 8 Oct 2020 20:49:26 -0400 Subject: [PATCH] try to work on https://github.com/rust-lang/rust/issues/77732 this breaks because it still goes through `resolve_with_disambiguator()`; it should skip that logic altogether --- .../passes/collect_intra_doc_links.rs | 18 +++++++++++++----- src/llvm-project | 2 +- src/test/rustdoc/intra-link-self.rs | 4 ++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index e6eee552c6d48..5a0614c610621 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -797,6 +797,7 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> { }; Some(Res::Def(self.cx.tcx.def_kind(id), id)) }); + debug!("self_id={:?}", self_id); if item.is_mod() && item.attrs.inner_docs { self.mod_ids.push(item.def_id); @@ -921,11 +922,14 @@ impl LinkCollector<'_, '_> { }; // replace `Self` with suitable item's parent name - if path_str.starts_with("Self::") { + let starts_with_self = path_str.starts_with("Self::"); + let starts_with_crate = path_str.starts_with("crate::"); + if starts_with_self || path_str == "Self" { if let Some(id) = self_id { debug!("resolving Self as {:?}", id); // FIXME: this overwrites the link text in both error messages and the link body - path_str = &path_str["Self::".len()..]; + let idx = if starts_with_self { "Self::" } else { "Self" }.len(); + path_str = &path_str[idx..]; } else { return resolution_failure( self, @@ -937,7 +941,7 @@ impl LinkCollector<'_, '_> { smallvec![ResolutionFailure::NoSelf], ); } - } else if path_str.starts_with("crate::") { + } else if starts_with_crate || path_str == "crate" { use rustc_span::def_id::CRATE_DEF_INDEX; // HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented. @@ -945,8 +949,12 @@ impl LinkCollector<'_, '_> { // To work around this, remove it and resolve relative to the crate root instead. // HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous // (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root. - resolved_crate = format!("self::{}", &path_str["crate::".len()..]); - path_str = &resolved_crate; + if starts_with_crate { + resolved_crate = format!("self::{}", &path_str["crate::".len()..]); + path_str = &resolved_crate; + } else { + path_str = "self"; + } module_id = DefId { krate: item.def_id.krate, index: CRATE_DEF_INDEX }; self_id = None; } else { diff --git a/src/llvm-project b/src/llvm-project index e8b556b6a8836..2c56ba7db75b5 160000 --- a/src/llvm-project +++ b/src/llvm-project @@ -1 +1 @@ -Subproject commit e8b556b6a8836147429abe391d6ed18806867b45 +Subproject commit 2c56ba7db75b536b0432228b4760ed79174eca30 diff --git a/src/test/rustdoc/intra-link-self.rs b/src/test/rustdoc/intra-link-self.rs index 81545fec7411b..deea35a20fa48 100644 --- a/src/test/rustdoc/intra-link-self.rs +++ b/src/test/rustdoc/intra-link-self.rs @@ -115,3 +115,7 @@ impl MyTrait for MyStruct { unimplemented!() } } + +/// [Self] +// @has 'foo/struct.Stdout.html' '//a[@href="https://doc.rust-lang.org/nightly/std/io/struct.Stdout.html"]' 'Self' +pub use std::io::Stdout;