From 460dbce8cc5cfff535cff973d12b08b3a6f8a9dd Mon Sep 17 00:00:00 2001 From: Dan Burkert Date: Sat, 17 Jan 2015 16:32:29 -0800 Subject: [PATCH] Update for rustc 1.0.0-nightly (8903c21d6 2015-01-15 22:42:58 +0000) --- benches/bench_enum.rs | 4 +- benches/bench_log.rs | 12 +++--- benches/bench_map.rs | 4 +- benches/bench_struct.rs | 10 ++--- benches/bench_vec.rs | 8 ++-- serde2/Cargo.lock | 4 +- serde2/benches/bench_log.rs | 12 +++--- serde2/serde2_macros/src/lib.rs | 36 ++++++++-------- serde2/src/bin.rs | 50 +++++++++++----------- serde2/src/de.rs | 5 ++- serde2/src/json/error.rs | 2 +- serde2/src/ser.rs | 8 ++-- serde_macros/src/lib.rs | 36 ++++++++-------- src/de.rs | 73 +++++++++++++++++---------------- src/json/error.rs | 14 +++---- src/json/mod.rs | 8 ++-- src/json/value.rs | 15 +++++-- src/lib.rs | 1 + src/ser.rs | 5 ++- 19 files changed, 160 insertions(+), 147 deletions(-) diff --git a/benches/bench_enum.rs b/benches/bench_enum.rs index 855deceb..e523706f 100644 --- a/benches/bench_enum.rs +++ b/benches/bench_enum.rs @@ -72,13 +72,13 @@ mod decoder { // Primitive types: fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) } - fn read_uint(&mut self) -> Result { Err(SyntaxError) } + fn read_usize(&mut self) -> Result { Err(SyntaxError) } fn read_u64(&mut self) -> Result { Err(SyntaxError) } fn read_u32(&mut self) -> Result { Err(SyntaxError) } fn read_u16(&mut self) -> Result { Err(SyntaxError) } fn read_u8(&mut self) -> Result { Err(SyntaxError) } #[inline] - fn read_int(&mut self) -> Result { + fn read_isize(&mut self) -> Result { match self.stack.pop() { Some(IntState(x)) => Ok(x), _ => Err(SyntaxError), diff --git a/benches/bench_log.rs b/benches/bench_log.rs index 65f49a3b..cec2c2ec 100644 --- a/benches/bench_log.rs +++ b/benches/bench_log.rs @@ -52,7 +52,7 @@ impl rustc_serialize::Encodable for HttpProtocol { impl rustc_serialize::Decodable for HttpProtocol { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -96,7 +96,7 @@ impl rustc_serialize::Encodable for HttpMethod { impl rustc_serialize::Decodable for HttpMethod { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -133,7 +133,7 @@ impl rustc_serialize::Encodable for CacheStatus { impl rustc_serialize::Decodable for CacheStatus { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -179,7 +179,7 @@ impl rustc_serialize::Encodable for OriginProtocol { impl rustc_serialize::Decodable for OriginProtocol { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -217,7 +217,7 @@ impl rustc_serialize::Encodable for ZonePlan { impl rustc_serialize::Decodable for ZonePlan { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -506,7 +506,7 @@ impl rustc_serialize::Encodable for Country { impl rustc_serialize::Decodable for Country { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } diff --git a/benches/bench_map.rs b/benches/bench_map.rs index e44caeed..b3be22a6 100644 --- a/benches/bench_map.rs +++ b/benches/bench_map.rs @@ -66,13 +66,13 @@ mod decoder { // Primitive types: fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) } - fn read_uint(&mut self) -> Result { Err(SyntaxError) } + fn read_usize(&mut self) -> Result { Err(SyntaxError) } fn read_u64(&mut self) -> Result { Err(SyntaxError) } fn read_u32(&mut self) -> Result { Err(SyntaxError) } fn read_u16(&mut self) -> Result { Err(SyntaxError) } fn read_u8(&mut self) -> Result { Err(SyntaxError) } #[inline] - fn read_int(&mut self) -> Result { + fn read_isize(&mut self) -> Result { match self.stack.pop() { Some(IntValue(x)) => Ok(x), Some(_) => Err(SyntaxError), diff --git a/benches/bench_struct.rs b/benches/bench_struct.rs index 44a73733..9c04eeca 100644 --- a/benches/bench_struct.rs +++ b/benches/bench_struct.rs @@ -107,7 +107,7 @@ mod decoder { } } #[inline] - fn read_uint(&mut self) -> Result { + fn read_usize(&mut self) -> Result { match self.stack.pop() { Some(UintState(value)) => Ok(value), _ => Err(Error::SyntaxError("UintState".to_string())), @@ -117,7 +117,7 @@ mod decoder { fn read_u32(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } fn read_u16(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } fn read_u8(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } - fn read_int(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } + fn read_isize(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } fn read_i64(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } fn read_i32(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } fn read_i16(&mut self) -> Result { Err(Error::SyntaxError("".to_string())) } @@ -440,17 +440,17 @@ mod deserializer { #[inline] fn syntax_error(&mut self, token: de::Token, expected: &[de::TokenKind]) -> Error { - Error::SyntaxError(format!("expected {}, found {}", expected, token)) + Error::SyntaxError(format!("expected {:?}, found {:?}", expected, token)) } #[inline] fn unexpected_name_error(&mut self, token: de::Token) -> Error { - Error::UnexpectedName(format!("found {}", token)) + Error::UnexpectedName(format!("found {:?}", token)) } #[inline] fn conversion_error(&mut self, token: de::Token) -> Error { - Error::UnexpectedName(format!("found {}", token)) + Error::UnexpectedName(format!("found {:?}", token)) } #[inline] diff --git a/benches/bench_vec.rs b/benches/bench_vec.rs index 37c55243..3175a7ef 100644 --- a/benches/bench_vec.rs +++ b/benches/bench_vec.rs @@ -56,13 +56,13 @@ mod decoder { // Primitive types: fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) } - fn read_uint(&mut self) -> Result { Err(SyntaxError) } + fn read_usize(&mut self) -> Result { Err(SyntaxError) } fn read_u64(&mut self) -> Result { Err(SyntaxError) } fn read_u32(&mut self) -> Result { Err(SyntaxError) } fn read_u16(&mut self) -> Result { Err(SyntaxError) } fn read_u8(&mut self) -> Result { Err(SyntaxError) } #[inline] - fn read_int(&mut self) -> Result { + fn read_isize(&mut self) -> Result { match self.iter.next() { Some(value) => Ok(value), None => Err(EndOfStream), @@ -210,7 +210,7 @@ mod decoder { // Primitive types: fn read_nil(&mut self) -> Result<(), Error> { Err(SyntaxError) } - fn read_uint(&mut self) -> Result { Err(SyntaxError) } + fn read_usize(&mut self) -> Result { Err(SyntaxError) } fn read_u64(&mut self) -> Result { Err(SyntaxError) } fn read_u32(&mut self) -> Result { Err(SyntaxError) } fn read_u16(&mut self) -> Result { Err(SyntaxError) } @@ -222,7 +222,7 @@ mod decoder { } } #[inline] - fn read_int(&mut self) -> Result { Err(SyntaxError) } + fn read_isize(&mut self) -> Result { Err(SyntaxError) } fn read_i64(&mut self) -> Result { Err(SyntaxError) } fn read_i32(&mut self) -> Result { Err(SyntaxError) } fn read_i16(&mut self) -> Result { Err(SyntaxError) } diff --git a/serde2/Cargo.lock b/serde2/Cargo.lock index 1037cd6d..60a285be 100644 --- a/serde2/Cargo.lock +++ b/serde2/Cargo.lock @@ -2,13 +2,13 @@ name = "serde2" version = "0.1.0" dependencies = [ - "rustc-serialize 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde2_macros 0.1.0", ] [[package]] name = "rustc-serialize" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] diff --git a/serde2/benches/bench_log.rs b/serde2/benches/bench_log.rs index bbf55cc5..03013b1b 100644 --- a/serde2/benches/bench_log.rs +++ b/serde2/benches/bench_log.rs @@ -157,7 +157,7 @@ impl rustc_serialize::Encodable for HttpProtocol { impl rustc_serialize::Decodable for HttpProtocol { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -209,7 +209,7 @@ impl rustc_serialize::Encodable for HttpMethod { impl rustc_serialize::Decodable for HttpMethod { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -254,7 +254,7 @@ impl rustc_serialize::Encodable for CacheStatus { impl rustc_serialize::Decodable for CacheStatus { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -386,7 +386,7 @@ impl rustc_serialize::Encodable for OriginProtocol { impl rustc_serialize::Decodable for OriginProtocol { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -429,7 +429,7 @@ impl rustc_serialize::Encodable for ZonePlan { impl rustc_serialize::Decodable for ZonePlan { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } @@ -723,7 +723,7 @@ impl rustc_serialize::Encodable for Country { impl rustc_serialize::Decodable for Country { fn decode(d: &mut D) -> Result { - match FromPrimitive::from_uint(try!(d.read_uint())) { + match FromPrimitive::from_uint(try!(d.read_usize())) { Some(value) => Ok(value), None => Err(d.error("cannot convert from uint")), } diff --git a/serde2/serde2_macros/src/lib.rs b/serde2/serde2_macros/src/lib.rs index b6710e58..cb813212 100644 --- a/serde2/serde2_macros/src/lib.rs +++ b/serde2/serde2_macros/src/lib.rs @@ -49,12 +49,12 @@ use rustc::plugin::Registry; pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension( token::intern("derive_serialize"), - Decorator(box expand_derive_serialize)); + Decorator(Box::new(expand_derive_serialize))); /* reg.register_syntax_extension( token::intern("derive_deserialize"), - ItemDecorator(box expand_derive_deserialize)); + ItemDecorator(Box::new(expand_derive_deserialize))); */ } @@ -89,9 +89,9 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt, vec!["serde2", "ser", "Visitor"], None, vec![ - box Literal(Path::new_local("__S")), - box Literal(Path::new_local("__R")), - box Literal(Path::new_local("__E")), + Box::new(Literal(Path::new_local("__S"))), + Box::new(Literal(Path::new_local("__R"))), + Box::new(Literal(Path::new_local("__E"))), ], true ), @@ -102,7 +102,7 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: vec![ Ptr( - box Literal(Path::new_local("__S")), + Box::new(Literal(Path::new_local("__S"))), Borrowed(None, MutMutable) ), Literal( @@ -114,16 +114,16 @@ fn expand_derive_serialize<>(cx: &mut ExtCtxt, vec!("std", "result", "Result"), None, vec![ - box Literal(Path::new_local("__R")), - box Literal(Path::new_local("__E")), + Box::new(Literal(Path::new_local("__R"))), + Box::new(Literal(Path::new_local("__E"))), ], true ) ), attributes: attrs, - combine_substructure: combine_substructure(box |a, b, c| { + combine_substructure: combine_substructure(Box::new(|a, b, c| { serialize_substructure(a, b, c) - }), + })), } ] }; @@ -270,14 +270,14 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, span: span, attributes: Vec::new(), path: Path::new_(vec!("serde2", "de", "Deserialize"), None, - vec!(box Literal(Path::new_local("__D")), - box Literal(Path::new_local("__E"))), true), + vec!(Box::new(Literal(Path::new_local("__D"))), + Box::new(Literal(Path::new_local("__E")))), true), additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__D", None, vec!(Path::new_( vec!("serde2", "de", "Deserializer"), None, - vec!(box Literal(Path::new_local("__E"))), true))), + vec!(Box::new(Literal(Path::new_local("__E")))), true))), ("__E", None, vec!())) }, methods: vec!( @@ -287,7 +287,7 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, explicit_self: None, args: vec!( Ptr( - box Literal(Path::new_local("__D")), + Box::new(Literal(Path::new_local("__D"))), Borrowed(None, MutMutable) ), Literal(Path::new(vec!("serde2", "de", "Token"))), @@ -297,16 +297,16 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, vec!("std", "result", "Result"), None, vec!( - box Self, - box Literal(Path::new_local("__E")) + Box::new(Self), + Box::new(Literal(Path::new_local("__E"))) ), true ) ), attributes: Vec::new(), - combine_substructure: combine_substructure(box |a, b, c| { + combine_substructure: combine_substructure(Box::new(|a, b, c| { deserialize_substructure(a, b, c) - }), + })), }) }; diff --git a/serde2/src/bin.rs b/serde2/src/bin.rs index dbdd3143..9fce9f29 100644 --- a/serde2/src/bin.rs +++ b/serde2/src/bin.rs @@ -357,7 +357,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("vec: {}", v); + println!("vec: {:?}", v); //// @@ -370,7 +370,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result<(int, int), Error> = Deserialize::deserialize(&mut state); - println!("tuple: {}", v); + println!("tuple: {:?}", v); //// @@ -383,7 +383,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("value: {}", v); + println!("value: {:?}", v); //// @@ -394,7 +394,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("optiony: {}", v); + println!("optiony: {:?}", v); //// @@ -404,7 +404,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("optiony: {}", v); + println!("optiony: {:?}", v); //// @@ -415,7 +415,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("optiony value: {}", v); + println!("optiony value: {:?}", v); //// @@ -425,7 +425,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("optiony value: {}", v); + println!("optiony value: {:?}", v); //// @@ -435,7 +435,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("option: {}", v); + println!("option: {:?}", v); //// @@ -445,7 +445,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("option: {}", v); + println!("option: {:?}", v); //// @@ -455,7 +455,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("option value: {}", v); + println!("option value: {:?}", v); //// @@ -465,7 +465,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("option value: {}", v); + println!("option value: {:?}", v); //// @@ -480,7 +480,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result, Error> = Deserialize::deserialize(&mut state); - println!("{}", v); + println!("{:?}", v); //// @@ -495,7 +495,7 @@ pub fn main() { let mut state = MyDeserializer::new(tokens.into_iter()); let v: Result = Deserialize::deserialize(&mut state); - println!("{}", v); + println!("{:?}", v); } @@ -560,9 +560,9 @@ fn main() { let mut s = GatherTokens::new(); value.serialize(&mut s); - println!("tokens: {}", s.unwrap()); + println!("tokens: {:?}", s.unwrap()); - println!("json: {}", json::to_string(&value).unwrap().unwrap()); + println!("json: {:?}", json::to_string(&value).unwrap().unwrap()); println!(""); //// @@ -571,9 +571,9 @@ fn main() { let mut s = GatherTokens::new(); value.serialize(&mut s); - println!("tokens: {}", s.unwrap()); + println!("tokens: {:?}", s.unwrap()); - println!("json: {}", json::to_string(&value).unwrap().unwrap()); + println!("json: {:?}", json::to_string(&value).unwrap().unwrap()); println!(""); //// @@ -585,25 +585,25 @@ fn main() { let mut s = GatherTokens::new(); value.serialize(&mut s); - println!("tokens: {}", s.unwrap()); + println!("tokens: {:?}", s.unwrap()); - println!("json: {}", json::to_string(&value).unwrap().unwrap()); + println!("json: {:?}", json::to_string(&value).unwrap().unwrap()); println!(""); //// /* - println!("{}", to_format_vec(&5i)); - println!("{}", to_format_string(&5i)); + println!("{:?}", to_format_vec(&5i)); + println!("{:?}", to_format_string(&5i)); */ let value = Foo { x: 1, y: 2, z: "abc" }; let mut s = GatherTokens::new(); value.serialize(&mut s); - println!("tokens: {}", s.unwrap()); + println!("tokens: {:?}", s.unwrap()); - println!("json: {}", json::to_string(&value).unwrap().unwrap()); + println!("json: {:?}", json::to_string(&value).unwrap().unwrap()); println!(""); //// @@ -612,9 +612,9 @@ fn main() { let mut s = GatherTokens::new(); value.serialize(&mut s); - println!("tokens: {}", s.unwrap()); + println!("tokens: {:?}", s.unwrap()); - println!("json: {}", json::to_string(&value).unwrap().unwrap()); + println!("json: {:?}", json::to_string(&value).unwrap().unwrap()); println!(""); } */ diff --git a/serde2/src/de.rs b/serde2/src/de.rs index 4a8d0933..6f62fdf9 100644 --- a/serde2/src/de.rs +++ b/serde2/src/de.rs @@ -1,4 +1,5 @@ use std::collections::{HashMap, BTreeMap}; +use std::collections::hash_map::Hasher; use std::hash::Hash; use std::num::FromPrimitive; @@ -429,7 +430,7 @@ impl_deserialize_tuple! { T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, } /////////////////////////////////////////////////////////////////////////////// impl< - K: Deserialize + Eq + Hash, + K: Deserialize + Eq + Hash, V: Deserialize, S: Deserializer, E: Error, @@ -438,7 +439,7 @@ impl< struct Visitor; impl< - K: Deserialize + Eq + Hash, + K: Deserialize + Eq + Hash, V: Deserialize, S: Deserializer, E: Error, diff --git a/serde2/src/json/error.rs b/serde2/src/json/error.rs index ebe82f1b..d6850492 100644 --- a/serde2/src/json/error.rs +++ b/serde2/src/json/error.rs @@ -103,7 +103,7 @@ impl error::Error for Error { fn detail(&self) -> Option { match *self { Error::SyntaxError(ref code, line, col) => { - Some(format!("{} at line {} column {}", code, line, col)) + Some(format!("{:?} at line {:?} column {:?}", code, line, col)) } Error::IoError(ref error) => error.detail(), /* diff --git a/serde2/src/ser.rs b/serde2/src/ser.rs index c322b30e..a108b270 100644 --- a/serde2/src/ser.rs +++ b/serde2/src/ser.rs @@ -473,8 +473,8 @@ impl< > MapVisitor for MapIteratorVisitor { #[inline] fn visit< - V: Visitor, - >(&mut self, state: &mut S, visitor: V) -> Result, E> { + VS: Visitor, + >(&mut self, state: &mut S, visitor: VS) -> Result, E> { let first = self.first; self.first = false; @@ -504,8 +504,8 @@ impl< S, R, E, - V: Visitor, - >(&self, state: &mut S, visitor: V) -> Result { + VS: Visitor, + >(&self, state: &mut S, visitor: VS) -> Result { visitor.visit_map(state, MapIteratorVisitor::new(self.iter())) } } diff --git a/serde_macros/src/lib.rs b/serde_macros/src/lib.rs index 09ce36fd..cc322185 100644 --- a/serde_macros/src/lib.rs +++ b/serde_macros/src/lib.rs @@ -59,11 +59,11 @@ use rustc::plugin::Registry; pub fn plugin_registrar(reg: &mut Registry) { reg.register_syntax_extension( token::intern("derive_serialize"), - Decorator(box expand_derive_serialize)); + Decorator(Box::new(expand_derive_serialize))); reg.register_syntax_extension( token::intern("derive_deserialize"), - Decorator(box expand_derive_deserialize)); + Decorator(Box::new(expand_derive_deserialize))); } fn expand_derive_serialize(cx: &mut ExtCtxt, @@ -78,14 +78,14 @@ fn expand_derive_serialize(cx: &mut ExtCtxt, span: sp, attributes: vec!(), path: Path::new_(vec!("serde", "ser", "Serialize"), None, - vec!(box Literal(Path::new_local("__S")), - box Literal(Path::new_local("__E"))), true), + vec!(Box::new(Literal(Path::new_local("__S"))), + Box::new(Literal(Path::new_local("__E")))), true), additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__S", vec!(Path::new_( vec!("serde", "ser", "Serializer"), None, - vec!(box Literal(Path::new_local("__E"))), true))), + vec!(Box::new(Literal(Path::new_local("__E")))), true))), ("__E", vec!())) }, methods: vec!( @@ -93,23 +93,23 @@ fn expand_derive_serialize(cx: &mut ExtCtxt, name: "serialize", generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), - args: vec!(Ptr(box Literal(Path::new_local("__S")), + args: vec!(Ptr(Box::new(Literal(Path::new_local("__S"))), Borrowed(None, MutMutable))), ret_ty: Literal( Path::new_( vec!("std", "result", "Result"), None, vec!( - box Tuple(Vec::new()), - box Literal(Path::new_local("__E")) + Box::new(Tuple(Vec::new())), + Box::new(Literal(Path::new_local("__E"))) ), true ) ), attributes: attrs, - combine_substructure: combine_substructure(box |a, b, c| { + combine_substructure: combine_substructure(Box::new( |a, b, c| { serialize_substructure(a, b, c, item) - }), + })), }) }; @@ -204,14 +204,14 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, span: span, attributes: Vec::new(), path: Path::new_(vec!("serde", "de", "Deserialize"), None, - vec!(box Literal(Path::new_local("__D")), - box Literal(Path::new_local("__E"))), true), + vec!(Box::new(Literal(Path::new_local("__D"))), + Box::new(Literal(Path::new_local("__E")))), true), additional_bounds: Vec::new(), generics: LifetimeBounds { lifetimes: Vec::new(), bounds: vec!(("__D", vec!(Path::new_( vec!("serde", "de", "Deserializer"), None, - vec!(box Literal(Path::new_local("__E"))), true))), + vec!(Box::new(Literal(Path::new_local("__E")))), true))), ("__E", vec!())) }, methods: vec!( @@ -221,7 +221,7 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, explicit_self: None, args: vec!( Ptr( - box Literal(Path::new_local("__D")), + Box::new(Literal(Path::new_local("__D"))), Borrowed(None, MutMutable) ), Literal(Path::new(vec!("serde", "de", "Token"))), @@ -231,16 +231,16 @@ pub fn expand_derive_deserialize(cx: &mut ExtCtxt, vec!("std", "result", "Result"), None, vec!( - box Self, - box Literal(Path::new_local("__E")) + Box::new(Self), + Box::new(Literal(Path::new_local("__E"))) ), true ) ), attributes: Vec::new(), - combine_substructure: combine_substructure(box |a, b, c| { + combine_substructure: combine_substructure(Box::new(|a, b, c| { deserialize_substructure(a, b, c) - }), + })), }) }; diff --git a/src/de.rs b/src/de.rs index 5b5a0889..16d5e4fa 100644 --- a/src/de.rs +++ b/src/de.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet}; +use std::collections::hash_map::Hasher; use std::hash::Hash; use std::iter::FromIterator; use std::num::{self, FromPrimitive}; @@ -706,7 +707,7 @@ impl< > Deserialize for Box { #[inline] fn deserialize_token(d: &mut D, token: Token) -> Result, E> { - Ok(box try!(Deserialize::deserialize_token(d, token))) + Ok(Box::new(try!(Deserialize::deserialize_token(d, token)))) } } @@ -763,7 +764,7 @@ impl< impl< D: Deserializer, E, - K: Deserialize + Eq + Hash, + K: Deserialize + Eq + Hash, V: Deserialize > Deserialize for HashMap { #[inline] @@ -789,7 +790,7 @@ impl< impl< D: Deserializer, E, - T: Deserialize + Eq + Hash + T: Deserialize + Eq + Hash > Deserialize for HashSet { #[inline] fn deserialize_token(d: &mut D, token: Token) -> Result, E> { @@ -1253,7 +1254,7 @@ mod tests { ////////////////////////////////////////////////////////////////////////////// macro_rules! test_value { - ($name:ident, [$($tokens:expr => $value:expr: $ty:ty),*]) => { + ($name:ident, [$($tokens:expr => $value:expr, $ty:ty),*]) => { #[test] fn $name() { $( @@ -1267,31 +1268,31 @@ mod tests { } test_value!(test_primitives, [ - vec!(Token::Null) => (): (), - vec!(Token::Bool(true)) => true: bool, - vec!(Token::Bool(false)) => false: bool, - vec!(Token::Int(5)) => 5: int, - vec!(Token::I8(5)) => 5: i8, - vec!(Token::I16(5)) => 5: i16, - vec!(Token::I32(5)) => 5: i32, - vec!(Token::I64(5)) => 5: i64, - vec!(Token::Uint(5)) => 5: uint, - vec!(Token::U8(5)) => 5: u8, - vec!(Token::U16(5)) => 5: u16, - vec!(Token::U32(5)) => 5: u32, - vec!(Token::U64(5)) => 5: u64, - vec!(Token::F32(5.0)) => 5.0: f32, - vec!(Token::F64(5.0)) => 5.0: f64, - vec!(Token::Char('c')) => 'c': char, - vec!(Token::Str("abc")) => "abc": &str, - vec!(Token::String("abc".to_string())) => "abc".to_string(): string::String + vec!(Token::Null) => (), (), + vec!(Token::Bool(true)) => true, bool, + vec!(Token::Bool(false)) => false, bool, + vec!(Token::Int(5)) => 5, int, + vec!(Token::I8(5)) => 5, i8, + vec!(Token::I16(5)) => 5, i16, + vec!(Token::I32(5)) => 5, i32, + vec!(Token::I64(5)) => 5, i64, + vec!(Token::Uint(5)) => 5, uint, + vec!(Token::U8(5)) => 5, u8, + vec!(Token::U16(5)) => 5, u16, + vec!(Token::U32(5)) => 5, u32, + vec!(Token::U64(5)) => 5, u64, + vec!(Token::F32(5.0)) => 5.0, f32, + vec!(Token::F64(5.0)) => 5.0, f64, + vec!(Token::Char('c')) => 'c', char, + vec!(Token::Str("abc")) => "abc", &str, + vec!(Token::String("abc".to_string())) => "abc".to_string(), string::String ]); test_value!(test_tuples, [ vec!( Token::TupleStart(0), Token::End, - ) => (): (), + ) => (), (), vec!( Token::TupleStart(2), @@ -1299,7 +1300,7 @@ mod tests { Token::Str("a"), Token::End, - ) => (5, "a"): (int, &'static str), + ) => (5, "a"), (int, &'static str), vec!( Token::TupleStart(3), @@ -1314,16 +1315,16 @@ mod tests { Token::Str("a"), Token::End, Token::End, - ) => ((), (), (5, "a")): ((), (), (int, &'static str)) + ) => ((), (), (5, "a")), ((), (), (int, &'static str)) ]); test_value!(test_options, [ - vec!(Token::Option(false)) => None: option::Option, + vec!(Token::Option(false)) => None, option::Option, vec!( Token::Option(true), Token::Int(5), - ) => Some(5): option::Option + ) => Some(5), option::Option ]); test_value!(test_structs, [ @@ -1333,7 +1334,7 @@ mod tests { Token::SeqStart(0), Token::End, Token::End, - ) => Outer { inner: vec!() }: Outer, + ) => Outer { inner: vec!() }, Outer, vec!( Token::StructStart("Outer", 1), @@ -1364,28 +1365,28 @@ mod tests { c: treemap!("abc".to_string() => Some('c')), }, ), - }: Outer + }, Outer ]); test_value!(test_enums, [ vec!( Token::EnumStart("Animal", "Dog", 0), Token::End, - ) => Animal::Dog: Animal, + ) => Animal::Dog, Animal, vec!( Token::EnumStart("Animal", "Frog", 2), Token::String("Henry".to_string()), Token::Int(349), Token::End, - ) => Animal::Frog("Henry".to_string(), 349): Animal + ) => Animal::Frog("Henry".to_string(), 349), Animal ]); test_value!(test_vecs, [ vec!( Token::SeqStart(0), Token::End, - ) => vec!(): Vec, + ) => vec!(), Vec, vec!( Token::SeqStart(3), @@ -1395,7 +1396,7 @@ mod tests { Token::Int(7), Token::End, - ) => vec!(5, 6, 7): Vec, + ) => vec!(5, 6, 7), Vec, vec!( @@ -1418,14 +1419,14 @@ mod tests { Token::Int(6), Token::End, Token::End, - ) => vec!(vec!(1), vec!(2, 3), vec!(4, 5, 6)): Vec> + ) => vec!(vec!(1), vec!(2, 3), vec!(4, 5, 6)), Vec> ]); test_value!(test_treemaps, [ vec!( Token::MapStart(0), Token::End, - ) => treemap!(): BTreeMap, + ) => treemap!(), BTreeMap, vec!( Token::MapStart(2), @@ -1435,7 +1436,7 @@ mod tests { Token::Int(6), Token::String("b".to_string()), Token::End, - ) => treemap!(5i => "a".to_string(), 6i => "b".to_string()): BTreeMap treemap!(5i => "a".to_string(), 6i => "b".to_string()), BTreeMap ]); } diff --git a/src/json/error.rs b/src/json/error.rs index 795c429c..414d5141 100644 --- a/src/json/error.rs +++ b/src/json/error.rs @@ -43,7 +43,7 @@ pub enum ErrorCode { impl fmt::Show for ErrorCode { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - ErrorCode::ConversionError(ref token) => write!(f, "failed to convert {}", token), + ErrorCode::ConversionError(ref token) => write!(f, "failed to convert {:?}", token), ErrorCode::EOFWhileParsingList => "EOF While parsing list".fmt(f), ErrorCode::EOFWhileParsingObject => "EOF While parsing object".fmt(f), ErrorCode::EOFWhileParsingString => "EOF While parsing string".fmt(f), @@ -60,7 +60,7 @@ impl fmt::Show for ErrorCode { ErrorCode::ExpectedObjectCommaOrEnd => "expected `,` or `}`".fmt(f), ErrorCode::ExpectedSomeIdent => "expected ident".fmt(f), ErrorCode::ExpectedSomeValue => "expected value".fmt(f), - ErrorCode::ExpectedTokens(ref token, tokens) => write!(f, "expected {}, found {}", tokens, token), + ErrorCode::ExpectedTokens(ref token, tokens) => write!(f, "expected {:?}, found {:?}", tokens, token), ErrorCode::InvalidEscape => "invalid escape".fmt(f), ErrorCode::InvalidNumber => "invalid number".fmt(f), ErrorCode::InvalidUnicodeCodePoint => "invalid unicode code point".fmt(f), @@ -71,7 +71,7 @@ impl fmt::Show for ErrorCode { ErrorCode::NotUtf8 => "contents not utf-8".fmt(f), ErrorCode::TrailingCharacters => "trailing characters".fmt(f), ErrorCode::UnexpectedEndOfHexEscape => "unexpected end of hex escape".fmt(f), - ErrorCode::UnexpectedName(ref name) => write!(f, "unexpected name {}", name), + ErrorCode::UnexpectedName(ref name) => write!(f, "unexpected name {:?}", name), ErrorCode::UnknownVariant => "unknown variant".fmt(f), ErrorCode::UnrecognizedHex => "invalid \\u escape (unrecognized hex)".fmt(f), } @@ -102,17 +102,17 @@ impl error::Error for Error { fn detail(&self) -> Option { match *self { Error::SyntaxError(ref code, line, col) => { - Some(format!("{} at line {} column {}", code, line, col)) + Some(format!("{:?} at line {:?} column {:?}", code, line, col)) } Error::IoError(ref error) => error.detail(), Error::ExpectedError(ref expected, ref found) => { - Some(format!("expected {}, found {}", expected, found)) + Some(format!("expected {:?}, found {:?}", expected, found)) } Error::MissingFieldError(ref field) => { - Some(format!("missing field {}", field)) + Some(format!("missing field {:?}", field)) } Error::UnknownVariantError(ref variant) => { - Some(format!("unknown variant {}", variant)) + Some(format!("unknown variant {:?}", variant)) } } } diff --git a/src/json/mod.rs b/src/json/mod.rs index 9c0471e2..a7bd74c0 100644 --- a/src/json/mod.rs +++ b/src/json/mod.rs @@ -84,7 +84,7 @@ fn main() { let mut serializer = json::Serializer::new(wr.by_ref()); match to_serialize_object.serialize(&mut serializer) { Ok(()) => (), - Err(e) => panic!("json serialization error: {}", e), + Err(e) => panic!("json serialization error: {:?}", e), } } } @@ -192,7 +192,7 @@ fn main() { let mut parser = json::Parser::new(json_str_to_deserialize.bytes()); let deserialized_object: MyStruct = match Deserialize::deserialize(&mut parser) { Ok(v) => v, - Err(e) => panic!("Decoding error: {}", e) + Err(e) => panic!("Decoding error: {:?}", e) }; } ``` @@ -234,7 +234,7 @@ fn main() { let deserialized_object: TestStruct1 = match json::from_str(serialized_str.as_slice()) { Ok(deserialized_object) => deserialized_object, - Err(e) => panic!("json deserialization error: {}", e), + Err(e) => panic!("json deserialization error: {:?}", e), }; } ``` @@ -1918,7 +1918,7 @@ mod bench { match parser.next() { None => return, Some(Ok(_)) => { } - Some(Err(err)) => { panic!("error: {}", err); } + Some(Err(err)) => { panic!("error: {:?}", err); } } } }); diff --git a/src/json/value.rs b/src/json/value.rs index 87187e99..c4c83937 100644 --- a/src/json/value.rs +++ b/src/json/value.rs @@ -3,6 +3,7 @@ use std::fmt; use std::io::{ByRefWriter, IoResult}; use std::io; use std::str; +use std::string::ToString; use std::vec; use de::{self, Token, TokenKind}; @@ -207,6 +208,14 @@ impl Value { } } +impl ToString for Value { + fn to_string(&self) -> String { + let mut wr = Vec::new(); + self.to_writer(wr.by_ref()).unwrap(); + str::from_utf8(wr.as_slice()).unwrap().to_string() + } +} + struct WriterFormatter<'a, 'b: 'a> { inner: &'a mut fmt::Formatter<'b>, } @@ -449,7 +458,7 @@ impl de::Deserializer for Deserializer { return Err( Error::ExpectedError( "Array".to_string(), - format!("{} => {}", key, value) + format!("{:?} => {:?}", key, value) ) ); } @@ -464,7 +473,7 @@ impl de::Deserializer for Deserializer { return Err( Error::ExpectedError( "None".to_string(), - format!("{} => {}", key, value) + format!("{:?} => {:?}", key, value) ) ); } @@ -483,7 +492,7 @@ impl de::Deserializer for Deserializer { return Err( Error::ExpectedError( "String or Object".to_string(), - format!("{}", token) + format!("{:?}", token) ) ); } diff --git a/src/lib.rs b/src/lib.rs index d58a8ac1..9bda7ee4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ #![feature(plugin)] +#![allow(unstable)] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/ser.rs b/src/ser.rs index 19b84f66..fa70f114 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -9,6 +9,7 @@ // except according to those terms. use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet}; +use std::collections::hash_map::Hasher; use std::hash::Hash; use std::rc::Rc; use std::sync::Arc; @@ -225,7 +226,7 @@ impl< impl< S: Serializer, E, - K: Serialize + Eq + Hash, + K: Serialize + Eq + Hash, V: Serialize > Serialize for HashMap { #[inline] @@ -251,7 +252,7 @@ impl< impl< S: Serializer, E, - T: Serialize + Eq + Hash + T: Serialize + Eq + Hash > Serialize for HashSet { #[inline] fn serialize(&self, s: &mut S) -> Result<(), E> {