about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Nelson <jyn514@gmail.com>2020-12-02 10:07:29 -0500
committerJoshua Nelson <jyn514@gmail.com>2020-12-02 10:25:16 -0500
commit4e7a2dcabb0aa42f297284ead946d5787027d035 (patch)
treefd2fb03d2667c770c1c1112ae8f5d1602461ed31
parent18aa5ee209df502e48180b1b607520cfd370990f (diff)
downloadrust-4e7a2dcabb0aa42f297284ead946d5787027d035.tar.gz
rust-4e7a2dcabb0aa42f297284ead946d5787027d035.zip
Use `item_name` instead of pretty printing
Pretty printing would add a `r#` prefix to raw identifiers, which was
not correct. In general I think this change makes sense -
pretty-printing is for showing to the *user*, `item_name` is suitable to
pass to resolve.
-rw-r--r--src/librustdoc/passes/collect_intra_doc_links.rs13
-rw-r--r--src/test/rustdoc/intra-doc/raw-ident-self.rs13
2 files changed, 22 insertions, 4 deletions
diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs
index 3dcc0f240a3..551c086a8d4 100644
--- a/src/librustdoc/passes/collect_intra_doc_links.rs
+++ b/src/librustdoc/passes/collect_intra_doc_links.rs
@@ -847,12 +847,17 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
 
         // FIXME(jynelson): this shouldn't go through stringification, rustdoc should just use the DefId directly
         let self_name = self_id.and_then(|self_id| {
+            use ty::TyKind;
             if matches!(self.cx.tcx.def_kind(self_id), DefKind::Impl) {
-                // using `ty.to_string()` directly has issues with shortening paths
+                // using `ty.to_string()` (or any variant) has issues with raw idents
                 let ty = self.cx.tcx.type_of(self_id);
-                let name = ty::print::with_crate_prefix(|| ty.to_string());
-                debug!("using type_of(): {}", name);
-                Some(name)
+                let name = match ty.kind() {
+                    TyKind::Adt(def, _) => Some(self.cx.tcx.item_name(def.did).to_string()),
+                    other if other.is_primitive() => Some(ty.to_string()),
+                    _ => None,
+                };
+                debug!("using type_of(): {:?}", name);
+                name
             } else {
                 let name = self.cx.tcx.opt_item_name(self_id).map(|sym| sym.to_string());
                 debug!("using item_name(): {:?}", name);
diff --git a/src/test/rustdoc/intra-doc/raw-ident-self.rs b/src/test/rustdoc/intra-doc/raw-ident-self.rs
new file mode 100644
index 00000000000..d289797f146
--- /dev/null
+++ b/src/test/rustdoc/intra-doc/raw-ident-self.rs
@@ -0,0 +1,13 @@
+#![deny(broken_intra_doc_links)]
+pub mod r#impl {
+    pub struct S;
+
+    impl S {
+        /// See [Self::b].
+        // @has raw_ident_self/impl/struct.S.html
+        // @has - '//a[@href="../../raw_ident_self/impl/struct.S.html#method.b"]' 'Self::b'
+        pub fn a() {}
+
+        pub fn b() {}
+    }
+}