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.
This commit is contained in:
parent
6df26f897c
commit
0c193f82e7
@ -168,18 +168,17 @@ pub(super) fn root_path(&self) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_item(&self, it: &clean::Item, pushname: bool) -> String {
|
fn render_item(&self, it: &clean::Item, pushname: bool) -> String {
|
||||||
let mut title = if it.is_primitive() || it.is_keyword() {
|
let mut title = String::new();
|
||||||
// No need to include the namespace for primitive types and keywords
|
|
||||||
String::new()
|
|
||||||
} else {
|
|
||||||
self.current.join("::")
|
|
||||||
};
|
|
||||||
if pushname {
|
if pushname {
|
||||||
if !title.is_empty() {
|
|
||||||
title.push_str("::");
|
|
||||||
}
|
|
||||||
title.push_str(&it.name.unwrap().as_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");
|
title.push_str(" - Rust");
|
||||||
let tyname = it.type_();
|
let tyname = it.type_();
|
||||||
let desc = it.doc_value().as_ref().map(|doc| plain_text_summary(&doc));
|
let desc = it.doc_value().as_ref().map(|doc| plain_text_summary(&doc));
|
||||||
|
3
src/test/rustdoc/crate-title.rs
Normal file
3
src/test/rustdoc/crate-title.rs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/index.html '//head/title' 'foo - Rust'
|
33
src/test/rustdoc/item-title.rs
Normal file
33
src/test/rustdoc/item-title.rs
Normal file
@ -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 {}
|
12
src/test/rustdoc/mod-title.rs
Normal file
12
src/test/rustdoc/mod-title.rs
Normal file
@ -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() {}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user