#![allow(unused_variable)]
use any;
-use cell::Cell;
+use cell::{Cell, Ref, RefMut};
use char::Char;
use collections::Collection;
use iter::{Iterator, range};
use kinds::Copy;
use mem;
use option::{Option, Some, None};
+use ops::Deref;
use result::{Ok, Err};
use result;
use slice::{Vector, ImmutableVector};
args: &'a [Argument<'a>],
}
- enum CurrentlyFormatting<'a> {
- Nothing,
- RawString(&'a str),
- Number(uint),
- }
-
/// This struct represents the generic "argument" which is taken by the Xprintf
/// family of functions. It contains a function to format the given value. At
/// compile time it is ensured that the function and the value have the correct
curarg: args.args.iter(),
};
for piece in args.fmt.iter() {
- try!(formatter.run(piece, Nothing));
+ try!(formatter.run(piece));
}
Ok(())
}
// at runtime. This consumes all of the compile-time statics generated by
// the format! syntax extension.
- fn run(&mut self, piece: &rt::Piece, cur: CurrentlyFormatting) -> Result {
+ fn run(&mut self, piece: &rt::Piece) -> Result {
match *piece {
rt::String(s) => self.buf.write(s.as_bytes()),
- rt::CurrentArgument(()) => {
- match cur {
- Nothing => Ok(()),
- Number(n) => secret_show(&radix(n, 10), self),
- RawString(s) => self.buf.write(s.as_bytes()),
- }
- }
rt::Argument(ref arg) => {
// Fill in the format parameters into the formatter
self.fill = arg.format.fill;
};
// Then actually do some printing
- match arg.method {
- None => (value.formatter)(value.value, self),
- Some(ref method) => self.execute(*method, value)
- }
+ (value.formatter)(value.value, self)
}
}
}
}
}
- fn execute(&mut self, method: &rt::Method, arg: Argument) -> Result {
- match *method {
- // Pluralization is selection upon a numeric value specified as the
- // parameter.
- rt::Plural(offset, ref selectors, ref default) => {
- // This is validated at compile-time to be a pointer to a
- // '&uint' value.
- let value: &uint = unsafe { mem::transmute(arg.value) };
- let value = *value;
-
- // First, attempt to match against explicit values without the
- // offsetted value
- for s in selectors.iter() {
- match s.selector {
- rt::Literal(val) if value == val => {
- return self.runplural(value, s.result);
- }
- _ => {}
- }
- }
-
- // Next, offset the value and attempt to match against the
- // keyword selectors.
- let value = value - match offset { Some(i) => i, None => 0 };
- for s in selectors.iter() {
- let run = match s.selector {
- rt::Keyword(rt::Zero) => value == 0,
- rt::Keyword(rt::One) => value == 1,
- rt::Keyword(rt::Two) => value == 2,
-
- // FIXME: Few/Many should have a user-specified boundary
- // One possible option would be in the function
- // pointer of the 'arg: Argument' struct.
- rt::Keyword(rt::Few) => value < 8,
- rt::Keyword(rt::Many) => value >= 8,
-
- rt::Literal(..) => false
- };
- if run {
- return self.runplural(value, s.result);
- }
- }
-
- self.runplural(value, *default)
- }
-
- // Select is just a matching against the string specified.
- rt::Select(ref selectors, ref default) => {
- // This is validated at compile-time to be a pointer to a
- // string slice,
- let value: & &str = unsafe { mem::transmute(arg.value) };
- let value = *value;
-
- for s in selectors.iter() {
- if s.selector == value {
- for piece in s.result.iter() {
- try!(self.run(piece, RawString(value)));
- }
- return Ok(());
- }
- }
- for piece in default.iter() {
- try!(self.run(piece, RawString(value)));
- }
- Ok(())
- }
- }
- }
-
- fn runplural(&mut self, value: uint, pieces: &[rt::Piece]) -> Result {
- for piece in pieces.iter() {
- try!(self.run(piece, Number(value)));
- }
- Ok(())
- }
-
// Helper methods used for padding and processing formatting arguments that
// all formatting traits can use.
}
}
-impl<T: Show> Show for ~[T] {
- fn fmt(&self, f: &mut Formatter) -> Result {
- secret_show(&self.as_slice(), f)
- }
-}
-
impl Show for () {
fn fmt(&self, f: &mut Formatter) -> Result {
f.pad("()")
}
impl<T: Copy + Show> Show for Cell<T> {
+ #[cfg(stage0)]
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, r"Cell \{ value: {} \}", self.get())
}
+ #[cfg(not(stage0))]
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ write!(f, "Cell {{ value: {} }}", self.get())
+ }
}
+impl<'b, T: Show> Show for Ref<'b, T> {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ (**self).fmt(f)
+ }
+}
+
+impl<'b, T: Show> Show for RefMut<'b, T> {
+ fn fmt(&self, f: &mut Formatter) -> Result {
+ (*(self.deref())).fmt(f)
+ }
+}
+
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
// it's a lot easier than creating all of the rt::Piece structures here.
UnusedMustUse,
UnusedResult,
- DeprecatedOwnedVector,
-
Warnings,
RawPointerDeriving,
default: Allow,
}),
- ("deprecated_owned_vector",
- LintSpec {
- lint: DeprecatedOwnedVector,
- desc: "use of a `~[T]` vector",
- default: Allow,
- }),
-
("raw_pointer_deriving",
LintSpec {
lint: RawPointerDeriving,
let mut note = None;
let msg = match src {
+ #[cfg(stage0)]
Default => {
format!("{}, \\#[{}({})] on by default", msg,
level_to_str(level), lint_str)
},
+ #[cfg(not(stage0))]
+ Default => {
+ format!("{}, #[{}({})] on by default", msg,
+ level_to_str(level), lint_str)
+ },
CommandLine => {
format!("{} [-{} {}]", msg,
match level {
}
}
-fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) {
- let t = ty::expr_ty(cx.tcx, e);
- match ty::get(t).sty {
- ty::ty_uniq(t) => match ty::get(t).sty {
- ty::ty_vec(_, None) => {
- cx.span_lint(DeprecatedOwnedVector, e.span,
- "use of deprecated `~[]` vector; replaced by `std::vec::Vec`")
- }
- _ => {}
- },
- _ => {}
- }
-}
-
fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) {
fn is_camel_case(ident: ast::Ident) -> bool {
let ident = token::get_ident(ident);
check_type_limits(self, e);
check_unused_casts(self, e);
- check_deprecated_owned_vector(self, e);
visit::walk_expr(self, e, ());
}
}
Some(declaration) => {
for argument in declaration.inputs.iter() {
+ let mut bindings_list = HashMap::new();
this.resolve_pattern(&*argument.pat,
ArgumentIrrefutableMode,
- None);
+ &mut bindings_list);
this.resolve_type(&*argument.ty);
}
// Resolve the pattern.
- self.resolve_pattern(&*local.pat, LocalIrrefutableMode, None);
+ let mut bindings_list = HashMap::new();
+ self.resolve_pattern(&*local.pat,
+ LocalIrrefutableMode,
+ &mut bindings_list);
}
// build a map from pattern identifiers to binding-info's.
for (&key, &binding_0) in map_0.iter() {
match map_i.find(&key) {
+ #[cfg(stage0)]
None => {
self.resolve_error(
p.span,
token::get_name(key),
i + 1).as_slice());
}
+ #[cfg(not(stage0))]
+ None => {
+ self.resolve_error(
+ p.span,
+ format!("variable `{}` from pattern #1 is \
+ not bound in pattern #{}",
+ token::get_name(key),
+ i + 1).as_slice());
+ }
+ #[cfg(stage0)]
Some(binding_i) => {
if binding_0.binding_mode != binding_i.binding_mode {
self.resolve_error(
i + 1).as_slice());
}
}
+ #[cfg(not(stage0))]
+ Some(binding_i) => {
+ if binding_0.binding_mode != binding_i.binding_mode {
+ self.resolve_error(
+ binding_i.span,
+ format!("variable `{}` is bound with different \
+ mode in pattern #{} than in pattern #1",
+ token::get_name(key),
+ i + 1).as_slice());
+ }
+ }
}
}
if !map_0.contains_key(&key) {
self.resolve_error(
binding.span,
- format!("variable `{}` from pattern \\#{} is \
- not bound in pattern \\#1",
+ format!("variable `{}` from pattern {}{} is \
+ not bound in pattern {}1",
token::get_name(key),
- i + 1).as_slice());
+ "#", i + 1, "#").as_slice());
}
}
}
let mut bindings_list = HashMap::new();
for pattern in arm.pats.iter() {
- self.resolve_pattern(&**pattern,
- RefutableMode,
- Some(&mut bindings_list));
+ self.resolve_pattern(&**pattern, RefutableMode, &mut bindings_list);
}
// This has to happen *after* we determine which
mode: PatternBindingMode,
// Maps idents to the node ID for the (outermost)
// pattern that binds them
- mut bindings_list: Option<&mut HashMap<Name,NodeId>>) {
+ bindings_list: &mut HashMap<Name,NodeId>) {
let pat_id = pattern.id;
walk_pat(pattern, |pattern| {
match pattern.node {
// because that breaks the assumptions later
// passes make about or-patterns.)
- match bindings_list {
- Some(ref mut bindings_list)
- if !bindings_list.contains_key(&renamed) => {
- let this = &mut *self;
- let value_ribs = this.value_ribs.borrow();
- let length = value_ribs.len();
- let last_rib = value_ribs.get(
- length - 1);
- last_rib.bindings.borrow_mut()
- .insert(renamed, DlDef(def));
- bindings_list.insert(renamed, pat_id);
- }
- Some(ref mut b) => {
- if b.find(&renamed) == Some(&pat_id) {
- // Then this is a duplicate variable
- // in the same disjunct, which is an
- // error
- self.resolve_error(pattern.span,
- format!("identifier `{}` is bound \
- more than once in the same \
- pattern",
- path_to_str(path)).as_slice());
- }
- // Not bound in the same pattern: do nothing
- }
- None => {
- let this = &mut *self;
- {
- let value_ribs = this.value_ribs.borrow();
- let length = value_ribs.len();
- let last_rib = value_ribs.get(
- length - 1);
- last_rib.bindings.borrow_mut()
- .insert(renamed, DlDef(def));
- }
- }
+ if !bindings_list.contains_key(&renamed) {
+ let this = &mut *self;
+ let value_ribs = this.value_ribs.borrow();
+ let length = value_ribs.len();
+ let last_rib = value_ribs.get(
+ length - 1);
+ last_rib.bindings.borrow_mut()
+ .insert(renamed, DlDef(def));
+ bindings_list.insert(renamed, pat_id);
+ } else if bindings_list.find(&renamed) ==
+ Some(&pat_id) {
+ // Then this is a duplicate variable in the
+ // same disjunction, which is an error.
+ self.resolve_error(pattern.span,
+ format!("identifier `{}` is bound \
+ more than once in the same \
+ pattern",
+ path_to_str(path)).as_slice());
}
+ // Else, not bound in the same pattern: do
+ // nothing.
}
}
// structs, which wouldn't result in this error.)
match self.with_no_errors(|this|
this.resolve_path(expr.id, path, TypeNS, false)) {
+ #[cfg(stage0)]
Some((DefTy(struct_id), _))
if self.structs.contains_key(&struct_id) => {
self.resolve_error(expr.span,
`{} \\{ /* fields */ \\}`?",
wrong_name).as_slice());
+ }
+ #[cfg(not(stage0))]
+ Some((DefTy(struct_id), _))
+ if self.structs.contains_key(&struct_id) => {
+ self.resolve_error(expr.span,
+ format!("`{}` is a structure name, but \
+ this expression \
+ uses it like a function name",
+ wrong_name).as_slice());
+
+ self.session.span_note(expr.span,
+ format!("Did you mean to write: \
+ `{} {{ /* fields */ }}`?",
+ wrong_name).as_slice());
+
}
_ => {
let mut method_scope = false;
}
impl fmt::Show for TyVid {
+ #[cfg(stage0)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
write!(f, "<generic \\#{}>", self.to_uint())
}
+ #[cfg(not(stage0))]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
+ write!(f, "<generic #{}>", self.to_uint())
+ }
}
impl Vid for IntVid {
}
impl fmt::Show for IntVid {
+ #[cfg(stage0)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<generic integer \\#{}>", self.to_uint())
}
+ #[cfg(not(stage0))]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "<generic integer #{}>", self.to_uint())
+ }
}
impl Vid for FloatVid {
}
impl fmt::Show for FloatVid {
+ #[cfg(stage0)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "<generic float \\#{}>", self.to_uint())
}
+ #[cfg(not(stage0))]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "<generic float #{}>", self.to_uint())
+ }
}
impl Vid for RegionVid {
}
_ => None
}
+}
+
+/// If the given def ID describes a method belonging to an impl, return the
+/// ID of the impl that the method belongs to. Otherwise, return `None`.
+pub fn impl_of_method(tcx: &ctxt, def_id: ast::DefId)
+ -> Option<ast::DefId> {
+ if def_id.krate != LOCAL_CRATE {
+ return match csearch::get_method(tcx, def_id).container {
+ TraitContainer(_) => None,
+ ImplContainer(def_id) => Some(def_id),
+ };
+ }
+ match tcx.methods.borrow().find_copy(&def_id) {
+ Some(method) => {
+ match method.container {
+ TraitContainer(_) => None,
+ ImplContainer(def_id) => Some(def_id),
+ }
+ }
+ None => None
+ }
}
/// If the given def ID describes a method belonging to a trait (either a
```
Two wrapper functions are provided to encode a Encodable object
-into a string (String) or buffer (~[u8]): `str_encode(&m)` and `buffer_encode(&m)`.
+into a string (String) or buffer (vec![u8]): `str_encode(&m)` and `buffer_encode(&m)`.
```rust
use serialize::json;
_name: &str,
f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult { f(self) }
+ #[cfg(stage0)]
fn emit_enum_variant(&mut self,
name: &str,
_id: uint,
write!(self.wr, "]\\}")
}
}
+ #[cfg(not(stage0))]
+ fn emit_enum_variant(&mut self,
+ name: &str,
+ _id: uint,
+ cnt: uint,
+ f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+ // enums are encoded as strings or objects
+ // Bunny => "Bunny"
+ // Kangaroo(34,"William") => {"variant": "Kangaroo", "fields": [34,"William"]}
+ if cnt == 0 {
+ write!(self.wr, "{}", escape_str(name))
+ } else {
+ try!(write!(self.wr, "{{\"variant\":"));
+ try!(write!(self.wr, "{}", escape_str(name)));
+ try!(write!(self.wr, ",\"fields\":["));
+ try!(f(self));
+ write!(self.wr, "]}}")
+ }
+ }
fn emit_enum_variant_arg(&mut self,
idx: uint,
self.emit_enum_variant_arg(idx, f)
}
+ #[cfg(stage0)]
fn emit_struct(&mut self,
_: &str,
_: uint,
try!(f(self));
write!(self.wr, r"\}")
}
+ #[cfg(not(stage0))]
+ fn emit_struct(&mut self,
+ _: &str,
+ _: uint,
+ f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+ try!(write!(self.wr, "{{"));
+ try!(f(self));
+ write!(self.wr, "}}")
+ }
fn emit_struct_field(&mut self,
name: &str,
f(self)
}
+ #[cfg(stage0)]
fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
try!(write!(self.wr, r"\{"));
try!(f(self));
write!(self.wr, r"\}")
}
+ #[cfg(not(stage0))]
+ fn emit_map(&mut self, _len: uint, f: |&mut Encoder<'a>| -> EncodeResult) -> EncodeResult {
+ try!(write!(self.wr, "{{"));
+ try!(f(self));
+ write!(self.wr, "}}")
+ }
fn emit_map_elt_key(&mut self,
idx: uint,
}
+ #[cfg(stage0)]
fn emit_struct(&mut self,
_: &str,
len: uint,
write!(self.wr, "\n{}\\}", spaces(self.indent))
}
}
+ #[cfg(not(stage0))]
+ fn emit_struct(&mut self,
+ _: &str,
+ len: uint,
+ f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
+ if len == 0 {
+ write!(self.wr, "{{}}")
+ } else {
+ try!(write!(self.wr, "{{"));
+ self.indent += 2;
+ try!(f(self));
+ self.indent -= 2;
+ write!(self.wr, "\n{}}}", spaces(self.indent))
+ }
+ }
fn emit_struct_field(&mut self,
name: &str,
f(self)
}
+ #[cfg(stage0)]
fn emit_map(&mut self,
len: uint,
f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
write!(self.wr, "\n{}\\}", spaces(self.indent))
}
}
+ #[cfg(not(stage0))]
+ fn emit_map(&mut self,
+ len: uint,
+ f: |&mut PrettyEncoder<'a>| -> EncodeResult) -> EncodeResult {
+ if len == 0 {
+ write!(self.wr, "{{}}")
+ } else {
+ try!(write!(self.wr, "{{"));
+ self.indent += 2;
+ try!(f(self));
+ self.indent -= 2;
+ write!(self.wr, "\n{}}}", spaces(self.indent))
+ }
+ }
fn emit_map_elt_key(&mut self,
idx: uint,
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
}
-impl<A:ToJson> ToJson for ~[A] {
- fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
-}
-
impl<A:ToJson> ToJson for Vec<A> {
fn to_json(&self) -> Json { List(self.iter().map(|elt| elt.to_json()).collect()) }
}
let _hm: HashMap<uint, bool> = Decodable::decode(&mut decoder).unwrap();
}
- fn assert_stream_equal(src: &str, expected: ~[(JsonEvent, ~[StackElement])]) {
+ fn assert_stream_equal(src: &str,
+ expected: Vec<(JsonEvent, Vec<StackElement>)>) {
let mut parser = Parser::new(src.chars());
let mut i = 0;
loop {
Some(e) => e,
None => { break; }
};
- let (ref expected_evt, ref expected_stack) = expected[i];
+ let (ref expected_evt, ref expected_stack) = *expected.get(i);
if !parser.stack().is_equal_to(expected_stack.as_slice()) {
fail!("Parser stack is not equal to {}", expected_stack);
}
}
}
#[test]
+ #[ignore(cfg(target_word_size = "32"))] // FIXME(#14064)
fn test_streaming_parser() {
assert_stream_equal(
r#"{ "foo":"bar", "array" : [0, 1, 2,3 ,4,5], "idents":[null,true,false]}"#,
- ~[
- (ObjectStart, ~[]),
- (StringValue("bar".to_string()), ~[Key("foo")]),
- (ListStart, ~[Key("array")]),
- (NumberValue(0.0), ~[Key("array"), Index(0)]),
- (NumberValue(1.0), ~[Key("array"), Index(1)]),
- (NumberValue(2.0), ~[Key("array"), Index(2)]),
- (NumberValue(3.0), ~[Key("array"), Index(3)]),
- (NumberValue(4.0), ~[Key("array"), Index(4)]),
- (NumberValue(5.0), ~[Key("array"), Index(5)]),
- (ListEnd, ~[Key("array")]),
- (ListStart, ~[Key("idents")]),
- (NullValue, ~[Key("idents"), Index(0)]),
- (BooleanValue(true), ~[Key("idents"), Index(1)]),
- (BooleanValue(false), ~[Key("idents"), Index(2)]),
- (ListEnd, ~[Key("idents")]),
- (ObjectEnd, ~[]),
+ vec![
+ (ObjectStart, vec![]),
+ (StringValue("bar".to_string()), vec![Key("foo")]),
+ (ListStart, vec![Key("array")]),
+ (NumberValue(0.0), vec![Key("array"), Index(0)]),
+ (NumberValue(1.0), vec![Key("array"), Index(1)]),
+ (NumberValue(2.0), vec![Key("array"), Index(2)]),
+ (NumberValue(3.0), vec![Key("array"), Index(3)]),
+ (NumberValue(4.0), vec![Key("array"), Index(4)]),
+ (NumberValue(5.0), vec![Key("array"), Index(5)]),
+ (ListEnd, vec![Key("array")]),
+ (ListStart, vec![Key("idents")]),
+ (NullValue, vec![Key("idents"), Index(0)]),
+ (BooleanValue(true), vec![Key("idents"), Index(1)]),
+ (BooleanValue(false), vec![Key("idents"), Index(2)]),
+ (ListEnd, vec![Key("idents")]),
+ (ObjectEnd, vec![]),
]
);
}
assert_stream_equal(
"{}",
- box [(ObjectStart, box []), (ObjectEnd, box [])]
+ vec![(ObjectStart, vec![]), (ObjectEnd, vec![])]
);
assert_stream_equal(
"{\"a\": 3}",
- box [
- (ObjectStart, box []),
- (NumberValue(3.0), box [Key("a")]),
- (ObjectEnd, box []),
+ vec![
+ (ObjectStart, vec![]),
+ (NumberValue(3.0), vec![Key("a")]),
+ (ObjectEnd, vec![]),
]
);
assert_stream_equal(
"{ \"a\": null, \"b\" : true }",
- box [
- (ObjectStart, box []),
- (NullValue, box [Key("a")]),
- (BooleanValue(true), box [Key("b")]),
- (ObjectEnd, box []),
+ vec![
+ (ObjectStart, vec![]),
+ (NullValue, vec![Key("a")]),
+ (BooleanValue(true), vec![Key("b")]),
+ (ObjectEnd, vec![]),
]
);
assert_stream_equal(
"{\"a\" : 1.0 ,\"b\": [ true ]}",
- box [
- (ObjectStart, box []),
- (NumberValue(1.0), box [Key("a")]),
- (ListStart, box [Key("b")]),
- (BooleanValue(true),box [Key("b"), Index(0)]),
- (ListEnd, box [Key("b")]),
- (ObjectEnd, box []),
+ vec![
+ (ObjectStart, vec![]),
+ (NumberValue(1.0), vec![Key("a")]),
+ (ListStart, vec![Key("b")]),
+ (BooleanValue(true),vec![Key("b"), Index(0)]),
+ (ListEnd, vec![Key("b")]),
+ (ObjectEnd, vec![]),
]
);
assert_stream_equal(
{ "c": {"d": null} }
]
}"#,
- ~[
- (ObjectStart, ~[]),
- (NumberValue(1.0), ~[Key("a")]),
- (ListStart, ~[Key("b")]),
- (BooleanValue(true), ~[Key("b"), Index(0)]),
- (StringValue("foo\nbar".to_string()), ~[Key("b"), Index(1)]),
- (ObjectStart, ~[Key("b"), Index(2)]),
- (ObjectStart, ~[Key("b"), Index(2), Key("c")]),
- (NullValue, ~[Key("b"), Index(2), Key("c"), Key("d")]),
- (ObjectEnd, ~[Key("b"), Index(2), Key("c")]),
- (ObjectEnd, ~[Key("b"), Index(2)]),
- (ListEnd, ~[Key("b")]),
- (ObjectEnd, ~[]),
+ vec![
+ (ObjectStart, vec![]),
+ (NumberValue(1.0), vec![Key("a")]),
+ (ListStart, vec![Key("b")]),
+ (BooleanValue(true), vec![Key("b"), Index(0)]),
+ (StringValue("foo\nbar".to_string()), vec![Key("b"), Index(1)]),
+ (ObjectStart, vec![Key("b"), Index(2)]),
+ (ObjectStart, vec![Key("b"), Index(2), Key("c")]),
+ (NullValue, vec![Key("b"), Index(2), Key("c"), Key("d")]),
+ (ObjectEnd, vec![Key("b"), Index(2), Key("c")]),
+ (ObjectEnd, vec![Key("b"), Index(2)]),
+ (ListEnd, vec![Key("b")]),
+ (ObjectEnd, vec![]),
]
);
}
fn test_read_list_streaming() {
assert_stream_equal(
"[]",
- box [
- (ListStart, box []),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[ ]",
- box [
- (ListStart, box []),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[true]",
- box [
- (ListStart, box []),
- (BooleanValue(true), box [Index(0)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (BooleanValue(true), vec![Index(0)]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[ false ]",
- box [
- (ListStart, box []),
- (BooleanValue(false), box [Index(0)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (BooleanValue(false), vec![Index(0)]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[null]",
- box [
- (ListStart, box []),
- (NullValue, box [Index(0)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (NullValue, vec![Index(0)]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[3, 1]",
- box [
- (ListStart, box []),
- (NumberValue(3.0), box [Index(0)]),
- (NumberValue(1.0), box [Index(1)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (NumberValue(3.0), vec![Index(0)]),
+ (NumberValue(1.0), vec![Index(1)]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"\n[3, 2]\n",
- box [
- (ListStart, box []),
- (NumberValue(3.0), box [Index(0)]),
- (NumberValue(2.0), box [Index(1)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (NumberValue(3.0), vec![Index(0)]),
+ (NumberValue(2.0), vec![Index(1)]),
+ (ListEnd, vec![]),
]
);
assert_stream_equal(
"[2, [4, 1]]",
- box [
- (ListStart, box []),
- (NumberValue(2.0), box [Index(0)]),
- (ListStart, box [Index(1)]),
- (NumberValue(4.0), box [Index(1), Index(0)]),
- (NumberValue(1.0), box [Index(1), Index(1)]),
- (ListEnd, box [Index(1)]),
- (ListEnd, box []),
+ vec![
+ (ListStart, vec![]),
+ (NumberValue(2.0), vec![Index(0)]),
+ (ListStart, vec![Index(1)]),
+ (NumberValue(4.0), vec![Index(1), Index(0)]),
+ (NumberValue(1.0), vec![Index(1), Index(1)]),
+ (ListEnd, vec![Index(1)]),
+ (ListEnd, vec![]),
]
);
assert_eq!((1, 2, 3).to_json(), list3);
assert_eq!([1, 2].to_json(), list2);
assert_eq!((&[1, 2, 3]).to_json(), list3);
- assert_eq!((~[1, 2]).to_json(), list2);
+ assert_eq!((vec![1, 2]).to_json(), list2);
assert_eq!(vec!(1, 2, 3).to_json(), list3);
let mut tree_map = TreeMap::new();
tree_map.insert("a".to_string(), 1);
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Iterator, Map};
use mem;
use option::{Option, Some, None};
-use slice::{Vector, OwnedVector, ImmutableVector};
+use slice::{Vector, ImmutableVector};
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
use string::String;
use vec::Vec;
// \\?\D:\
Path::new(repr.slice_from(4))
}
+ #[cfg(stage0)]
Some(VerbatimUNCPrefix(_,_)) => {
// \\?\UNC\server\share
Path::new(format!(r"\\{}", repr.slice_from(7)))
}
+ #[cfg(not(stage0))]
+ Some(VerbatimUNCPrefix(_,_)) => {
+ // \\?\UNC\server\share
+ Path::new(format!(r"\{}", repr.slice_from(7)))
+ }
};
if new_path.prefix.is_none() {
// \\?\UNC\server is a VerbatimUNCPrefix
})
}
+ #[cfg(stage0)]
_ => {
let token_str = p.this_token_to_str();
p.fatal((format!("expected `;` or `\\{` but found `{}`",
token_str)).as_slice())
}
+ #[cfg(not(stage0))]
+ _ => {
+ let token_str = p.this_token_to_str();
+ p.fatal((format!("expected `;` or `{{` but found `{}`",
+ token_str)).as_slice())
+ }
}
})
}
// OWNED POINTER
self.bump();
match self.token {
- token::IDENT(ref ident, _)
- if "str" == token::get_ident(*ident).get() => {
- // This is OK (for now).
- }
- token::LBRACKET => {} // Also OK.
+ token::LBRACKET =>
+ self.obsolete(self.last_span, ObsoleteOwnedVector),
_ => self.obsolete(self.last_span, ObsoleteOwnedType),
};
TyUniq(self.parse_ty(false))
hi = e.span.hi;
// HACK: turn ~[...] into a ~-vec
ex = match e.node {
- ExprVec(..) | ExprRepeat(..) => ExprVstore(e, ExprVstoreUniq),
+ ExprVec(..) | ExprRepeat(..) => {
+ self.obsolete(self.last_span, ObsoleteOwnedVector);
+ ExprVstore(e, ExprVstoreUniq)
+ }
ExprLit(lit) if lit_is_str(lit) => {
self.obsolete(self.last_span, ObsoleteOwnedExpr);
ExprVstore(e, ExprVstoreUniq)
// HACK: turn `box [...]` into a boxed-vec
ex = match subexpression.node {
ExprVec(..) | ExprRepeat(..) => {
+ self.obsolete(self.last_span, ObsoleteOwnedVector);
ExprVstore(subexpression, ExprVstoreUniq)
}
ExprLit(lit) if lit_is_str(lit) => {
self.bump();
if self.token != token::RBRACE {
let token_str = self.this_token_to_str();
- self.fatal(format!("expected `\\}`, found `{}`",
+ self.fatal(format!("expected `{}`, found `{}`", "}",
token_str).as_slice())
}
etc = true;
// consuming more tokens).
let (bra, ket) = match token::close_delimiter_for(&self.token) {
Some(ket) => (self.token.clone(), ket),
+ #[cfg(stage0)]
None => {
// we only expect an ident if we didn't parse one
// above.
ident_str,
tok_str).as_slice())
}
+ #[cfg(not(stage0))]
+ None => {
+ // we only expect an ident if we didn't parse one
+ // above.
+ let ident_str = if id == token::special_idents::invalid {
+ "identifier, "
+ } else {
+ ""
+ };
+ let tok_str = self.this_token_to_str();
+ self.fatal(format!("expected {}`(` or `{{`, but found `{}`",
+ ident_str,
+ tok_str).as_slice())
+ }
};
let tts = self.parse_unspanned_seq(
fields = Vec::new();
} else {
let token_str = self.this_token_to_str();
- self.fatal(format!("expected `\\{`, `(`, or `;` after struct \
- name but found `{}`",
+ self.fatal(format!("expected `{}`, `(`, or `;` after struct \
+ name but found `{}`", "{",
token_str).as_slice())
}
self.bump();
}
token::RBRACE => {}
+ #[cfg(stage0)]
_ => {
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
format!("expected `,`, or `\\}` but found `{}`",
token_str).as_slice())
}
+ #[cfg(not(stage0))]
+ _ => {
+ let token_str = self.this_token_to_str();
+ self.span_fatal(self.span,
+ format!("expected `,`, or `}}` but found `{}`",
+ token_str).as_slice())
+ }
}
a_var
}
let token_str = self.this_token_to_str();
self.span_fatal(self.span,
- format!("expected `\\{` or `fn` but found `{}`",
+ format!("expected `{}` or `fn` but found `{}`", "{",
token_str).as_slice());
}
impl<'a,T: FloatMath + FromPrimitive> Stats<T> for &'a [T] {
// FIXME #11059 handle NaN, inf and overflow
- #[allow(deprecated_owned_vector)]
fn sum(self) -> T {
let mut partials = vec![];
v = v + char_step;
c += 1;
}
- try!(write!(w, r"\#"));
+ try!(write!(w, "#"));
c += 1;
while c < range_width && v < q3 {
try!(write!(w, "*"));
#[test]
fn test_boxplot_nonpositive() {
- #[allow(deprecated_owned_vector)]
fn t(s: &Summary<f64>, expected: String) {
use std::io::MemWriter;
let mut m = MemWriter::new();
#![feature(macro_rules, managed_boxes)]
#![deny(warnings)]
#![allow(unused_must_use)]
-#![allow(deprecated_owned_vector)]
extern crate debug;
// Various edge cases without formats
t!(format!(""), "");
t!(format!("hello"), "hello");
- t!(format!("hello \\{"), "hello {");
+ t!(format!("hello {{"), "hello {");
// default formatters should work
t!(format!("{}", 1.0f32), "1");
t!(format!("{foo_bar}", foo_bar=1), "1");
t!(format!("{:d}", 5 + 5), "10");
- // Methods should probably work
- t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 0u), "c0");
- t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 1u), "a1");
- t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 2u), "b2");
- t!(format!("{0, plural, =1{a#} =2{b#} zero{c#} other{d#}}", 3u), "d3");
- t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "a"), "aa");
- t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "b"), "bb");
- t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "c"), "cc");
- t!(format!("{0, select, a{a#} b{b#} c{c#} other{d#}}", "d"), "dd");
- t!(format!("{1, select, a{#{0:s}} other{#}}", "b", "a"), "ab");
- t!(format!("{1, select, a{#{0}} other{#}}", "c", "b"), "b");
-
// Formatting strings and their arguments
t!(format!("{:s}", "a"), "a");
t!(format!("{:4s}", "a"), "a ");
t!(format!("{:+10.3e}", -1.2345e6f64), " -1.234e6");
// Escaping
- t!(format!("\\{"), "{");
- t!(format!("\\}"), "}");
- t!(format!("\\#"), "#");
- t!(format!("\\\\"), "\\");
+ t!(format!("{{"), "{");
+ t!(format!("}}"), "}");
test_write();
test_print();