Register new snapshots
Conflicts: src/librbml/lib.rs src/libserialize/json_stage0.rs src/libserialize/serialize_stage0.rs src/libsyntax/ast.rs src/libsyntax/ext/deriving/generic/mod.rs src/libsyntax/parse/token.rs
This commit is contained in:
parent
5c3ddcb15d
commit
e2f97f51ad
59 changed files with 94 additions and 6419 deletions
|
@ -16,14 +16,8 @@
|
|||
extern crate test;
|
||||
extern crate getopts;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
extern crate regex;
|
||||
|
||||
use std::os;
|
||||
|
|
|
@ -65,36 +65,16 @@
|
|||
|
||||
#![no_std]
|
||||
#![allow(unknown_features)]
|
||||
#![feature(lang_items, phase, unsafe_destructor, default_type_params, old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(lang_items, phase, unsafe_destructor)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate core;
|
||||
|
||||
extern crate libc;
|
||||
|
||||
// Allow testing this library
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(test)] #[macro_use] extern crate std;
|
||||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
||||
// Heaps provided for low-level allocation strategies
|
||||
|
||||
|
|
|
@ -21,19 +21,9 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, default_type_params, phase, globs)]
|
||||
#![feature(unsafe_destructor, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
#![no_std]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate core;
|
||||
|
||||
|
@ -41,22 +31,8 @@ extern crate unicode;
|
|||
extern crate alloc;
|
||||
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(test)] #[macro_use] extern crate std;
|
||||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
||||
pub use binary_heap::BinaryHeap;
|
||||
pub use bitv::Bitv;
|
||||
|
@ -73,8 +49,7 @@ pub use vec_map::VecMap;
|
|||
// Needed for the vec! macro
|
||||
pub use alloc::boxed;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
pub mod binary_heap;
|
||||
|
|
|
@ -8,21 +8,7 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
/// Creates a `std::vec::Vec` containing the arguments.
|
||||
// NOTE: remove after the next snapshot
|
||||
#[cfg(stage0)]
|
||||
macro_rules! vec {
|
||||
($($e:expr),*) => ({
|
||||
// leading _ to allow empty construction without a warning.
|
||||
let mut _temp = ::vec::Vec::new();
|
||||
$(_temp.push($e);)*
|
||||
_temp
|
||||
});
|
||||
($($e:expr),+,) => (vec!($($e),+))
|
||||
}
|
||||
|
||||
/// Creates a `Vec` containing the arguments.
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_export]
|
||||
macro_rules! vec {
|
||||
($($x:expr),*) => ({
|
||||
|
|
|
@ -27,9 +27,6 @@ use slice::SliceExt;
|
|||
use slice;
|
||||
use str::{self, StrExt, Utf8Error};
|
||||
|
||||
// NOTE: for old macros; remove after the next snapshot
|
||||
#[cfg(stage0)] use result::Result::Err;
|
||||
|
||||
pub use self::num::radix;
|
||||
pub use self::num::Radix;
|
||||
pub use self::num::RadixFmt;
|
||||
|
|
|
@ -56,29 +56,25 @@
|
|||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![no_std]
|
||||
#![allow(unknown_features, raw_pointer_deriving)]
|
||||
#![feature(globs, intrinsics, lang_items, macro_rules, phase)]
|
||||
#![allow(unknown_features, raw_pointer_derive)]
|
||||
#![feature(intrinsics, lang_items)]
|
||||
#![feature(simd, unsafe_destructor, slicing_syntax)]
|
||||
#![feature(default_type_params, unboxed_closures, associated_types)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
#[path = "num/float_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod float_macros;
|
||||
|
||||
#[path = "num/int_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod int_macros;
|
||||
|
||||
#[path = "num/uint_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod uint_macros;
|
||||
|
||||
#[path = "num/int.rs"] pub mod int;
|
||||
|
|
|
@ -142,16 +142,9 @@ macro_rules! debug_assert_eq {
|
|||
($($arg:tt)*) => (if cfg!(not(ndebug)) { assert_eq!($($arg)*); })
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[macro_export]
|
||||
macro_rules! try {
|
||||
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
|
||||
}
|
||||
|
||||
/// Short circuiting evaluation on Err
|
||||
///
|
||||
/// `libstd` contains a more general `try!` macro that uses `FromError`.
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_export]
|
||||
macro_rules! try {
|
||||
($e:expr) => ({
|
||||
|
|
|
@ -14,8 +14,7 @@ use core::num::{NumCast, cast};
|
|||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||
use core::kinds::Copy;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod int_macros;
|
||||
|
||||
mod i8;
|
||||
|
@ -24,8 +23,7 @@ mod i32;
|
|||
mod i64;
|
||||
mod int;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod uint_macros;
|
||||
|
||||
mod u8;
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
#![feature(unboxed_closures, associated_types)]
|
||||
|
||||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![feature(globs, slicing_syntax)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
pub use self::Piece::*;
|
||||
pub use self::Position::*;
|
||||
|
|
|
@ -85,8 +85,7 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![feature(globs, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(slicing_syntax)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
|
|
@ -271,8 +271,7 @@
|
|||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
#![feature(globs, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
use self::LabelText::*;
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(globs)]
|
||||
#![crate_name = "libc"]
|
||||
#![experimental]
|
||||
#![no_std] // we don't need std, and we can't have std, since it doesn't exist
|
||||
|
@ -76,7 +75,7 @@
|
|||
#![allow(non_upper_case_globals)]
|
||||
#![allow(missing_docs)]
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(raw_pointer_deriving)]
|
||||
#![allow(raw_pointer_derive)]
|
||||
|
||||
extern crate core;
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![feature(macro_rules, unboxed_closures, slicing_syntax)]
|
||||
#![feature(slicing_syntax)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
extern crate regex;
|
||||
|
@ -182,8 +182,7 @@ use regex::Regex;
|
|||
|
||||
use directive::LOG_LEVEL_NAMES;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
|
||||
mod directive;
|
||||
|
|
|
@ -23,35 +23,14 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![feature(macro_rules, phase, globs)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
#![no_std]
|
||||
#![experimental]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(test)] #[macro_use] extern crate std;
|
||||
#[cfg(test)] #[macro_use] extern crate log;
|
||||
|
||||
use core::prelude::*;
|
||||
|
||||
|
|
|
@ -24,19 +24,10 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, phase, slicing_syntax, globs)]
|
||||
#![feature(unboxed_closures, associated_types)]
|
||||
#![allow(missing_docs)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
extern crate serialize;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
|
@ -424,263 +415,6 @@ pub mod reader {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'doc> serialize::Decoder<Error> for Decoder<'doc> {
|
||||
fn read_nil(&mut self) -> DecodeResult<()> { Ok(()) }
|
||||
|
||||
fn read_u64(&mut self) -> DecodeResult<u64> { Ok(doc_as_u64(try!(self.next_doc(EsU64)))) }
|
||||
fn read_u32(&mut self) -> DecodeResult<u32> { Ok(doc_as_u32(try!(self.next_doc(EsU32)))) }
|
||||
fn read_u16(&mut self) -> DecodeResult<u16> { Ok(doc_as_u16(try!(self.next_doc(EsU16)))) }
|
||||
fn read_u8 (&mut self) -> DecodeResult<u8 > { Ok(doc_as_u8 (try!(self.next_doc(EsU8 )))) }
|
||||
fn read_uint(&mut self) -> DecodeResult<uint> {
|
||||
let v = doc_as_u64(try!(self.next_doc(EsUint)));
|
||||
if v > (::std::uint::MAX as u64) {
|
||||
Err(IntTooBig(v as uint))
|
||||
} else {
|
||||
Ok(v as uint)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_i64(&mut self) -> DecodeResult<i64> {
|
||||
Ok(doc_as_u64(try!(self.next_doc(EsI64))) as i64)
|
||||
}
|
||||
fn read_i32(&mut self) -> DecodeResult<i32> {
|
||||
Ok(doc_as_u32(try!(self.next_doc(EsI32))) as i32)
|
||||
}
|
||||
fn read_i16(&mut self) -> DecodeResult<i16> {
|
||||
Ok(doc_as_u16(try!(self.next_doc(EsI16))) as i16)
|
||||
}
|
||||
fn read_i8 (&mut self) -> DecodeResult<i8> {
|
||||
Ok(doc_as_u8(try!(self.next_doc(EsI8 ))) as i8)
|
||||
}
|
||||
fn read_int(&mut self) -> DecodeResult<int> {
|
||||
let v = doc_as_u64(try!(self.next_doc(EsInt))) as i64;
|
||||
if v > (int::MAX as i64) || v < (int::MIN as i64) {
|
||||
debug!("FIXME \\#6122: Removing this makes this function miscompile");
|
||||
Err(IntTooBig(v as uint))
|
||||
} else {
|
||||
Ok(v as int)
|
||||
}
|
||||
}
|
||||
|
||||
fn read_bool(&mut self) -> DecodeResult<bool> {
|
||||
Ok(doc_as_u8(try!(self.next_doc(EsBool))) != 0)
|
||||
}
|
||||
|
||||
fn read_f64(&mut self) -> DecodeResult<f64> {
|
||||
let bits = doc_as_u64(try!(self.next_doc(EsF64)));
|
||||
Ok(unsafe { transmute(bits) })
|
||||
}
|
||||
fn read_f32(&mut self) -> DecodeResult<f32> {
|
||||
let bits = doc_as_u32(try!(self.next_doc(EsF32)));
|
||||
Ok(unsafe { transmute(bits) })
|
||||
}
|
||||
fn read_char(&mut self) -> DecodeResult<char> {
|
||||
Ok(char::from_u32(doc_as_u32(try!(self.next_doc(EsChar)))).unwrap())
|
||||
}
|
||||
fn read_str(&mut self) -> DecodeResult<String> {
|
||||
Ok(try!(self.next_doc(EsStr)).as_str())
|
||||
}
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T, F>(&mut self, name: &str, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_enum({:?})", name);
|
||||
try!(self._check_label(name));
|
||||
|
||||
let doc = try!(self.next_doc(EsEnum));
|
||||
|
||||
let (old_parent, old_pos) = (self.parent, self.pos);
|
||||
self.parent = doc;
|
||||
self.pos = self.parent.start;
|
||||
|
||||
let result = try!(f(self));
|
||||
|
||||
self.parent = old_parent;
|
||||
self.pos = old_pos;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, _: &[&str],
|
||||
mut f: F) -> DecodeResult<T>
|
||||
where F: FnMut(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_enum_variant()");
|
||||
let idx = try!(self._next_uint(EsEnumVid));
|
||||
debug!(" idx={:?}", idx);
|
||||
|
||||
let doc = try!(self.next_doc(EsEnumBody));
|
||||
|
||||
let (old_parent, old_pos) = (self.parent, self.pos);
|
||||
self.parent = doc;
|
||||
self.pos = self.parent.start;
|
||||
|
||||
let result = try!(f(self, idx));
|
||||
|
||||
self.parent = old_parent;
|
||||
self.pos = old_pos;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn read_enum_variant_arg<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_enum_variant_arg(idx={:?})", idx);
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, _: &[&str],
|
||||
mut f: F) -> DecodeResult<T>
|
||||
where F: FnMut(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_enum_struct_variant()");
|
||||
let idx = try!(self._next_uint(EsEnumVid));
|
||||
debug!(" idx={:?}", idx);
|
||||
|
||||
let doc = try!(self.next_doc(EsEnumBody));
|
||||
|
||||
let (old_parent, old_pos) = (self.parent, self.pos);
|
||||
self.parent = doc;
|
||||
self.pos = self.parent.start;
|
||||
|
||||
let result = try!(f(self, idx));
|
||||
|
||||
self.parent = old_parent;
|
||||
self.pos = old_pos;
|
||||
Ok(result)
|
||||
}
|
||||
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self,
|
||||
name: &str,
|
||||
idx: uint,
|
||||
f: F)
|
||||
-> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_enum_struct_variant_arg(name={:?}, idx={:?})", name, idx);
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_struct<T, F>(&mut self, name: &str, _: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_struct(name={:?})", name);
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_struct_field<T, F>(&mut self, name: &str, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_struct_field(name={:?}, idx={:?})", name, idx);
|
||||
try!(self._check_label(name));
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn read_tuple<T, F>(&mut self, tuple_len: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_tuple()");
|
||||
self.read_seq(move |d, len| {
|
||||
if len == tuple_len {
|
||||
f(d)
|
||||
} else {
|
||||
Err(Expected(format!("Expected tuple of length `{}`, \
|
||||
found tuple of length `{}`", tuple_len, len)))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn read_tuple_arg<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_tuple_arg(idx={:?})", idx);
|
||||
self.read_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, name: &str, len: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_tuple_struct(name={:?})", name);
|
||||
self.read_tuple(len, f)
|
||||
}
|
||||
|
||||
fn read_tuple_struct_arg<T, F>(&mut self,
|
||||
idx: uint,
|
||||
f: F)
|
||||
-> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_tuple_struct_arg(idx={:?})", idx);
|
||||
self.read_tuple_arg(idx, f)
|
||||
}
|
||||
|
||||
fn read_option<T, F>(&mut self, mut f: F) -> DecodeResult<T> where
|
||||
F: FnMut(&mut Decoder<'doc>, bool) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_option()");
|
||||
self.read_enum("Option", move |this| {
|
||||
this.read_enum_variant(&["None", "Some"], move |this, idx| {
|
||||
match idx {
|
||||
0 => f(this, false),
|
||||
1 => f(this, true),
|
||||
_ => {
|
||||
Err(Expected(format!("Expected None or Some")))
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn read_seq<T, F>(&mut self, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_seq()");
|
||||
self.push_doc(EsVec, move |d| {
|
||||
let len = try!(d._next_uint(EsVecLen));
|
||||
debug!(" len={:?}", len);
|
||||
f(d, len)
|
||||
})
|
||||
}
|
||||
|
||||
fn read_seq_elt<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_seq_elt(idx={:?})", idx);
|
||||
self.push_doc(EsVecElt, f)
|
||||
}
|
||||
|
||||
fn read_map<T, F>(&mut self, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>, uint) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_map()");
|
||||
self.push_doc(EsMap, move |d| {
|
||||
let len = try!(d._next_uint(EsMapLen));
|
||||
debug!(" len={:?}", len);
|
||||
f(d, len)
|
||||
})
|
||||
}
|
||||
|
||||
fn read_map_elt_key<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_map_elt_key(idx={:?})", idx);
|
||||
self.push_doc(EsMapKey, f)
|
||||
}
|
||||
|
||||
fn read_map_elt_val<T, F>(&mut self, idx: uint, f: F) -> DecodeResult<T> where
|
||||
F: FnOnce(&mut Decoder<'doc>) -> DecodeResult<T>,
|
||||
{
|
||||
debug!("read_map_elt_val(idx={:?})", idx);
|
||||
self.push_doc(EsMapVal, f)
|
||||
}
|
||||
|
||||
fn error(&mut self, err: &str) -> Error {
|
||||
ApplicationError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<'doc> serialize::Decoder for Decoder<'doc> {
|
||||
type Error = Error;
|
||||
fn read_nil(&mut self) -> DecodeResult<()> { Ok(()) }
|
||||
|
@ -1137,209 +871,6 @@ pub mod writer {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<'a, W: Writer + Seek> serialize::Encoder<io::IoError> for Encoder<'a, W> {
|
||||
|
||||
fn emit_nil(&mut self) -> EncodeResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn emit_uint(&mut self, v: uint) -> EncodeResult {
|
||||
self.wr_tagged_u64(EsUint as uint, v as u64)
|
||||
}
|
||||
fn emit_u64(&mut self, v: u64) -> EncodeResult {
|
||||
self.wr_tagged_u64(EsU64 as uint, v)
|
||||
}
|
||||
fn emit_u32(&mut self, v: u32) -> EncodeResult {
|
||||
self.wr_tagged_u32(EsU32 as uint, v)
|
||||
}
|
||||
fn emit_u16(&mut self, v: u16) -> EncodeResult {
|
||||
self.wr_tagged_u16(EsU16 as uint, v)
|
||||
}
|
||||
fn emit_u8(&mut self, v: u8) -> EncodeResult {
|
||||
self.wr_tagged_u8(EsU8 as uint, v)
|
||||
}
|
||||
|
||||
fn emit_int(&mut self, v: int) -> EncodeResult {
|
||||
self.wr_tagged_i64(EsInt as uint, v as i64)
|
||||
}
|
||||
fn emit_i64(&mut self, v: i64) -> EncodeResult {
|
||||
self.wr_tagged_i64(EsI64 as uint, v)
|
||||
}
|
||||
fn emit_i32(&mut self, v: i32) -> EncodeResult {
|
||||
self.wr_tagged_i32(EsI32 as uint, v)
|
||||
}
|
||||
fn emit_i16(&mut self, v: i16) -> EncodeResult {
|
||||
self.wr_tagged_i16(EsI16 as uint, v)
|
||||
}
|
||||
fn emit_i8(&mut self, v: i8) -> EncodeResult {
|
||||
self.wr_tagged_i8(EsI8 as uint, v)
|
||||
}
|
||||
|
||||
fn emit_bool(&mut self, v: bool) -> EncodeResult {
|
||||
self.wr_tagged_u8(EsBool as uint, v as u8)
|
||||
}
|
||||
|
||||
fn emit_f64(&mut self, v: f64) -> EncodeResult {
|
||||
let bits = unsafe { mem::transmute(v) };
|
||||
self.wr_tagged_u64(EsF64 as uint, bits)
|
||||
}
|
||||
fn emit_f32(&mut self, v: f32) -> EncodeResult {
|
||||
let bits = unsafe { mem::transmute(v) };
|
||||
self.wr_tagged_u32(EsF32 as uint, bits)
|
||||
}
|
||||
fn emit_char(&mut self, v: char) -> EncodeResult {
|
||||
self.wr_tagged_u32(EsChar as uint, v as u32)
|
||||
}
|
||||
|
||||
fn emit_str(&mut self, v: &str) -> EncodeResult {
|
||||
self.wr_tagged_str(EsStr as uint, v)
|
||||
}
|
||||
|
||||
fn emit_enum<F>(&mut self, name: &str, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
try!(self._emit_label(name));
|
||||
try!(self.start_tag(EsEnum as uint));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_enum_variant<F>(&mut self,
|
||||
_: &str,
|
||||
v_id: uint,
|
||||
_: uint,
|
||||
f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
try!(self._emit_tagged_uint(EsEnumVid, v_id));
|
||||
try!(self.start_tag(EsEnumBody as uint));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_enum_variant_arg<F>(&mut self, _: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant<F>(&mut self,
|
||||
v_name: &str,
|
||||
v_id: uint,
|
||||
cnt: uint,
|
||||
f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_enum_variant(v_name, v_id, cnt, f)
|
||||
}
|
||||
|
||||
fn emit_enum_struct_variant_field<F>(&mut self,
|
||||
_: &str,
|
||||
idx: uint,
|
||||
f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_enum_variant_arg(idx, f)
|
||||
}
|
||||
|
||||
fn emit_struct<F>(&mut self, _: &str, _len: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_struct_field<F>(&mut self, name: &str, _: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
try!(self._emit_label(name));
|
||||
f(self)
|
||||
}
|
||||
|
||||
fn emit_tuple<F>(&mut self, len: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_arg<F>(&mut self, idx: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_tuple_struct<F>(&mut self, _: &str, len: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_seq(len, f)
|
||||
}
|
||||
fn emit_tuple_struct_arg<F>(&mut self, idx: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_seq_elt(idx, f)
|
||||
}
|
||||
|
||||
fn emit_option<F>(&mut self, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
self.emit_enum("Option", f)
|
||||
}
|
||||
fn emit_option_none(&mut self) -> EncodeResult {
|
||||
self.emit_enum_variant("None", 0, 0, |_| Ok(()))
|
||||
}
|
||||
fn emit_option_some<F>(&mut self, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
|
||||
self.emit_enum_variant("Some", 1, 1, f)
|
||||
}
|
||||
|
||||
fn emit_seq<F>(&mut self, len: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
|
||||
try!(self.start_tag(EsVec as uint));
|
||||
try!(self._emit_tagged_uint(EsVecLen, len));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_seq_elt<F>(&mut self, _idx: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
|
||||
try!(self.start_tag(EsVecElt as uint));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_map<F>(&mut self, len: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
|
||||
try!(self.start_tag(EsMap as uint));
|
||||
try!(self._emit_tagged_uint(EsMapLen, len));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_map_elt_key<F>(&mut self, _idx: uint, mut f: F) -> EncodeResult where
|
||||
F: FnMut(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
|
||||
try!(self.start_tag(EsMapKey as uint));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
|
||||
fn emit_map_elt_val<F>(&mut self, _idx: uint, f: F) -> EncodeResult where
|
||||
F: FnOnce(&mut Encoder<'a, W>) -> EncodeResult,
|
||||
{
|
||||
try!(self.start_tag(EsMapVal as uint));
|
||||
try!(f(self));
|
||||
self.end_tag()
|
||||
}
|
||||
}
|
||||
#[cfg(not(stage0))]
|
||||
impl<'a, W: Writer + Seek> serialize::Encoder for Encoder<'a, W> {
|
||||
type Error = io::IoError;
|
||||
|
||||
|
|
|
@ -23,9 +23,7 @@
|
|||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, slicing_syntax, globs)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(slicing_syntax)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -22,13 +22,9 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(default_type_params, globs, macro_rules, phase, quote)]
|
||||
#![feature(quote)]
|
||||
#![feature(slicing_syntax, unsafe_destructor)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
extern crate arena;
|
||||
extern crate flate;
|
||||
|
@ -40,22 +36,8 @@ extern crate rustc_back;
|
|||
extern crate serialize;
|
||||
extern crate rbml;
|
||||
extern crate collections;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
extern crate "serialize" as rustc_serialize; // used by deriving
|
||||
|
||||
|
|
|
@ -675,14 +675,14 @@ pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeI
|
|||
debug!("Looking up item: {}", id);
|
||||
let item_doc = lookup_item(id, cdata.data());
|
||||
let path = item_path(item_doc).init().to_vec();
|
||||
match decode_inlined_item.call_mut((cdata, tcx, path, item_doc)) {
|
||||
match decode_inlined_item(cdata, tcx, path, item_doc) {
|
||||
Ok(ii) => csearch::found(ii),
|
||||
Err(path) => {
|
||||
match item_parent_item(item_doc) {
|
||||
Some(did) => {
|
||||
let did = translate_def_id(cdata, did);
|
||||
let parent_item = lookup_item(did.node, cdata.data());
|
||||
match decode_inlined_item.call_mut((cdata, tcx, path, parent_item)) {
|
||||
match decode_inlined_item(cdata, tcx, path, parent_item) {
|
||||
Ok(ii) => csearch::found_parent(did, ii),
|
||||
Err(_) => csearch::not_found
|
||||
}
|
||||
|
|
|
@ -953,7 +953,7 @@ fn encode_inlined_item(ecx: &EncodeContext,
|
|||
ii: InlinedItemRef) {
|
||||
let mut eii = ecx.encode_inlined_item.borrow_mut();
|
||||
let eii: &mut EncodeInlinedItem = &mut *eii;
|
||||
eii.call_mut((ecx, rbml_w, ii))
|
||||
eii(ecx, rbml_w, ii)
|
||||
}
|
||||
|
||||
const FN_FAMILY: char = 'f';
|
||||
|
|
|
@ -263,14 +263,6 @@ trait def_id_encoder_helpers {
|
|||
fn emit_def_id(&mut self, did: ast::DefId);
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:serialize::Encoder<E>, E> def_id_encoder_helpers for S {
|
||||
fn emit_def_id(&mut self, did: ast::DefId) {
|
||||
did.encode(self).ok().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<S:serialize::Encoder> def_id_encoder_helpers for S {
|
||||
fn emit_def_id(&mut self, did: ast::DefId) {
|
||||
did.encode(self).ok().unwrap()
|
||||
|
@ -283,21 +275,6 @@ trait def_id_decoder_helpers {
|
|||
cdata: &cstore::crate_metadata) -> ast::DefId;
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:serialize::Decoder<E>, E> def_id_decoder_helpers for D {
|
||||
fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
|
||||
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
|
||||
did.tr(dcx)
|
||||
}
|
||||
|
||||
fn read_def_id_nodcx(&mut self,
|
||||
cdata: &cstore::crate_metadata) -> ast::DefId {
|
||||
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
|
||||
decoder::translate_def_id(cdata, did)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<D:serialize::Decoder> def_id_decoder_helpers for D {
|
||||
fn read_def_id(&mut self, dcx: &DecodeContext) -> ast::DefId {
|
||||
let did: ast::DefId = Decodable::decode(self).ok().unwrap();
|
||||
|
|
|
@ -205,7 +205,7 @@ impl<'a, 'tcx> IntrinsicCheckingVisitor<'a, 'tcx> {
|
|||
debug!("with_each_combination(substs={})",
|
||||
substs.repr(self.tcx));
|
||||
|
||||
callback.call_mut((substs,));
|
||||
callback(substs);
|
||||
}
|
||||
|
||||
Some((space, index, ¶m_ty)) => {
|
||||
|
|
|
@ -844,7 +844,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionFolder<'a, 'tcx>
|
|||
_ => {
|
||||
debug!("RegionFolder.fold_region({}) folding free region (current_depth={})",
|
||||
r.repr(self.tcx()), self.current_depth);
|
||||
self.fld_r.call_mut((r, self.current_depth))
|
||||
(self.fld_r)(r, self.current_depth)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,22 +28,11 @@
|
|||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(globs, phase, macro_rules, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
extern crate syntax;
|
||||
extern crate serialize;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
pub mod abi;
|
||||
pub mod archive;
|
||||
|
|
|
@ -17,28 +17,13 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(default_type_params, globs, macro_rules, phase, quote)]
|
||||
#![feature(quote)]
|
||||
#![feature(slicing_syntax, unsafe_destructor)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
// for "clarity", rename the graphviz crate to dot; graphviz within `borrowck`
|
||||
// refers to the borrowck-specific graphviz adapter traits.
|
||||
|
|
|
@ -22,11 +22,9 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(default_type_params, globs, macro_rules, phase, quote)]
|
||||
#![feature(quote)]
|
||||
#![feature(slicing_syntax, unsafe_destructor)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
extern crate arena;
|
||||
extern crate flate;
|
||||
|
@ -41,22 +39,8 @@ extern crate rustc_trans;
|
|||
extern crate rustc_typeck;
|
||||
extern crate serialize;
|
||||
extern crate "rustc_llvm" as llvm;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
pub use syntax::diagnostic;
|
||||
|
||||
|
|
|
@ -21,10 +21,7 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(globs)]
|
||||
#![feature(link_args)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
|
||||
extern crate libc;
|
||||
|
||||
|
|
|
@ -16,26 +16,11 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(globs, phase, slicing_syntax)]
|
||||
#![feature(slicing_syntax)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(old_orphan_check)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
extern crate rustc;
|
||||
|
||||
|
|
|
@ -22,13 +22,9 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(default_type_params, globs, macro_rules, phase, quote)]
|
||||
#![feature(quote)]
|
||||
#![feature(slicing_syntax, unsafe_destructor)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
extern crate arena;
|
||||
extern crate flate;
|
||||
|
@ -40,21 +36,8 @@ extern crate rustc_back;
|
|||
extern crate serialize;
|
||||
extern crate "rustc_llvm" as llvm;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
pub use rustc::session;
|
||||
pub use rustc::metadata;
|
||||
|
|
|
@ -16,8 +16,7 @@ pub use self::base::trans_crate;
|
|||
pub use self::context::CrateContext;
|
||||
pub use self::common::gensym_name;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
mod doc;
|
||||
|
|
|
@ -71,27 +71,13 @@ This API is completely unstable and subject to change.
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(default_type_params, globs, macro_rules, phase, quote)]
|
||||
#![feature(quote)]
|
||||
#![feature(slicing_syntax, unsafe_destructor)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate syntax;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate syntax;
|
||||
#[macro_use] extern crate log;
|
||||
#[macro_use] extern crate syntax;
|
||||
|
||||
extern crate arena;
|
||||
extern crate rustc;
|
||||
|
|
|
@ -16,12 +16,7 @@
|
|||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(globs, macro_rules, phase, slicing_syntax)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
extern crate arena;
|
||||
extern crate getopts;
|
||||
|
@ -32,14 +27,7 @@ extern crate rustc_driver;
|
|||
extern crate serialize;
|
||||
extern crate syntax;
|
||||
extern crate "test" as testing;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
extern crate "serialize" as rustc_serialize; // used by deriving
|
||||
|
||||
|
@ -56,8 +44,7 @@ use rustc::session::search_paths::SearchPaths;
|
|||
// reexported from `clean` so it can be easily updated with the mod itself
|
||||
pub use clean::SCHEMA_VERSION;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod externalfiles;
|
||||
|
||||
pub mod clean;
|
||||
|
|
|
@ -1,289 +0,0 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Implementations of serialization for structures found in libcollections
|
||||
|
||||
use std::uint;
|
||||
use std::default::Default;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use {Decodable, Encodable, Decoder, Encoder};
|
||||
use std::collections::{DList, RingBuf, BTreeMap, BTreeSet, HashMap, HashSet, VecMap};
|
||||
use collections::enum_set::{EnumSet, CLike};
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E>
|
||||
> Encodable<S, E> for DList<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for DList<T> {
|
||||
fn decode(d: &mut D) -> Result<DList<T>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut list = DList::new();
|
||||
for i in range(0u, len) {
|
||||
list.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
Ok(list)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E>
|
||||
> Encodable<S, E> for RingBuf<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for RingBuf<T> {
|
||||
fn decode(d: &mut D) -> Result<RingBuf<T>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut deque: RingBuf<T> = RingBuf::new();
|
||||
for i in range(0u, len) {
|
||||
deque.push_back(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
Ok(deque)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
K: Encodable<S, E> + PartialEq + Ord,
|
||||
V: Encodable<S, E> + PartialEq
|
||||
> Encodable<S, E> for BTreeMap<K, V> {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
e.emit_map(self.len(), |e| {
|
||||
let mut i = 0;
|
||||
for (key, val) in self.iter() {
|
||||
try!(e.emit_map_elt_key(i, |e| key.encode(e)));
|
||||
try!(e.emit_map_elt_val(i, |e| val.encode(e)));
|
||||
i += 1;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
K: Decodable<D, E> + PartialEq + Ord,
|
||||
V: Decodable<D, E> + PartialEq
|
||||
> Decodable<D, E> for BTreeMap<K, V> {
|
||||
fn decode(d: &mut D) -> Result<BTreeMap<K, V>, E> {
|
||||
d.read_map(|d, len| {
|
||||
let mut map = BTreeMap::new();
|
||||
for i in range(0u, len) {
|
||||
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
|
||||
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
|
||||
map.insert(key, val);
|
||||
}
|
||||
Ok(map)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E> + PartialEq + Ord
|
||||
> Encodable<S, E> for BTreeSet<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
let mut i = 0;
|
||||
for e in self.iter() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)));
|
||||
i += 1;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
T: Decodable<D, E> + PartialEq + Ord
|
||||
> Decodable<D, E> for BTreeSet<T> {
|
||||
fn decode(d: &mut D) -> Result<BTreeSet<T>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut set = BTreeSet::new();
|
||||
for i in range(0u, len) {
|
||||
set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
Ok(set)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E> + CLike
|
||||
> Encodable<S, E> for EnumSet<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
let mut bits = 0;
|
||||
for item in self.iter() {
|
||||
bits |= item.to_uint();
|
||||
}
|
||||
s.emit_uint(bits)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
T: Decodable<D, E> + CLike
|
||||
> Decodable<D, E> for EnumSet<T> {
|
||||
fn decode(d: &mut D) -> Result<EnumSet<T>, E> {
|
||||
let bits = try!(d.read_uint());
|
||||
let mut set = EnumSet::new();
|
||||
for bit in range(0, uint::BITS) {
|
||||
if bits & (1 << bit) != 0 {
|
||||
set.insert(CLike::from_uint(1 << bit));
|
||||
}
|
||||
}
|
||||
Ok(set)
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
K: Encodable<S, E> + Hash<X> + Eq,
|
||||
V: Encodable<S, E>,
|
||||
X,
|
||||
H: Hasher<X>
|
||||
> Encodable<S, E> for HashMap<K, V, H> {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
e.emit_map(self.len(), |e| {
|
||||
let mut i = 0;
|
||||
for (key, val) in self.iter() {
|
||||
try!(e.emit_map_elt_key(i, |e| key.encode(e)));
|
||||
try!(e.emit_map_elt_val(i, |e| val.encode(e)));
|
||||
i += 1;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
K: Decodable<D, E> + Hash<S> + Eq,
|
||||
V: Decodable<D, E>,
|
||||
S,
|
||||
H: Hasher<S> + Default
|
||||
> Decodable<D, E> for HashMap<K, V, H> {
|
||||
fn decode(d: &mut D) -> Result<HashMap<K, V, H>, E> {
|
||||
d.read_map(|d, len| {
|
||||
let hasher = Default::default();
|
||||
let mut map = HashMap::with_capacity_and_hasher(len, hasher);
|
||||
for i in range(0u, len) {
|
||||
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
|
||||
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
|
||||
map.insert(key, val);
|
||||
}
|
||||
Ok(map)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
T: Encodable<S, E> + Hash<X> + Eq,
|
||||
X,
|
||||
H: Hasher<X>
|
||||
> Encodable<S, E> for HashSet<T, H> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
let mut i = 0;
|
||||
for e in self.iter() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)));
|
||||
i += 1;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
T: Decodable<D, E> + Hash<S> + Eq,
|
||||
S,
|
||||
H: Hasher<S> + Default
|
||||
> Decodable<D, E> for HashSet<T, H> {
|
||||
fn decode(d: &mut D) -> Result<HashSet<T, H>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut set = HashSet::with_capacity_and_hasher(len, Default::default());
|
||||
for i in range(0u, len) {
|
||||
set.insert(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
Ok(set)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
S: Encoder<E>,
|
||||
V: Encodable<S, E>
|
||||
> Encodable<S, E> for VecMap<V> {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
e.emit_map(self.len(), |e| {
|
||||
for (i, (key, val)) in self.iter().enumerate() {
|
||||
try!(e.emit_map_elt_key(i, |e| key.encode(e)));
|
||||
try!(e.emit_map_elt_val(i, |e| val.encode(e)));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<
|
||||
E,
|
||||
D: Decoder<E>,
|
||||
V: Decodable<D, E>
|
||||
> Decodable<D, E> for VecMap<V> {
|
||||
fn decode(d: &mut D) -> Result<VecMap<V>, E> {
|
||||
d.read_map(|d, len| {
|
||||
let mut map = VecMap::new();
|
||||
for i in range(0u, len) {
|
||||
let key = try!(d.read_map_elt_key(i, |d| Decodable::decode(d)));
|
||||
let val = try!(d.read_map_elt_val(i, |d| Decodable::decode(d)));
|
||||
map.insert(key, val);
|
||||
}
|
||||
Ok(map)
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -23,48 +23,23 @@ Core encoding and decoding interfaces.
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, default_type_params, phase, slicing_syntax, globs)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
// test harness access
|
||||
#[cfg(test)]
|
||||
extern crate test;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(test)] extern crate test;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
extern crate unicode;
|
||||
|
||||
extern crate collections;
|
||||
|
||||
pub use self::serialize::{Decoder, Encoder, Decodable, Encodable,
|
||||
DecoderHelpers, EncoderHelpers};
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[path = "serialize_stage0.rs"]
|
||||
mod serialize;
|
||||
#[cfg(not(stage0))]
|
||||
mod serialize;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[path = "collection_impls_stage0.rs"]
|
||||
mod collection_impls;
|
||||
#[cfg(not(stage0))]
|
||||
mod collection_impls;
|
||||
|
||||
pub mod base64;
|
||||
pub mod hex;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[path = "json_stage0.rs"]
|
||||
pub mod json;
|
||||
#[cfg(not(stage0))]
|
||||
pub mod json;
|
||||
|
||||
mod rustc_serialize {
|
||||
|
|
|
@ -1,630 +0,0 @@
|
|||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Support code for encoding and decoding types.
|
||||
|
||||
/*
|
||||
Core encoding and decoding interfaces.
|
||||
*/
|
||||
|
||||
use std::ops::FullRange;
|
||||
use std::path;
|
||||
use std::rc::Rc;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait Encoder<E> {
|
||||
// Primitive types:
|
||||
fn emit_nil(&mut self) -> Result<(), E>;
|
||||
fn emit_uint(&mut self, v: uint) -> Result<(), E>;
|
||||
fn emit_u64(&mut self, v: u64) -> Result<(), E>;
|
||||
fn emit_u32(&mut self, v: u32) -> Result<(), E>;
|
||||
fn emit_u16(&mut self, v: u16) -> Result<(), E>;
|
||||
fn emit_u8(&mut self, v: u8) -> Result<(), E>;
|
||||
fn emit_int(&mut self, v: int) -> Result<(), E>;
|
||||
fn emit_i64(&mut self, v: i64) -> Result<(), E>;
|
||||
fn emit_i32(&mut self, v: i32) -> Result<(), E>;
|
||||
fn emit_i16(&mut self, v: i16) -> Result<(), E>;
|
||||
fn emit_i8(&mut self, v: i8) -> Result<(), E>;
|
||||
fn emit_bool(&mut self, v: bool) -> Result<(), E>;
|
||||
fn emit_f64(&mut self, v: f64) -> Result<(), E>;
|
||||
fn emit_f32(&mut self, v: f32) -> Result<(), E>;
|
||||
fn emit_char(&mut self, v: char) -> Result<(), E>;
|
||||
fn emit_str(&mut self, v: &str) -> Result<(), E>;
|
||||
|
||||
// Compound types:
|
||||
fn emit_enum<F>(&mut self, name: &str, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_enum_variant<F>(&mut self, v_name: &str,
|
||||
v_id: uint,
|
||||
len: uint,
|
||||
f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_enum_variant_arg<F>(&mut self, a_idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_enum_struct_variant<F>(&mut self, v_name: &str,
|
||||
v_id: uint,
|
||||
len: uint,
|
||||
f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_enum_struct_variant_field<F>(&mut self,
|
||||
f_name: &str,
|
||||
f_idx: uint,
|
||||
f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_struct<F>(&mut self, name: &str, len: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_struct_field<F>(&mut self, f_name: &str, f_idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_tuple<F>(&mut self, len: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_tuple_arg<F>(&mut self, idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_tuple_struct<F>(&mut self, name: &str, len: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_tuple_struct_arg<F>(&mut self, f_idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
// Specialized types:
|
||||
fn emit_option<F>(&mut self, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_option_none(&mut self) -> Result<(), E>;
|
||||
fn emit_option_some<F>(&mut self, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_seq<F>(&mut self, len: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_seq_elt<F>(&mut self, idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
|
||||
fn emit_map<F>(&mut self, len: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
fn emit_map_elt_key<F>(&mut self, idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnMut(&mut Self) -> Result<(), E>;
|
||||
fn emit_map_elt_val<F>(&mut self, idx: uint, f: F) -> Result<(), E> where
|
||||
F: FnOnce(&mut Self) -> Result<(), E>;
|
||||
}
|
||||
|
||||
pub trait Decoder<E> {
|
||||
// Primitive types:
|
||||
fn read_nil(&mut self) -> Result<(), E>;
|
||||
fn read_uint(&mut self) -> Result<uint, E>;
|
||||
fn read_u64(&mut self) -> Result<u64, E>;
|
||||
fn read_u32(&mut self) -> Result<u32, E>;
|
||||
fn read_u16(&mut self) -> Result<u16, E>;
|
||||
fn read_u8(&mut self) -> Result<u8, E>;
|
||||
fn read_int(&mut self) -> Result<int, E>;
|
||||
fn read_i64(&mut self) -> Result<i64, E>;
|
||||
fn read_i32(&mut self) -> Result<i32, E>;
|
||||
fn read_i16(&mut self) -> Result<i16, E>;
|
||||
fn read_i8(&mut self) -> Result<i8, E>;
|
||||
fn read_bool(&mut self) -> Result<bool, E>;
|
||||
fn read_f64(&mut self) -> Result<f64, E>;
|
||||
fn read_f32(&mut self) -> Result<f32, E>;
|
||||
fn read_char(&mut self) -> Result<char, E>;
|
||||
fn read_str(&mut self) -> Result<String, E>;
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T, F>(&mut self, name: &str, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_enum_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where
|
||||
F: FnMut(&mut Self, uint) -> Result<T, E>;
|
||||
fn read_enum_variant_arg<T, F>(&mut self, a_idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_enum_struct_variant<T, F>(&mut self, names: &[&str], f: F) -> Result<T, E> where
|
||||
F: FnMut(&mut Self, uint) -> Result<T, E>;
|
||||
fn read_enum_struct_variant_field<T, F>(&mut self,
|
||||
&f_name: &str,
|
||||
f_idx: uint,
|
||||
f: F)
|
||||
-> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_struct<T, F>(&mut self, s_name: &str, len: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
fn read_struct_field<T, F>(&mut self,
|
||||
f_name: &str,
|
||||
f_idx: uint,
|
||||
f: F)
|
||||
-> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_tuple<T, F>(&mut self, len: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
fn read_tuple_arg<T, F>(&mut self, a_idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_tuple_struct<T, F>(&mut self, s_name: &str, len: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
fn read_tuple_struct_arg<T, F>(&mut self, a_idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
// Specialized types:
|
||||
fn read_option<T, F>(&mut self, f: F) -> Result<T, E> where
|
||||
F: FnMut(&mut Self, bool) -> Result<T, E>;
|
||||
|
||||
fn read_seq<T, F>(&mut self, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self, uint) -> Result<T, E>;
|
||||
fn read_seq_elt<T, F>(&mut self, idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
fn read_map<T, F>(&mut self, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self, uint) -> Result<T, E>;
|
||||
fn read_map_elt_key<T, F>(&mut self, idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
fn read_map_elt_val<T, F>(&mut self, idx: uint, f: F) -> Result<T, E> where
|
||||
F: FnOnce(&mut Self) -> Result<T, E>;
|
||||
|
||||
// Failure
|
||||
fn error(&mut self, err: &str) -> E;
|
||||
}
|
||||
|
||||
pub trait Encodable<S:Encoder<E>, E> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E>;
|
||||
}
|
||||
|
||||
pub trait Decodable<D:Decoder<E>, E> {
|
||||
fn decode(d: &mut D) -> Result<Self, E>;
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for uint {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_uint(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for uint {
|
||||
fn decode(d: &mut D) -> Result<uint, E> {
|
||||
d.read_uint()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for u8 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_u8(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for u8 {
|
||||
fn decode(d: &mut D) -> Result<u8, E> {
|
||||
d.read_u8()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for u16 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_u16(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for u16 {
|
||||
fn decode(d: &mut D) -> Result<u16, E> {
|
||||
d.read_u16()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for u32 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_u32(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for u32 {
|
||||
fn decode(d: &mut D) -> Result<u32, E> {
|
||||
d.read_u32()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for u64 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_u64(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for u64 {
|
||||
fn decode(d: &mut D) -> Result<u64, E> {
|
||||
d.read_u64()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for int {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_int(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for int {
|
||||
fn decode(d: &mut D) -> Result<int, E> {
|
||||
d.read_int()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for i8 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_i8(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for i8 {
|
||||
fn decode(d: &mut D) -> Result<i8, E> {
|
||||
d.read_i8()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for i16 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_i16(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for i16 {
|
||||
fn decode(d: &mut D) -> Result<i16, E> {
|
||||
d.read_i16()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for i32 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_i32(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for i32 {
|
||||
fn decode(d: &mut D) -> Result<i32, E> {
|
||||
d.read_i32()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for i64 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_i64(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for i64 {
|
||||
fn decode(d: &mut D) -> Result<i64, E> {
|
||||
d.read_i64()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for str {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for String {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(self.index(&FullRange))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for String {
|
||||
fn decode(d: &mut D) -> Result<String, E> {
|
||||
d.read_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for f32 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_f32(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for f32 {
|
||||
fn decode(d: &mut D) -> Result<f32, E> {
|
||||
d.read_f32()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for f64 {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_f64(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for f64 {
|
||||
fn decode(d: &mut D) -> Result<f64, E> {
|
||||
d.read_f64()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for bool {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_bool(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for bool {
|
||||
fn decode(d: &mut D) -> Result<bool, E> {
|
||||
d.read_bool()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for char {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_char(*self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for char {
|
||||
fn decode(d: &mut D) -> Result<char, E> {
|
||||
d.read_char()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> Encodable<S, E> for () {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_nil()
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> Decodable<D, E> for () {
|
||||
fn decode(d: &mut D) -> Result<(), E> {
|
||||
d.read_nil()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E, S: Encoder<E>, T: ?Sized + Encodable<S, E>> Encodable<S, E> for &'a T {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>, T: ?Sized + Encodable<S, E>> Encodable<S, E> for Box<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for Box<T> {
|
||||
fn decode(d: &mut D) -> Result<Box<T>, E> {
|
||||
Ok(box try!(Decodable::decode(d)))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for Box<[T]> {
|
||||
fn decode(d: &mut D) -> Result<Box<[T]>, E> {
|
||||
let v: Vec<T> = try!(Decodable::decode(d));
|
||||
Ok(v.into_boxed_slice())
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Rc<T> {
|
||||
#[inline]
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for Rc<T> {
|
||||
#[inline]
|
||||
fn decode(d: &mut D) -> Result<Rc<T>, E> {
|
||||
Ok(Rc::new(try!(Decodable::decode(d))))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for [T] {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)))
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Vec<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_seq(self.len(), |s| {
|
||||
for (i, e) in self.iter().enumerate() {
|
||||
try!(s.emit_seq_elt(i, |s| e.encode(s)))
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for Vec<T> {
|
||||
fn decode(d: &mut D) -> Result<Vec<T>, E> {
|
||||
d.read_seq(|d, len| {
|
||||
let mut v = Vec::with_capacity(len);
|
||||
for i in range(0, len) {
|
||||
v.push(try!(d.read_seq_elt(i, |d| Decodable::decode(d))));
|
||||
}
|
||||
Ok(v)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>,T:Encodable<S, E>> Encodable<S, E> for Option<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_option(|s| {
|
||||
match *self {
|
||||
None => s.emit_option_none(),
|
||||
Some(ref v) => s.emit_option_some(|s| v.encode(s)),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>> Decodable<D, E> for Option<T> {
|
||||
fn decode(d: &mut D) -> Result<Option<T>, E> {
|
||||
d.read_option(|d, b| {
|
||||
if b {
|
||||
Ok(Some(try!(Decodable::decode(d))))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! peel {
|
||||
($name:ident, $($other:ident,)*) => (tuple! { $($other,)* })
|
||||
}
|
||||
|
||||
/// Evaluates to the number of identifiers passed to it, for example: `count_idents!(a, b, c) == 3
|
||||
macro_rules! count_idents {
|
||||
() => { 0u };
|
||||
($_i:ident $(, $rest:ident)*) => { 1 + count_idents!($($rest),*) }
|
||||
}
|
||||
|
||||
macro_rules! tuple {
|
||||
() => ();
|
||||
( $($name:ident,)+ ) => (
|
||||
impl<E, D:Decoder<E>,$($name:Decodable<D, E>),*> Decodable<D,E> for ($($name,)*) {
|
||||
#[allow(non_snake_case)]
|
||||
fn decode(d: &mut D) -> Result<($($name,)*), E> {
|
||||
let len: uint = count_idents!($($name),*);
|
||||
d.read_tuple(len, |d| {
|
||||
let mut i = 0;
|
||||
let ret = ($(try!(d.read_tuple_arg({ i+=1; i-1 }, |d| -> Result<$name,E> {
|
||||
Decodable::decode(d)
|
||||
})),)*);
|
||||
return Ok(ret);
|
||||
})
|
||||
}
|
||||
}
|
||||
impl<E, S:Encoder<E>,$($name:Encodable<S, E>),*> Encodable<S, E> for ($($name,)*) {
|
||||
#[allow(non_snake_case)]
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
let ($(ref $name,)*) = *self;
|
||||
let mut n = 0;
|
||||
$(let $name = $name; n += 1;)*
|
||||
s.emit_tuple(n, |s| {
|
||||
let mut i = 0;
|
||||
$(try!(s.emit_tuple_arg({ i+=1; i-1 }, |s| $name.encode(s)));)*
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
peel! { $($name,)* }
|
||||
)
|
||||
}
|
||||
|
||||
tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, }
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for path::posix::Path {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
self.as_vec().encode(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D: Decoder<E>> Decodable<D, E> for path::posix::Path {
|
||||
fn decode(d: &mut D) -> Result<path::posix::Path, E> {
|
||||
let bytes: Vec<u8> = try!(Decodable::decode(d));
|
||||
Ok(path::posix::Path::new(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>> Encodable<S, E> for path::windows::Path {
|
||||
fn encode(&self, e: &mut S) -> Result<(), E> {
|
||||
self.as_vec().encode(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D: Decoder<E>> Decodable<D, E> for path::windows::Path {
|
||||
fn decode(d: &mut D) -> Result<path::windows::Path, E> {
|
||||
let bytes: Vec<u8> = try!(Decodable::decode(d));
|
||||
Ok(path::windows::Path::new(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S: Encoder<E>, T: Encodable<S, E> + Copy> Encodable<S, E> for Cell<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
self.get().encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D: Decoder<E>, T: Decodable<D, E> + Copy> Decodable<D, E> for Cell<T> {
|
||||
fn decode(d: &mut D) -> Result<Cell<T>, E> {
|
||||
Ok(Cell::new(try!(Decodable::decode(d))))
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: #15036
|
||||
// Should use `try_borrow`, returning a
|
||||
// `encoder.error("attempting to Encode borrowed RefCell")`
|
||||
// from `encode` when `try_borrow` returns `None`.
|
||||
|
||||
impl<E, S: Encoder<E>, T: Encodable<S, E>> Encodable<S, E> for RefCell<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
self.borrow().encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D: Decoder<E>, T: Decodable<D, E>> Decodable<D, E> for RefCell<T> {
|
||||
fn decode(d: &mut D) -> Result<RefCell<T>, E> {
|
||||
Ok(RefCell::new(try!(Decodable::decode(d))))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>, T:Encodable<S, E>> Encodable<S, E> for Arc<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>,T:Decodable<D, E>+Send+Sync> Decodable<D, E> for Arc<T> {
|
||||
fn decode(d: &mut D) -> Result<Arc<T>, E> {
|
||||
Ok(Arc::new(try!(Decodable::decode(d))))
|
||||
}
|
||||
}
|
||||
|
||||
// ___________________________________________________________________________
|
||||
// Helper routines
|
||||
|
||||
pub trait EncoderHelpers<E> {
|
||||
fn emit_from_vec<T, F>(&mut self, v: &[T], f: F) -> Result<(), E> where
|
||||
F: FnMut(&mut Self, &T) -> Result<(), E>;
|
||||
}
|
||||
|
||||
impl<E, S:Encoder<E>> EncoderHelpers<E> for S {
|
||||
fn emit_from_vec<T, F>(&mut self, v: &[T], mut f: F) -> Result<(), E> where
|
||||
F: FnMut(&mut S, &T) -> Result<(), E>,
|
||||
{
|
||||
self.emit_seq(v.len(), |this| {
|
||||
for (i, e) in v.iter().enumerate() {
|
||||
try!(this.emit_seq_elt(i, |this| {
|
||||
f(this, e)
|
||||
}));
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub trait DecoderHelpers<E> {
|
||||
fn read_to_vec<T, F>(&mut self, f: F) -> Result<Vec<T>, E> where
|
||||
F: FnMut(&mut Self) -> Result<T, E>;
|
||||
}
|
||||
|
||||
impl<E, D:Decoder<E>> DecoderHelpers<E> for D {
|
||||
fn read_to_vec<T, F>(&mut self, mut f: F) -> Result<Vec<T>, E> where F:
|
||||
FnMut(&mut D) -> Result<T, E>,
|
||||
{
|
||||
self.read_seq(|this, len| {
|
||||
let mut v = Vec::with_capacity(len);
|
||||
for i in range(0, len) {
|
||||
v.push(try!(this.read_seq_elt(i, |this| f(this))));
|
||||
}
|
||||
Ok(v)
|
||||
})
|
||||
}
|
||||
}
|
|
@ -22,9 +22,6 @@ use iter::{Iterator, IteratorExt, FromIterator, Map, Chain, Extend};
|
|||
use ops::{BitOr, BitAnd, BitXor, Sub};
|
||||
use option::Option::{Some, None, self};
|
||||
|
||||
// NOTE: for old macros; remove after the next snapshot
|
||||
#[cfg(stage0)] use result::Result::{Ok, Err};
|
||||
|
||||
use super::map::{self, HashMap, Keys, INITIAL_CAPACITY};
|
||||
|
||||
// Future Optimization (FIXME!)
|
||||
|
|
|
@ -23,9 +23,6 @@ use slice::{SliceExt};
|
|||
use slice;
|
||||
use vec::Vec;
|
||||
|
||||
// NOTE: for old macros; remove after the next snapshot
|
||||
#[cfg(stage0)] use result::Result::Err;
|
||||
|
||||
/// Wraps a Reader and buffers input from it
|
||||
///
|
||||
/// It can be excessively inefficient to work directly with a `Reader`. For
|
||||
|
|
|
@ -285,8 +285,7 @@ pub mod stdio;
|
|||
pub mod timer;
|
||||
pub mod util;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod test;
|
||||
|
||||
/// The default buffer size for various I/O operations
|
||||
|
|
|
@ -104,42 +104,24 @@
|
|||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, globs, linkage, thread_local, asm)]
|
||||
#![feature(default_type_params, phase, lang_items, unsafe_destructor)]
|
||||
#![feature(linkage, thread_local, asm)]
|
||||
#![feature(phase, lang_items, unsafe_destructor)]
|
||||
#![feature(slicing_syntax, unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
// Don't link to std. We are std.
|
||||
#![no_std]
|
||||
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
#[cfg(all(test, stage0))]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(all(test, not(stage0)))]
|
||||
#[cfg(test)]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
#[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq,
|
||||
unreachable, unimplemented, write, writeln)]
|
||||
unreachable, unimplemented, write, writeln)]
|
||||
extern crate core;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate "collections" as core_collections;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
#[macro_reexport(vec)]
|
||||
extern crate "collections" as core_collections;
|
||||
|
@ -190,18 +172,10 @@ pub use unicode::char;
|
|||
|
||||
/* Exported macros */
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
pub mod macros_stage0;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod macros;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod bitflags;
|
||||
|
||||
mod rtdeps;
|
||||
|
@ -214,18 +188,15 @@ pub mod prelude;
|
|||
/* Primitive types */
|
||||
|
||||
#[path = "num/float_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod float_macros;
|
||||
|
||||
#[path = "num/int_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod int_macros;
|
||||
|
||||
#[path = "num/uint_macros.rs"]
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod uint_macros;
|
||||
|
||||
#[path = "num/int.rs"] pub mod int;
|
||||
|
@ -253,8 +224,7 @@ pub mod num;
|
|||
|
||||
/* Runtime and platform support */
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod thread_local;
|
||||
|
||||
pub mod dynamic_lib;
|
||||
|
|
|
@ -1,648 +0,0 @@
|
|||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Standard library macros
|
||||
//!
|
||||
//! This modules contains a set of macros which are exported from the standard
|
||||
//! library. Each macro is available for use when linking against the standard
|
||||
//! library.
|
||||
|
||||
#![experimental]
|
||||
|
||||
/// The entry point for panic of Rust tasks.
|
||||
///
|
||||
/// This macro is used to inject panic into a Rust task, causing the task to
|
||||
/// unwind and panic entirely. Each task's panic can be reaped as the
|
||||
/// `Box<Any>` type, and the single-argument form of the `panic!` macro will be
|
||||
/// the value which is transmitted.
|
||||
///
|
||||
/// The multi-argument form of this macro panics with a string and has the
|
||||
/// `format!` syntax for building a string.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```should_fail
|
||||
/// # #![allow(unreachable_code)]
|
||||
/// panic!();
|
||||
/// panic!("this is a terrible mistake!");
|
||||
/// panic!(4i); // panic with the value of 4 to be collected elsewhere
|
||||
/// panic!("this is a {} {message}", "fancy", message = "message");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! panic {
|
||||
() => ({
|
||||
panic!("explicit panic")
|
||||
});
|
||||
($msg:expr) => ({
|
||||
// static requires less code at runtime, more constant data
|
||||
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
|
||||
::std::rt::begin_unwind($msg, &_FILE_LINE)
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
// The leading _'s are to avoid dead code warnings if this is
|
||||
// used inside a dead function. Just `#[allow(dead_code)]` is
|
||||
// insufficient, since the user may have
|
||||
// `#[forbid(dead_code)]` and which cannot be overridden.
|
||||
static _FILE_LINE: (&'static str, uint) = (file!(), line!());
|
||||
::std::rt::begin_unwind_fmt(format_args!($fmt, $($arg)*), &_FILE_LINE)
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/// Ensure that a boolean expression is `true` at runtime.
|
||||
///
|
||||
/// This will invoke the `panic!` macro if the provided expression cannot be
|
||||
/// evaluated to `true` at runtime.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// // the panic message for these assertions is the stringified value of the
|
||||
/// // expression given.
|
||||
/// assert!(true);
|
||||
/// # fn some_computation() -> bool { true }
|
||||
/// assert!(some_computation());
|
||||
///
|
||||
/// // assert with a custom message
|
||||
/// # let x = true;
|
||||
/// assert!(x, "x wasn't true!");
|
||||
/// # let a = 3i; let b = 27i;
|
||||
/// assert!(a + b == 30, "a = {}, b = {}", a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert {
|
||||
($cond:expr) => (
|
||||
if !$cond {
|
||||
panic!(concat!("assertion failed: ", stringify!($cond)))
|
||||
}
|
||||
);
|
||||
($cond:expr, $($arg:expr),+) => (
|
||||
if !$cond {
|
||||
panic!($($arg),+)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/// Asserts that two expressions are equal to each other, testing equality in
|
||||
/// both directions.
|
||||
///
|
||||
/// On panic, this macro will print the values of the expressions.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let a = 3i;
|
||||
/// let b = 1i + 2i;
|
||||
/// assert_eq!(a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! assert_eq {
|
||||
($left:expr , $right:expr) => ({
|
||||
match (&($left), &($right)) {
|
||||
(left_val, right_val) => {
|
||||
// check both directions of equality....
|
||||
if !((*left_val == *right_val) &&
|
||||
(*right_val == *left_val)) {
|
||||
panic!("assertion failed: `(left == right) && (right == left)` \
|
||||
(left: `{}`, right: `{}`)", *left_val, *right_val)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Ensure that a boolean expression is `true` at runtime.
|
||||
///
|
||||
/// This will invoke the `panic!` macro if the provided expression cannot be
|
||||
/// evaluated to `true` at runtime.
|
||||
///
|
||||
/// Unlike `assert!`, `debug_assert!` statements can be disabled by passing
|
||||
/// `--cfg ndebug` to the compiler. This makes `debug_assert!` useful for
|
||||
/// checks that are too expensive to be present in a release build but may be
|
||||
/// helpful during development.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// // the panic message for these assertions is the stringified value of the
|
||||
/// // expression given.
|
||||
/// debug_assert!(true);
|
||||
/// # fn some_expensive_computation() -> bool { true }
|
||||
/// debug_assert!(some_expensive_computation());
|
||||
///
|
||||
/// // assert with a custom message
|
||||
/// # let x = true;
|
||||
/// debug_assert!(x, "x wasn't true!");
|
||||
/// # let a = 3i; let b = 27i;
|
||||
/// debug_assert!(a + b == 30, "a = {}, b = {}", a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! debug_assert {
|
||||
($($arg:tt)*) => (if cfg!(not(ndebug)) { assert!($($arg)*); })
|
||||
}
|
||||
|
||||
/// Asserts that two expressions are equal to each other, testing equality in
|
||||
/// both directions.
|
||||
///
|
||||
/// On panic, this macro will print the values of the expressions.
|
||||
///
|
||||
/// Unlike `assert_eq!`, `debug_assert_eq!` statements can be disabled by
|
||||
/// passing `--cfg ndebug` to the compiler. This makes `debug_assert_eq!`
|
||||
/// useful for checks that are too expensive to be present in a release build
|
||||
/// but may be helpful during development.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let a = 3i;
|
||||
/// let b = 1i + 2i;
|
||||
/// debug_assert_eq!(a, b);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! debug_assert_eq {
|
||||
($($arg:tt)*) => (if cfg!(not(ndebug)) { assert_eq!($($arg)*); })
|
||||
}
|
||||
|
||||
/// A utility macro for indicating unreachable code.
|
||||
///
|
||||
/// This is useful any time that the compiler can't determine that some code is unreachable. For
|
||||
/// example:
|
||||
///
|
||||
/// * Match arms with guard conditions.
|
||||
/// * Loops that dynamically terminate.
|
||||
/// * Iterators that dynamically terminate.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This will always panic.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// Match arms:
|
||||
///
|
||||
/// ```rust
|
||||
/// fn foo(x: Option<int>) {
|
||||
/// match x {
|
||||
/// Some(n) if n >= 0 => println!("Some(Non-negative)"),
|
||||
/// Some(n) if n < 0 => println!("Some(Negative)"),
|
||||
/// Some(_) => unreachable!(), // compile error if commented out
|
||||
/// None => println!("None")
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Iterators:
|
||||
///
|
||||
/// ```rust
|
||||
/// fn divide_by_three(x: u32) -> u32 { // one of the poorest implementations of x/3
|
||||
/// for i in std::iter::count(0_u32, 1) {
|
||||
/// if 3*i < i { panic!("u32 overflow"); }
|
||||
/// if x < 3*i { return i-1; }
|
||||
/// }
|
||||
/// unreachable!();
|
||||
/// }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! unreachable {
|
||||
() => ({
|
||||
panic!("internal error: entered unreachable code")
|
||||
});
|
||||
($msg:expr) => ({
|
||||
unreachable!("{}", $msg)
|
||||
});
|
||||
($fmt:expr, $($arg:tt)*) => ({
|
||||
panic!(concat!("internal error: entered unreachable code: ", $fmt), $($arg)*)
|
||||
});
|
||||
}
|
||||
|
||||
/// A standardised placeholder for marking unfinished code. It panics with the
|
||||
/// message `"not yet implemented"` when executed.
|
||||
#[macro_export]
|
||||
macro_rules! unimplemented {
|
||||
() => (panic!("not yet implemented"))
|
||||
}
|
||||
|
||||
/// Use the syntax described in `std::fmt` to create a value of type `String`.
|
||||
/// See `std::fmt` for more information.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// format!("test");
|
||||
/// format!("hello {}", "world!");
|
||||
/// format!("x = {}, y = {y}", 10i, y = 30i);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! format {
|
||||
($($arg:tt)*) => (::std::fmt::format(format_args!($($arg)*)))
|
||||
}
|
||||
|
||||
/// Use the `format!` syntax to write data into a buffer of type `&mut Writer`.
|
||||
/// See `std::fmt` for more information.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # #![allow(unused_must_use)]
|
||||
///
|
||||
/// let mut w = Vec::new();
|
||||
/// write!(&mut w, "test");
|
||||
/// write!(&mut w, "formatted {}", "arguments");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! write {
|
||||
($dst:expr, $($arg:tt)*) => ((&mut *$dst).write_fmt(format_args!($($arg)*)))
|
||||
}
|
||||
|
||||
/// Equivalent to the `write!` macro, except that a newline is appended after
|
||||
/// the message is written.
|
||||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! writeln {
|
||||
($dst:expr, $fmt:expr $($arg:tt)*) => (
|
||||
write!($dst, concat!($fmt, "\n") $($arg)*)
|
||||
)
|
||||
}
|
||||
|
||||
/// Equivalent to the `println!` macro except that a newline is not printed at
|
||||
/// the end of the message.
|
||||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => (::std::io::stdio::print_args(format_args!($($arg)*)))
|
||||
}
|
||||
|
||||
/// Macro for printing to a task's stdout handle.
|
||||
///
|
||||
/// Each task can override its stdout handle via `std::io::stdio::set_stdout`.
|
||||
/// The syntax of this macro is the same as that used for `format!`. For more
|
||||
/// information, see `std::fmt` and `std::io::stdio`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// println!("hello there!");
|
||||
/// println!("format {} arguments", "some");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
#[stable]
|
||||
macro_rules! println {
|
||||
($($arg:tt)*) => (::std::io::stdio::println_args(format_args!($($arg)*)))
|
||||
}
|
||||
|
||||
/// Helper macro for unwrapping `Result` values while returning early with an
|
||||
/// error if the value of the expression is `Err`. For more information, see
|
||||
/// `std::io`.
|
||||
#[macro_export]
|
||||
macro_rules! try {
|
||||
($expr:expr) => ({
|
||||
match $expr {
|
||||
Ok(val) => val,
|
||||
Err(err) => return Err(::std::error::FromError::from_error(err))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Create a `std::vec::Vec` containing the arguments.
|
||||
#[macro_export]
|
||||
macro_rules! vec {
|
||||
($($x:expr),*) => ({
|
||||
let xs: ::std::boxed::Box<[_]> = box [$($x),*];
|
||||
::std::slice::SliceExt::into_vec(xs)
|
||||
});
|
||||
($($x:expr,)*) => (vec![$($x),*])
|
||||
}
|
||||
|
||||
/// A macro to select an event from a number of receivers.
|
||||
///
|
||||
/// This macro is used to wait for the first event to occur on a number of
|
||||
/// receivers. It places no restrictions on the types of receivers given to
|
||||
/// this macro, this can be viewed as a heterogeneous select.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::thread::Thread;
|
||||
/// use std::sync::mpsc::channel;
|
||||
///
|
||||
/// let (tx1, rx1) = channel();
|
||||
/// let (tx2, rx2) = channel();
|
||||
/// # fn long_running_task() {}
|
||||
/// # fn calculate_the_answer() -> int { 42i }
|
||||
///
|
||||
/// Thread::spawn(move|| { long_running_task(); tx1.send(()) }).detach();
|
||||
/// Thread::spawn(move|| { tx2.send(calculate_the_answer()) }).detach();
|
||||
///
|
||||
/// select! (
|
||||
/// _ = rx1.recv() => println!("the long running task finished first"),
|
||||
/// answer = rx2.recv() => {
|
||||
/// println!("the answer was: {}", answer.unwrap());
|
||||
/// }
|
||||
/// )
|
||||
/// ```
|
||||
///
|
||||
/// For more information about select, see the `std::sync::mpsc::Select` structure.
|
||||
#[macro_export]
|
||||
#[experimental]
|
||||
macro_rules! select {
|
||||
(
|
||||
$($name:pat = $rx:ident.$meth:ident() => $code:expr),+
|
||||
) => ({
|
||||
use std::sync::mpsc::Select;
|
||||
let sel = Select::new();
|
||||
$( let mut $rx = sel.handle(&$rx); )+
|
||||
unsafe {
|
||||
$( $rx.add(); )+
|
||||
}
|
||||
let ret = sel.wait();
|
||||
$( if ret == $rx.id() { let $name = $rx.$meth(); $code } else )+
|
||||
{ unreachable!() }
|
||||
})
|
||||
}
|
||||
|
||||
// When testing the standard library, we link to the liblog crate to get the
|
||||
// logging macros. In doing so, the liblog crate was linked against the real
|
||||
// version of libstd, and uses a different std::fmt module than the test crate
|
||||
// uses. To get around this difference, we redefine the log!() macro here to be
|
||||
// just a dumb version of what it should be.
|
||||
#[cfg(test)]
|
||||
macro_rules! log {
|
||||
($lvl:expr, $($args:tt)*) => (
|
||||
if log_enabled!($lvl) { println!($($args)*) }
|
||||
)
|
||||
}
|
||||
|
||||
/// Built-in macros to the compiler itself.
|
||||
///
|
||||
/// These macros do not have any corresponding definition with a `macro_rules!`
|
||||
/// macro, but are documented here. Their implementations can be found hardcoded
|
||||
/// into libsyntax itself.
|
||||
#[cfg(dox)]
|
||||
pub mod builtin {
|
||||
/// The core macro for formatted string creation & output.
|
||||
///
|
||||
/// This macro produces a value of type `fmt::Arguments`. This value can be
|
||||
/// passed to the functions in `std::fmt` for performing useful functions.
|
||||
/// All other formatting macros (`format!`, `write!`, `println!`, etc) are
|
||||
/// proxied through this one.
|
||||
///
|
||||
/// For more information, see the documentation in `std::fmt`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::fmt;
|
||||
///
|
||||
/// let s = fmt::format(format_args!("hello {}", "world"));
|
||||
/// assert_eq!(s, format!("hello {}", "world"));
|
||||
///
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! format_args { ($fmt:expr $($args:tt)*) => ({
|
||||
/* compiler built-in */
|
||||
}) }
|
||||
|
||||
/// Inspect an environment variable at compile time.
|
||||
///
|
||||
/// This macro will expand to the value of the named environment variable at
|
||||
/// compile time, yielding an expression of type `&'static str`.
|
||||
///
|
||||
/// If the environment variable is not defined, then a compilation error
|
||||
/// will be emitted. To not emit a compile error, use the `option_env!`
|
||||
/// macro instead.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let path: &'static str = env!("PATH");
|
||||
/// println!("the $PATH variable at the time of compiling was: {}", path);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! env { ($name:expr) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Optionally inspect an environment variable at compile time.
|
||||
///
|
||||
/// If the named environment variable is present at compile time, this will
|
||||
/// expand into an expression of type `Option<&'static str>` whose value is
|
||||
/// `Some` of the value of the environment variable. If the environment
|
||||
/// variable is not present, then this will expand to `None`.
|
||||
///
|
||||
/// A compile time error is never emitted when using this macro regardless
|
||||
/// of whether the environment variable is present or not.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let key: Option<&'static str> = option_env!("SECRET_KEY");
|
||||
/// println!("the secret key might be: {}", key);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! option_env { ($name:expr) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Concatenate literals into a static byte slice.
|
||||
///
|
||||
/// This macro takes any number of comma-separated literal expressions,
|
||||
/// yielding an expression of type `&'static [u8]` which is the
|
||||
/// concatenation (left to right) of all the literals in their byte format.
|
||||
///
|
||||
/// This extension currently only supports string literals, character
|
||||
/// literals, and integers less than 256. The byte slice returned is the
|
||||
/// utf8-encoding of strings and characters.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let rust = bytes!("r", 'u', "st", 255);
|
||||
/// assert_eq!(rust[1], b'u');
|
||||
/// assert_eq!(rust[4], 255);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! bytes { ($($e:expr),*) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Concatenate identifiers into one identifier.
|
||||
///
|
||||
/// This macro takes any number of comma-separated identifiers, and
|
||||
/// concatenates them all into one, yielding an expression which is a new
|
||||
/// identifier. Note that hygiene makes it such that this macro cannot
|
||||
/// capture local variables, and macros are only allowed in item,
|
||||
/// statement or expression position, meaning this macro may be difficult to
|
||||
/// use in some situations.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(concat_idents)]
|
||||
///
|
||||
/// # fn main() {
|
||||
/// fn foobar() -> int { 23 }
|
||||
///
|
||||
/// let f = concat_idents!(foo, bar);
|
||||
/// println!("{}", f());
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! concat_idents {
|
||||
($($e:ident),*) => ({ /* compiler built-in */ })
|
||||
}
|
||||
|
||||
/// Concatenates literals into a static string slice.
|
||||
///
|
||||
/// This macro takes any number of comma-separated literals, yielding an
|
||||
/// expression of type `&'static str` which represents all of the literals
|
||||
/// concatenated left-to-right.
|
||||
///
|
||||
/// Integer and floating point literals are stringified in order to be
|
||||
/// concatenated.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let s = concat!("test", 10i, 'b', true);
|
||||
/// assert_eq!(s, "test10btrue");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! concat { ($($e:expr),*) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// A macro which expands to the line number on which it was invoked.
|
||||
///
|
||||
/// The expanded expression has type `uint`, and the returned line is not
|
||||
/// the invocation of the `line!()` macro itself, but rather the first macro
|
||||
/// invocation leading up to the invocation of the `line!()` macro.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let current_line = line!();
|
||||
/// println!("defined on line: {}", current_line);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! line { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// A macro which expands to the column number on which it was invoked.
|
||||
///
|
||||
/// The expanded expression has type `uint`, and the returned column is not
|
||||
/// the invocation of the `column!()` macro itself, but rather the first macro
|
||||
/// invocation leading up to the invocation of the `column!()` macro.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let current_col = column!();
|
||||
/// println!("defined on column: {}", current_col);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! column { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// A macro which expands to the file name from which it was invoked.
|
||||
///
|
||||
/// The expanded expression has type `&'static str`, and the returned file
|
||||
/// is not the invocation of the `file!()` macro itself, but rather the
|
||||
/// first macro invocation leading up to the invocation of the `file!()`
|
||||
/// macro.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let this_file = file!();
|
||||
/// println!("defined in file: {}", this_file);
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! file { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// A macro which stringifies its argument.
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static str` which is the
|
||||
/// stringification of all the tokens passed to the macro. No restrictions
|
||||
/// are placed on the syntax of the macro invocation itself.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// let one_plus_one = stringify!(1 + 1);
|
||||
/// assert_eq!(one_plus_one, "1 + 1");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! stringify { ($t:tt) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Includes a utf8-encoded file as a string.
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static str` which is the
|
||||
/// contents of the filename specified. The file is located relative to the
|
||||
/// current file (similarly to how modules are found),
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// let secret_key = include_str!("secret-key.ascii");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! include_str { ($file:expr) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Includes a file as a byte slice.
|
||||
///
|
||||
/// This macro will yield an expression of type `&'static [u8]` which is
|
||||
/// the contents of the filename specified. The file is located relative to
|
||||
/// the current file (similarly to how modules are found),
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,ignore
|
||||
/// let secret_key = include_bytes!("secret-key.bin");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! include_bytes { ($file:expr) => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Deprecated alias for `include_bytes!()`.
|
||||
#[macro_export]
|
||||
macro_rules! include_bin { ($file:expr) => ({ /* compiler built-in */}) }
|
||||
|
||||
/// Expands to a string that represents the current module path.
|
||||
///
|
||||
/// The current module path can be thought of as the hierarchy of modules
|
||||
/// leading back up to the crate root. The first component of the path
|
||||
/// returned is the name of the crate currently being compiled.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// mod test {
|
||||
/// pub fn foo() {
|
||||
/// assert!(module_path!().ends_with("test"));
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// test::foo();
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! module_path { () => ({ /* compiler built-in */ }) }
|
||||
|
||||
/// Boolean evaluation of configuration flags.
|
||||
///
|
||||
/// In addition to the `#[cfg]` attribute, this macro is provided to allow
|
||||
/// boolean expression evaluation of configuration flags. This frequently
|
||||
/// leads to less duplicated code.
|
||||
///
|
||||
/// The syntax given to this macro is the same syntax as the `cfg`
|
||||
/// attribute.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// let my_directory = if cfg!(windows) {
|
||||
/// "windows-specific-directory"
|
||||
/// } else {
|
||||
/// "unix-directory"
|
||||
/// };
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! cfg { ($cfg:tt) => ({ /* compiler built-in */ }) }
|
||||
}
|
|
@ -28,9 +28,6 @@ mod imp {
|
|||
use mem;
|
||||
use os::errno;
|
||||
|
||||
// NOTE: for old macros; remove after the next snapshot
|
||||
#[cfg(stage0)] use result::Result::Err;
|
||||
|
||||
#[cfg(all(target_os = "linux",
|
||||
any(target_arch = "x86_64",
|
||||
target_arch = "x86",
|
||||
|
|
|
@ -39,8 +39,7 @@ pub use alloc::heap;
|
|||
pub mod backtrace;
|
||||
|
||||
// Internals
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
mod macros;
|
||||
|
||||
// These should be refactored/moved/made private over time
|
||||
|
|
|
@ -40,8 +40,7 @@ use prelude::v1::*;
|
|||
|
||||
use cell::UnsafeCell;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod scoped;
|
||||
|
||||
// Sure wish we had macro hygiene, no?
|
||||
|
|
|
@ -19,9 +19,6 @@ use option::Option::{Some, None};
|
|||
use num::Int;
|
||||
use result::Result::Ok;
|
||||
|
||||
// NOTE: for old macros; remove after the next snapshot
|
||||
#[cfg(stage0)] use result::Result::Err;
|
||||
|
||||
/// The number of nanoseconds in a microsecond.
|
||||
const NANOS_PER_MICRO: i32 = 1000;
|
||||
/// The number of nanoseconds in a millisecond.
|
||||
|
|
|
@ -195,28 +195,12 @@ impl Name {
|
|||
/// A mark represents a unique id associated with a macro expansion
|
||||
pub type Mrk = u32;
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S: Encoder<E>, E> Encodable<S, E> for Ident {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(token::get_ident(*self).get())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Encodable for Ident {
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
s.emit_str(token::get_ident(*self).get())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D: Decoder<E>, E> Decodable<D, E> for Ident {
|
||||
fn decode(d: &mut D) -> Result<Ident, E> {
|
||||
Ok(str_to_ident(try!(d.read_str()).index(&FullRange)))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Decodable for Ident {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<Ident, D::Error> {
|
||||
Ok(str_to_ident(try!(d.read_str()).index(&FullRange)))
|
||||
|
|
|
@ -120,15 +120,6 @@ impl PartialEq for Span {
|
|||
|
||||
impl Eq for Span {}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:Encoder<E>, E> Encodable<S, E> for Span {
|
||||
/* Note #1972 -- spans are encoded but not decoded */
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_nil()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Encodable for Span {
|
||||
/* Note #1972 -- spans are encoded but not decoded */
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
|
@ -136,14 +127,6 @@ impl Encodable for Span {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:Decoder<E>, E> Decodable<D, E> for Span {
|
||||
fn decode(_d: &mut D) -> Result<Span, E> {
|
||||
Ok(DUMMY_SP)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Decodable for Span {
|
||||
fn decode<D: Decoder>(_d: &mut D) -> Result<Span, D::Error> {
|
||||
Ok(DUMMY_SP)
|
||||
|
|
|
@ -602,7 +602,7 @@ impl<'a> MethodDef<'a> {
|
|||
};
|
||||
let mut f = self.combine_substructure.borrow_mut();
|
||||
let f: &mut CombineSubstructureFunc = &mut *f;
|
||||
f.call_mut((cx, trait_.span, &substructure))
|
||||
f(cx, trait_.span, &substructure)
|
||||
}
|
||||
|
||||
fn get_ret_ty(&self,
|
||||
|
@ -1365,8 +1365,8 @@ pub fn cs_fold<F>(use_foldl: bool,
|
|||
}
|
||||
},
|
||||
EnumNonMatchingCollapsed(ref all_args, _, tuple) =>
|
||||
enum_nonmatch_f.call_mut((cx, trait_span, (all_args.index(&FullRange), tuple),
|
||||
substructure.nonself_args)),
|
||||
enum_nonmatch_f(cx, trait_span, (all_args.index(&FullRange), tuple),
|
||||
substructure.nonself_args),
|
||||
StaticEnum(..) | StaticStruct(..) => {
|
||||
cx.span_bug(trait_span, "static function in `derive`")
|
||||
}
|
||||
|
@ -1405,8 +1405,8 @@ pub fn cs_same_method<F>(f: F,
|
|||
f(cx, trait_span, called)
|
||||
},
|
||||
EnumNonMatchingCollapsed(ref all_self_args, _, tuple) =>
|
||||
enum_nonmatch_f.call_mut((cx, trait_span, (all_self_args.index(&FullRange), tuple),
|
||||
substructure.nonself_args)),
|
||||
enum_nonmatch_f(cx, trait_span, (all_self_args.index(&FullRange), tuple),
|
||||
substructure.nonself_args),
|
||||
StaticEnum(..) | StaticStruct(..) => {
|
||||
cx.span_bug(trait_span, "static function in `derive`")
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ pub fn expand_meta_derive(cx: &mut ExtCtxt,
|
|||
MetaWord(ref tname) => {
|
||||
macro_rules! expand {
|
||||
($func:path) => ($func(cx, titem.span, &**titem, item,
|
||||
|i| push.call_mut((i,))))
|
||||
|i| push(i)))
|
||||
}
|
||||
|
||||
match tname.get() {
|
||||
|
|
|
@ -44,7 +44,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
|
|||
("non_ascii_idents", Active),
|
||||
("thread_local", Active),
|
||||
("link_args", Active),
|
||||
("phase", Active), // NOTE(stage0): switch to Removed after next snapshot
|
||||
("phase", Removed),
|
||||
("plugin_registrar", Active),
|
||||
("log_syntax", Active),
|
||||
("trace_macros", Active),
|
||||
|
|
|
@ -23,25 +23,15 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, globs, default_type_params, phase, slicing_syntax)]
|
||||
#![feature(slicing_syntax)]
|
||||
#![feature(quote, unsafe_destructor)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(associated_types)]
|
||||
|
||||
extern crate arena;
|
||||
extern crate fmt_macros;
|
||||
extern crate serialize;
|
||||
extern crate term;
|
||||
extern crate libc;
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
extern crate "serialize" as rustc_serialize; // used by deriving
|
||||
|
||||
|
|
|
@ -82,31 +82,12 @@ impl<T> FromIterator<T> for OwnedSlice<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S: Encoder<E>, T: Encodable<S, E>, E> Encodable<S, E> for OwnedSlice<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
self.as_slice().encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: Encodable> Encodable for OwnedSlice<T> {
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
self.as_slice().encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D: Decoder<E>, T: Decodable<D, E>, E> Decodable<D, E> for OwnedSlice<T> {
|
||||
fn decode(d: &mut D) -> Result<OwnedSlice<T>, E> {
|
||||
Ok(OwnedSlice::from_vec(match Decodable::decode(d) {
|
||||
Ok(t) => t,
|
||||
Err(e) => return Err(e)
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: Decodable> Decodable for OwnedSlice<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<OwnedSlice<T>, D::Error> {
|
||||
Ok(OwnedSlice::from_vec(match Decodable::decode(d) {
|
||||
|
|
|
@ -24,8 +24,7 @@ use std::num::Int;
|
|||
use std::str;
|
||||
use std::iter;
|
||||
|
||||
#[cfg_attr(stage0, macro_escape)]
|
||||
#[cfg_attr(not(stage0), macro_use)]
|
||||
#[macro_use]
|
||||
pub mod parser;
|
||||
|
||||
pub mod lexer;
|
||||
|
|
|
@ -684,29 +684,12 @@ impl<'a> PartialEq<InternedString > for &'a str {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<D:Decoder<E>, E> Decodable<D, E> for InternedString {
|
||||
fn decode(d: &mut D) -> Result<InternedString, E> {
|
||||
Ok(get_name(get_ident_interner().intern(
|
||||
try!(d.read_str()).index(&FullRange))))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Decodable for InternedString {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
|
||||
Ok(get_name(get_ident_interner().intern(try!(d.read_str()).index(&FullRange))))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<S:Encoder<E>, E> Encodable<S, E> for InternedString {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
s.emit_str(self.string.index(&FullRange))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl Encodable for InternedString {
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
s.emit_str(self.string.index(&FullRange))
|
||||
|
|
|
@ -111,28 +111,12 @@ impl<S, T: Hash<S>> Hash<S> for P<T> {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<E, D: Decoder<E>, T: 'static + Decodable<D, E>> Decodable<D, E> for P<T> {
|
||||
fn decode(d: &mut D) -> Result<P<T>, E> {
|
||||
Decodable::decode(d).map(P)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: 'static + Decodable> Decodable for P<T> {
|
||||
fn decode<D: Decoder>(d: &mut D) -> Result<P<T>, D::Error> {
|
||||
Decodable::decode(d).map(P)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage0)]
|
||||
impl<E, S: Encoder<E>, T: Encodable<S, E>> Encodable<S, E> for P<T> {
|
||||
fn encode(&self, s: &mut S) -> Result<(), E> {
|
||||
(**self).encode(s)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
impl<T: Encodable> Encodable for P<T> {
|
||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
(**self).encode(s)
|
||||
|
|
|
@ -48,17 +48,10 @@
|
|||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(macro_rules, phase, slicing_syntax, globs)]
|
||||
|
||||
#![feature(slicing_syntax)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#[cfg(stage0)]
|
||||
#[phase(plugin, link)]
|
||||
extern crate log;
|
||||
|
||||
#[cfg(not(stage0))]
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
pub use terminfo::TerminfoTerminal;
|
||||
#[cfg(windows)]
|
||||
|
|
|
@ -30,11 +30,7 @@
|
|||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![allow(unknown_features)]
|
||||
#![feature(asm, globs, slicing_syntax)]
|
||||
#![feature(unboxed_closures, default_type_params)]
|
||||
#![feature(old_orphan_check)]
|
||||
#![feature(asm, slicing_syntax)]
|
||||
|
||||
extern crate getopts;
|
||||
extern crate regex;
|
||||
|
|
|
@ -28,8 +28,7 @@
|
|||
html_root_url = "http://doc.rust-lang.org/nightly/",
|
||||
html_playground_url = "http://play.rust-lang.org/")]
|
||||
#![no_std]
|
||||
#![feature(globs, macro_rules, slicing_syntax, unboxed_closures)]
|
||||
#![feature(associated_types)]
|
||||
#![feature(slicing_syntax)]
|
||||
|
||||
extern crate core;
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
S 2015-01-06 340ac04
|
||||
freebsd-x86_64 5413b8931d7076e90c873e0cc7a43e0793c2b17a
|
||||
linux-i386 cacb8e3ad15937916e455d8f63e740c30a807b10
|
||||
linux-x86_64 e4a7f73959130671a5eb9107d593d37b43e571b0
|
||||
macos-i386 da6b0b7d12964e815175eb1fe5fc495098ca3125
|
||||
macos-x86_64 edf8a109e175be6e5bc44484261d2248946f1dd1
|
||||
winnt-i386 34fc7d9905d5845cdc7901f661d43a463534a20d
|
||||
winnt-x86_64 99580840f5763f517f47cd55ff373e4d116b018d
|
||||
|
||||
S 2015-01-04 b2085d9
|
||||
freebsd-x86_64 50ccb6bf9c0645d0746a5167493a39b2be40c2d4
|
||||
linux-i386 b880b98d832c9a049b8ef6a50df50061e363de5a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue