Merge remote-tracking branch 'rust-lang/master'
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
This commit is contained in:
commit
63fcbcf3ce
433 changed files with 7348 additions and 12011 deletions
|
|
@ -19,7 +19,7 @@ use std::fmt;
|
|||
/// string when passed to a format string.
|
||||
pub struct Escape<'a>(pub &'a str);
|
||||
|
||||
impl<'a> fmt::String for Escape<'a> {
|
||||
impl<'a> fmt::Display for Escape<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
// Because the internet is always right, turns out there's not that many
|
||||
// characters to escape: http://stackoverflow.com/questions/7381974
|
||||
|
|
@ -29,7 +29,7 @@ impl<'a> fmt::String for Escape<'a> {
|
|||
for (i, ch) in s.bytes().enumerate() {
|
||||
match ch as char {
|
||||
'<' | '>' | '&' | '\'' | '"' => {
|
||||
try!(fmt.write_str(pile_o_bits.slice(last, i)));
|
||||
try!(fmt.write_str(&pile_o_bits[last.. i]));
|
||||
let s = match ch as char {
|
||||
'>' => ">",
|
||||
'<' => "<",
|
||||
|
|
@ -46,7 +46,7 @@ impl<'a> fmt::String for Escape<'a> {
|
|||
}
|
||||
|
||||
if last < s.len() {
|
||||
try!(fmt.write_str(pile_o_bits.slice_from(last)));
|
||||
try!(fmt.write_str(&pile_o_bits[last..]));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ impl UnsafetySpace {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, T: fmt::String> fmt::String for CommaSep<'a, T> {
|
||||
impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (i, item) in self.0.iter().enumerate() {
|
||||
if i != 0 { try!(write!(f, ", ")); }
|
||||
|
|
@ -76,7 +76,7 @@ impl<'a, T: fmt::String> fmt::String for CommaSep<'a, T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for TyParamBounds<'a> {
|
||||
impl<'a> fmt::Display for TyParamBounds<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let &TyParamBounds(bounds) = self;
|
||||
for (i, bound) in bounds.iter().enumerate() {
|
||||
|
|
@ -89,7 +89,7 @@ impl<'a> fmt::String for TyParamBounds<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::Generics {
|
||||
impl fmt::Display for clean::Generics {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.lifetimes.len() == 0 && self.type_params.len() == 0 { return Ok(()) }
|
||||
try!(f.write_str("<"));
|
||||
|
|
@ -126,7 +126,7 @@ impl fmt::String for clean::Generics {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for WhereClause<'a> {
|
||||
impl<'a> fmt::Display for WhereClause<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let &WhereClause(gens) = self;
|
||||
if gens.where_predicates.len() == 0 {
|
||||
|
|
@ -163,14 +163,14 @@ impl<'a> fmt::String for WhereClause<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::Lifetime {
|
||||
impl fmt::Display for clean::Lifetime {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(f.write_str(self.get_ref()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::PolyTrait {
|
||||
impl fmt::Display for clean::PolyTrait {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.lifetimes.len() > 0 {
|
||||
try!(f.write_str("for<"));
|
||||
|
|
@ -186,7 +186,7 @@ impl fmt::String for clean::PolyTrait {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::TyParamBound {
|
||||
impl fmt::Display for clean::TyParamBound {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::RegionBound(ref lt) => {
|
||||
|
|
@ -203,7 +203,7 @@ impl fmt::String for clean::TyParamBound {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::PathParameters {
|
||||
impl fmt::Display for clean::PathParameters {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::PathParameters::AngleBracketed {
|
||||
|
|
@ -257,14 +257,14 @@ impl fmt::String for clean::PathParameters {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::PathSegment {
|
||||
impl fmt::Display for clean::PathSegment {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(f.write_str(self.name.as_slice()));
|
||||
write!(f, "{}", self.params)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::Path {
|
||||
impl fmt::Display for clean::Path {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.global {
|
||||
try!(f.write_str("::"))
|
||||
|
|
@ -358,7 +358,7 @@ fn path<F, G>(w: &mut fmt::Formatter,
|
|||
// This is a documented path, link to it!
|
||||
Some((ref fqp, shortty)) if abs_root.is_some() => {
|
||||
let mut url = String::from_str(abs_root.unwrap().as_slice());
|
||||
let to_link = &fqp[..(fqp.len() - 1)];
|
||||
let to_link = &fqp[..fqp.len() - 1];
|
||||
for component in to_link.iter() {
|
||||
url.push_str(component.as_slice());
|
||||
url.push_str("/");
|
||||
|
|
@ -450,7 +450,7 @@ fn tybounds(w: &mut fmt::Formatter,
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::Type {
|
||||
impl fmt::Display for clean::Type {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::TyParamBinder(id) => {
|
||||
|
|
@ -539,7 +539,7 @@ impl fmt::String for clean::Type {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::Arguments {
|
||||
impl fmt::Display for clean::Arguments {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
for (i, input) in self.values.iter().enumerate() {
|
||||
if i > 0 { try!(write!(f, ", ")); }
|
||||
|
|
@ -552,7 +552,7 @@ impl fmt::String for clean::Arguments {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::FunctionRetTy {
|
||||
impl fmt::Display for clean::FunctionRetTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
clean::Return(clean::Tuple(ref tys)) if tys.is_empty() => Ok(()),
|
||||
|
|
@ -563,13 +563,13 @@ impl fmt::String for clean::FunctionRetTy {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::FnDecl {
|
||||
impl fmt::Display for clean::FnDecl {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for Method<'a> {
|
||||
impl<'a> fmt::Display for Method<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Method(selfty, d) = *self;
|
||||
let mut args = String::new();
|
||||
|
|
@ -599,7 +599,7 @@ impl<'a> fmt::String for Method<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for VisSpace {
|
||||
impl fmt::Display for VisSpace {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.get() {
|
||||
Some(ast::Public) => write!(f, "pub "),
|
||||
|
|
@ -608,7 +608,7 @@ impl fmt::String for VisSpace {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for UnsafetySpace {
|
||||
impl fmt::Display for UnsafetySpace {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.get() {
|
||||
ast::Unsafety::Unsafe => write!(f, "unsafe "),
|
||||
|
|
@ -617,7 +617,7 @@ impl fmt::String for UnsafetySpace {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String 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) => {
|
||||
|
|
@ -644,7 +644,7 @@ impl fmt::String for clean::ViewPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::ImportSource {
|
||||
impl fmt::Display for clean::ImportSource {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.did {
|
||||
Some(did) => resolved_path(f, did, &self.path, true),
|
||||
|
|
@ -661,7 +661,7 @@ impl fmt::String for clean::ImportSource {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::ViewListIdent {
|
||||
impl fmt::Display for clean::ViewListIdent {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self.source {
|
||||
Some(did) => {
|
||||
|
|
@ -683,13 +683,13 @@ impl fmt::String for clean::ViewListIdent {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for clean::TypeBinding {
|
||||
impl fmt::Display for clean::TypeBinding {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}={}", self.name, self.ty)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::String for MutableSpace {
|
||||
impl fmt::Display for MutableSpace {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
MutableSpace(clean::Immutable) => Ok(()),
|
||||
|
|
@ -698,7 +698,7 @@ impl fmt::String for MutableSpace {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for RawMutableSpace {
|
||||
impl fmt::Display for RawMutableSpace {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
RawMutableSpace(clean::Immutable) => write!(f, "const "),
|
||||
|
|
@ -707,7 +707,7 @@ impl fmt::String for RawMutableSpace {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for Stability<'a> {
|
||||
impl<'a> fmt::Display for Stability<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Stability(stab) = *self;
|
||||
match *stab {
|
||||
|
|
@ -721,7 +721,7 @@ impl<'a> fmt::String for Stability<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for ConciseStability<'a> {
|
||||
impl<'a> fmt::Display for ConciseStability<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let ConciseStability(stab) = *self;
|
||||
match *stab {
|
||||
|
|
@ -738,7 +738,7 @@ impl<'a> fmt::String for ConciseStability<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for ModuleSummary {
|
||||
impl fmt::Display for ModuleSummary {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt_inner<'a>(f: &mut fmt::Formatter,
|
||||
context: &mut Vec<&'a str>,
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -103,7 +105,7 @@ impl ItemType {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::String for ItemType {
|
||||
impl fmt::Display for ItemType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.to_static_str().fmt(f)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ pub struct Page<'a> {
|
|||
pub keywords: &'a str
|
||||
}
|
||||
|
||||
pub fn render<T: fmt::String, S: fmt::String>(
|
||||
pub fn render<T: fmt::Display, S: fmt::Display>(
|
||||
dst: &mut io::Writer, layout: &Layout, page: &Page, sidebar: &S, t: &T)
|
||||
-> io::IoResult<()>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -72,16 +72,40 @@ type blockcodefn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
|||
type headerfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
||||
libc::c_int, *mut libc::c_void);
|
||||
|
||||
type linkfn = extern "C" fn (*mut hoedown_buffer, *const hoedown_buffer,
|
||||
*const hoedown_buffer, *const hoedown_buffer,
|
||||
*mut libc::c_void) -> libc::c_int;
|
||||
|
||||
type normaltextfn = extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
||||
*mut libc::c_void);
|
||||
|
||||
#[repr(C)]
|
||||
struct hoedown_renderer {
|
||||
opaque: *mut hoedown_html_renderer_state,
|
||||
opaque: *mut libc::c_void,
|
||||
|
||||
blockcode: Option<blockcodefn>,
|
||||
blockquote: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
||||
*mut libc::c_void)>,
|
||||
blockhtml: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
||||
*mut libc::c_void)>,
|
||||
header: Option<headerfn>,
|
||||
other: [libc::size_t; 28],
|
||||
|
||||
other_block_level_callbacks: [libc::size_t; 9],
|
||||
|
||||
/* span level callbacks - NULL or return 0 prints the span verbatim */
|
||||
other_span_level_callbacks_1: [libc::size_t; 9],
|
||||
link: Option<linkfn>,
|
||||
other_span_level_callbacks_2: [libc::size_t; 5],
|
||||
// hoedown will add `math` callback here, but we use an old version of it.
|
||||
|
||||
/* low level callbacks - NULL copies input directly into the output */
|
||||
entity: Option<extern "C" fn(*mut hoedown_buffer, *const hoedown_buffer,
|
||||
*mut libc::c_void)>,
|
||||
normal_text: Option<normaltextfn>,
|
||||
|
||||
/* header and footer */
|
||||
doc_header: Option<extern "C" fn(*mut hoedown_buffer, *mut libc::c_void)>,
|
||||
doc_footer: Option<extern "C" fn(*mut hoedown_buffer, *mut libc::c_void)>,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
|
@ -134,6 +158,8 @@ extern {
|
|||
fn hoedown_document_free(md: *mut hoedown_document);
|
||||
|
||||
fn hoedown_buffer_new(unit: libc::size_t) -> *mut hoedown_buffer;
|
||||
fn hoedown_buffer_put(b: *mut hoedown_buffer, c: *const libc::c_char,
|
||||
n: libc::size_t);
|
||||
fn hoedown_buffer_puts(b: *mut hoedown_buffer, c: *const libc::c_char);
|
||||
fn hoedown_buffer_free(b: *mut hoedown_buffer);
|
||||
|
||||
|
|
@ -146,7 +172,7 @@ extern {
|
|||
fn stripped_filtered_line<'a>(s: &'a str) -> Option<&'a str> {
|
||||
let trimmed = s.trim();
|
||||
if trimmed.starts_with("# ") {
|
||||
Some(trimmed.slice_from(2))
|
||||
Some(&trimmed[2..])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -279,7 +305,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
|
|||
dfltblk: (*renderer).blockcode.unwrap(),
|
||||
toc_builder: if print_toc {Some(TocBuilder::new())} else {None}
|
||||
};
|
||||
(*(*renderer).opaque).opaque = &mut opaque as *mut _ as *mut libc::c_void;
|
||||
(*((*renderer).opaque as *mut hoedown_html_renderer_state)).opaque
|
||||
= &mut opaque as *mut _ as *mut libc::c_void;
|
||||
(*renderer).blockcode = Some(block as blockcodefn);
|
||||
(*renderer).header = Some(header as headerfn);
|
||||
|
||||
|
|
@ -355,7 +382,8 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
|
|||
let renderer = hoedown_html_renderer_new(0, 0);
|
||||
(*renderer).blockcode = Some(block as blockcodefn);
|
||||
(*renderer).header = Some(header as headerfn);
|
||||
(*(*renderer).opaque).opaque = tests as *mut _ as *mut libc::c_void;
|
||||
(*((*renderer).opaque as *mut hoedown_html_renderer_state)).opaque
|
||||
= tests as *mut _ as *mut libc::c_void;
|
||||
|
||||
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
|
||||
hoedown_document_render(document, ob, doc.as_ptr(),
|
||||
|
|
@ -426,7 +454,7 @@ pub fn reset_headers() {
|
|||
USED_HEADER_MAP.with(|s| s.borrow_mut().clear());
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for Markdown<'a> {
|
||||
impl<'a> fmt::Display for Markdown<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Markdown(md) = *self;
|
||||
// This is actually common enough to special-case
|
||||
|
|
@ -435,16 +463,67 @@ impl<'a> fmt::String for Markdown<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for MarkdownWithToc<'a> {
|
||||
impl<'a> fmt::Display for MarkdownWithToc<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let MarkdownWithToc(md) = *self;
|
||||
render(fmt, md.as_slice(), true)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plain_summary_line(md: &str) -> String {
|
||||
extern fn link(_ob: *mut hoedown_buffer,
|
||||
_link: *const hoedown_buffer,
|
||||
_title: *const hoedown_buffer,
|
||||
content: *const hoedown_buffer,
|
||||
opaque: *mut libc::c_void) -> libc::c_int
|
||||
{
|
||||
unsafe {
|
||||
if !content.is_null() && (*content).size > 0 {
|
||||
let ob = opaque as *mut hoedown_buffer;
|
||||
hoedown_buffer_put(ob, (*content).data as *const libc::c_char,
|
||||
(*content).size);
|
||||
}
|
||||
}
|
||||
1
|
||||
}
|
||||
|
||||
extern fn normal_text(_ob: *mut hoedown_buffer,
|
||||
text: *const hoedown_buffer,
|
||||
opaque: *mut libc::c_void)
|
||||
{
|
||||
unsafe {
|
||||
let ob = opaque as *mut hoedown_buffer;
|
||||
hoedown_buffer_put(ob, (*text).data as *const libc::c_char,
|
||||
(*text).size);
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ob = hoedown_buffer_new(DEF_OUNIT);
|
||||
let mut plain_renderer: hoedown_renderer = ::std::mem::zeroed();
|
||||
let renderer = &mut plain_renderer as *mut hoedown_renderer;
|
||||
(*renderer).opaque = ob as *mut libc::c_void;
|
||||
(*renderer).link = Some(link as linkfn);
|
||||
(*renderer).normal_text = Some(normal_text as normaltextfn);
|
||||
|
||||
let document = hoedown_document_new(renderer, HOEDOWN_EXTENSIONS, 16);
|
||||
hoedown_document_render(document, ob, md.as_ptr(),
|
||||
md.len() as libc::size_t);
|
||||
hoedown_document_free(document);
|
||||
let plain_slice = slice::from_raw_buf(&(*ob).data, (*ob).size as uint);
|
||||
let plain = match str::from_utf8(plain_slice) {
|
||||
Ok(s) => s.to_string(),
|
||||
Err(_) => "".to_string(),
|
||||
};
|
||||
hoedown_buffer_free(ob);
|
||||
plain
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{LangString, Markdown};
|
||||
use super::plain_summary_line;
|
||||
|
||||
#[test]
|
||||
fn test_lang_string_parse() {
|
||||
|
|
@ -478,4 +557,18 @@ mod tests {
|
|||
let markdown = "# title";
|
||||
format!("{}", Markdown(markdown.as_slice()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plain_summary_line() {
|
||||
fn t(input: &str, expect: &str) {
|
||||
let output = plain_summary_line(input);
|
||||
assert_eq!(output, expect);
|
||||
}
|
||||
|
||||
t("hello [Rust](http://rust-lang.org) :)", "hello Rust :)");
|
||||
t("code `let x = i32;` ...", "code `let x = i32;` ...");
|
||||
t("type `Type<'static>` ...", "type `Type<'static>` ...");
|
||||
t("# top header", "top header");
|
||||
t("## header", "header");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -64,8 +64,13 @@ use html::item_type::ItemType;
|
|||
use html::layout;
|
||||
use html::markdown::Markdown;
|
||||
use html::markdown;
|
||||
use html::escape::Escape;
|
||||
use stability_summary;
|
||||
|
||||
/// A pair of name and its optional document.
|
||||
#[derive(Clone, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub struct NameDoc(String, Option<String>);
|
||||
|
||||
/// Major driving force in all rustdoc rendering. This contains information
|
||||
/// about where in the tree-like hierarchy rendering is occurring and controls
|
||||
/// how the current page is being rendered.
|
||||
|
|
@ -95,7 +100,7 @@ pub struct Context {
|
|||
/// functions), and the value is the list of containers belonging to this
|
||||
/// header. This map will change depending on the surrounding context of the
|
||||
/// page.
|
||||
pub sidebar: HashMap<String, Vec<String>>,
|
||||
pub sidebar: HashMap<String, Vec<NameDoc>>,
|
||||
/// This flag indicates whether [src] links should be generated or not. If
|
||||
/// the source files are present in the html rendering, then this will be
|
||||
/// `true`.
|
||||
|
|
@ -404,7 +409,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> io::IoResult<String>
|
|||
search_index.push(IndexItem {
|
||||
ty: shortty(item),
|
||||
name: item.name.clone().unwrap(),
|
||||
path: fqp[..(fqp.len() - 1)].connect("::"),
|
||||
path: fqp[..fqp.len() - 1].connect("::"),
|
||||
desc: shorter(item.doc_value()).to_string(),
|
||||
parent: Some(did),
|
||||
});
|
||||
|
|
@ -559,7 +564,7 @@ fn write_shared(cx: &Context,
|
|||
};
|
||||
|
||||
let mut mydst = dst.clone();
|
||||
for part in remote_path[..(remote_path.len() - 1)].iter() {
|
||||
for part in remote_path[..remote_path.len() - 1].iter() {
|
||||
mydst.push(part.as_slice());
|
||||
try!(mkdir(&mydst));
|
||||
}
|
||||
|
|
@ -749,7 +754,7 @@ impl<'a> SourceCollector<'a> {
|
|||
|
||||
// Remove the utf-8 BOM if any
|
||||
let contents = if contents.starts_with("\u{feff}") {
|
||||
contents.slice_from(3)
|
||||
&contents[3..]
|
||||
} else {
|
||||
contents
|
||||
};
|
||||
|
|
@ -842,7 +847,7 @@ impl DocFolder for Cache {
|
|||
clean::StructFieldItem(..) |
|
||||
clean::VariantItem(..) => {
|
||||
((Some(*self.parent_stack.last().unwrap()),
|
||||
Some(&self.stack[..(self.stack.len() - 1)])),
|
||||
Some(&self.stack[..self.stack.len() - 1])),
|
||||
false)
|
||||
}
|
||||
clean::MethodItem(..) => {
|
||||
|
|
@ -853,13 +858,13 @@ impl DocFolder for Cache {
|
|||
let did = *last;
|
||||
let path = match self.paths.get(&did) {
|
||||
Some(&(_, ItemType::Trait)) =>
|
||||
Some(&self.stack[..(self.stack.len() - 1)]),
|
||||
Some(&self.stack[..self.stack.len() - 1]),
|
||||
// The current stack not necessarily has correlation for
|
||||
// where the type was defined. On the other hand,
|
||||
// `paths` always has the right information if present.
|
||||
Some(&(ref fqp, ItemType::Struct)) |
|
||||
Some(&(ref fqp, ItemType::Enum)) =>
|
||||
Some(&fqp[..(fqp.len() - 1)]),
|
||||
Some(&fqp[..fqp.len() - 1]),
|
||||
Some(..) => Some(self.stack.as_slice()),
|
||||
None => None
|
||||
};
|
||||
|
|
@ -1185,7 +1190,7 @@ impl Context {
|
|||
.collect::<String>();
|
||||
match cache().paths.get(&it.def_id) {
|
||||
Some(&(ref names, _)) => {
|
||||
for name in (&names[..(names.len() - 1)]).iter() {
|
||||
for name in (&names[..names.len() - 1]).iter() {
|
||||
url.push_str(name.as_slice());
|
||||
url.push_str("/");
|
||||
}
|
||||
|
|
@ -1245,7 +1250,7 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
fn build_sidebar(&self, m: &clean::Module) -> HashMap<String, Vec<String>> {
|
||||
fn build_sidebar(&self, m: &clean::Module) -> HashMap<String, Vec<NameDoc>> {
|
||||
let mut map = HashMap::new();
|
||||
for item in m.items.iter() {
|
||||
if self.ignore_private_item(item) { continue }
|
||||
|
|
@ -1262,7 +1267,7 @@ impl Context {
|
|||
let short = short.to_string();
|
||||
let v = map.entry(short).get().unwrap_or_else(
|
||||
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
|
||||
v.push(myname);
|
||||
v.push(NameDoc(myname, Some(shorter_line(item.doc_value()))));
|
||||
}
|
||||
|
||||
for (_, items) in map.iter_mut() {
|
||||
|
|
@ -1351,7 +1356,7 @@ impl<'a> Item<'a> {
|
|||
}
|
||||
|
||||
|
||||
impl<'a> fmt::String for Item<'a> {
|
||||
impl<'a> fmt::Display for Item<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
// Write the breadcrumb trail header for the top
|
||||
try!(write!(fmt, "\n<h1 class='fqn'><span class='in-band'>"));
|
||||
|
|
@ -1469,13 +1474,18 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
|
|||
fn shorter<'a>(s: Option<&'a str>) -> &'a str {
|
||||
match s {
|
||||
Some(s) => match s.find_str("\n\n") {
|
||||
Some(pos) => s.slice_to(pos),
|
||||
Some(pos) => &s[..pos],
|
||||
None => s,
|
||||
},
|
||||
None => ""
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn shorter_line(s: Option<&str>) -> String {
|
||||
shorter(s).replace("\n", " ")
|
||||
}
|
||||
|
||||
fn document(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
|
||||
match item.doc_value() {
|
||||
Some(s) => {
|
||||
|
|
@ -1497,18 +1507,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 +1529,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 +1540,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 +1560,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 +1575,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));
|
||||
}
|
||||
|
||||
_ => {
|
||||
|
|
@ -1626,7 +1620,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
|||
|
||||
struct Initializer<'a>(&'a str);
|
||||
|
||||
impl<'a> fmt::String for Initializer<'a> {
|
||||
impl<'a> fmt::Display for Initializer<'a> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Initializer(s) = *self;
|
||||
if s.len() == 0 { return Ok(()); }
|
||||
|
|
@ -2085,6 +2079,10 @@ fn render_impl(w: &mut fmt::Formatter, i: &Impl) -> fmt::Result {
|
|||
try!(write!(w, "<h3 class='impl'>{}<code>impl{} ",
|
||||
ConciseStability(&i.stability),
|
||||
i.impl_.generics));
|
||||
match i.impl_.polarity {
|
||||
Some(clean::ImplPolarity::Negative) => try!(write!(w, "!")),
|
||||
_ => {}
|
||||
}
|
||||
match i.impl_.trait_ {
|
||||
Some(ref ty) => try!(write!(w, "{} for ", *ty)),
|
||||
None => {}
|
||||
|
|
@ -2188,7 +2186,7 @@ fn item_typedef(w: &mut fmt::Formatter, it: &clean::Item,
|
|||
document(w, it)
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for Sidebar<'a> {
|
||||
impl<'a> fmt::Display for Sidebar<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let cx = self.cx;
|
||||
let it = self.item;
|
||||
|
|
@ -2213,21 +2211,22 @@ impl<'a> fmt::String for Sidebar<'a> {
|
|||
None => return Ok(())
|
||||
};
|
||||
try!(write!(w, "<div class='block {}'><h2>{}</h2>", short, longty));
|
||||
for item in items.iter() {
|
||||
for &NameDoc(ref name, ref doc) in items.iter() {
|
||||
let curty = shortty(cur).to_static_str();
|
||||
let class = if cur.name.as_ref().unwrap() == item &&
|
||||
let class = if cur.name.as_ref().unwrap() == name &&
|
||||
short == curty { "current" } else { "" };
|
||||
try!(write!(w, "<a class='{ty} {class}' href='{href}{path}'>\
|
||||
{name}</a>",
|
||||
try!(write!(w, "<a class='{ty} {class}' href='{href}{path}' \
|
||||
title='{title}'>{name}</a>",
|
||||
ty = short,
|
||||
class = class,
|
||||
href = if curty == "mod" {"../"} else {""},
|
||||
path = if short == "mod" {
|
||||
format!("{}/index.html", item.as_slice())
|
||||
format!("{}/index.html", name.as_slice())
|
||||
} else {
|
||||
format!("{}.{}.html", short, item.as_slice())
|
||||
format!("{}.{}.html", short, name.as_slice())
|
||||
},
|
||||
name = item.as_slice()));
|
||||
title = Escape(doc.as_ref().unwrap().as_slice()),
|
||||
name = name.as_slice()));
|
||||
}
|
||||
try!(write!(w, "</div>"));
|
||||
Ok(())
|
||||
|
|
@ -2243,7 +2242,7 @@ impl<'a> fmt::String for Sidebar<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::String for Source<'a> {
|
||||
impl<'a> fmt::Display for Source<'a> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
let Source(s) = *self;
|
||||
let lines = s.lines().count();
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
@ -669,6 +668,15 @@
|
|||
search();
|
||||
}
|
||||
|
||||
function plainSummaryLine(markdown) {
|
||||
var str = markdown.replace(/\n/g, ' ')
|
||||
str = str.replace(/'/g, "\'")
|
||||
str = str.replace(/^#+? (.+?)/, "$1")
|
||||
str = str.replace(/\[(.*?)\]\(.*?\)/g, "$1")
|
||||
str = str.replace(/\[(.*?)\]\[.*?\]/g, "$1")
|
||||
return str;
|
||||
}
|
||||
|
||||
index = buildIndex(rawSearchIndex);
|
||||
startSearch();
|
||||
|
||||
|
|
@ -689,8 +697,10 @@
|
|||
if (crates[i] == window.currentCrate) {
|
||||
klass += ' current';
|
||||
}
|
||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
||||
div.append($('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'class': klass}).text(crates[i]));
|
||||
'title': plainSummaryLine(desc),
|
||||
'class': klass}).text(crates[i]));
|
||||
}
|
||||
sidebar.append(div);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,13 +176,13 @@ impl TocBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for Toc {
|
||||
impl fmt::Debug for Toc {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fmt::String::fmt(self, f)
|
||||
fmt::Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::String for Toc {
|
||||
impl fmt::Display for Toc {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(write!(fmt, "<ul>"));
|
||||
for entry in self.entries.iter() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue