Skip to content

Commit 0c193f8

Browse files
committed
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.
1 parent 6df26f8 commit 0c193f8

File tree

4 files changed

+56
-9
lines changed

4 files changed

+56
-9
lines changed

src/librustdoc/html/render/context.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,17 @@ impl<'tcx> Context<'tcx> {
168168
}
169169

170170
fn render_item(&self, it: &clean::Item, pushname: bool) -> String {
171-
let mut title = if it.is_primitive() || it.is_keyword() {
172-
// No need to include the namespace for primitive types and keywords
173-
String::new()
174-
} else {
175-
self.current.join("::")
176-
};
171+
let mut title = String::new();
177172
if pushname {
178-
if !title.is_empty() {
179-
title.push_str("::");
180-
}
181173
title.push_str(&it.name.unwrap().as_str());
182174
}
175+
if !it.is_primitive() && !it.is_keyword() {
176+
if pushname {
177+
title.push_str(" in ");
178+
}
179+
// No need to include the namespace for primitive types and keywords
180+
title.push_str(&self.current.join("::"));
181+
};
183182
title.push_str(" - Rust");
184183
let tyname = it.type_();
185184
let desc = it.doc_value().as_ref().map(|doc| plain_text_summary(&doc));

src/test/rustdoc/crate-title.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/index.html '//head/title' 'foo - Rust'

src/test/rustdoc/item-title.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![crate_name = "foo"]
2+
#![feature(doc_keyword)]
3+
4+
// @has foo/fn.widget_count.html '//head/title' 'widget_count in foo - Rust'
5+
/// blah
6+
pub fn widget_count() {}
7+
8+
// @has foo/struct.Widget.html '//head/title' 'Widget in foo - Rust'
9+
pub struct Widget;
10+
11+
// @has foo/constant.ANSWER.html '//head/title' 'ANSWER in foo - Rust'
12+
pub const ANSWER: u8 = 42;
13+
14+
pub mod blah {
15+
// @has foo/blah/struct.Widget.html '//head/title' 'Widget in foo::blah - Rust'
16+
pub struct Widget;
17+
18+
// @has foo/blah/trait.Awesome.html '//head/title' 'Awesome in foo::blah - Rust'
19+
pub trait Awesome {}
20+
21+
// @has foo/blah/fn.make_widget.html '//head/title' 'make_widget in foo::blah - Rust'
22+
pub fn make_widget() {}
23+
24+
// @has foo/macro.cool_macro.html '//head/title' 'cool_macro in foo - Rust'
25+
#[macro_export]
26+
macro_rules! cool_macro {
27+
($t:tt) => { $t }
28+
}
29+
}
30+
31+
// @has foo/keyword.continue.html '//head/title' 'continue - Rust'
32+
#[doc(keyword = "continue")]
33+
mod continue_keyword {}

src/test/rustdoc/mod-title.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name = "foo"]
2+
3+
// @has foo/bar/index.html '//head/title' 'foo::bar - Rust'
4+
/// blah
5+
pub mod bar {
6+
pub fn a() {}
7+
}
8+
9+
// @has foo/baz/index.html '//head/title' 'foo::baz - Rust'
10+
pub mod baz {
11+
pub fn a() {}
12+
}

0 commit comments

Comments
 (0)