1
Fork 0

rollup merge of #20179: eddyb/blind-items

Conflicts:
	src/librustc/diagnostics.rs
	src/librustdoc/clean/mod.rs
	src/librustdoc/html/format.rs
	src/libsyntax/parse/parser.rs
This commit is contained in:
Alex Crichton 2015-01-21 11:56:00 -08:00
commit df1cddf20a
60 changed files with 1098 additions and 1520 deletions

View file

@ -617,7 +617,7 @@ impl fmt::Display for UnsafetySpace {
}
}
impl fmt::Display for clean::ViewPath {
impl fmt::Display for clean::Import {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
clean::SimpleImport(ref name, ref src) => {

View file

@ -22,29 +22,31 @@ use clean;
#[derive(Copy, PartialEq, Clone)]
pub enum ItemType {
Module = 0,
Struct = 1,
Enum = 2,
Function = 3,
Typedef = 4,
Static = 5,
Trait = 6,
Impl = 7,
ViewItem = 8,
TyMethod = 9,
Method = 10,
StructField = 11,
Variant = 12,
// we used to have ForeignFunction and ForeignStatic. they are retired now.
Macro = 15,
Primitive = 16,
AssociatedType = 17,
Constant = 18,
ExternCrate = 1,
Import = 2,
Struct = 3,
Enum = 4,
Function = 5,
Typedef = 6,
Static = 7,
Trait = 8,
Impl = 9,
TyMethod = 10,
Method = 11,
StructField = 12,
Variant = 13,
Macro = 14,
Primitive = 15,
AssociatedType = 16,
Constant = 17,
}
impl ItemType {
pub fn from_item(item: &clean::Item) -> ItemType {
match item.inner {
clean::ModuleItem(..) => ItemType::Module,
clean::ExternCrateItem(..) => ItemType::ExternCrate,
clean::ImportItem(..) => ItemType::Import,
clean::StructItem(..) => ItemType::Struct,
clean::EnumItem(..) => ItemType::Enum,
clean::FunctionItem(..) => ItemType::Function,
@ -53,7 +55,6 @@ impl ItemType {
clean::ConstantItem(..) => ItemType::Constant,
clean::TraitItem(..) => ItemType::Trait,
clean::ImplItem(..) => ItemType::Impl,
clean::ViewItemItem(..) => ItemType::ViewItem,
clean::TyMethodItem(..) => ItemType::TyMethod,
clean::MethodItem(..) => ItemType::Method,
clean::StructFieldItem(..) => ItemType::StructField,
@ -83,6 +84,8 @@ impl ItemType {
pub fn to_static_str(&self) -> &'static str {
match *self {
ItemType::Module => "mod",
ItemType::ExternCrate => "externcrate",
ItemType::Import => "import",
ItemType::Struct => "struct",
ItemType::Enum => "enum",
ItemType::Function => "fn",
@ -90,7 +93,6 @@ impl ItemType {
ItemType::Static => "static",
ItemType::Trait => "trait",
ItemType::Impl => "impl",
ItemType::ViewItem => "viewitem",
ItemType::TyMethod => "tymethod",
ItemType::Method => "method",
ItemType::StructField => "structfield",

View file

@ -35,7 +35,7 @@
pub use self::ExternalLocation::*;
use std::cell::RefCell;
use std::cmp::Ordering::{self, Less, Greater, Equal};
use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::default::Default;
use std::fmt;
@ -1497,18 +1497,19 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
// the order of item types in the listing
fn reorder(ty: ItemType) -> u8 {
match ty {
ItemType::ViewItem => 0,
ItemType::Primitive => 1,
ItemType::Module => 2,
ItemType::Macro => 3,
ItemType::Struct => 4,
ItemType::Enum => 5,
ItemType::Constant => 6,
ItemType::Static => 7,
ItemType::Trait => 8,
ItemType::Function => 9,
ItemType::Typedef => 10,
_ => 11 + ty as u8,
ItemType::ExternCrate => 0,
ItemType::Import => 1,
ItemType::Primitive => 2,
ItemType::Module => 3,
ItemType::Macro => 4,
ItemType::Struct => 5,
ItemType::Enum => 6,
ItemType::Constant => 7,
ItemType::Static => 8,
ItemType::Trait => 9,
ItemType::Function => 10,
ItemType::Typedef => 12,
_ => 13 + ty as u8,
}
}
@ -1518,25 +1519,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
if ty1 == ty2 {
return i1.name.cmp(&i2.name);
}
let tycmp = reorder(ty1).cmp(&reorder(ty2));
if let Equal = tycmp {
// for reexports, `extern crate` takes precedence.
match (&i1.inner, &i2.inner) {
(&clean::ViewItemItem(ref a), &clean::ViewItemItem(ref b)) => {
match (&a.inner, &b.inner) {
(&clean::ExternCrate(..), _) => return Less,
(_, &clean::ExternCrate(..)) => return Greater,
_ => {}
}
}
(_, _) => {}
}
idx1.cmp(&idx2)
} else {
tycmp
}
(reorder(ty1), idx1).cmp(&(reorder(ty2), idx2))
}
indices.sort_by(|&i1, &i2| cmp(&items[i1], &items[i2], i1, i2));
@ -1547,12 +1530,17 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
let myitem = &items[idx];
let myty = Some(shortty(myitem));
if myty != curty {
if curty == Some(ItemType::ExternCrate) && myty == Some(ItemType::Import) {
// Put `extern crate` and `use` re-exports in the same section.
curty = myty;
} else if myty != curty {
if curty.is_some() {
try!(write!(w, "</table>"));
}
curty = myty;
let (short, name) = match myty.unwrap() {
ItemType::ExternCrate |
ItemType::Import => ("reexports", "Reexports"),
ItemType::Module => ("modules", "Modules"),
ItemType::Struct => ("structs", "Structs"),
ItemType::Enum => ("enums", "Enums"),
@ -1562,7 +1550,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
ItemType::Constant => ("constants", "Constants"),
ItemType::Trait => ("traits", "Traits"),
ItemType::Impl => ("impls", "Implementations"),
ItemType::ViewItem => ("reexports", "Reexports"),
ItemType::TyMethod => ("tymethods", "Type Methods"),
ItemType::Method => ("methods", "Methods"),
ItemType::StructField => ("fields", "Struct Fields"),
@ -1578,28 +1565,25 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
}
match myitem.inner {
clean::ViewItemItem(ref item) => {
match item.inner {
clean::ExternCrate(ref name, ref src, _) => {
match *src {
Some(ref src) =>
try!(write!(w, "<tr><td><code>extern crate \"{}\" as {}",
src.as_slice(),
name.as_slice())),
None =>
try!(write!(w, "<tr><td><code>extern crate {}",
name.as_slice())),
}
try!(write!(w, ";</code></td></tr>"));
clean::ExternCrateItem(ref name, ref src) => {
match *src {
Some(ref src) => {
try!(write!(w, "<tr><td><code>{}extern crate \"{}\" as {};",
VisSpace(myitem.visibility),
src.as_slice(),
name.as_slice()))
}
clean::Import(ref import) => {
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility),
*import));
None => {
try!(write!(w, "<tr><td><code>{}extern crate {};",
VisSpace(myitem.visibility), name.as_slice()))
}
}
try!(write!(w, "</code></td></tr>"));
}
clean::ImportItem(ref import) => {
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility), *import));
}
_ => {

View file

@ -245,7 +245,6 @@ nav.sub {
.content .highlighted.method { background-color: #c6afb3; }
.content .highlighted.tymethod { background-color: #c6afb3; }
.content .highlighted.type { background-color: #c6afb3; }
.content .highlighted.ffi { background-color: #c6afb3; }
.docblock.short.nowrap {
display: block;
@ -365,7 +364,6 @@ p a:hover { text-decoration: underline; }
.content span.fn, .content a.fn, .block a.current.fn { color: #8c6067; }
.content span.method, .content a.method, .block a.current.method { color: #8c6067; }
.content span.tymethod, .content a.tymethod, .block a.current.tymethod { color: #8c6067; }
.content span.ffi, .content a.ffi, .block a.current.ffi { color: #8c6067; }
.content .fnname { color: #8c6067; }
.search-input {

View file

@ -555,6 +555,8 @@
// This mapping table should match the discriminants of
// `rustdoc::html::item_type::ItemType` type in Rust.
var itemTypes = ["mod",
"externcrate",
"import",
"struct",
"enum",
"fn",
@ -562,13 +564,10 @@
"static",
"trait",
"impl",
"viewitem",
"tymethod",
"method",
"structfield",
"variant",
"ffi", // retained for backward compatibility
"ffs", // retained for backward compatibility
"macro",
"primitive",
"associatedtype",