From 22465b75e7ac476ed02c8d68d9b250d6513405da Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 11 Apr 2013 07:02:23 -0700 Subject: [PATCH 1/4] std: change Encoder variables to be 'e' instead of 's' --- src/libstd/serialize.rs | 284 ++++++++++++++++++++-------------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/src/libstd/serialize.rs b/src/libstd/serialize.rs index 68ae9a6641726..09e7749dfa096 100644 --- a/src/libstd/serialize.rs +++ b/src/libstd/serialize.rs @@ -133,16 +133,16 @@ pub trait Decoder { fn read_map_elt_val(&self, idx: uint, f: &fn() -> T) -> T; } -pub trait Encodable { - fn encode(&self, s: &S); +pub trait Encodable { + fn encode(&self, e: &E); } pub trait Decodable { fn decode(d: &D) -> Self; } -impl Encodable for uint { - fn encode(&self, s: &S) { s.emit_uint(*self) } +impl Encodable for uint { + fn encode(&self, e: &E) { e.emit_uint(*self) } } impl Decodable for uint { @@ -151,8 +151,8 @@ impl Decodable for uint { } } -impl Encodable for u8 { - fn encode(&self, s: &S) { s.emit_u8(*self) } +impl Encodable for u8 { + fn encode(&self, e: &E) { e.emit_u8(*self) } } impl Decodable for u8 { @@ -161,8 +161,8 @@ impl Decodable for u8 { } } -impl Encodable for u16 { - fn encode(&self, s: &S) { s.emit_u16(*self) } +impl Encodable for u16 { + fn encode(&self, e: &E) { e.emit_u16(*self) } } impl Decodable for u16 { @@ -171,8 +171,8 @@ impl Decodable for u16 { } } -impl Encodable for u32 { - fn encode(&self, s: &S) { s.emit_u32(*self) } +impl Encodable for u32 { + fn encode(&self, e: &E) { e.emit_u32(*self) } } impl Decodable for u32 { @@ -181,8 +181,8 @@ impl Decodable for u32 { } } -impl Encodable for u64 { - fn encode(&self, s: &S) { s.emit_u64(*self) } +impl Encodable for u64 { + fn encode(&self, e: &E) { e.emit_u64(*self) } } impl Decodable for u64 { @@ -191,8 +191,8 @@ impl Decodable for u64 { } } -impl Encodable for int { - fn encode(&self, s: &S) { s.emit_int(*self) } +impl Encodable for int { + fn encode(&self, e: &E) { e.emit_int(*self) } } impl Decodable for int { @@ -201,8 +201,8 @@ impl Decodable for int { } } -impl Encodable for i8 { - fn encode(&self, s: &S) { s.emit_i8(*self) } +impl Encodable for i8 { + fn encode(&self, e: &E) { e.emit_i8(*self) } } impl Decodable for i8 { @@ -211,8 +211,8 @@ impl Decodable for i8 { } } -impl Encodable for i16 { - fn encode(&self, s: &S) { s.emit_i16(*self) } +impl Encodable for i16 { + fn encode(&self, e: &E) { e.emit_i16(*self) } } impl Decodable for i16 { @@ -221,8 +221,8 @@ impl Decodable for i16 { } } -impl Encodable for i32 { - fn encode(&self, s: &S) { s.emit_i32(*self) } +impl Encodable for i32 { + fn encode(&self, e: &E) { e.emit_i32(*self) } } impl Decodable for i32 { @@ -231,8 +231,8 @@ impl Decodable for i32 { } } -impl Encodable for i64 { - fn encode(&self, s: &S) { s.emit_i64(*self) } +impl Encodable for i64 { + fn encode(&self, e: &E) { e.emit_i64(*self) } } impl Decodable for i64 { @@ -241,12 +241,12 @@ impl Decodable for i64 { } } -impl<'self, S:Encoder> Encodable for &'self str { - fn encode(&self, s: &S) { s.emit_str(*self) } +impl<'self, E: Encoder> Encodable for &'self str { + fn encode(&self, e: &E) { e.emit_str(*self) } } -impl Encodable for ~str { - fn encode(&self, s: &S) { s.emit_str(*self) } +impl Encodable for ~str { + fn encode(&self, e: &E) { e.emit_str(*self) } } impl Decodable for ~str { @@ -255,16 +255,16 @@ impl Decodable for ~str { } } -impl Encodable for @str { - fn encode(&self, s: &S) { s.emit_str(*self) } +impl Encodable for @str { + fn encode(&self, e: &E) { e.emit_str(*self) } } impl Decodable for @str { fn decode(d: &D) -> @str { d.read_str().to_managed() } } -impl Encodable for float { - fn encode(&self, s: &S) { s.emit_float(*self) } +impl Encodable for float { + fn encode(&self, e: &E) { e.emit_float(*self) } } impl Decodable for float { @@ -273,8 +273,8 @@ impl Decodable for float { } } -impl Encodable for f32 { - fn encode(&self, s: &S) { s.emit_f32(*self) } +impl Encodable for f32 { + fn encode(&self, e: &E) { e.emit_f32(*self) } } impl Decodable for f32 { @@ -282,8 +282,8 @@ impl Decodable for f32 { d.read_f32() } } -impl Encodable for f64 { - fn encode(&self, s: &S) { s.emit_f64(*self) } +impl Encodable for f64 { + fn encode(&self, e: &E) { e.emit_f64(*self) } } impl Decodable for f64 { @@ -292,8 +292,8 @@ impl Decodable for f64 { } } -impl Encodable for bool { - fn encode(&self, s: &S) { s.emit_bool(*self) } +impl Encodable for bool { + fn encode(&self, e: &E) { e.emit_bool(*self) } } impl Decodable for bool { @@ -302,8 +302,8 @@ impl Decodable for bool { } } -impl Encodable for () { - fn encode(&self, s: &S) { s.emit_nil() } +impl Encodable for () { + fn encode(&self, e: &E) { e.emit_nil() } } impl Decodable for () { @@ -312,15 +312,15 @@ impl Decodable for () { } } -impl<'self, S:Encoder,T:Encodable> Encodable for &'self T { - fn encode(&self, s: &S) { - (**self).encode(s) +impl<'self, E: Encoder,T:Encodable> Encodable for &'self T { + fn encode(&self, e: &E) { + (**self).encode(e) } } -impl> Encodable for ~T { - fn encode(&self, s: &S) { - (**self).encode(s) +impl> Encodable for ~T { + fn encode(&self, e: &E) { + (**self).encode(e) } } @@ -330,9 +330,9 @@ impl> Decodable for ~T { } } -impl> Encodable for @T { - fn encode(&self, s: &S) { - (**self).encode(s) +impl> Encodable for @T { + fn encode(&self, e: &E) { + (**self).encode(e) } } @@ -342,21 +342,21 @@ impl> Decodable for @T { } } -impl<'self, S:Encoder,T:Encodable> Encodable for &'self [T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) +impl<'self, E: Encoder,T:Encodable> Encodable for &'self [T] { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { + for self.eachi |i, elt| { + e.emit_seq_elt(i, || elt.encode(e)) } } } } -impl> Encodable for ~[T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) +impl> Encodable for ~[T] { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { + for self.eachi |i, elt| { + e.emit_seq_elt(i, || elt.encode(e)) } } } @@ -372,11 +372,11 @@ impl> Decodable for ~[T] { } } -impl> Encodable for @[T] { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)) +impl> Encodable for @[T] { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { + for self.eachi |i, elt| { + e.emit_seq_elt(i, || elt.encode(e)) } } } @@ -392,12 +392,12 @@ impl> Decodable for @[T] { } } -impl> Encodable for Option { - fn encode(&self, s: &S) { - do s.emit_option { +impl> Encodable for Option { + fn encode(&self, e: &E) { + do e.emit_option { match *self { - None => s.emit_option_none(), - Some(ref v) => s.emit_option_some(|| v.encode(s)), + None => e.emit_option_none(), + Some(ref v) => e.emit_option_some(|| v.encode(e)), } } } @@ -415,13 +415,13 @@ impl> Decodable for Option { } } -impl,T1:Encodable> Encodable for (T0, T1) { - fn encode(&self, s: &S) { +impl,T1:Encodable> Encodable for (T0, T1) { + fn encode(&self, e: &E) { match *self { (ref t0, ref t1) => { - do s.emit_seq(2) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); + do e.emit_seq(2) { + e.emit_seq_elt(0, || t0.encode(e)); + e.emit_seq_elt(1, || t1.encode(e)); } } } @@ -441,18 +441,18 @@ impl,T1:Decodable> Decodable for (T0, T1) { } impl< - S: Encoder, - T0: Encodable, - T1: Encodable, - T2: Encodable -> Encodable for (T0, T1, T2) { - fn encode(&self, s: &S) { + E: Encoder, + T0: Encodable, + T1: Encodable, + T2: Encodable +> Encodable for (T0, T1, T2) { + fn encode(&self, e: &E) { match *self { (ref t0, ref t1, ref t2) => { - do s.emit_seq(3) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); + do e.emit_seq(3) { + e.emit_seq_elt(0, || t0.encode(e)); + e.emit_seq_elt(1, || t1.encode(e)); + e.emit_seq_elt(2, || t2.encode(e)); } } } @@ -478,20 +478,20 @@ impl< } impl< - S: Encoder, - T0: Encodable, - T1: Encodable, - T2: Encodable, - T3: Encodable -> Encodable for (T0, T1, T2, T3) { - fn encode(&self, s: &S) { + E: Encoder, + T0: Encodable, + T1: Encodable, + T2: Encodable, + T3: Encodable +> Encodable for (T0, T1, T2, T3) { + fn encode(&self, e: &E) { match *self { (ref t0, ref t1, ref t2, ref t3) => { - do s.emit_seq(4) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); - s.emit_seq_elt(3, || t3.encode(s)); + do e.emit_seq(4) { + e.emit_seq_elt(0, || t0.encode(e)); + e.emit_seq_elt(1, || t1.encode(e)); + e.emit_seq_elt(2, || t2.encode(e)); + e.emit_seq_elt(3, || t3.encode(e)); } } } @@ -519,22 +519,22 @@ impl< } impl< - S: Encoder, - T0: Encodable, - T1: Encodable, - T2: Encodable, - T3: Encodable, - T4: Encodable -> Encodable for (T0, T1, T2, T3, T4) { - fn encode(&self, s: &S) { + E: Encoder, + T0: Encodable, + T1: Encodable, + T2: Encodable, + T3: Encodable, + T4: Encodable +> Encodable for (T0, T1, T2, T3, T4) { + fn encode(&self, e: &E) { match *self { (ref t0, ref t1, ref t2, ref t3, ref t4) => { - do s.emit_seq(5) { - s.emit_seq_elt(0, || t0.encode(s)); - s.emit_seq_elt(1, || t1.encode(s)); - s.emit_seq_elt(2, || t2.encode(s)); - s.emit_seq_elt(3, || t3.encode(s)); - s.emit_seq_elt(4, || t4.encode(s)); + do e.emit_seq(5) { + e.emit_seq_elt(0, || t0.encode(e)); + e.emit_seq_elt(1, || t1.encode(e)); + e.emit_seq_elt(2, || t2.encode(e)); + e.emit_seq_elt(3, || t3.encode(e)); + e.emit_seq_elt(4, || t4.encode(e)); } } } @@ -565,14 +565,14 @@ impl< } impl< - S: Encoder, - T: Encodable + Copy -> Encodable for @mut DList { - fn encode(&self, s: &S) { - do s.emit_seq(self.size) { + E: Encoder, + T: Encodable + Copy +> Encodable for @mut DList { + fn encode(&self, e: &E) { + do e.emit_seq(self.size) { let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); + for self.each |elt| { + e.emit_seq_elt(i, || elt.encode(e)); i += 1; } } @@ -592,13 +592,13 @@ impl> Decodable for @mut DList { } impl< - S: Encoder, - T: Encodable -> Encodable for Deque { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { - for self.eachi |i, e| { - s.emit_seq_elt(i, || e.encode(s)); + E: Encoder, + T: Encodable +> Encodable for Deque { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { + for self.eachi |i, elt| { + e.emit_seq_elt(i, || elt.encode(e)); } } } @@ -652,14 +652,14 @@ impl< } impl< - S: Encoder, - T: Encodable + Hash + IterBytes + Eq -> Encodable for HashSet { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { + E: Encoder, + T: Encodable + Hash + IterBytes + Eq +> Encodable for HashSet { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); + for self.each |elt| { + e.emit_seq_elt(i, || elt.encode(e)); i += 1; } } @@ -714,12 +714,12 @@ impl< } } -impl Encodable for TrieSet { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { +impl Encodable for TrieSet { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); + for self.each |elt| { + e.emit_seq_elt(i, || elt.encode(e)); i += 1; } } @@ -774,14 +774,14 @@ impl< } impl< - S: Encoder, - T: Encodable + Eq + TotalOrd -> Encodable for TreeSet { - fn encode(&self, s: &S) { - do s.emit_seq(self.len()) { + E: Encoder, + T: Encodable + Eq + TotalOrd +> Encodable for TreeSet { + fn encode(&self, e: &E) { + do e.emit_seq(self.len()) { let mut i = 0; - for self.each |e| { - s.emit_seq_elt(i, || e.encode(s)); + for self.each |elt| { + e.emit_seq_elt(i, || elt.encode(e)); i += 1; } } @@ -812,7 +812,7 @@ pub trait EncoderHelpers { fn emit_from_vec(&self, v: &[T], f: &fn(v: &T)); } -impl EncoderHelpers for S { +impl EncoderHelpers for E { fn emit_from_vec(&self, v: &[T], f: &fn(v: &T)) { do self.emit_seq(v.len()) { for v.eachi |i, e| { From ca50608cac2391ec7f6567353b63ecbeca588698 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 11 Apr 2013 07:46:04 -0700 Subject: [PATCH 2/4] core: change result::map{,_err} to consume the result --- src/libcore/result.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 8fd81a2060342..c91235bd3dff6 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -200,11 +200,11 @@ pub fn iter_err(res: &Result, f: &fn(&E)) { * } */ #[inline(always)] -pub fn map(res: &Result, op: &fn(&T) -> U) +pub fn map(res: Result, op: &fn(T) -> U) -> Result { - match *res { - Ok(ref t) => Ok(op(t)), - Err(copy e) => Err(e) + match res { + Ok(t) => Ok(op(t)), + Err(e) => Err(e) } } @@ -217,11 +217,11 @@ pub fn map(res: &Result, op: &fn(&T) -> U) * successful result while handling an error. */ #[inline(always)] -pub fn map_err(res: &Result, op: &fn(&E) -> F) +pub fn map_err(res: Result, op: &fn(E) -> F) -> Result { - match *res { - Ok(copy t) => Ok(t), - Err(ref e) => Err(op(e)) + match res { + Ok(t) => Ok(t), + Err(e) => Err(op(e)) } } @@ -256,26 +256,26 @@ pub impl Result { fn chain_err(self, op: &fn(E) -> Result) -> Result { chain_err(self, op) } -} -pub impl Result { #[inline(always)] - fn get(&self) -> T { get(self) } + fn map(self, op: &fn(T) -> U) -> Result { + map(self, op) + } #[inline(always)] - fn map_err(&self, op: &fn(&E) -> F) -> Result { + fn map_err(self, op: &fn(E) -> F) -> Result { map_err(self, op) } } -pub impl Result { +pub impl Result { #[inline(always)] - fn get_err(&self) -> E { get_err(self) } + fn get(&self) -> T { get(self) } +} +pub impl Result { #[inline(always)] - fn map(&self, op: &fn(&T) -> U) -> Result { - map(self, op) - } + fn get_err(&self) -> E { get_err(self) } } /** From aa9f6da3504b294eefd595294ac0c30aeaa7bfd1 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 11 Apr 2013 11:35:45 -0700 Subject: [PATCH 3/4] syntax: Auto derived code should have inherited visibility This fixes the pretty printer from printing the obsolete syntax `pub impl...for...`. --- src/libsyntax/ext/auto_encode.rs | 6 +++--- src/libsyntax/ext/deriving/clone.rs | 2 +- src/libsyntax/ext/deriving/decodable.rs | 2 +- src/libsyntax/ext/deriving/encodable.rs | 2 +- src/libsyntax/ext/deriving/eq.rs | 2 +- src/libsyntax/ext/deriving/iter_bytes.rs | 2 +- src/libsyntax/ext/deriving/mod.rs | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index e53a8f361b5fe..444a962a80f25 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -501,7 +501,7 @@ fn mk_impl( attrs: ~[], id: cx.next_id(), node: ast::item_impl(generics, opt_trait, ty, ~[f(ty)]), - vis: ast::public, + vis: ast::inherited, span: span, } } @@ -652,7 +652,7 @@ fn mk_ser_method( id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: ast::public, + vis: ast::inherited, } } @@ -706,7 +706,7 @@ fn mk_deser_method( id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: ast::public, + vis: ast::inherited, } } diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index c8ba6b990e47a..0a9977b75021f 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -105,7 +105,7 @@ fn create_clone_method(cx: @ext_ctxt, id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: public, + vis: inherited, } } diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 11f492316e281..9c479b872c2ea 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -133,7 +133,7 @@ fn create_decode_method( id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: public + vis: inherited } } diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index 81bfb03724f30..097265017f4d4 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -126,7 +126,7 @@ fn create_encode_method( id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: public + vis: inherited } } diff --git a/src/libsyntax/ext/deriving/eq.rs b/src/libsyntax/ext/deriving/eq.rs index c427a206c2e32..235a8506a92b6 100644 --- a/src/libsyntax/ext/deriving/eq.rs +++ b/src/libsyntax/ext/deriving/eq.rs @@ -113,7 +113,7 @@ fn create_eq_method(cx: @ext_ctxt, id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: public + vis: inherited } } diff --git a/src/libsyntax/ext/deriving/iter_bytes.rs b/src/libsyntax/ext/deriving/iter_bytes.rs index 4124e6ee6c165..62973f8f3a6cc 100644 --- a/src/libsyntax/ext/deriving/iter_bytes.rs +++ b/src/libsyntax/ext/deriving/iter_bytes.rs @@ -104,7 +104,7 @@ fn create_iter_bytes_method(cx: @ext_ctxt, id: cx.next_id(), span: span, self_id: cx.next_id(), - vis: public + vis: inherited } } diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 63106eae48ae8..d016d1208b1cc 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -18,7 +18,7 @@ use ast::{Ty, bind_by_ref, deref, enum_def}; use ast::{expr, expr_match, ident, item, item_}; use ast::{item_enum, item_impl, item_struct, Generics}; use ast::{m_imm, meta_item, method}; -use ast::{named_field, pat, pat_ident, public}; +use ast::{named_field, pat, pat_ident}; use ast::{struct_def, struct_variant_kind}; use ast::{tuple_variant_kind}; use ast::{ty_path, unnamed_field, variant}; @@ -131,7 +131,7 @@ fn create_impl_item(cx: @ext_ctxt, span: span, +item: item_) -> @item { attrs: ~[], id: cx.next_id(), node: item, - vis: public, + vis: ast::inherited, span: span, } } From 5cac59a71afa9e14965aaab1388ed55e179ffb5a Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 11 Apr 2013 11:48:53 -0700 Subject: [PATCH 4/4] Add Dan Luu to the AUTHORS.txt --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index ae583d6409e23..ef27872d2ba24 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -41,6 +41,7 @@ Cody Schroeder Damian Gryski Damien Grassart Damien Schoof +Dan Luu Daniel Brooks Daniel Luz Daniel Micay