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

rustdoc: simplify URLs #35020

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 9 additions & 9 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const MAX_THREE_B: u32 = 0x10000;
/// Point], but only ones within a certain range. `MAX` is the highest valid
/// code point that's a valid [Unicode Scalar Value].
///
/// [`char`]: ../../std/primitive.char.html
/// [`char`]: ../../std/char.t.html
/// [Unicode Scalar Value]: http://www.unicode.org/glossary/#unicode_scalar_value
/// [Code Point]: http://www.unicode.org/glossary/#code_point
#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -90,8 +90,8 @@ pub const MAX: char = '\u{10ffff}';
/// [`char`]s. `from_u32()` will return `None` if the input is not a valid value
/// for a [`char`].
///
/// [`char`]: ../../std/primitive.char.html
/// [`u32`]: ../../std/primitive.u32.html
/// [`char`]: ../../std/char.t.html
/// [`u32`]: ../../std/u32.t.html
/// [`as`]: ../../book/casting-between-types.html#as
///
/// For an unsafe version of this function which ignores these checks, see
Expand Down Expand Up @@ -147,8 +147,8 @@ pub fn from_u32(i: u32) -> Option<char> {
/// [`char`]s. `from_u32_unchecked()` will ignore this, and blindly cast to
/// [`char`], possibly creating an invalid one.
///
/// [`char`]: ../../std/primitive.char.html
/// [`u32`]: ../../std/primitive.u32.html
/// [`char`]: ../../std/char.t.html
/// [`u32`]: ../../std/u32.t.html
/// [`as`]: ../../book/casting-between-types.html#as
///
/// # Safety
Expand Down Expand Up @@ -413,8 +413,8 @@ impl CharExt for char {
/// This `struct` is created by the [`escape_unicode()`] method on [`char`]. See
/// its documentation for more.
///
/// [`escape_unicode()`]: ../../std/primitive.char.html#method.escape_unicode
/// [`char`]: ../../std/primitive.char.html
/// [`escape_unicode()`]: ../../std/char.t.html#method.escape_unicode
/// [`char`]: ../../std/char.t.html
#[derive(Clone, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct EscapeUnicode {
Expand Down Expand Up @@ -521,8 +521,8 @@ impl ExactSizeIterator for EscapeUnicode {
/// This `struct` is created by the [`escape_default()`] method on [`char`]. See
/// its documentation for more.
///
/// [`escape_default()`]: ../../std/primitive.char.html#method.escape_default
/// [`char`]: ../../std/primitive.char.html
/// [`escape_default()`]: ../../std/char.t.html#method.escape_default
/// [`char`]: ../../std/char.t.html
#[derive(Clone, Debug)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct EscapeDefault {
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.

//! Operations and constants for 32-bits floats (`f32` type)
//!
//! *[See also the `f32` primitive type](../../std/f32.t.html).*

// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// except according to those terms.

//! Operations and constants for 64-bits floats (`f64` type)
//!
//! *[See also the `f64` primitive type](../../std/f64.t.html).*

// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 16-bit signed integer type.
//!
//! *[See also the `i16` primitive type](../../std/primitive.i16.html).*
//! *[See also the `i16` primitive type](../../std/i16.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 32-bit signed integer type.
//!
//! *[See also the `i32` primitive type](../../std/primitive.i32.html).*
//! *[See also the `i32` primitive type](../../std/i32.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 64-bit signed integer type.
//!
//! *[See also the `i64` primitive type](../../std/primitive.i64.html).*
//! *[See also the `i64` primitive type](../../std/i64.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 8-bit signed integer type.
//!
//! *[See also the `i8` primitive type](../../std/primitive.i8.html).*
//! *[See also the `i8` primitive type](../../std/i8.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/isize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The pointer-sized signed integer type.
//!
//! *[See also the `isize` primitive type](../../std/primitive.isize.html).*
//! *[See also the `isize` primitive type](../../std/isize.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 16-bit unsigned integer type.
//!
//! *[See also the `u16` primitive type](../../std/primitive.u16.html).*
//! *[See also the `u16` primitive type](../../std/u16.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 32-bit unsigned integer type.
//!
//! *[See also the `u32` primitive type](../../std/primitive.u32.html).*
//! *[See also the `u32` primitive type](../../std/u32.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 64-bit unsigned integer type.
//!
//! *[See also the `u64` primitive type](../../std/primitive.u64.html).*
//! *[See also the `u64` primitive type](../../std/u64.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The 8-bit unsigned integer type.
//!
//! *[See also the `u8` primitive type](../../std/primitive.u8.html).*
//! *[See also the `u8` primitive type](../../std/u8.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/num/usize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

//! The pointer-sized unsigned integer type.
//!
//! *[See also the `usize` primitive type](../../std/primitive.usize.html).*
//! *[See also the `usize` primitive type](../../std/usize.t.html).*

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
8 changes: 5 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2727,7 +2727,7 @@ pub struct Macro {

impl Clean<Item> for doctree::Macro {
fn clean(&self, cx: &DocContext) -> Item {
let name = format!("{}!", self.name.clean(cx));
let name = self.name.clean(cx);
Item {
name: Some(name.clone()),
attrs: self.attrs.clean(cx),
Expand All @@ -2738,8 +2738,10 @@ impl Clean<Item> for doctree::Macro {
def_id: cx.map.local_def_id(self.id),
inner: MacroItem(Macro {
source: format!("macro_rules! {} {{\n{}}}",
name.trim_right_matches('!'), self.matchers.iter().map(|span|
format!(" {} => {{ ... }};\n", span.to_src(cx))).collect::<String>()),
name,
self.matchers.iter().map(|span| {
format!(" {} => {{ ... }};\n", span.to_src(cx))
}).collect::<String>()),
imported_from: self.imported_from.clean(cx),
}),
}
Expand Down
10 changes: 5 additions & 5 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
url.push_str("/index.html");
}
_ => {
url.push_str(shortty.to_static_str());
url.push_str(".");
url.push_str(fqp.last().unwrap());
url.push_str(".");
url.push_str(shortty.name_space().to_static_str());
url.push_str(".html");
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ fn primitive_link(f: &mut fmt::Formatter,
Some(&LOCAL_CRATE) => {
let len = CURRENT_LOCATION_KEY.with(|s| s.borrow().len());
let len = if len == 0 {0} else {len - 1};
write!(f, "<a class='primitive' href='{}primitive.{}.html'>",
write!(f, "<a class='primitive' href='{}{}.t.html'>",
repeat("../").take(len).collect::<String>(),
prim.to_url_str())?;
needs_termination = true;
Expand All @@ -397,7 +397,7 @@ fn primitive_link(f: &mut fmt::Formatter,
(_, render::Unknown) => None,
};
if let Some((cname, root)) = loc {
write!(f, "<a class='primitive' href='{}{}/primitive.{}.html'>",
write!(f, "<a class='primitive' href='{}{}/{}.t.html'>",
root,
cname,
prim.to_url_str())?;
Expand Down Expand Up @@ -439,7 +439,7 @@ impl<'a> fmt::Display for HRef<'a> {
match href(self.did) {
Some((url, shortty, fqp)) => {
write!(f, "<a class='{}' href='{}' title='{}'>{}</a>",
shortty, url, fqp.join("::"), self.text)
shortty.css_class(), url, fqp.join("::"), self.text)
}
_ => write!(f, "{}", self.text),
}
Expand Down
51 changes: 49 additions & 2 deletions src/librustdoc/html/item_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ pub enum ItemType {
AssociatedConst = 18,
}

#[derive(Copy, Eq, PartialEq, Clone)]
pub enum NameSpace {
Type,
Value,
Macro,
}

impl ItemType {
pub fn from_item(item: &clean::Item) -> ItemType {
let inner = match item.inner {
Expand Down Expand Up @@ -90,7 +97,7 @@ impl ItemType {
}
}

pub fn to_static_str(&self) -> &'static str {
pub fn css_class(&self) -> &'static str {
match *self {
ItemType::Module => "mod",
ItemType::ExternCrate => "externcrate",
Expand All @@ -113,9 +120,49 @@ impl ItemType {
ItemType::AssociatedConst => "associatedconstant",
}
}

pub fn name_space(&self) -> NameSpace {
match *self {
ItemType::Struct |
ItemType::Enum |
ItemType::Module |
ItemType::Typedef |
ItemType::Trait |
ItemType::Primitive |
ItemType::AssociatedType => NameSpace::Type,

ItemType::ExternCrate |
ItemType::Import |
ItemType::Function |
ItemType::Static |
ItemType::Impl |
ItemType::TyMethod |
ItemType::Method |
ItemType::StructField |
ItemType::Variant |
ItemType::Constant |
ItemType::AssociatedConst => NameSpace::Value,

ItemType::Macro => NameSpace::Macro,
}
}
}

pub const NAMESPACE_TYPE: &'static str = "t";
pub const NAMESPACE_VALUE: &'static str = "v";
pub const NAMESPACE_MACRO: &'static str = "m";

impl NameSpace {
pub fn to_static_str(&self) -> &'static str {
match *self {
NameSpace::Type => NAMESPACE_TYPE,
NameSpace::Value => NAMESPACE_VALUE,
NameSpace::Macro => NAMESPACE_MACRO,
}
}
}

impl fmt::Display for ItemType {
impl fmt::Display for NameSpace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.to_static_str().fmt(f)
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Layout {

pub struct Page<'a> {
pub title: &'a str,
pub ty: &'a str,
pub css_class: &'a str,
pub root_path: &'a str,
pub description: &'a str,
pub keywords: &'a str,
Expand Down Expand Up @@ -80,7 +80,7 @@ r##"<!DOCTYPE html>
</form>
</nav>

<section id='main' class="content {ty}">{content}</section>
<section id='main' class="content {css_class}">{content}</section>
<section id='search' class="content hidden"></section>

<section class="footer"></section>
Expand Down Expand Up @@ -152,7 +152,7 @@ r##"<!DOCTYPE html>
},
content = *t,
root_path = page.root_path,
ty = page.ty,
css_class = page.css_class,
logo = if layout.logo.is_empty() {
"".to_string()
} else {
Expand Down
Loading