about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSmitty <me@smitop.com>2021-04-20 17:31:18 -0400
committerSmitty <me@smitop.com>2021-04-20 17:31:18 -0400
commit0c193f82e7525cba88d67320fc3d706683a9cb9b (patch)
tree89a4f5fe66226df4f17de99ef6e3eb69e4f99f34
parent6df26f897cffb2d86880544bb451c6b5f8509b2d (diff)
downloadrust-0c193f82e7525cba88d67320fc3d706683a9cb9b.tar.gz
rust-0c193f82e7525cba88d67320fc3d706683a9cb9b.zip
Write Rustdoc titles like "x in crate::mod - Rust"
This makes Rustdoc titles for items read like
"x in cratename::blah::foo - Rust". Title for modules and other
non-items are unchanged, and still read like
"doccratenameconst::blah::foo - Rust". This makes managing several open
Rustdoc tabs easier.

Closes #84371.
-rw-r--r--src/librustdoc/html/render/context.rs17
-rw-r--r--src/test/rustdoc/crate-title.rs3
-rw-r--r--src/test/rustdoc/item-title.rs33
-rw-r--r--src/test/rustdoc/mod-title.rs12
4 files changed, 56 insertions, 9 deletions
diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs
index 05d20013859..3fcf972a5b8 100644
--- a/src/librustdoc/html/render/context.rs
+++ b/src/librustdoc/html/render/context.rs
@@ -168,18 +168,17 @@ impl<'tcx> Context<'tcx> {
     }
 
     fn render_item(&self, it: &clean::Item, pushname: bool) -> String {
-        let mut title = if it.is_primitive() || it.is_keyword() {
-            // No need to include the namespace for primitive types and keywords
-            String::new()
-        } else {
-            self.current.join("::")
-        };
+        let mut title = String::new();
         if pushname {
-            if !title.is_empty() {
-                title.push_str("::");
-            }
             title.push_str(&it.name.unwrap().as_str());
         }
+        if !it.is_primitive() && !it.is_keyword() {
+            if pushname {
+                title.push_str(" in ");
+            }
+            // No need to include the namespace for primitive types and keywords
+            title.push_str(&self.current.join("::"));
+        };
         title.push_str(" - Rust");
         let tyname = it.type_();
         let desc = it.doc_value().as_ref().map(|doc| plain_text_summary(&doc));
diff --git a/src/test/rustdoc/crate-title.rs b/src/test/rustdoc/crate-title.rs
new file mode 100644
index 00000000000..6f96f98e707
--- /dev/null
+++ b/src/test/rustdoc/crate-title.rs
@@ -0,0 +1,3 @@
+#![crate_name = "foo"]
+
+// @has foo/index.html '//head/title' 'foo - Rust'
diff --git a/src/test/rustdoc/item-title.rs b/src/test/rustdoc/item-title.rs
new file mode 100644
index 00000000000..d0fbdf95ddc
--- /dev/null
+++ b/src/test/rustdoc/item-title.rs
@@ -0,0 +1,33 @@
+#![crate_name = "foo"]
+#![feature(doc_keyword)]
+
+// @has foo/fn.widget_count.html '//head/title' 'widget_count in foo - Rust'
+/// blah
+pub fn widget_count() {}
+
+// @has foo/struct.Widget.html '//head/title' 'Widget in foo - Rust'
+pub struct Widget;
+
+// @has foo/constant.ANSWER.html '//head/title' 'ANSWER in foo - Rust'
+pub const ANSWER: u8 = 42;
+
+pub mod blah {
+    // @has foo/blah/struct.Widget.html '//head/title' 'Widget in foo::blah - Rust'
+    pub struct Widget;
+
+    // @has foo/blah/trait.Awesome.html '//head/title' 'Awesome in foo::blah - Rust'
+    pub trait Awesome {}
+
+    // @has foo/blah/fn.make_widget.html '//head/title' 'make_widget in foo::blah - Rust'
+    pub fn make_widget() {}
+
+    // @has foo/macro.cool_macro.html '//head/title' 'cool_macro in foo - Rust'
+    #[macro_export]
+    macro_rules! cool_macro {
+        ($t:tt) => { $t }
+    }
+}
+
+// @has foo/keyword.continue.html '//head/title' 'continue - Rust'
+#[doc(keyword = "continue")]
+mod continue_keyword {}
diff --git a/src/test/rustdoc/mod-title.rs b/src/test/rustdoc/mod-title.rs
new file mode 100644
index 00000000000..6b7f67d17ab
--- /dev/null
+++ b/src/test/rustdoc/mod-title.rs
@@ -0,0 +1,12 @@
+#![crate_name = "foo"]
+
+// @has foo/bar/index.html '//head/title' 'foo::bar - Rust'
+/// blah
+pub mod bar {
+    pub fn a() {}
+}
+
+// @has foo/baz/index.html '//head/title' 'foo::baz - Rust'
+pub mod baz {
+    pub fn a() {}
+}