Skip to content

Commit 76f22f4

Browse files
committed
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.
1 parent c2b56fb commit 76f22f4

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
@@ -1308,7 +1308,12 @@ impl Context {
13081308
*slot.borrow_mut() = cx.current.clone();
13091309
});
13101310

1311-
let mut title = cx.current.join("::");
1311+
let mut title = if it.is_primitive() {
1312+
// No need to include the namespace for primitive types
1313+
String::new()
1314+
} else {
1315+
cx.current.join("::")
1316+
};
13121317
if pushname {
13131318
if !title.is_empty() {
13141319
title.push_str("::");
@@ -1559,11 +1564,7 @@ impl<'a> fmt::Display for Item<'a> {
15591564
clean::PrimitiveItem(..) => write!(fmt, "Primitive Type ")?,
15601565
_ => {}
15611566
}
1562-
let is_primitive = match self.item.inner {
1563-
clean::PrimitiveItem(..) => true,
1564-
_ => false,
1565-
};
1566-
if !is_primitive {
1567+
if !self.item.is_primitive() {
15671568
let cur = &self.cx.current;
15681569
let amt = if self.item.is_mod() { cur.len() - 1 } else { cur.len() };
15691570
for (i, component) in cur.iter().enumerate().take(amt) {
@@ -1595,7 +1596,7 @@ impl<'a> fmt::Display for Item<'a> {
15951596
// [src] link in the downstream documentation will actually come back to
15961597
// this page, and this link will be auto-clicked. The `id` attribute is
15971598
// used to find the link to auto-click.
1598-
if self.cx.shared.include_sources && !is_primitive {
1599+
if self.cx.shared.include_sources && !self.item.is_primitive() {
15991600
if let Some(l) = self.href() {
16001601
write!(fmt, "<a id='src-{}' class='srclink' \
16011602
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)