Skip to content

Commit a7c671b

Browse files
committed
rustdoc: Add missing item types to page titles
Most pages include the item type in the title such as "Struct std::vec::Vec". However it is missing from the pages for foreign functions, type definitions, macros, statics and constants. This adds them so for example, instead of a title of "std::u32::MAX" it is "Constant std::u32::MAX" to match the others.
1 parent 71bdeea commit a7c671b

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

src/librustdoc/html/render.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,12 +1552,21 @@ impl<'a> fmt::Display for Item<'a> {
15521552
} else {
15531553
write!(fmt, "Module ")?;
15541554
},
1555-
clean::FunctionItem(..) => write!(fmt, "Function ")?,
1555+
clean::FunctionItem(..) | clean::ForeignFunctionItem(..) =>
1556+
write!(fmt, "Function ")?,
15561557
clean::TraitItem(..) => write!(fmt, "Trait ")?,
15571558
clean::StructItem(..) => write!(fmt, "Struct ")?,
15581559
clean::EnumItem(..) => write!(fmt, "Enum ")?,
1560+
clean::TypedefItem(..) => write!(fmt, "Type Definition ")?,
1561+
clean::MacroItem(..) => write!(fmt, "Macro ")?,
15591562
clean::PrimitiveItem(..) => write!(fmt, "Primitive Type ")?,
1560-
_ => {}
1563+
clean::StaticItem(..) | clean::ForeignStaticItem(..) =>
1564+
write!(fmt, "Static ")?,
1565+
clean::ConstantItem(..) => write!(fmt, "Constant ")?,
1566+
_ => {
1567+
// We don't generate pages for any other type.
1568+
unreachable!();
1569+
}
15611570
}
15621571
if !self.item.is_primitive() {
15631572
let cur = &self.cx.current;
@@ -1618,7 +1627,10 @@ impl<'a> fmt::Display for Item<'a> {
16181627
clean::StaticItem(ref i) | clean::ForeignStaticItem(ref i) =>
16191628
item_static(fmt, self.cx, self.item, i),
16201629
clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c),
1621-
_ => Ok(())
1630+
_ => {
1631+
// We don't generate pages for any other type.
1632+
unreachable!();
1633+
}
16221634
}
16231635
}
16241636
}

src/test/rustdoc/titles.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// @matches 'foo/index.html' '//h1' 'Crate foo'
14+
15+
// @matches 'foo/foo_mod/index.html' '//h1' 'Module foo::foo_mod'
16+
pub mod foo_mod {
17+
pub struct __Thing {}
18+
}
19+
20+
extern {
21+
// @matches 'foo/fn.foo_ffn.html' '//h1' 'Function foo::foo_ffn'
22+
pub fn foo_ffn();
23+
}
24+
25+
// @matches 'foo/fn.foo_fn.html' '//h1' 'Function foo::foo_fn'
26+
pub fn foo_fn() {}
27+
28+
// @matches 'foo/trait.FooTrait.html' '//h1' 'Trait foo::FooTrait'
29+
pub trait FooTrait {}
30+
31+
// @matches 'foo/struct.FooStruct.html' '//h1' 'Struct foo::FooStruct'
32+
pub struct FooStruct;
33+
34+
// @matches 'foo/enum.FooEnum.html' '//h1' 'Enum foo::FooEnum'
35+
pub enum FooEnum {}
36+
37+
// @matches 'foo/type.FooType.html' '//h1' 'Type Definition foo::FooType'
38+
pub type FooType = FooStruct;
39+
40+
// @matches 'foo/macro.foo_macro.html' '//h1' 'Macro foo::foo_macro'
41+
#[macro_export]
42+
macro_rules! foo_macro {
43+
() => ();
44+
}
45+
46+
// @matches 'foo/primitive.bool.html' '//h1' 'Primitive Type bool'
47+
#[doc(primitive = "bool")]
48+
mod bool {}
49+
50+
// @matches 'foo/static.FOO_STATIC.html' '//h1' 'Static foo::FOO_STATIC'
51+
pub static FOO_STATIC: FooStruct = FooStruct;
52+
53+
extern {
54+
// @matches 'foo/static.FOO_FSTATIC.html' '//h1' 'Static foo::FOO_FSTATIC'
55+
pub static FOO_FSTATIC: FooStruct;
56+
}
57+
58+
// @matches 'foo/constant.FOO_CONSTANT.html' '//h1' 'Constant foo::FOO_CONSTANT'
59+
pub const FOO_CONSTANT: FooStruct = FooStruct;

0 commit comments

Comments
 (0)