Skip to content

Commit d1e5e3a

Browse files
authored
Auto merge of #34587 - ollie27:rustdoc_prim_titles, r=steveklabnik
rustdoc: Remove paths from primitive page <title> tags Currently primitive pages have a title like "std::u8 - Rust" this changes it to "u8 - Rust" as "std::u8" is the name of a module not a primitive type.
2 parents 731d375 + 76f22f4 commit d1e5e3a

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/librustdoc/clean/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,9 @@ impl Item {
317317
pub fn is_ty_method(&self) -> bool {
318318
ItemType::from_item(self) == ItemType::TyMethod
319319
}
320+
pub fn is_primitive(&self) -> bool {
321+
ItemType::from_item(self) == ItemType::Primitive
322+
}
320323
pub fn is_stripped(&self) -> bool {
321324
match self.inner { StrippedItem(..) => true, _ => false }
322325
}

src/librustdoc/html/render.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,12 @@ impl Context {
13041304
*slot.borrow_mut() = cx.current.clone();
13051305
});
13061306

1307-
let mut title = cx.current.join("::");
1307+
let mut title = if it.is_primitive() {
1308+
// No need to include the namespace for primitive types
1309+
String::new()
1310+
} else {
1311+
cx.current.join("::")
1312+
};
13081313
if pushname {
13091314
if !title.is_empty() {
13101315
title.push_str("::");
@@ -1555,11 +1560,7 @@ impl<'a> fmt::Display for Item<'a> {
15551560
clean::PrimitiveItem(..) => write!(fmt, "Primitive Type ")?,
15561561
_ => {}
15571562
}
1558-
let is_primitive = match self.item.inner {
1559-
clean::PrimitiveItem(..) => true,
1560-
_ => false,
1561-
};
1562-
if !is_primitive {
1563+
if !self.item.is_primitive() {
15631564
let cur = &self.cx.current;
15641565
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
15651566
for (i, component) in cur.iter().enumerate().take(amt) {
@@ -1591,7 +1592,7 @@ impl<'a> fmt::Display for Item<'a> {
15911592
// [src] link in the downstream documentation will actually come back to
15921593
// this page, and this link will be auto-clicked. The `id` attribute is
15931594
// used to find the link to auto-click.
1594-
if self.cx.shared.include_sources && !is_primitive {
1595+
if self.cx.shared.include_sources && !self.item.is_primitive() {
15951596
if let Some(l) = self.href() {
15961597
write!(fmt, "<a id='src-{}' class='srclink' \
15971598
href='{}' title='{}'>[src]</a>",

src/test/rustdoc/prim-title.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_name = "foo"]
12+
13+
// @has foo/primitive.u8.html '//head/title' 'u8 - Rust'
14+
// @!has - '//head/title' 'foo'
15+
#[doc(primitive = "u8")]
16+
/// `u8` docs
17+
mod u8 {}

0 commit comments

Comments
 (0)