Skip to content

Commit 6c0d66a

Browse files
authored
Auto merge of #35236 - nrc:rustdoc-redirects, r=@alexcrichton
rustdoc: redirect URLs cc #35020 which does this properly r? @alexcrichton
2 parents d6d0590 + 879637f commit 6c0d66a

12 files changed

+270
-136
lines changed

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
326326
url.push_str("/index.html");
327327
}
328328
_ => {
329-
url.push_str(shortty.to_static_str());
329+
url.push_str(shortty.css_class());
330330
url.push_str(".");
331331
url.push_str(fqp.last().unwrap());
332332
url.push_str(".html");

src/librustdoc/html/item_type.rs

+55-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ pub enum ItemType {
4242
AssociatedConst = 18,
4343
}
4444

45+
46+
#[derive(Copy, Eq, PartialEq, Clone)]
47+
pub enum NameSpace {
48+
Type,
49+
Value,
50+
Macro,
51+
}
52+
4553
impl ItemType {
4654
pub fn from_item(item: &clean::Item) -> ItemType {
4755
let inner = match item.inner {
@@ -90,7 +98,7 @@ impl ItemType {
9098
}
9199
}
92100

93-
pub fn to_static_str(&self) -> &'static str {
101+
pub fn css_class(&self) -> &'static str {
94102
match *self {
95103
ItemType::Module => "mod",
96104
ItemType::ExternCrate => "externcrate",
@@ -113,9 +121,55 @@ impl ItemType {
113121
ItemType::AssociatedConst => "associatedconstant",
114122
}
115123
}
124+
125+
pub fn name_space(&self) -> NameSpace {
126+
match *self {
127+
ItemType::Struct |
128+
ItemType::Enum |
129+
ItemType::Module |
130+
ItemType::Typedef |
131+
ItemType::Trait |
132+
ItemType::Primitive |
133+
ItemType::AssociatedType => NameSpace::Type,
134+
135+
ItemType::ExternCrate |
136+
ItemType::Import |
137+
ItemType::Function |
138+
ItemType::Static |
139+
ItemType::Impl |
140+
ItemType::TyMethod |
141+
ItemType::Method |
142+
ItemType::StructField |
143+
ItemType::Variant |
144+
ItemType::Constant |
145+
ItemType::AssociatedConst => NameSpace::Value,
146+
147+
ItemType::Macro => NameSpace::Macro,
148+
}
149+
}
116150
}
117151

118152
impl fmt::Display for ItemType {
153+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154+
self.css_class().fmt(f)
155+
}
156+
}
157+
158+
pub const NAMESPACE_TYPE: &'static str = "t";
159+
pub const NAMESPACE_VALUE: &'static str = "v";
160+
pub const NAMESPACE_MACRO: &'static str = "m";
161+
162+
impl NameSpace {
163+
pub fn to_static_str(&self) -> &'static str {
164+
match *self {
165+
NameSpace::Type => NAMESPACE_TYPE,
166+
NameSpace::Value => NAMESPACE_VALUE,
167+
NameSpace::Macro => NAMESPACE_MACRO,
168+
}
169+
}
170+
}
171+
172+
impl fmt::Display for NameSpace {
119173
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
120174
self.to_static_str().fmt(f)
121175
}

src/librustdoc/html/layout.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub struct Layout {
2424

2525
pub struct Page<'a> {
2626
pub title: &'a str,
27-
pub ty: &'a str,
27+
pub css_class: &'a str,
2828
pub root_path: &'a str,
2929
pub description: &'a str,
3030
pub keywords: &'a str,
@@ -80,7 +80,7 @@ r##"<!DOCTYPE html>
8080
</form>
8181
</nav>
8282
83-
<section id='main' class="content {ty}">{content}</section>
83+
<section id='main' class="content {css_class}">{content}</section>
8484
<section id='search' class="content hidden"></section>
8585
8686
<section class="footer"></section>
@@ -152,7 +152,7 @@ r##"<!DOCTYPE html>
152152
},
153153
content = *t,
154154
root_path = page.root_path,
155-
ty = page.ty,
155+
css_class = page.css_class,
156156
logo = if layout.logo.is_empty() {
157157
"".to_string()
158158
} else {

0 commit comments

Comments
 (0)