Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write Rustdoc titles like "x in crate::mod - Rust" #84380

Merged
merged 6 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,17 @@ impl<'tcx> Context<'tcx> {
}

fn render_item(&self, it: &clean::Item, pushname: bool) -> String {
syvb marked this conversation as resolved.
Show resolved Hide resolved
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));
Expand Down
3 changes: 3 additions & 0 deletions src/test/rustdoc/crate-title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![crate_name = "foo"]

// @has foo/index.html '//head/title' 'foo - Rust'
syvb marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions src/test/rustdoc/item-title.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions src/test/rustdoc/mod-title.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![crate_name = "foo"]
syvb marked this conversation as resolved.
Show resolved Hide resolved

// @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() {}
}