From 82641d4c39dd547c44c2d2ef4c0c98c5bfbd8b55 Mon Sep 17 00:00:00 2001 From: Jens Nockert Date: Fri, 21 Dec 2012 19:30:33 +0100 Subject: [PATCH 01/21] Add support for bitcount intrinsics Adds support for the llvm.ctpop, llvm.ctlz and llvm.cttz intrinsics. --- src/librustc/middle/trans/base.rs | 36 ++++++++ src/librustc/middle/trans/foreign.rs | 68 ++++++++++++++ src/librustc/middle/trans/type_use.rs | 5 ++ src/librustc/middle/typeck/check/mod.rs | 50 ++++++++++- src/test/run-pass/intrinsics-integer.rs | 112 ++++++++++++++++++++++++ 5 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/intrinsics-integer.rs diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index a65f6668cd35..d0ce66da43f5 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2396,6 +2396,30 @@ fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> { T_fn(~[T_f32()], T_f32())); let truncf64 = decl_cdecl_fn(llmod, ~"llvm.trunc.f64", T_fn(~[T_f64()], T_f64())); + let ctpop8 = decl_cdecl_fn(llmod, ~"llvm.ctpop.i8", + T_fn(~[T_i8()], T_i8())); + let ctpop16 = decl_cdecl_fn(llmod, ~"llvm.ctpop.i16", + T_fn(~[T_i16()], T_i16())); + let ctpop32 = decl_cdecl_fn(llmod, ~"llvm.ctpop.i32", + T_fn(~[T_i32()], T_i32())); + let ctpop64 = decl_cdecl_fn(llmod, ~"llvm.ctpop.i64", + T_fn(~[T_i64()], T_i64())); + let ctlz8 = decl_cdecl_fn(llmod, ~"llvm.ctlz.i8", + T_fn(~[T_i8(), T_i1()], T_i8())); + let ctlz16 = decl_cdecl_fn(llmod, ~"llvm.ctlz.i16", + T_fn(~[T_i16(), T_i1()], T_i16())); + let ctlz32 = decl_cdecl_fn(llmod, ~"llvm.ctlz.i32", + T_fn(~[T_i32(), T_i1()], T_i32())); + let ctlz64 = decl_cdecl_fn(llmod, ~"llvm.ctlz.i64", + T_fn(~[T_i64(), T_i1()], T_i64())); + let cttz8 = decl_cdecl_fn(llmod, ~"llvm.cttz.i8", + T_fn(~[T_i8(), T_i1()], T_i8())); + let cttz16 = decl_cdecl_fn(llmod, ~"llvm.cttz.i16", + T_fn(~[T_i16(), T_i1()], T_i16())); + let cttz32 = decl_cdecl_fn(llmod, ~"llvm.cttz.i32", + T_fn(~[T_i32(), T_i1()], T_i32())); + let cttz64 = decl_cdecl_fn(llmod, ~"llvm.cttz.i64", + T_fn(~[T_i64(), T_i1()], T_i64())); let intrinsics = HashMap(); intrinsics.insert(~"llvm.gcroot", gcroot); @@ -2436,6 +2460,18 @@ fn declare_intrinsics(llmod: ModuleRef) -> HashMap<~str, ValueRef> { intrinsics.insert(~"llvm.ceil.f64", ceilf64); intrinsics.insert(~"llvm.trunc.f32", truncf32); intrinsics.insert(~"llvm.trunc.f64", truncf64); + intrinsics.insert(~"llvm.ctpop.i8", ctpop8); + intrinsics.insert(~"llvm.ctpop.i16", ctpop16); + intrinsics.insert(~"llvm.ctpop.i32", ctpop32); + intrinsics.insert(~"llvm.ctpop.i64", ctpop64); + intrinsics.insert(~"llvm.ctlz.i8", ctlz8); + intrinsics.insert(~"llvm.ctlz.i16", ctlz16); + intrinsics.insert(~"llvm.ctlz.i32", ctlz32); + intrinsics.insert(~"llvm.ctlz.i64", ctlz64); + intrinsics.insert(~"llvm.cttz.i8", cttz8); + intrinsics.insert(~"llvm.cttz.i16", cttz16); + intrinsics.insert(~"llvm.cttz.i32", cttz32); + intrinsics.insert(~"llvm.cttz.i64", cttz64); return intrinsics; } diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index 38c3a4f7cb35..e7cdf82fd151 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -1194,6 +1194,74 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item, let truncf = ccx.intrinsics.get(~"llvm.trunc.f64"); Store(bcx, Call(bcx, truncf, ~[x]), fcx.llretptr); } + ~"ctpop8" => { + let x = get_param(decl, first_real_arg); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i8"); + Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) + } + ~"ctpop16" => { + let x = get_param(decl, first_real_arg); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i16"); + Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) + } + ~"ctpop32" => { + let x = get_param(decl, first_real_arg); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i32"); + Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) + } + ~"ctpop64" => { + let x = get_param(decl, first_real_arg); + let ctpop = ccx.intrinsics.get(~"llvm.ctpop.i64"); + Store(bcx, Call(bcx, ctpop, ~[x]), fcx.llretptr) + } + ~"ctlz8" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i8"); + Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) + } + ~"ctlz16" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i16"); + Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) + } + ~"ctlz32" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i32"); + Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) + } + ~"ctlz64" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let ctlz = ccx.intrinsics.get(~"llvm.ctlz.i64"); + Store(bcx, Call(bcx, ctlz, ~[x, y]), fcx.llretptr) + } + ~"cttz8" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i8"); + Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) + } + ~"cttz16" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i16"); + Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) + } + ~"cttz32" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i32"); + Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) + } + ~"cttz64" => { + let x = get_param(decl, first_real_arg); + let y = C_bool(false); + let cttz = ccx.intrinsics.get(~"llvm.cttz.i64"); + Store(bcx, Call(bcx, cttz, ~[x, y]), fcx.llretptr) + } _ => { // Could we make this an enum rather than a string? does it get // checked earlier? diff --git a/src/librustc/middle/trans/type_use.rs b/src/librustc/middle/trans/type_use.rs index 08ee59f5d89f..7f3b78359fec 100644 --- a/src/librustc/middle/trans/type_use.rs +++ b/src/librustc/middle/trans/type_use.rs @@ -130,6 +130,11 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint) ~"floorf32"| ~"floorf64"| ~"ceilf32" | ~"ceilf64" | ~"truncf32"| ~"truncf64" => 0, + ~"ctpop8" | ~"ctpop16" | ~"ctpop32" | ~"ctpop64" => 0, + + ~"ctlz8" | ~"ctlz16" | ~"ctlz32" | ~"ctlz64" => 0, + ~"cttz8" | ~"cttz16" | ~"cttz32" | ~"cttz64" => 0, + // would be cool to make these an enum instead of strings! _ => fail ~"unknown intrinsic in type_use" }; diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 8af091fdb9ad..93bdfd5ccda6 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3156,7 +3156,55 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) { (0u, ~[arg(ast::by_copy, ty::mk_f64(tcx))], ty::mk_f64(tcx)) } - ref other => { + ~"ctpop8" => { + (0u, ~[arg(ast::by_copy, ty::mk_i8(tcx))], + ty::mk_i8(tcx)) + } + ~"ctpop16" => { + (0u, ~[arg(ast::by_copy, ty::mk_i16(tcx))], + ty::mk_i16(tcx)) + } + ~"ctpop32" => { + (0u, ~[arg(ast::by_copy, ty::mk_i32(tcx))], + ty::mk_i32(tcx)) + } + ~"ctpop64" => { + (0u, ~[arg(ast::by_copy, ty::mk_i64(tcx))], + ty::mk_i64(tcx)) + } + ~"ctlz8" => { + (0u, ~[arg(ast::by_copy, ty::mk_i8(tcx))], + ty::mk_i8(tcx)) + } + ~"ctlz16" => { + (0u, ~[arg(ast::by_copy, ty::mk_i16(tcx))], + ty::mk_i16(tcx)) + } + ~"ctlz32" => { + (0u, ~[arg(ast::by_copy, ty::mk_i32(tcx))], + ty::mk_i32(tcx)) + } + ~"ctlz64" => { + (0u, ~[arg(ast::by_copy, ty::mk_i64(tcx))], + ty::mk_i64(tcx)) + } + ~"cttz8" => { + (0u, ~[arg(ast::by_copy, ty::mk_i8(tcx))], + ty::mk_i8(tcx)) + } + ~"cttz16" => { + (0u, ~[arg(ast::by_copy, ty::mk_i16(tcx))], + ty::mk_i16(tcx)) + } + ~"cttz32" => { + (0u, ~[arg(ast::by_copy, ty::mk_i32(tcx))], + ty::mk_i32(tcx)) + } + ~"cttz64" => { + (0u, ~[arg(ast::by_copy, ty::mk_i64(tcx))], + ty::mk_i64(tcx)) + } + ref other => { tcx.sess.span_err(it.span, ~"unrecognized intrinsic function: `" + (*other) + ~"`"); return; diff --git a/src/test/run-pass/intrinsics-integer.rs b/src/test/run-pass/intrinsics-integer.rs new file mode 100644 index 000000000000..588cc496b282 --- /dev/null +++ b/src/test/run-pass/intrinsics-integer.rs @@ -0,0 +1,112 @@ +// xfail-fast + +// Copyright 2012 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern mod std; + +#[abi = "rust-intrinsic"] +extern mod rusti { + fn ctpop8(x: i8) -> i8; + fn ctpop16(x: i16) -> i16; + fn ctpop32(x: i32) -> i32; + fn ctpop64(x: i64) -> i64; + + fn ctlz8(x: i8) -> i8; + fn ctlz16(x: i16) -> i16; + fn ctlz32(x: i32) -> i32; + fn ctlz64(x: i64) -> i64; + + fn cttz8(x: i8) -> i8; + fn cttz16(x: i16) -> i16; + fn cttz32(x: i32) -> i32; + fn cttz64(x: i64) -> i64; +} + +fn main() { + + use rusti::*; + + assert(ctpop8(0i8) == 0i8); + assert(ctpop16(0i16) == 0i16); + assert(ctpop32(0i32) == 0i32); + assert(ctpop64(0i64) == 0i64); + + assert(ctpop8(1i8) == 1i8); + assert(ctpop16(1i16) == 1i16); + assert(ctpop32(1i32) == 1i32); + assert(ctpop64(1i64) == 1i64); + + assert(ctpop8(10i8) == 2i8); + assert(ctpop16(10i16) == 2i16); + assert(ctpop32(10i32) == 2i32); + assert(ctpop64(10i64) == 2i64); + + assert(ctpop8(100i8) == 3i8); + assert(ctpop16(100i16) == 3i16); + assert(ctpop32(100i32) == 3i32); + assert(ctpop64(100i64) == 3i64); + + assert(ctpop8(-1i8) == 8i8); + assert(ctpop16(-1i16) == 16i16); + assert(ctpop32(-1i32) == 32i32); + assert(ctpop64(-1i64) == 64i64); + + assert(ctlz8(0i8) == 8i8); + assert(ctlz16(0i16) == 16i16); + assert(ctlz32(0i32) == 32i32); + assert(ctlz64(0i64) == 64i64); + + assert(ctlz8(1i8) == 7i8); + assert(ctlz16(1i16) == 15i16); + assert(ctlz32(1i32) == 31i32); + assert(ctlz64(1i64) == 63i64); + + assert(ctlz8(10i8) == 4i8); + assert(ctlz16(10i16) == 12i16); + assert(ctlz32(10i32) == 28i32); + assert(ctlz64(10i64) == 60i64); + + assert(ctlz8(100i8) == 1i8); + assert(ctlz16(100i16) == 9i16); + assert(ctlz32(100i32) == 25i32); + assert(ctlz64(100i64) == 57i64); + + assert(cttz8(-1i8) == 0i8); + assert(cttz16(-1i16) == 0i16); + assert(cttz32(-1i32) == 0i32); + assert(cttz64(-1i64) == 0i64); + + assert(cttz8(0i8) == 8i8); + assert(cttz16(0i16) == 16i16); + assert(cttz32(0i32) == 32i32); + assert(cttz64(0i64) == 64i64); + + assert(cttz8(1i8) == 0i8); + assert(cttz16(1i16) == 0i16); + assert(cttz32(1i32) == 0i32); + assert(cttz64(1i64) == 0i64); + + assert(cttz8(10i8) == 1i8); + assert(cttz16(10i16) == 1i16); + assert(cttz32(10i32) == 1i32); + assert(cttz64(10i64) == 1i64); + + assert(cttz8(100i8) == 2i8); + assert(cttz16(100i16) == 2i16); + assert(cttz32(100i32) == 2i32); + assert(cttz64(100i64) == 2i64); + + assert(cttz8(-1i8) == 0i8); + assert(cttz16(-1i16) == 0i16); + assert(cttz32(-1i32) == 0i32); + assert(cttz64(-1i64) == 0i64); + +} From 6c056976678e103f23fd29557174d7718b75a617 Mon Sep 17 00:00:00 2001 From: Martin DeMello Date: Fri, 21 Dec 2012 23:13:06 -0800 Subject: [PATCH 02/21] Fix options passed to gpg in cargo init --- src/libcargo/pgp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcargo/pgp.rs b/src/libcargo/pgp.rs index 8fd4994ba145..6659ed031ca7 100644 --- a/src/libcargo/pgp.rs +++ b/src/libcargo/pgp.rs @@ -102,7 +102,7 @@ fn verify(root: &Path, data: &Path, sig: &Path) -> bool { let path = root.push("gpg"); let res = gpgv(~[~"--homedir", path.to_str(), ~"--keyring", ~"pubring.gpg", - ~"--verbose", + ~"--verify", sig.to_str(), data.to_str()]); if res.status != 0 { return false; From 50902bb3025ed9e583bf029c78406cb5b9abf7c7 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 20 Dec 2012 21:15:25 -0800 Subject: [PATCH 03/21] Fix Option::unwrap_err. --- src/libcore/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 26064345b59f..e93d186049ec 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -234,7 +234,7 @@ impl Result { pure fn unwrap(self) -> T { unwrap(self) } #[inline(always)] - pure fn unwrap_err(self) -> T { unwrap(self) } + pure fn unwrap_err(self) -> E { unwrap_err(self) } #[inline(always)] pure fn chain(self, op: fn(T) -> Result) -> Result { From 03b5fcabbd34c9ceb8466bfbca2cf6ca4cd36731 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 20 Dec 2012 21:15:49 -0800 Subject: [PATCH 04/21] Switch chain calls to use Option::chain method --- src/libstd/time.rs | 117 +++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 78 deletions(-) diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 545393848621..1058910c35a6 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -385,36 +385,22 @@ priv fn do_strptime(s: &str, format: &str) -> Result { None => Err(~"Invalid year") }, 'c' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'a', tm), - |pos| parse_char(s, pos, ' ')), - |pos| parse_type(s, pos, 'b', tm)), - |pos| parse_char(s, pos, ' ')), - |pos| parse_type(s, pos, 'e', tm)), - |pos| parse_char(s, pos, ' ')), - |pos| parse_type(s, pos, 'T', tm)), - |pos| parse_char(s, pos, ' ')), - |pos| parse_type(s, pos, 'Y', tm)) + parse_type(s, pos, 'a', tm) + .chain(|pos| parse_char(s, pos, ' ')) + .chain(|pos| parse_type(s, pos, 'b', tm)) + .chain(|pos| parse_char(s, pos, ' ')) + .chain(|pos| parse_type(s, pos, 'e', tm)) + .chain(|pos| parse_char(s, pos, ' ')) + .chain(|pos| parse_type(s, pos, 'T', tm)) + .chain(|pos| parse_char(s, pos, ' ')) + .chain(|pos| parse_type(s, pos, 'Y', tm)) } 'D' | 'x' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'm', tm), - |pos| parse_char(s, pos, '/')), - |pos| parse_type(s, pos, 'd', tm)), - |pos| parse_char(s, pos, '/')), - |pos| parse_type(s, pos, 'y', tm)) + parse_type(s, pos, 'm', tm) + .chain(|pos| parse_char(s, pos, '/')) + .chain(|pos| parse_type(s, pos, 'd', tm)) + .chain(|pos| parse_char(s, pos, '/')) + .chain(|pos| parse_type(s, pos, 'y', tm)) } 'd' => match match_digits(s, pos, 2u, false) { Some(item) => { let (v, pos) = item; tm.tm_mday = v; Ok(pos) } @@ -425,16 +411,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result { None => Err(~"Invalid day of the month") }, 'F' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'Y', tm), - |pos| parse_char(s, pos, '-')), - |pos| parse_type(s, pos, 'm', tm)), - |pos| parse_char(s, pos, '-')), - |pos| parse_type(s, pos, 'd', tm)) + parse_type(s, pos, 'Y', tm) + .chain(|pos| parse_char(s, pos, '-')) + .chain(|pos| parse_type(s, pos, 'm', tm)) + .chain(|pos| parse_char(s, pos, '-')) + .chain(|pos| parse_type(s, pos, 'd', tm)) } 'H' => { // FIXME (#2350): range check. @@ -515,28 +496,18 @@ priv fn do_strptime(s: &str, format: &str) -> Result { None => Err(~"Invalid hour") }, 'R' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - move parse_type(s, pos, 'H', tm), - |pos| parse_char(s, pos, ':')), - |pos| parse_type(s, pos, 'M', tm)) + parse_type(s, pos, 'H', tm) + .chain(|pos| parse_char(s, pos, ':')) + .chain(|pos| parse_type(s, pos, 'M', tm)) } 'r' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'I', tm), - |pos| parse_char(s, pos, ':')), - |pos| parse_type(s, pos, 'M', tm)), - |pos| parse_char(s, pos, ':')), - |pos| parse_type(s, pos, 'S', tm)), - |pos| parse_char(s, pos, ' ')), - |pos| parse_type(s, pos, 'p', tm)) + parse_type(s, pos, 'I', tm) + .chain(|pos| parse_char(s, pos, ':')) + .chain(|pos| parse_type(s, pos, 'M', tm)) + .chain(|pos| parse_char(s, pos, ':')) + .chain(|pos| parse_type(s, pos, 'S', tm)) + .chain(|pos| parse_char(s, pos, ' ')) + .chain(|pos| parse_type(s, pos, 'p', tm)) } 'S' => { // FIXME (#2350): range check. @@ -551,16 +522,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result { } //'s' {} 'T' | 'X' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'H', tm), - |pos| parse_char(s, pos, ':')), - |pos| parse_type(s, pos, 'M', tm)), - |pos| parse_char(s, pos, ':')), - |pos| parse_type(s, pos, 'S', tm)) + parse_type(s, pos, 'H', tm) + .chain(|pos| parse_char(s, pos, ':')) + .chain(|pos| parse_type(s, pos, 'M', tm)) + .chain(|pos| parse_char(s, pos, ':')) + .chain(|pos| parse_type(s, pos, 'S', tm)) } 't' => parse_char(s, pos, '\t'), 'u' => { @@ -575,16 +541,11 @@ priv fn do_strptime(s: &str, format: &str) -> Result { } } 'v' => { - // FIXME(#3724): cleanup - result::chain( - result::chain( - result::chain( - result::chain( - move parse_type(s, pos, 'e', tm), - |pos| parse_char(s, pos, '-')), - |pos| parse_type(s, pos, 'b', tm)), - |pos| parse_char(s, pos, '-')), - |pos| parse_type(s, pos, 'Y', tm)) + parse_type(s, pos, 'e', tm) + .chain(|pos| parse_char(s, pos, '-')) + .chain(|pos| parse_type(s, pos, 'b', tm)) + .chain(|pos| parse_char(s, pos, '-')) + .chain(|pos| parse_type(s, pos, 'Y', tm)) } //'W' {} 'w' => { From b6f0f300d572cc8e6a1cc8ab9aad101dcf20efac Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Fri, 21 Dec 2012 07:47:32 -0800 Subject: [PATCH 05/21] std: modernize net_url This switches over to using structs and send_maps for query string parsing. --- src/libstd/net_url.rs | 692 ++++++++++++++++++++---------------------- 1 file changed, 322 insertions(+), 370 deletions(-) diff --git a/src/libstd/net_url.rs b/src/libstd/net_url.rs index 6b7dc3f1afdb..a6ba728ccbb0 100644 --- a/src/libstd/net_url.rs +++ b/src/libstd/net_url.rs @@ -11,15 +11,10 @@ //! Types/fns concerning URLs (see RFC 3986) #[forbid(deprecated_mode)]; -use core::cmp::Eq; -use map::HashMap; -use io::{Reader, ReaderUtil}; -use dvec::DVec; -use from_str::FromStr; -use result::{Err, Ok}; -use to_str::ToStr; -use to_bytes::IterBytes; +use io::ReaderUtil; +use send_map::linear::LinearMap; +#[deriving_eq] struct Url { scheme: ~str, user: Option, @@ -30,23 +25,40 @@ struct Url { fragment: Option<~str> } -type UserInfo = { +#[deriving_eq] +struct UserInfo { user: ~str, pass: Option<~str> -}; +} pub type Query = ~[(~str, ~str)]; -pub pure fn Url(scheme: ~str, user: Option, host: ~str, - port: Option<~str>, path: ~str, query: Query, - fragment: Option<~str>) -> Url { - Url { scheme: move scheme, user: move user, host: move host, - port: move port, path: move path, query: move query, - fragment: move fragment } +pub impl Url { + static pure fn new( + scheme: ~str, + user: Option, + host: ~str, + port: Option<~str>, + path: ~str, + query: Query, + fragment: Option<~str> + ) -> Url { + Url { + scheme: scheme, + user: user, + host: host, + port: port, + path: path, + query: query, + fragment: fragment, + } + } } -pure fn UserInfo(user: ~str, pass: Option<~str>) -> UserInfo { - {user: move user, pass: move pass} +pub impl UserInfo { + static pure fn new(user: ~str, pass: Option<~str>) -> UserInfo { + UserInfo { user: user, pass: pass } + } } fn encode_inner(s: &str, full_url: bool) -> ~str { @@ -95,7 +107,7 @@ fn encode_inner(s: &str, full_url: bool) -> ~str { * This function is compliant with RFC 3986. */ pub pure fn encode(s: &str) -> ~str { - // unsafe only because encode_inner does (string) IO + // FIXME(#3722): unsafe only because encode_inner does (string) IO unsafe {encode_inner(s, true)} } @@ -107,7 +119,7 @@ pub pure fn encode(s: &str) -> ~str { */ pub pure fn encode_component(s: &str) -> ~str { - // unsafe only because encode_inner does (string) IO + // FIXME(#3722): unsafe only because encode_inner does (string) IO unsafe {encode_inner(s, false)} } @@ -152,10 +164,10 @@ fn decode_inner(s: &str, full_url: bool) -> ~str { /** * Decode a string encoded with percent encoding. * - * This will only decode escape sequences generated by encode_uri. + * This will only decode escape sequences generated by encode. */ pub pure fn decode(s: &str) -> ~str { - // unsafe only because decode_inner does (string) IO + // FIXME(#3722): unsafe only because decode_inner does (string) IO unsafe {decode_inner(s, true)} } @@ -163,7 +175,7 @@ pub pure fn decode(s: &str) -> ~str { * Decode a string encoded with percent encoding. */ pub pure fn decode_component(s: &str) -> ~str { - // unsafe only because decode_inner does (string) IO + // FIXME(#3722): unsafe only because decode_inner does (string) IO unsafe {decode_inner(s, false)} } @@ -189,12 +201,12 @@ fn encode_plus(s: &str) -> ~str { /** * Encode a hashmap to the 'application/x-www-form-urlencoded' media type. */ -pub fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str { +pub fn encode_form_urlencoded(m: &LinearMap<~str, ~[~str]>) -> ~str { let mut out = ~""; let mut first = true; for m.each |key, values| { - let key = encode_plus(key); + let key = encode_plus(*key); for (*values).each |value| { if first { @@ -204,7 +216,7 @@ pub fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str { first = false; } - out += fmt!("%s=%s", key, encode_plus(**value)); + out += fmt!("%s=%s", key, encode_plus(*value)); } } @@ -215,62 +227,60 @@ pub fn encode_form_urlencoded(m: HashMap<~str, @DVec<@~str>>) -> ~str { * Decode a string encoded with the 'application/x-www-form-urlencoded' media * type into a hashmap. */ -pub fn decode_form_urlencoded(s: ~[u8]) -> - map::HashMap<~str, @dvec::DVec<@~str>> { +pub fn decode_form_urlencoded( + s: &[u8] +) -> send_map::linear::LinearMap<~str, ~[~str]> { do io::with_bytes_reader(s) |rdr| { - let m = HashMap(); + let mut m = LinearMap(); let mut key = ~""; let mut value = ~""; let mut parsing_key = true; while !rdr.eof() { match rdr.read_char() { - '&' | ';' => { - if key != ~"" && value != ~"" { - let values = match m.find(key) { - Some(values) => values, - None => { - let values = @DVec(); + '&' | ';' => { + if key != ~"" && value != ~"" { + let mut values = match m.pop(&key) { + Some(move values) => values, + None => ~[], + }; + + values.push(value); m.insert(key, values); - values - } + } + + parsing_key = true; + key = ~""; + value = ~""; + } + '=' => parsing_key = false, + ch => { + let ch = match ch { + '%' => { + let bytes = rdr.read_bytes(2u); + uint::parse_bytes(bytes, 16u).get() as char + } + '+' => ' ', + ch => ch }; - (*values).push(@value) - } - parsing_key = true; - key = ~""; - value = ~""; - } - '=' => parsing_key = false, - ch => { - let ch = match ch { - '%' => { - uint::parse_bytes(rdr.read_bytes(2u), 16u).get() as char - } - '+' => ' ', - ch => ch - }; - - if parsing_key { - str::push_char(&mut key, ch) - } else { - str::push_char(&mut value, ch) + if parsing_key { + str::push_char(&mut key, ch) + } else { + str::push_char(&mut value, ch) + } } - } } } if key != ~"" && value != ~"" { - let values = match m.find(key) { - Some(values) => values, - None => { - let values = @DVec(); - m.insert(key, values); - values - } + let mut values = match m.pop(&key) { + Some(move values) => values, + None => ~[], }; - (*values).push(@value) + + values.push(value); + m.insert(key, values); } m @@ -282,9 +292,10 @@ pure fn split_char_first(s: &str, c: char) -> (~str, ~str) { let len = str::len(s); let mut index = len; let mut mat = 0; + // FIXME(#3722): unsafe only because decode_inner does (string) IO unsafe { do io::with_str_reader(s) |rdr| { - let mut ch : char; + let mut ch; while !rdr.eof() { ch = rdr.read_byte() as char; if ch == c { @@ -307,107 +318,88 @@ pure fn split_char_first(s: &str, c: char) -> (~str, ~str) { pure fn userinfo_from_str(uinfo: &str) -> UserInfo { let (user, p) = split_char_first(uinfo, ':'); let pass = if str::len(p) == 0 { - option::None + None } else { - option::Some(p) + Some(p) }; - return UserInfo(user, pass); + return UserInfo::new(user, pass); } -pure fn userinfo_to_str(userinfo: UserInfo) -> ~str { - if option::is_some(&userinfo.pass) { - return str::concat(~[copy userinfo.user, ~":", - option::unwrap(copy userinfo.pass), - ~"@"]); - } else { - return str::concat(~[copy userinfo.user, ~"@"]); +pure fn userinfo_to_str(userinfo: &UserInfo) -> ~str { + match userinfo.pass { + Some(ref pass) => fmt!("%s:%s@", userinfo.user, *pass), + None => fmt!("%s@", userinfo.user), } } -impl UserInfo : Eq { - pure fn eq(&self, other: &UserInfo) -> bool { - (*self).user == (*other).user && (*self).pass == (*other).pass - } - pure fn ne(&self, other: &UserInfo) -> bool { !(*self).eq(other) } -} - pure fn query_from_str(rawquery: &str) -> Query { let mut query: Query = ~[]; if str::len(rawquery) != 0 { for str::split_char(rawquery, '&').each |p| { let (k, v) = split_char_first(*p, '='); + // FIXME(#3722): unsafe only because decode_inner does (string) IO unsafe {query.push((decode_component(k), decode_component(v)));} }; } return query; } -pub pure fn query_to_str(query: Query) -> ~str { +pub pure fn query_to_str(query: &Query) -> ~str unsafe { + // FIXME(#3722): unsafe only because decode_inner does (string) IO let mut strvec = ~[]; for query.each |kv| { - let (k, v) = copy *kv; - // This is really safe... - unsafe { - strvec += ~[fmt!("%s=%s", - encode_component(k), encode_component(v))]; + match kv { + &(ref k, ref v) => { + strvec.push(fmt!("%s=%s", + encode_component(*k), + encode_component(*v)) + ); + } } - }; + } return str::connect(strvec, ~"&"); } // returns the scheme and the rest of the url, or a parsing error -pub pure fn get_scheme(rawurl: &str) -> result::Result<(~str, ~str), @~str> { +pub pure fn get_scheme(rawurl: &str) -> Result<(~str, ~str), ~str> { for str::each_chari(rawurl) |i,c| { match c { 'A' .. 'Z' | 'a' .. 'z' => loop, '0' .. '9' | '+' | '-' | '.' => { if i == 0 { - return result::Err(@~"url: Scheme must begin with a letter."); + return Err(~"url: Scheme must begin with a letter."); } loop; } ':' => { if i == 0 { - return result::Err(@~"url: Scheme cannot be empty."); + return Err(~"url: Scheme cannot be empty."); } else { - return result::Ok((rawurl.slice(0,i), + return Ok((rawurl.slice(0,i), rawurl.slice(i+1,str::len(rawurl)))); } } _ => { - return result::Err(@~"url: Invalid character in scheme."); + return Err(~"url: Invalid character in scheme."); } } }; - return result::Err(@~"url: Scheme must be terminated with a colon."); + return Err(~"url: Scheme must be terminated with a colon."); } +#[deriving_eq] enum Input { Digit, // all digits Hex, // digits and letters a-f Unreserved // all other legal characters } -impl Input : Eq { - pure fn eq(&self, other: &Input) -> bool { - match ((*self), (*other)) { - (Digit, Digit) => true, - (Hex, Hex) => true, - (Unreserved, Unreserved) => true, - (Digit, _) => false, - (Hex, _) => false, - (Unreserved, _) => false - } - } - pure fn ne(&self, other: &Input) -> bool { !(*self).eq(other) } -} - // returns userinfo, host, port, and unparsed part, or an error pure fn get_authority(rawurl: &str) -> - result::Result<(Option, ~str, Option<~str>, ~str), @~str> { + Result<(Option, ~str, Option<~str>, ~str), ~str> { if !str::starts_with(rawurl, ~"//") { // there is no authority. - return result::Ok((option::None, ~"", option::None, rawurl.to_str())); + return Ok((None, ~"", None, rawurl.to_str())); } enum State { @@ -419,16 +411,16 @@ pure fn get_authority(rawurl: &str) -> InPort // are in port } - let len = str::len(rawurl); - let mut st : State = Start; - let mut in : Input = Digit; // most restricted, start here. + let len = rawurl.len(); + let mut st = Start; + let mut in = Digit; // most restricted, start here. - let mut userinfo : Option = option::None; - let mut host : ~str = ~""; - let mut port : option::Option<~str> = option::None; + let mut userinfo = None; + let mut host = ~""; + let mut port = None; let mut colon_count = 0; - let mut pos : uint = 0, begin : uint = 2, end : uint = len; + let mut pos = 0, begin = 2, end = len; for str::each_chari(rawurl) |i,c| { if i < 2 { loop; } // ignore the leading // @@ -449,7 +441,7 @@ pure fn get_authority(rawurl: &str) -> // separators, don't change anything } _ => { - return result::Err(@~"Illegal character in authority"); + return Err(~"Illegal character in authority"); } } @@ -465,8 +457,8 @@ pure fn get_authority(rawurl: &str) -> PassHostPort => { // multiple colons means ipv6 address. if in == Unreserved { - return result::Err( - @~"Illegal characters in IPv6 address."); + return Err( + ~"Illegal characters in IPv6 address."); } st = Ip6Host; } @@ -474,13 +466,13 @@ pure fn get_authority(rawurl: &str) -> pos = i; // can't be sure whether this is an ipv6 address or a port if in == Unreserved { - return result::Err(@~"Illegal characters in authority."); + return Err(~"Illegal characters in authority."); } st = Ip6Port; } Ip6Port => { if in == Unreserved { - return result::Err(@~"Illegal characters in authority."); + return Err(~"Illegal characters in authority."); } st = Ip6Host; } @@ -492,7 +484,7 @@ pure fn get_authority(rawurl: &str) -> } } _ => { - return result::Err(@~"Invalid ':' in authority."); + return Err(~"Invalid ':' in authority."); } } in = Digit; // reset input class @@ -504,19 +496,17 @@ pure fn get_authority(rawurl: &str) -> match st { Start => { let user = str::slice(rawurl, begin, i); - userinfo = option::Some({user : user, - pass: option::None}); + userinfo = Some(UserInfo::new(user, None)); st = InHost; } PassHostPort => { let user = str::slice(rawurl, begin, pos); let pass = str::slice(rawurl, pos+1, i); - userinfo = option::Some({user: user, - pass: option::Some(pass)}); + userinfo = Some(UserInfo::new(user, Some(pass))); st = InHost; } _ => { - return result::Err(@~"Invalid '@' in authority."); + return Err(~"Invalid '@' in authority."); } } begin = i+1; @@ -549,31 +539,31 @@ pure fn get_authority(rawurl: &str) -> } PassHostPort | Ip6Port => { if in != Digit { - return result::Err(@~"Non-digit characters in port."); + return Err(~"Non-digit characters in port."); } host = str::slice(rawurl, begin, pos); - port = option::Some(str::slice(rawurl, pos+1, end)); + port = Some(str::slice(rawurl, pos+1, end)); } Ip6Host | InHost => { host = str::slice(rawurl, begin, end); } InPort => { if in != Digit { - return result::Err(@~"Non-digit characters in port."); + return Err(~"Non-digit characters in port."); } - port = option::Some(str::slice(rawurl, pos+1, end)); + port = Some(str::slice(rawurl, pos+1, end)); } } let rest = if host_is_end_plus_one() { ~"" } else { str::slice(rawurl, end, len) }; - return result::Ok((userinfo, host, port, rest)); + return Ok((userinfo, host, port, rest)); } // returns the path and unparsed part of url, or an error -pure fn get_path(rawurl: &str, authority : bool) -> - result::Result<(~str, ~str), @~str> { +pure fn get_path(rawurl: &str, authority: bool) -> + Result<(~str, ~str), ~str> { let len = str::len(rawurl); let mut end = len; for str::each_chari(rawurl) |i,c| { @@ -587,39 +577,39 @@ pure fn get_path(rawurl: &str, authority : bool) -> end = i; break; } - _ => return result::Err(@~"Invalid character in path.") + _ => return Err(~"Invalid character in path.") } } if authority { if end != 0 && !str::starts_with(rawurl, ~"/") { - return result::Err(@~"Non-empty path must begin with\ + return Err(~"Non-empty path must begin with\ '/' in presence of authority."); } } - return result::Ok((decode_component(str::slice(rawurl, 0, end)), + return Ok((decode_component(str::slice(rawurl, 0, end)), str::slice(rawurl, end, len))); } // returns the parsed query and the fragment, if present pure fn get_query_fragment(rawurl: &str) -> - result::Result<(Query, Option<~str>), @~str> { + Result<(Query, Option<~str>), ~str> { if !str::starts_with(rawurl, ~"?") { if str::starts_with(rawurl, ~"#") { let f = decode_component(str::slice(rawurl, 1, str::len(rawurl))); - return result::Ok((~[], option::Some(f))); + return Ok((~[], Some(f))); } else { - return result::Ok((~[], option::None)); + return Ok((~[], None)); } } let (q, r) = split_char_first(str::slice(rawurl, 1, str::len(rawurl)), '#'); let f = if str::len(r) != 0 { - option::Some(decode_component(r)) } else { option::None }; - return result::Ok((query_from_str(q), f)); + Some(decode_component(r)) } else { None }; + return Ok((query_from_str(q), f)); } /** @@ -635,41 +625,36 @@ pure fn get_query_fragment(rawurl: &str) -> * */ -pub pure fn from_str(rawurl: &str) -> result::Result { +pub pure fn from_str(rawurl: &str) -> Result { // scheme - let mut schm = get_scheme(rawurl); - if result::is_err(&schm) { - return result::Err(copy *result::get_err(&schm)); - } - let (scheme, rest) = schm.get(); + let (scheme, rest) = match get_scheme(rawurl) { + Ok(val) => val, + Err(e) => return Err(e), + }; // authority - let mut auth = get_authority(rest); - if result::is_err(&auth) { - return result::Err(copy *result::get_err(&auth)); - } - let (userinfo, host, port, rest) = auth.get(); + let (userinfo, host, port, rest) = match get_authority(rest) { + Ok(val) => val, + Err(e) => return Err(e), + }; // path let has_authority = if host == ~"" { false } else { true }; - let mut pth = get_path(rest, has_authority); - if result::is_err(&pth) { - return result::Err(copy *result::get_err(&pth)); - } - let (path, rest) = pth.get(); + let (path, rest) = match get_path(rest, has_authority) { + Ok(val) => val, + Err(e) => return Err(e), + }; // query and fragment - let mut qry = get_query_fragment(rest); - if result::is_err(&qry) { - return result::Err(copy *result::get_err(&qry)); - } - let (query, fragment) = qry.get(); + let (query, fragment) = match get_query_fragment(rest) { + Ok(val) => val, + Err(e) => return Err(e), + }; - return result::Ok(Url(scheme, userinfo, host, - port, path, query, fragment)); + Ok(Url::new(scheme, userinfo, host, port, path, query, fragment)) } -impl Url : FromStr { +impl Url: from_str::FromStr { static pure fn from_str(s: &str) -> Option { match from_str(s) { Ok(move url) => Some(url), @@ -693,63 +678,41 @@ impl Url : FromStr { * result in just "http://somehost.com". * */ -pub pure fn to_str(url: Url) -> ~str { - let user = if url.user.is_some() { - userinfo_to_str(option::unwrap(copy url.user)) - } else { - ~"" - }; - let authority = if str::len(url.host) != 0 { - str::concat(~[~"//", user, copy url.host]) - } else { - ~"" - }; - let query = if url.query.len() == 0 { - ~"" - } else { - str::concat(~[~"?", query_to_str(url.query)]) - }; - // ugh, this really is safe - let fragment = if url.fragment.is_some() unsafe { - str::concat(~[~"#", encode_component( - option::unwrap(copy url.fragment))]) - } else { - ~"" +pub pure fn to_str(url: &Url) -> ~str { + let user = match url.user { + Some(ref user) => userinfo_to_str(user), + None => ~"", }; - return str::concat(~[copy url.scheme, - ~":", - authority, - copy url.path, - query, - fragment]); + let authority = if url.host.is_empty() { + ~"" + } else { + fmt!("//%s%s", user, url.host) + }; + + let query = if url.query.is_empty() { + ~"" + } else { + fmt!("?%s", query_to_str(&url.query)) + }; + + let fragment = match url.fragment { + Some(ref fragment) => fmt!("#%s", encode_component(*fragment)), + None => ~"", + }; + + fmt!("%s:%s%s%s%s", url.scheme, authority, url.path, query, fragment) } impl Url: to_str::ToStr { pub pure fn to_str() -> ~str { - to_str(self) + to_str(&self) } } -impl Url : Eq { - pure fn eq(&self, other: &Url) -> bool { - (*self).scheme == (*other).scheme - && (*self).user == (*other).user - && (*self).host == (*other).host - && (*self).port == (*other).port - && (*self).path == (*other).path - && (*self).query == (*other).query - && (*self).fragment == (*other).fragment - } - - pure fn ne(&self, other: &Url) -> bool { - !(*self).eq(other) - } -} - -impl Url: IterBytes { +impl Url: to_bytes::IterBytes { pure fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) { - unsafe { self.to_str() }.iter_bytes(lsb0, f) + self.to_str().iter_bytes(lsb0, f) } } @@ -769,81 +732,73 @@ mod tests { #[test] fn test_get_authority() { - let (u, h, p, r) = result::unwrap(get_authority( - ~"//user:pass@rust-lang.org/something")); - assert u == option::Some({user: ~"user", - pass: option::Some(~"pass")}); + let (u, h, p, r) = get_authority( + "//user:pass@rust-lang.org/something").unwrap(); + assert u == Some(UserInfo::new(~"user", Some(~"pass"))); assert h == ~"rust-lang.org"; assert p.is_none(); assert r == ~"/something"; - let (u, h, p, r) = result::unwrap(get_authority( - ~"//rust-lang.org:8000?something")); + let (u, h, p, r) = get_authority( + "//rust-lang.org:8000?something").unwrap(); assert u.is_none(); assert h == ~"rust-lang.org"; - assert p == option::Some(~"8000"); + assert p == Some(~"8000"); assert r == ~"?something"; - let (u, h, p, r) = result::unwrap(get_authority( - ~"//rust-lang.org#blah")); + let (u, h, p, r) = get_authority( + "//rust-lang.org#blah").unwrap(); assert u.is_none(); assert h == ~"rust-lang.org"; assert p.is_none(); assert r == ~"#blah"; // ipv6 tests - let (_, h, _, _) = result::unwrap(get_authority( - ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah")); + let (_, h, _, _) = get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334#blah").unwrap(); assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - let (_, h, p, _) = result::unwrap(get_authority( - ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah")); + let (_, h, p, _) = get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah").unwrap(); assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - assert p == option::Some(~"8000"); + assert p == Some(~"8000"); - let (u, h, p, _) = result::unwrap(get_authority( - ~"//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah")); - assert u == option::Some({user: ~"us", pass : option::Some(~"p")}); + let (u, h, p, _) = get_authority( + "//us:p@2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000#blah" + ).unwrap(); + assert u == Some(UserInfo::new(~"us", Some(~"p"))); assert h == ~"2001:0db8:85a3:0042:0000:8a2e:0370:7334"; - assert p == option::Some(~"8000"); + assert p == Some(~"8000"); // invalid authorities; - assert result::is_err(&get_authority( - ~"//user:pass@rust-lang:something")); - assert result::is_err(&get_authority( - ~"//user@rust-lang:something:/path")); - assert result::is_err(&get_authority( - ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a")); - assert result::is_err(&get_authority( - ~"//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00")); + assert get_authority("//user:pass@rust-lang:something").is_err(); + assert get_authority("//user@rust-lang:something:/path").is_err(); + assert get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:800a").is_err(); + assert get_authority( + "//2001:0db8:85a3:0042:0000:8a2e:0370:7334:8000:00").is_err(); // these parse as empty, because they don't start with '//' - let (_, h, _, _) = result::unwrap( - get_authority(~"user:pass@rust-lang")); + let (_, h, _, _) = get_authority(~"user:pass@rust-lang").unwrap(); assert h == ~""; - let (_, h, _, _) = result::unwrap( - get_authority(~"rust-lang.org")); + let (_, h, _, _) = get_authority(~"rust-lang.org").unwrap(); assert h == ~""; - } #[test] fn test_get_path() { - let (p, r) = result::unwrap(get_path( - ~"/something+%20orother", true)); + let (p, r) = get_path("/something+%20orother", true).unwrap(); assert p == ~"/something+ orother"; assert r == ~""; - let (p, r) = result::unwrap(get_path( - ~"test@email.com#fragment", false)); + let (p, r) = get_path("test@email.com#fragment", false).unwrap(); assert p == ~"test@email.com"; assert r == ~"#fragment"; - let (p, r) = result::unwrap(get_path(~"/gen/:addr=?q=v", false)); + let (p, r) = get_path(~"/gen/:addr=?q=v", false).unwrap(); assert p == ~"/gen/:addr="; assert r == ~"?q=v"; //failure cases - assert result::is_err(&get_path(~"something?q", true)); - + assert get_path(~"something?q", true).is_err(); } #[test] @@ -851,22 +806,21 @@ mod tests { let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; let up = from_str(url); - let u = result::unwrap(up); + let u = up.unwrap(); assert u.scheme == ~"http"; - assert option::unwrap(copy u.user).user == ~"user"; - assert option::unwrap(copy option::unwrap(copy u.user).pass) - == ~"pass"; + let userinfo = u.user.get_ref(); + assert userinfo.user == ~"user"; + assert userinfo.pass.get_ref() == &~"pass"; assert u.host == ~"rust-lang.org"; assert u.path == ~"/doc"; - assert u.query.find(|kv| kv.first() == ~"s").get().second() == ~"v"; - assert option::unwrap(copy u.fragment) == ~"something"; + assert u.query == ~[(~"s", ~"v")]; + assert u.fragment.get_ref() == &~"something"; } #[test] fn test_url_parse_host_slash() { let urlstr = ~"http://0.42.42.42/"; - let url = from_str(urlstr).get(); - debug!("url: %?", url); + let url = from_str(urlstr).unwrap(); assert url.host == ~"0.42.42.42"; assert url.path == ~"/"; } @@ -874,98 +828,95 @@ mod tests { #[test] fn test_url_with_underscores() { let urlstr = ~"http://dotcom.com/file_name.html"; - let url = from_str(urlstr).get(); - debug!("url: %?", url); + let url = from_str(urlstr).unwrap(); assert url.path == ~"/file_name.html"; } #[test] fn test_url_with_dashes() { let urlstr = ~"http://dotcom.com/file-name.html"; - let url = from_str(urlstr).get(); - debug!("url: %?", url); + let url = from_str(urlstr).unwrap(); assert url.path == ~"/file-name.html"; } #[test] fn test_no_scheme() { - assert result::is_err(&get_scheme(~"noschemehere.html")); + assert get_scheme("noschemehere.html").is_err(); } #[test] fn test_invalid_scheme_errors() { - assert result::is_err(&from_str(~"99://something")); - assert result::is_err(&from_str(~"://something")); + assert from_str("99://something").is_err(); + assert from_str("://something").is_err(); } #[test] fn test_full_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org/doc?s=v#something"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_userless_url_parse_and_format() { let url = ~"http://rust-lang.org/doc?s=v#something"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_queryless_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org/doc#something"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_empty_query_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org/doc?#something"; let should_be = ~"http://user:pass@rust-lang.org/doc#something"; - assert to_str(result::unwrap(from_str(url))) == should_be; + assert from_str(url).unwrap().to_str() == should_be; } #[test] fn test_fragmentless_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org/doc?q=v"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_minimal_url_parse_and_format() { let url = ~"http://rust-lang.org/doc"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_scheme_host_only_url_parse_and_format() { let url = ~"http://rust-lang.org"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_pathless_url_parse_and_format() { let url = ~"http://user:pass@rust-lang.org?q=v#something"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_scheme_host_fragment_only_url_parse_and_format() { let url = ~"http://rust-lang.org#something"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] fn test_url_component_encoding() { let url = ~"http://rust-lang.org/doc%20uments?ba%25d%20=%23%26%2B"; - let u = result::unwrap(from_str(url)); + let u = from_str(url).unwrap(); assert u.path == ~"/doc uments"; - assert u.query.find(|kv| kv.first() == ~"ba%d ") - .get().second() == ~"#&+"; + assert u.query == ~[(~"ba%d ", ~"#&+")]; } #[test] fn test_url_without_authority() { let url = ~"mailto:test@email.com"; - assert to_str(result::unwrap(from_str(url))) == url; + assert from_str(url).unwrap().to_str() == url; } #[test] @@ -998,113 +949,114 @@ mod tests { #[test] fn test_encode_component() { - assert encode_component(~"") == ~""; - assert encode_component(~"http://example.com") == + assert encode_component("") == ~""; + assert encode_component("http://example.com") == ~"http%3A%2F%2Fexample.com"; - assert encode_component(~"foo bar% baz") == ~"foo%20bar%25%20baz"; - assert encode_component(~" ") == ~"%20"; - assert encode_component(~"!") == ~"%21"; - assert encode_component(~"#") == ~"%23"; - assert encode_component(~"$") == ~"%24"; - assert encode_component(~"%") == ~"%25"; - assert encode_component(~"&") == ~"%26"; - assert encode_component(~"'") == ~"%27"; - assert encode_component(~"(") == ~"%28"; - assert encode_component(~")") == ~"%29"; - assert encode_component(~"*") == ~"%2A"; - assert encode_component(~"+") == ~"%2B"; - assert encode_component(~",") == ~"%2C"; - assert encode_component(~"/") == ~"%2F"; - assert encode_component(~":") == ~"%3A"; - assert encode_component(~";") == ~"%3B"; - assert encode_component(~"=") == ~"%3D"; - assert encode_component(~"?") == ~"%3F"; - assert encode_component(~"@") == ~"%40"; - assert encode_component(~"[") == ~"%5B"; - assert encode_component(~"]") == ~"%5D"; + assert encode_component("foo bar% baz") == ~"foo%20bar%25%20baz"; + assert encode_component(" ") == ~"%20"; + assert encode_component("!") == ~"%21"; + assert encode_component("#") == ~"%23"; + assert encode_component("$") == ~"%24"; + assert encode_component("%") == ~"%25"; + assert encode_component("&") == ~"%26"; + assert encode_component("'") == ~"%27"; + assert encode_component("(") == ~"%28"; + assert encode_component(")") == ~"%29"; + assert encode_component("*") == ~"%2A"; + assert encode_component("+") == ~"%2B"; + assert encode_component(",") == ~"%2C"; + assert encode_component("/") == ~"%2F"; + assert encode_component(":") == ~"%3A"; + assert encode_component(";") == ~"%3B"; + assert encode_component("=") == ~"%3D"; + assert encode_component("?") == ~"%3F"; + assert encode_component("@") == ~"%40"; + assert encode_component("[") == ~"%5B"; + assert encode_component("]") == ~"%5D"; } #[test] fn test_decode() { - assert decode(~"") == ~""; - assert decode(~"abc/def 123") == ~"abc/def 123"; - assert decode(~"abc%2Fdef%20123") == ~"abc%2Fdef 123"; - assert decode(~"%20") == ~" "; - assert decode(~"%21") == ~"%21"; - assert decode(~"%22") == ~"%22"; - assert decode(~"%23") == ~"%23"; - assert decode(~"%24") == ~"%24"; - assert decode(~"%25") == ~"%"; - assert decode(~"%26") == ~"%26"; - assert decode(~"%27") == ~"'"; - assert decode(~"%28") == ~"%28"; - assert decode(~"%29") == ~"%29"; - assert decode(~"%2A") == ~"%2A"; - assert decode(~"%2B") == ~"%2B"; - assert decode(~"%2C") == ~"%2C"; - assert decode(~"%2F") == ~"%2F"; - assert decode(~"%3A") == ~"%3A"; - assert decode(~"%3B") == ~"%3B"; - assert decode(~"%3D") == ~"%3D"; - assert decode(~"%3F") == ~"%3F"; - assert decode(~"%40") == ~"%40"; - assert decode(~"%5B") == ~"%5B"; - assert decode(~"%5D") == ~"%5D"; + assert decode("") == ~""; + assert decode("abc/def 123") == ~"abc/def 123"; + assert decode("abc%2Fdef%20123") == ~"abc%2Fdef 123"; + assert decode("%20") == ~" "; + assert decode("%21") == ~"%21"; + assert decode("%22") == ~"%22"; + assert decode("%23") == ~"%23"; + assert decode("%24") == ~"%24"; + assert decode("%25") == ~"%"; + assert decode("%26") == ~"%26"; + assert decode("%27") == ~"'"; + assert decode("%28") == ~"%28"; + assert decode("%29") == ~"%29"; + assert decode("%2A") == ~"%2A"; + assert decode("%2B") == ~"%2B"; + assert decode("%2C") == ~"%2C"; + assert decode("%2F") == ~"%2F"; + assert decode("%3A") == ~"%3A"; + assert decode("%3B") == ~"%3B"; + assert decode("%3D") == ~"%3D"; + assert decode("%3F") == ~"%3F"; + assert decode("%40") == ~"%40"; + assert decode("%5B") == ~"%5B"; + assert decode("%5D") == ~"%5D"; } #[test] fn test_decode_component() { - assert decode_component(~"") == ~""; - assert decode_component(~"abc/def 123") == ~"abc/def 123"; - assert decode_component(~"abc%2Fdef%20123") == ~"abc/def 123"; - assert decode_component(~"%20") == ~" "; - assert decode_component(~"%21") == ~"!"; - assert decode_component(~"%22") == ~"\""; - assert decode_component(~"%23") == ~"#"; - assert decode_component(~"%24") == ~"$"; - assert decode_component(~"%25") == ~"%"; - assert decode_component(~"%26") == ~"&"; - assert decode_component(~"%27") == ~"'"; - assert decode_component(~"%28") == ~"("; - assert decode_component(~"%29") == ~")"; - assert decode_component(~"%2A") == ~"*"; - assert decode_component(~"%2B") == ~"+"; - assert decode_component(~"%2C") == ~","; - assert decode_component(~"%2F") == ~"/"; - assert decode_component(~"%3A") == ~":"; - assert decode_component(~"%3B") == ~";"; - assert decode_component(~"%3D") == ~"="; - assert decode_component(~"%3F") == ~"?"; - assert decode_component(~"%40") == ~"@"; - assert decode_component(~"%5B") == ~"["; - assert decode_component(~"%5D") == ~"]"; + assert decode_component("") == ~""; + assert decode_component("abc/def 123") == ~"abc/def 123"; + assert decode_component("abc%2Fdef%20123") == ~"abc/def 123"; + assert decode_component("%20") == ~" "; + assert decode_component("%21") == ~"!"; + assert decode_component("%22") == ~"\""; + assert decode_component("%23") == ~"#"; + assert decode_component("%24") == ~"$"; + assert decode_component("%25") == ~"%"; + assert decode_component("%26") == ~"&"; + assert decode_component("%27") == ~"'"; + assert decode_component("%28") == ~"("; + assert decode_component("%29") == ~")"; + assert decode_component("%2A") == ~"*"; + assert decode_component("%2B") == ~"+"; + assert decode_component("%2C") == ~","; + assert decode_component("%2F") == ~"/"; + assert decode_component("%3A") == ~":"; + assert decode_component("%3B") == ~";"; + assert decode_component("%3D") == ~"="; + assert decode_component("%3F") == ~"?"; + assert decode_component("%40") == ~"@"; + assert decode_component("%5B") == ~"["; + assert decode_component("%5D") == ~"]"; } #[test] fn test_encode_form_urlencoded() { - let m = HashMap(); - assert encode_form_urlencoded(m) == ~""; + let mut m = LinearMap(); + assert encode_form_urlencoded(&m) == ~""; - m.insert(~"", @DVec()); - m.insert(~"foo", @DVec()); - assert encode_form_urlencoded(m) == ~""; + m.insert(~"", ~[]); + m.insert(~"foo", ~[]); + assert encode_form_urlencoded(&m) == ~""; - let m = HashMap(); - m.insert(~"foo", @dvec::from_vec(~[@~"bar", @~"123"])); - assert encode_form_urlencoded(m) == ~"foo=bar&foo=123"; + let mut m = LinearMap(); + m.insert(~"foo", ~[~"bar", ~"123"]); + assert encode_form_urlencoded(&m) == ~"foo=bar&foo=123"; - let m = HashMap(); - m.insert(~"foo bar", @dvec::from_vec(~[@~"abc", @~"12 = 34"])); - assert encode_form_urlencoded(m) == ~"foo+bar=abc&foo+bar=12+%3D+34"; + let mut m = LinearMap(); + m.insert(~"foo bar", ~[~"abc", ~"12 = 34"]); + assert encode_form_urlencoded(&m) == ~"foo+bar=abc&foo+bar=12+%3D+34"; } #[test] fn test_decode_form_urlencoded() { - assert decode_form_urlencoded(~[]).size() == 0; + assert decode_form_urlencoded(~[]).len() == 0; - let s = str::to_bytes(~"a=1&foo+bar=abc&foo+bar=12+%3D+34"); - assert decode_form_urlencoded(s).size() == 2; + let s = str::to_bytes("a=1&foo+bar=abc&foo+bar=12+%3D+34"); + let form = decode_form_urlencoded(s); + assert form.len() == 2; + assert form.get_ref(&~"a") == &~[~"1"]; + assert form.get_ref(&~"foo bar") == &~[~"abc", ~"12 = 34"]; } - } - From 329316ce1501e6bd0fb6dc3c82f3c2a0572c4011 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 21 Dec 2012 15:35:15 -0800 Subject: [PATCH 06/21] bump 0.5 => 0.6, redirect some URLs in docs. --- Makefile.in | 2 +- README.md | 8 ++++---- doc/tutorial.md | 6 +++--- src/compiletest/compiletest.rc | 4 ++-- src/driver/driver.rs | 12 ++++++------ src/libcargo/cargo.rc | 10 +++++----- src/libcore/core.rc | 6 +++--- src/libcore/float.rs | 6 +++--- src/libfuzzer/fuzzer.rc | 8 ++++---- src/librustc/rustc.rc | 8 ++++---- src/librustdoc/rustdoc.rc | 10 +++++----- src/librusti/rusti.rc | 10 +++++----- src/libstd/std.rc | 4 ++-- src/libsyntax/syntax.rc | 6 +++--- src/test/run-pass/use.rs | 2 +- 15 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Makefile.in b/Makefile.in index 9ed69c69e46c..963f455fe8ab 100644 --- a/Makefile.in +++ b/Makefile.in @@ -154,7 +154,7 @@ LIBRUSTI_DSYM_GLOB :=$(call CFG_LIB_DSYM_GLOB,rusti) # version-string calculation CFG_GIT_DIR := $(CFG_SRC_DIR).git -CFG_RELEASE = 0.5 +CFG_RELEASE = 0.6 CFG_VERSION = $(CFG_RELEASE) ifneq ($(wildcard $(CFG_GIT)),) diff --git a/README.md b/README.md index 1c0a86b1fdfb..9f4ee0a44ff9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ packages: Assuming you're on a relatively modern *nix system and have met the prerequisites, something along these lines should work. - $ wget http://dl.rust-lang.org/dist/rust-0.5.tar.gz + $ wget http://static.rust-lang.org/dist/rust-0.5.tar.gz $ tar -xzf rust-0.5.tar.gz $ cd rust-0.5 $ ./configure @@ -59,8 +59,8 @@ When complete, `make install` will place several programs into API-documentation tool, and `cargo`, the Rust package manager. [wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust -[tarball]: http://dl.rust-lang.org/dist/rust-0.5.tar.gz -[win-exe]: http://dl.rust-lang.org/dist/rust-0.5-install.exe +[tarball]: http://static.rust-lang.org/dist/rust-0.5.tar.gz +[win-exe]: http://static.rust-lang.org/dist/rust-0.5-install.exe ## License @@ -74,4 +74,4 @@ See LICENSE.txt for details. The [tutorial] is a good starting point. -[tutorial]: http://dl.rust-lang.org/doc/tutorial.html +[tutorial]: http://static.rust-lang.org/doc/tutorial.html diff --git a/doc/tutorial.md b/doc/tutorial.md index 3a90b0baacd7..a9f532c3892a 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -99,7 +99,7 @@ If you've fulfilled those prerequisites, something along these lines should work. ~~~~ {.notrust} -$ curl -O http://dl.rust-lang.org/dist/rust-0.5.tar.gz +$ curl -O http://static.rust-lang.org/dist/rust-0.5.tar.gz $ tar -xzf rust-0.5.tar.gz $ cd rust-0.5 $ ./configure @@ -118,8 +118,8 @@ API-documentation tool, `cargo`, the Rust package manager, and `rusti`, the Rust REPL. [wiki-start]: https://github.com/mozilla/rust/wiki/Note-getting-started-developing-Rust -[tarball]: http://dl.rust-lang.org/dist/rust-0.5.tar.gz -[win-exe]: http://dl.rust-lang.org/dist/rust-0.5-install.exe +[tarball]: http://static.rust-lang.org/dist/rust-0.5.tar.gz +[win-exe]: http://static.rust-lang.org/dist/rust-0.5-install.exe ## Compiling your first program diff --git a/src/compiletest/compiletest.rc b/src/compiletest/compiletest.rc index ceceeee9d7ad..8505e4816386 100644 --- a/src/compiletest/compiletest.rc +++ b/src/compiletest/compiletest.rc @@ -18,8 +18,8 @@ #[allow(deprecated_mode)]; #[allow(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); use core::*; diff --git a/src/driver/driver.rs b/src/driver/driver.rs index e96ff9662ebf..5801c23f8146 100644 --- a/src/driver/driver.rs +++ b/src/driver/driver.rs @@ -9,21 +9,21 @@ // except according to those terms. #[no_core]; -extern mod core(vers = "0.5"); +extern mod core(vers = "0.6"); #[cfg(cargo)] -extern mod self(name = "cargo", vers = "0.5"); +extern mod self(name = "cargo", vers = "0.6"); #[cfg(fuzzer)] -extern mod self(name = "fuzzer", vers = "0.5"); +extern mod self(name = "fuzzer", vers = "0.6"); #[cfg(rustdoc)] -extern mod self(name = "rustdoc", vers = "0.5"); +extern mod self(name = "rustdoc", vers = "0.6"); #[cfg(rusti)] -extern mod self(name = "rusti", vers = "0.5"); +extern mod self(name = "rusti", vers = "0.6"); #[cfg(rustc)] -extern mod self(name = "rustc", vers = "0.5"); +extern mod self(name = "rustc", vers = "0.6"); fn main() { self::main() } \ No newline at end of file diff --git a/src/libcargo/cargo.rc b/src/libcargo/cargo.rc index 4fc8ddd9cdb1..d4e68746fd4c 100644 --- a/src/libcargo/cargo.rc +++ b/src/libcargo/cargo.rc @@ -20,7 +20,7 @@ // End: #[link(name = "cargo", - vers = "0.5", + vers = "0.6", uuid = "9ff87a04-8fed-4295-9ff8-f99bb802650b", url = "https://github.com/mozilla/rust/tree/master/src/cargo")]; @@ -37,10 +37,10 @@ #[allow(deprecated_mode)]; #[allow(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); -extern mod rustc(vers = "0.5"); -extern mod syntax(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); +extern mod rustc(vers = "0.6"); +extern mod syntax(vers = "0.6"); #[legacy_exports] mod pgp; diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 72a0ddb21f9b..bac6bae90a0a 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -36,7 +36,7 @@ Implicitly, all crates behave as if they included the following prologue: #[link(name = "core", - vers = "0.5", + vers = "0.6", uuid = "c70c24a7-5551-4f73-8e37-380b11d80be8", url = "https://github.com/mozilla/rust/tree/master/src/libcore")]; @@ -103,7 +103,7 @@ pub mod owned; #[cfg(notest)] pub mod cmp; // Make core testable by not duplicating lang items. See #2912 -#[cfg(test)] extern mod realcore(name = "core", vers = "0.5"); +#[cfg(test)] extern mod realcore(name = "core", vers = "0.6"); #[cfg(test)] pub use kinds = realcore::kinds; #[cfg(test)] pub use ops = realcore::ops; #[cfg(test)] pub use cmp = realcore::cmp; @@ -249,7 +249,7 @@ mod core { // Similar to above. Some magic to make core testable. #[cfg(test)] mod std { - extern mod std(vers = "0.5"); + extern mod std(vers = "0.6"); pub use std::std::test; } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index 27184a397087..8450251c6184 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -466,9 +466,9 @@ pub fn test_from_str() { assert from_str(~".e-1") == Some(0.); assert from_str(~"5.") == Some(5.); assert from_str(~".5") == Some(0.5); - assert from_str(~"0.5") == Some(0.5); - assert from_str(~"0.5") == Some(0.5); - assert from_str(~"0.5") == Some(0.5); + assert from_str(~"0.6") == Some(0.5); + assert from_str(~"0.6") == Some(0.5); + assert from_str(~"0.6") == Some(0.5); assert from_str(~"-.5") == Some(-0.5); assert from_str(~"-.5") == Some(-0.5); assert from_str(~"-5") == Some(-5.); diff --git a/src/libfuzzer/fuzzer.rc b/src/libfuzzer/fuzzer.rc index 66ef622fcd87..cf242ddd8e21 100644 --- a/src/libfuzzer/fuzzer.rc +++ b/src/libfuzzer/fuzzer.rc @@ -11,7 +11,7 @@ #[link(name = "fuzzer", - vers = "0.5", + vers = "0.6", uuid = "d6418797-2736-4833-bd82-d3c684b7c1b0", url = "https://github.com/mozilla/rust/tree/master/src/libfuzzer")]; @@ -28,9 +28,9 @@ #[allow(deprecated_mode)]; #[allow(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); -extern mod syntax(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); +extern mod syntax(vers = "0.6"); use core::*; diff --git a/src/librustc/rustc.rc b/src/librustc/rustc.rc index 85d440ebff9c..9331693bf0a5 100644 --- a/src/librustc/rustc.rc +++ b/src/librustc/rustc.rc @@ -11,7 +11,7 @@ #[link(name = "rustc", - vers = "0.5", + vers = "0.6", uuid = "0ce89b41-2f92-459e-bbc1-8f5fe32f16cf", url = "https://github.com/mozilla/rust/tree/master/src/rustc")]; @@ -29,9 +29,9 @@ #[allow(deprecated_mode)]; #[warn(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); -extern mod syntax(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); +extern mod syntax(vers = "0.6"); use core::*; diff --git a/src/librustdoc/rustdoc.rc b/src/librustdoc/rustdoc.rc index a2e0dc91b3f9..77ed564aab47 100644 --- a/src/librustdoc/rustdoc.rc +++ b/src/librustdoc/rustdoc.rc @@ -11,7 +11,7 @@ //! Rustdoc - The Rust documentation generator #[link(name = "rustdoc", - vers = "0.5", + vers = "0.6", uuid = "f8abd014-b281-484d-a0c3-26e3de8e2412", url = "https://github.com/mozilla/rust/tree/master/src/rustdoc")]; @@ -27,10 +27,10 @@ #[allow(deprecated_mode)]; #[allow(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); -extern mod rustc(vers = "0.5"); -extern mod syntax(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); +extern mod rustc(vers = "0.6"); +extern mod syntax(vers = "0.6"); use core::*; use std::par; diff --git a/src/librusti/rusti.rc b/src/librusti/rusti.rc index 80eedbb3bc44..8afb8d3f8513 100644 --- a/src/librusti/rusti.rc +++ b/src/librusti/rusti.rc @@ -11,7 +11,7 @@ // rusti - REPL using the JIT backend #[link(name = "rusti", - vers = "0.5", + vers = "0.6", uuid = "7fb5bf52-7d45-4fee-8325-5ad3311149fc", url = "https://github.com/mozilla/rust/tree/master/src/rusti")]; @@ -22,10 +22,10 @@ #[allow(vecs_implicitly_copyable, non_implicitly_copyable_typarams)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); -extern mod rustc(vers = "0.5"); -extern mod syntax(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); +extern mod rustc(vers = "0.6"); +extern mod syntax(vers = "0.6"); use core::*; use core::io::{ReaderUtil, WriterUtil}; diff --git a/src/libstd/std.rc b/src/libstd/std.rc index eb3a74108280..f3781c386761 100644 --- a/src/libstd/std.rc +++ b/src/libstd/std.rc @@ -18,7 +18,7 @@ not required in or otherwise suitable for the core library. */ #[link(name = "std", - vers = "0.5", + vers = "0.6", uuid = "122bed0b-c19b-4b82-b0b7-7ae8aead7297", url = "https://github.com/mozilla/rust/tree/master/src/libstd")]; @@ -35,7 +35,7 @@ not required in or otherwise suitable for the core library. #[allow(deprecated_mode)]; #[forbid(deprecated_pattern)]; -extern mod core(vers = "0.5"); +extern mod core(vers = "0.6"); use core::*; // General io and system-services modules diff --git a/src/libsyntax/syntax.rc b/src/libsyntax/syntax.rc index 522e46422d62..687504b873e3 100644 --- a/src/libsyntax/syntax.rc +++ b/src/libsyntax/syntax.rc @@ -9,7 +9,7 @@ // except according to those terms. #[link(name = "syntax", - vers = "0.5", + vers = "0.6", uuid = "9311401b-d6ea-4cd9-a1d9-61f89499c645")]; @@ -26,8 +26,8 @@ #[allow(deprecated_mode)]; #[warn(deprecated_pattern)]; -extern mod core(vers = "0.5"); -extern mod std(vers = "0.5"); +extern mod core(vers = "0.6"); +extern mod std(vers = "0.6"); use core::*; diff --git a/src/test/run-pass/use.rs b/src/test/run-pass/use.rs index d58c168e7cd3..0afac13303d8 100644 --- a/src/test/run-pass/use.rs +++ b/src/test/run-pass/use.rs @@ -13,7 +13,7 @@ #[no_core]; extern mod core; extern mod zed(name = "core"); -extern mod bar(name = "core", vers = "0.5"); +extern mod bar(name = "core", vers = "0.6"); use core::str; From b8fe575e79d9bfa7f15321949f3b8202d6213bb7 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Fri, 21 Dec 2012 21:31:18 -0500 Subject: [PATCH 07/21] update after/syntax/rust.vim for removal of <- --- src/etc/vim/after/syntax/rust.vim | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/etc/vim/after/syntax/rust.vim b/src/etc/vim/after/syntax/rust.vim index c624e4c7befb..58a623cb4e47 100644 --- a/src/etc/vim/after/syntax/rust.vim +++ b/src/etc/vim/after/syntax/rust.vim @@ -7,10 +7,6 @@ if exists('g:rust_conceal_mod_path') syn match rustNiceOperator "::" conceal cchar=ㆍ endif -syn match rustLeftArrowHead contained "-" conceal cchar=  -syn match rustLeftArrowTail contained "<" conceal cchar=⟵ -syn match rustNiceOperator "<-" contains=rustLeftArrowHead,rustLeftArrowTail - syn match rustRightArrowHead contained ">" conceal cchar=  syn match rustRightArrowTail contained "-" conceal cchar=⟶ syn match rustNiceOperator "->" contains=rustRightArrowHead,rustRightArrowTail From d722217a683b29be460cd51d7c9ab5af9bf57791 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sat, 22 Dec 2012 14:57:54 -0800 Subject: [PATCH 08/21] tests: Add test case. Closes #3250 --- src/test/run-pass/issue-3250.rs | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/test/run-pass/issue-3250.rs diff --git a/src/test/run-pass/issue-3250.rs b/src/test/run-pass/issue-3250.rs new file mode 100644 index 000000000000..086f94b2f62e --- /dev/null +++ b/src/test/run-pass/issue-3250.rs @@ -0,0 +1,7 @@ +#[auto_serialize] + +type t = (uint, uint); + + + +fn main() { } From 8d438747a5121159a1f2bbe10a90f57908f12c2a Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sat, 22 Dec 2012 15:07:37 -0800 Subject: [PATCH 09/21] Remove xfail-fast from trait-composition-trivial --- src/test/run-pass/trait-composition-trivial.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/run-pass/trait-composition-trivial.rs b/src/test/run-pass/trait-composition-trivial.rs index 36c66fb5cbf7..bd4b1a9f4de3 100644 --- a/src/test/run-pass/trait-composition-trivial.rs +++ b/src/test/run-pass/trait-composition-trivial.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// xfail-fast - ICE trait Foo { fn foo(); } From d30224a3d477752bf3ff9cfd889e8210a7066f62 Mon Sep 17 00:00:00 2001 From: Ted Horst Date: Thu, 20 Dec 2012 11:35:12 -0600 Subject: [PATCH 10/21] update mandelbrot to pipes, a few other updates --- src/test/bench/shootout-mandelbrot.rs | 33 +++++++++------------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index a45138d72d95..b6c1baac4125 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -12,18 +12,14 @@ // http://shootout.alioth.debian.org/ // u64q/program.php?test=mandelbrot&lang=python3&id=2 // -// takes 3 optional args: +// takes 2 optional args: // square image size, defaults to 80_u -// yield frequency, defaults to 10_u (yield every 10 spawns) // output path, default is "" (no output), "-" means stdout // // in the shootout, they use 16000 as image size -// yield frequency doesn't seem to have much effect // // writes pbm image to output path -#[legacy_modes]; - extern mod std; use io::WriterUtil; use std::map::HashMap; @@ -51,7 +47,7 @@ impl cmplx : ops::Add { } } -type line = {i: uint, b: ~[u8]}; +struct Line {i: uint, b: ~[u8]} pure fn cabs(x: cmplx) -> f64 { @@ -87,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 { rv } -fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () +fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () { let mut crv = ~[]; let incr = 2f64/(size as f64); @@ -97,22 +93,22 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y}; crv.push(fillbyte(x, incr)); }; - oldcomm::send(ch, {i:i, b:crv}); + oldcomm::send(ch, Line {i:i, b: move crv}); } type devnull = {dn: int}; impl devnull: io::Writer { fn write(_b: &[const u8]) {} - fn seek(+_i: int, +_s: io::SeekStyle) {} + fn seek(_i: int, _s: io::SeekStyle) {} fn tell() -> uint {0_u} fn flush() -> int {0} fn get_type() -> io::WriterType { io::File } } -fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) +fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) { - let p: oldcomm::Port = oldcomm::Port(); + let p: oldcomm::Port = oldcomm::Port(); let ch = oldcomm::Chan(&p); oldcomm::send(writech, ch); let cout: io::Writer = match path { @@ -164,16 +160,13 @@ fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) fn main() { let args = os::args(); let args = if os::getenv(~"RUST_BENCH").is_some() { - ~[~"", ~"4000", ~"10"] + ~[~"", ~"4000"] } else { args }; - let path = if vec::len(args) < 4_u { ~"" } - else { copy args[3] }; // FIXME: bad for perf - - let yieldevery = if vec::len(args) < 3_u { 10_u } - else { uint::from_str(args[2]).get() }; + let path = if vec::len(args) < 3_u { ~"" } + else { copy args[2] }; // FIXME: bad for perf let size = if vec::len(args) < 2_u { 80_u } else { uint::from_str(args[1]).get() }; @@ -185,10 +178,6 @@ fn main() { }; let ch = oldcomm::recv(writep); for uint::range(0_u, size) |j| { - task::spawn(|| chanmb(j, size, ch) ); - if j % yieldevery == 0_u { - debug!("Y %u", j); - task::yield(); - }; + do task::spawn { chanmb(j, size, ch) }; }; } From 40a3e20bbbb5e4f61758cbe9668a7a968bb44e61 Mon Sep 17 00:00:00 2001 From: "Eric J. Holmes" Date: Sat, 22 Dec 2012 23:58:27 -0800 Subject: [PATCH 11/21] Fix example. --- doc/tutorial-ffi.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index 895aaf224364..8324f752c1d3 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -22,7 +22,7 @@ extern mod crypto { fn as_hex(data: ~[u8]) -> ~str { let mut acc = ~""; - for data.each |byte| { acc += fmt!("%02x", byte as uint); } + for data.each |&byte| { acc += fmt!("%02x", byte as uint); } return acc; } @@ -33,8 +33,8 @@ fn sha1(data: ~str) -> ~str unsafe { return as_hex(vec::from_buf(hash, 20)); } -fn main(args: ~[~str]) { - io::println(sha1(args[1])); +fn main() { + io::println(sha1(core::os::args()[1])); } ~~~~ From 8223a1278db4da579d162b2160d46280960930d0 Mon Sep 17 00:00:00 2001 From: "Eric J. Holmes" Date: Sat, 22 Dec 2012 23:51:49 -0800 Subject: [PATCH 12/21] Fix example. --- doc/tutorial.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index a9f532c3892a..1add1054cc55 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2419,10 +2419,10 @@ these two files: pub fn explore() -> &str { "world" } ~~~~ -~~~~ {.xfail-test} +~~~~ // main.rs extern mod world; -fn main() { io::println("hello " + world::explore()); } +fn main() { io::println(~"hello " + world::explore()); } ~~~~ Now compile and run like this (adjust to your platform if necessary): From e44fb67c8793bd5627080955885a4b1c73994afc Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sun, 23 Dec 2012 13:33:50 -0800 Subject: [PATCH 13/21] Add Eric Holmes to AUTHORS --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 645d6be9babe..5901e857572b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -44,6 +44,7 @@ Drew Willcoxon Elliott Slaughter Elly Fong-Jones Eric Holk +Eric Holmes Erick Tryzelaar Erik Rose Evan McClanahan From 5e73b0972b3cf1416b36448475075e3e9421df09 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sun, 23 Dec 2012 13:38:13 -0800 Subject: [PATCH 14/21] Add Martin DeMello to AUTHORS --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index 5901e857572b..f049de1047c8 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -90,6 +90,7 @@ Magnus Auvinen Mahmut Bulut Margaret Meyerhofer Marijn Haverbeke +Martin DeMello Matt Brubeck Matthew O'Connor Max Penet From 889df548865c87bb79be595a7130f21b13f220a3 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Sun, 23 Dec 2012 13:50:58 -0800 Subject: [PATCH 15/21] Add Jens Nockert to AUTHORS --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index f049de1047c8..9117d5b3a01b 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -69,6 +69,7 @@ Jeff Balogh Jeff Muizelaar Jeff Olson Jeffrey Yasskin +Jens Nockert Jesse Ruderman Jim Blandy Jimmy Lu From c1e58aad70f01667145bfefd2c3eebe834156dc1 Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 23 Dec 2012 14:37:44 -0800 Subject: [PATCH 16/21] core: Mark some functions as pure --- src/libcore/dvec.rs | 6 +++--- src/libcore/float.rs | 4 ++-- src/libcore/int-template/int.rs | 4 ++-- src/libcore/ptr.rs | 4 ++-- src/libcore/rand.rs | 4 ++-- src/libcore/str.rs | 6 ++---- src/libcore/uint-template/uint.rs | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index b02a6f5c8b53..236d6bce9f03 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -67,17 +67,17 @@ pub pure fn DVec() -> DVec { } /// Creates a new dvec with a single element -pub fn from_elem(e: A) -> DVec { +pub pure fn from_elem(e: A) -> DVec { DVec {mut data: ~[move e]} } /// Creates a new dvec with the contents of a vector -pub fn from_vec(v: ~[A]) -> DVec { +pub pure fn from_vec(v: ~[A]) -> DVec { DVec {mut data: move v} } /// Consumes the vector and returns its contents -pub fn unwrap(d: DVec) -> ~[A] { +pub pure fn unwrap(d: DVec) -> ~[A] { let DVec {data: v} = move d; move v } diff --git a/src/libcore/float.rs b/src/libcore/float.rs index 8450251c6184..d7d68582aefd 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -188,7 +188,7 @@ pub pure fn to_str_common(num: float, digits: uint, exact: bool) -> ~str { * * num - The float value * * digits - The number of significant digits */ -pub fn to_str_exact(num: float, digits: uint) -> ~str { +pub pure fn to_str_exact(num: float, digits: uint) -> ~str { to_str_common(num, digits, true) } @@ -238,7 +238,7 @@ pub pure fn to_str(num: float, digits: uint) -> ~str { * `none` if the string did not represent a valid number. Otherwise, * `Some(n)` where `n` is the floating-point number represented by `[num]`. */ -pub fn from_str(num: &str) -> Option { +pub pure fn from_str(num: &str) -> Option { if num == "inf" { return Some(infinity as float); } else if num == "-inf" { diff --git a/src/libcore/int-template/int.rs b/src/libcore/int-template/int.rs index c281185c75e2..61a7c3bd07ab 100644 --- a/src/libcore/int-template/int.rs +++ b/src/libcore/int-template/int.rs @@ -17,12 +17,12 @@ mod inst { pub const bits: uint = uint::bits; /// Returns `base` raised to the power of `exponent` - pub fn pow(base: int, exponent: uint) -> int { + pub pure fn pow(base: int, exponent: uint) -> int { if exponent == 0u { //Not mathemtically true if ~[base == 0] return 1; } - if base == 0 { return 0; } + if base == 0 { return 0; } let mut my_pow = exponent; let mut acc = 1; let mut multiplier = base; diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 0e83157c82d6..c838af700f65 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -170,13 +170,13 @@ pub pure fn to_mut_unsafe_ptr(thing: &mut T) -> *mut T { (I couldn't think of a cutesy name for this one.) */ #[inline(always)] -pub fn to_uint(thing: &T) -> uint unsafe { +pub pure fn to_uint(thing: &T) -> uint unsafe { cast::reinterpret_cast(&thing) } /// Determine if two borrowed pointers point to the same thing. #[inline(always)] -pub fn ref_eq(thing: &a/T, other: &b/T) -> bool { +pub pure fn ref_eq(thing: &a/T, other: &b/T) -> bool { to_uint(thing) == to_uint(other) } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index 96caf062d27a..8ee857ef927d 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -309,12 +309,12 @@ impl XorShiftState: Rng { } } -pub fn xorshift() -> Rng { +pub pure fn xorshift() -> Rng { // constants taken from http://en.wikipedia.org/wiki/Xorshift seeded_xorshift(123456789u32, 362436069u32, 521288629u32, 88675123u32) } -pub fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng { +pub pure fn seeded_xorshift(x: u32, y: u32, z: u32, w: u32) -> Rng { {mut x: x, mut y: y, mut z: z, mut w: w} as Rng } diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1154a86f96ca..e68966945caa 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -214,7 +214,7 @@ pub pure fn connect(v: &[~str], sep: &str) -> ~str { } /// Given a string, make a new string with repeated copies of it -pub fn repeat(ss: &str, nn: uint) -> ~str { +pub pure fn repeat(ss: &str, nn: uint) -> ~str { let mut acc = ~""; for nn.times { acc += ss; } acc @@ -1684,9 +1684,7 @@ pub struct CharRange { * * This function can be used to iterate over a unicode string in reverse. */ -pure fn char_range_at_reverse(ss: &str, start: uint) - -> CharRange { - +pure fn char_range_at_reverse(ss: &str, start: uint) -> CharRange { let mut prev = start; // while there is a previous byte == 10...... diff --git a/src/libcore/uint-template/uint.rs b/src/libcore/uint-template/uint.rs index bd7f8c09f479..b2ae1aa921b7 100644 --- a/src/libcore/uint-template/uint.rs +++ b/src/libcore/uint-template/uint.rs @@ -104,7 +104,7 @@ mod inst { /// Returns the smallest power of 2 greater than or equal to `n` #[inline(always)] - pub fn next_power_of_two(n: uint) -> uint { + pub pure fn next_power_of_two(n: uint) -> uint { let halfbits: uint = sys::size_of::() * 4u; let mut tmp: uint = n - 1u; let mut shift: uint = 1u; From 8060bd846af76798bf8585b20485cc66fbb865bc Mon Sep 17 00:00:00 2001 From: Chris Peterson Date: Sun, 23 Dec 2012 14:38:01 -0800 Subject: [PATCH 17/21] std: Mark some functions as pure --- src/libstd/arena.rs | 2 +- src/libstd/c_vec.rs | 2 +- src/libstd/list.rs | 12 ++++++------ src/libstd/rope.rs | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/libstd/arena.rs b/src/libstd/arena.rs index 105e8fb122fe..9054f9355ad8 100644 --- a/src/libstd/arena.rs +++ b/src/libstd/arena.rs @@ -95,7 +95,7 @@ pub fn Arena() -> Arena { } #[inline(always)] -fn round_up_to(base: uint, align: uint) -> uint { +pure fn round_up_to(base: uint, align: uint) -> uint { (base + (align - 1)) & !(align - 1) } diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index cd1fa33a08f7..cc8cadb709d9 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -135,7 +135,7 @@ pub fn set(t: CVec, ofs: uint, v: T) { */ /// Returns the length of the vector -pub fn len(t: CVec) -> uint { +pub pure fn len(t: CVec) -> uint { return (*t).len; } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 6d2c10eb8274..e41aab8ec1ff 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -22,8 +22,8 @@ pub enum List { Nil, } -/// Cregate a list from a vector -pub fn from_vec(v: &[T]) -> @List { +/// Create a list from a vector +pub pure fn from_vec(v: &[T]) -> @List { vec::foldr(v, @Nil::, |h, t| @Cons(*h, t)) } @@ -53,7 +53,7 @@ pub fn foldl(z: T, ls: @List, f: fn(&T, &U) -> T) -> T { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pub fn find(ls: @List, f: fn(&T) -> bool) -> Option { +pub pure fn find(ls: @List, f: fn(&T) -> bool) -> Option { let mut ls = ls; loop { ls = match *ls { @@ -88,7 +88,7 @@ pub pure fn is_not_empty(ls: @List) -> bool { } /// Returns the length of a list -pub fn len(ls: @List) -> uint { +pub pure fn len(ls: @List) -> uint { let mut count = 0u; iter(ls, |_e| count += 1u); count @@ -131,7 +131,7 @@ pure fn push(ll: &mut @list, vv: T) { */ /// Iterate over a list -pub fn iter(l: @List, f: fn(&T)) { +pub pure fn iter(l: @List, f: fn(&T)) { let mut cur = l; loop { cur = match *cur { @@ -145,7 +145,7 @@ pub fn iter(l: @List, f: fn(&T)) { } /// Iterate over a list -pub fn each(l: @List, f: fn(&T) -> bool) { +pub pure fn each(l: @List, f: fn(&T) -> bool) { let mut cur = l; loop { cur = match *cur { diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 473992e68206..aa78d22e4c8d 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -43,7 +43,7 @@ pub type Rope = node::Root; */ /// Create an empty rope -pub fn empty() -> Rope { +pub pure fn empty() -> Rope { return node::Empty; } @@ -479,7 +479,7 @@ pub mod iterator { * * Constant time. */ -pub fn height(rope: Rope) -> uint { +pub pure fn height(rope: Rope) -> uint { match (rope) { node::Empty => return 0u, node::Content(x) => return node::height(x) @@ -1019,7 +1019,7 @@ mod node { }) } - pub fn height(node: @Node) -> uint { + pub pure fn height(node: @Node) -> uint { match (*node) { Leaf(_) => return 0u, Concat(ref x) => return x.height @@ -1100,7 +1100,7 @@ mod node { * proportional to the height of the rope + the (bounded) * length of the largest leaf. */ - pub fn char_at(node: @Node, pos: uint) -> char { + pub pure fn char_at(node: @Node, pos: uint) -> char { let mut node = node; let mut pos = pos; loop { From fddc849d751cb3ed4b866cef5245b00744a8914a Mon Sep 17 00:00:00 2001 From: gareth Date: Mon, 24 Dec 2012 18:52:53 +0000 Subject: [PATCH 18/21] Convert core::io to use explicit self (for issue #4118 and issue #2004) --- src/libcore/hash.rs | 12 +- src/libcore/io.rs | 332 ++++++++++++++++++++-------------------- src/libstd/flatpipes.rs | 10 +- src/libstd/net_tcp.rs | 20 +-- 4 files changed, 184 insertions(+), 190 deletions(-) diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index 26f4f0840cdd..5331019e5f33 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -188,11 +188,11 @@ fn SipState(key0: u64, key1: u64) -> SipState { } -impl &SipState : io::Writer { +impl SipState : io::Writer { // Methods for io::writer #[inline(always)] - fn write(msg: &[const u8]) { + fn write(&self, msg: &[const u8]) { macro_rules! u8to64_le ( ($buf:expr, $i:expr) => @@ -282,16 +282,16 @@ impl &SipState : io::Writer { self.ntail = left; } - fn seek(_x: int, _s: io::SeekStyle) { + fn seek(&self, _x: int, _s: io::SeekStyle) { fail; } - fn tell() -> uint { + fn tell(&self) -> uint { self.length } - fn flush() -> int { + fn flush(&self) -> int { 0 } - fn get_type() -> io::WriterType { + fn get_type(&self) -> io::WriterType { io::File } } diff --git a/src/libcore/io.rs b/src/libcore/io.rs index 098e24e03dd1..e76eb9f2f99d 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -49,122 +49,122 @@ pub trait Reader { /// Read up to len bytes (or EOF) and put them into bytes (which /// must be at least len bytes long). Return number of bytes read. // FIXME (#2982): This should probably return an error. - fn read(bytes: &[mut u8], len: uint) -> uint; + fn read(&self, bytes: &[mut u8], len: uint) -> uint; /// Read a single byte, returning a negative value for EOF or read error. - fn read_byte() -> int; + fn read_byte(&self) -> int; /// Return whether the stream is currently at EOF position. - fn eof() -> bool; + fn eof(&self) -> bool; /// Move the current position within the stream. The second parameter /// determines the position that the first parameter is relative to. - fn seek(position: int, style: SeekStyle); + fn seek(&self, position: int, style: SeekStyle); /// Return the current position within the stream. - fn tell() -> uint; + fn tell(&self) -> uint; } /// Generic utility functions defined on readers. pub trait ReaderUtil { /// Read len bytes into a new vec. - fn read_bytes(len: uint) -> ~[u8]; + fn read_bytes(&self, len: uint) -> ~[u8]; /// Read up until the first '\n' char (which is not returned), or EOF. - fn read_line() -> ~str; + fn read_line(&self) -> ~str; /// Read n utf-8 encoded chars. - fn read_chars(n: uint) -> ~[char]; + fn read_chars(&self, n: uint) -> ~[char]; /// Read a single utf-8 encoded char. - fn read_char() -> char; + fn read_char(&self) -> char; /// Read up until the first null byte (which is not returned), or EOF. - fn read_c_str() -> ~str; + fn read_c_str(&self) -> ~str; /// Read all the data remaining in the stream in one go. - fn read_whole_stream() -> ~[u8]; + fn read_whole_stream(&self) -> ~[u8]; /// Iterate over every byte until the iterator breaks or EOF. - fn each_byte(it: fn(int) -> bool); + fn each_byte(&self, it: fn(int) -> bool); /// Iterate over every char until the iterator breaks or EOF. - fn each_char(it: fn(char) -> bool); + fn each_char(&self, it: fn(char) -> bool); /// Iterate over every line until the iterator breaks or EOF. - fn each_line(it: fn(&str) -> bool); + fn each_line(&self, it: fn(&str) -> bool); /// Read n (between 1 and 8) little-endian unsigned integer bytes. - fn read_le_uint_n(nbytes: uint) -> u64; + fn read_le_uint_n(&self, nbytes: uint) -> u64; /// Read n (between 1 and 8) little-endian signed integer bytes. - fn read_le_int_n(nbytes: uint) -> i64; + fn read_le_int_n(&self, nbytes: uint) -> i64; /// Read n (between 1 and 8) big-endian unsigned integer bytes. - fn read_be_uint_n(nbytes: uint) -> u64; + fn read_be_uint_n(&self, nbytes: uint) -> u64; /// Read n (between 1 and 8) big-endian signed integer bytes. - fn read_be_int_n(nbytes: uint) -> i64; + fn read_be_int_n(&self, nbytes: uint) -> i64; /// Read a little-endian uint (number of bytes depends on system). - fn read_le_uint() -> uint; + fn read_le_uint(&self) -> uint; /// Read a little-endian int (number of bytes depends on system). - fn read_le_int() -> int; + fn read_le_int(&self) -> int; /// Read a big-endian uint (number of bytes depends on system). - fn read_be_uint() -> uint; + fn read_be_uint(&self) -> uint; /// Read a big-endian int (number of bytes depends on system). - fn read_be_int() -> int; + fn read_be_int(&self) -> int; /// Read a big-endian u64 (8 bytes). - fn read_be_u64() -> u64; + fn read_be_u64(&self) -> u64; /// Read a big-endian u32 (4 bytes). - fn read_be_u32() -> u32; + fn read_be_u32(&self) -> u32; /// Read a big-endian u16 (2 bytes). - fn read_be_u16() -> u16; + fn read_be_u16(&self) -> u16; /// Read a big-endian i64 (8 bytes). - fn read_be_i64() -> i64; + fn read_be_i64(&self) -> i64; /// Read a big-endian i32 (4 bytes). - fn read_be_i32() -> i32; + fn read_be_i32(&self) -> i32; /// Read a big-endian i16 (2 bytes). - fn read_be_i16() -> i16; + fn read_be_i16(&self) -> i16; /// Read a little-endian u64 (8 bytes). - fn read_le_u64() -> u64; + fn read_le_u64(&self) -> u64; /// Read a little-endian u32 (4 bytes). - fn read_le_u32() -> u32; + fn read_le_u32(&self) -> u32; /// Read a little-endian u16 (2 bytes). - fn read_le_u16() -> u16; + fn read_le_u16(&self) -> u16; /// Read a litle-endian i64 (8 bytes). - fn read_le_i64() -> i64; + fn read_le_i64(&self) -> i64; /// Read a litle-endian i32 (4 bytes). - fn read_le_i32() -> i32; + fn read_le_i32(&self) -> i32; /// Read a litle-endian i16 (2 bytes). - fn read_le_i16() -> i16; + fn read_le_i16(&self) -> i16; /// Read a u8 (1 byte). - fn read_u8() -> u8; + fn read_u8(&self) -> u8; /// Read a i8 (1 byte). - fn read_i8() -> i8; + fn read_i8(&self) -> i8; } impl T : ReaderUtil { - fn read_bytes(len: uint) -> ~[u8] { + fn read_bytes(&self,len: uint) -> ~[u8] { let mut bytes = vec::with_capacity(len); unsafe { vec::raw::set_len(&mut bytes, len); } @@ -174,7 +174,7 @@ impl T : ReaderUtil { move bytes } - fn read_line() -> ~str { + fn read_line(&self) -> ~str { let mut bytes = ~[]; loop { let ch = self.read_byte(); @@ -184,7 +184,7 @@ impl T : ReaderUtil { str::from_bytes(bytes) } - fn read_chars(n: uint) -> ~[char] { + fn read_chars(&self, n: uint) -> ~[char] { // returns the (consumed offset, n_req), appends characters to &chars fn chars_from_bytes(bytes: &~[u8], chars: &mut ~[char]) -> (uint, uint) { @@ -245,7 +245,7 @@ impl T : ReaderUtil { move chars } - fn read_char() -> char { + fn read_char(&self) -> char { let c = self.read_chars(1); if vec::len(c) == 0 { return -1 as char; // FIXME will this stay valid? // #2004 @@ -254,7 +254,7 @@ impl T : ReaderUtil { return c[0]; } - fn read_c_str() -> ~str { + fn read_c_str(&self) -> ~str { let mut bytes: ~[u8] = ~[]; loop { let ch = self.read_byte(); @@ -263,25 +263,25 @@ impl T : ReaderUtil { str::from_bytes(bytes) } - fn read_whole_stream() -> ~[u8] { + fn read_whole_stream(&self) -> ~[u8] { let mut bytes: ~[u8] = ~[]; while !self.eof() { bytes.push_all(self.read_bytes(2048u)); } move bytes } - fn each_byte(it: fn(int) -> bool) { + fn each_byte(&self, it: fn(int) -> bool) { while !self.eof() { if !it(self.read_byte()) { break; } } } - fn each_char(it: fn(char) -> bool) { + fn each_char(&self, it: fn(char) -> bool) { while !self.eof() { if !it(self.read_char()) { break; } } } - fn each_line(it: fn(s: &str) -> bool) { + fn each_line(&self, it: fn(s: &str) -> bool) { while !self.eof() { if !it(self.read_line()) { break; } } @@ -289,7 +289,7 @@ impl T : ReaderUtil { // FIXME int reading methods need to deal with eof - issue #2004 - fn read_le_uint_n(nbytes: uint) -> u64 { + fn read_le_uint_n(&self, nbytes: uint) -> u64 { assert nbytes > 0 && nbytes <= 8; let mut val = 0u64, pos = 0, i = nbytes; @@ -301,11 +301,11 @@ impl T : ReaderUtil { val } - fn read_le_int_n(nbytes: uint) -> i64 { + fn read_le_int_n(&self, nbytes: uint) -> i64 { extend_sign(self.read_le_uint_n(nbytes), nbytes) } - fn read_be_uint_n(nbytes: uint) -> u64 { + fn read_be_uint_n(&self, nbytes: uint) -> u64 { assert nbytes > 0 && nbytes <= 8; let mut val = 0u64, i = nbytes; @@ -316,79 +316,79 @@ impl T : ReaderUtil { val } - fn read_be_int_n(nbytes: uint) -> i64 { + fn read_be_int_n(&self, nbytes: uint) -> i64 { extend_sign(self.read_be_uint_n(nbytes), nbytes) } - fn read_le_uint() -> uint { + fn read_le_uint(&self) -> uint { self.read_le_uint_n(uint::bytes) as uint } - fn read_le_int() -> int { + fn read_le_int(&self) -> int { self.read_le_int_n(int::bytes) as int } - fn read_be_uint() -> uint { + fn read_be_uint(&self) -> uint { self.read_be_uint_n(uint::bytes) as uint } - fn read_be_int() -> int { + fn read_be_int(&self) -> int { self.read_be_int_n(int::bytes) as int } - fn read_be_u64() -> u64 { + fn read_be_u64(&self) -> u64 { self.read_be_uint_n(8) as u64 } - fn read_be_u32() -> u32 { + fn read_be_u32(&self) -> u32 { self.read_be_uint_n(4) as u32 } - fn read_be_u16() -> u16 { + fn read_be_u16(&self) -> u16 { self.read_be_uint_n(2) as u16 } - fn read_be_i64() -> i64 { + fn read_be_i64(&self) -> i64 { self.read_be_int_n(8) as i64 } - fn read_be_i32() -> i32 { + fn read_be_i32(&self) -> i32 { self.read_be_int_n(4) as i32 } - fn read_be_i16() -> i16 { + fn read_be_i16(&self) -> i16 { self.read_be_int_n(2) as i16 } - fn read_le_u64() -> u64 { + fn read_le_u64(&self) -> u64 { self.read_le_uint_n(8) as u64 } - fn read_le_u32() -> u32 { + fn read_le_u32(&self) -> u32 { self.read_le_uint_n(4) as u32 } - fn read_le_u16() -> u16 { + fn read_le_u16(&self) -> u16 { self.read_le_uint_n(2) as u16 } - fn read_le_i64() -> i64 { + fn read_le_i64(&self) -> i64 { self.read_le_int_n(8) as i64 } - fn read_le_i32() -> i32 { + fn read_le_i32(&self) -> i32 { self.read_le_int_n(4) as i32 } - fn read_le_i16() -> i16 { + fn read_le_i16(&self) -> i16 { self.read_le_int_n(2) as i16 } - fn read_u8() -> u8 { + fn read_u8(&self) -> u8 { self.read_byte() as u8 } - fn read_i8() -> i8 { + fn read_i8(&self) -> i8 { self.read_byte() as i8 } } @@ -409,36 +409,38 @@ fn convert_whence(whence: SeekStyle) -> i32 { } impl *libc::FILE: Reader { - fn read(bytes: &[mut u8], len: uint) -> uint { + fn read(&self, bytes: &[mut u8], len: uint) -> uint { do vec::as_mut_buf(bytes) |buf_p, buf_len| { assert buf_len >= len; let count = libc::fread(buf_p as *mut c_void, 1u as size_t, - len as size_t, self); + len as size_t, *self); count as uint } } - fn read_byte() -> int { return libc::fgetc(self) as int; } - fn eof() -> bool { return libc::feof(self) != 0 as c_int; } - fn seek(offset: int, whence: SeekStyle) { - assert libc::fseek(self, offset as c_long, convert_whence(whence)) + fn read_byte(&self) -> int { return libc::fgetc(*self) as int; } + fn eof(&self) -> bool { return libc::feof(*self) != 0 as c_int; } + fn seek(&self, offset: int, whence: SeekStyle) { + assert libc::fseek(*self, offset as c_long, convert_whence(whence)) == 0 as c_int; } - fn tell() -> uint { return libc::ftell(self) as uint; } + fn tell(&self) -> uint { return libc::ftell(*self) as uint; } } // A forwarding impl of reader that also holds on to a resource for the // duration of its lifetime. // FIXME there really should be a better way to do this // #2004 impl {base: T, cleanup: C}: Reader { - fn read(bytes: &[mut u8], len: uint) -> uint { + fn read(&self, bytes: &[mut u8], len: uint) -> uint { self.base.read(bytes, len) } - fn read_byte() -> int { self.base.read_byte() } - fn eof() -> bool { self.base.eof() } - fn seek(off: int, whence: SeekStyle) { self.base.seek(off, whence) } - fn tell() -> uint { self.base.tell() } + fn read_byte(&self) -> int { self.base.read_byte() } + fn eof(&self) -> bool { self.base.eof() } + fn seek(&self, off: int, whence: SeekStyle) { + self.base.seek(off, whence) + } + fn tell(&self) -> uint { self.base.tell() } } struct FILERes { @@ -487,7 +489,7 @@ pub struct BytesReader { } impl BytesReader: Reader { - fn read(bytes: &[mut u8], len: uint) -> uint { + fn read(&self, bytes: &[mut u8], len: uint) -> uint { let count = uint::min(len, self.bytes.len() - self.pos); let view = vec::view(self.bytes, self.pos, self.bytes.len()); @@ -497,18 +499,18 @@ impl BytesReader: Reader { count } - fn read_byte() -> int { + fn read_byte(&self) -> int { if self.pos == self.bytes.len() { return -1; } let b = self.bytes[self.pos]; self.pos += 1u; return b as int; } - fn eof() -> bool { self.pos == self.bytes.len() } - fn seek(offset: int, whence: SeekStyle) { + fn eof(&self) -> bool { self.pos == self.bytes.len() } + fn seek(&self, offset: int, whence: SeekStyle) { let pos = self.pos; self.pos = seek_in_buf(offset, pos, self.bytes.len(), whence); } - fn tell() -> uint { self.pos } + fn tell(&self) -> uint { self.pos } } pub pure fn with_bytes_reader(bytes: &[u8], f: fn(Reader) -> t) -> t { @@ -532,34 +534,34 @@ pub enum WriterType { Screen, File } pub trait Writer { /// Write all of the given bytes. - fn write(v: &[const u8]); + fn write(&self, v: &[const u8]); /// Move the current position within the stream. The second parameter /// determines the position that the first parameter is relative to. - fn seek(int, SeekStyle); + fn seek(&self, int, SeekStyle); /// Return the current position within the stream. - fn tell() -> uint; + fn tell(&self) -> uint; /// Flush the output buffer for this stream (if there is one). - fn flush() -> int; + fn flush(&self) -> int; /// Determine if this Writer is writing to a file or not. - fn get_type() -> WriterType; + fn get_type(&self) -> WriterType; } impl {base: T, cleanup: C}: Writer { - fn write(bs: &[const u8]) { self.base.write(bs); } - fn seek(off: int, style: SeekStyle) { self.base.seek(off, style); } - fn tell() -> uint { self.base.tell() } - fn flush() -> int { self.base.flush() } - fn get_type() -> WriterType { File } + fn write(&self, bs: &[const u8]) { self.base.write(bs); } + fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); } + fn tell(&self) -> uint { self.base.tell() } + fn flush(&self) -> int { self.base.flush() } + fn get_type(&self) -> WriterType { File } } impl *libc::FILE: Writer { - fn write(v: &[const u8]) { + fn write(&self, v: &[const u8]) { do vec::as_const_buf(v) |vbuf, len| { - let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, self); + let nout = libc::fwrite(vbuf as *c_void, 1, len as size_t, *self); if nout != len as size_t { error!("error writing buffer"); log(error, os::last_os_error()); @@ -567,14 +569,14 @@ impl *libc::FILE: Writer { } } } - fn seek(offset: int, whence: SeekStyle) { - assert libc::fseek(self, offset as c_long, convert_whence(whence)) + fn seek(&self, offset: int, whence: SeekStyle) { + assert libc::fseek(*self, offset as c_long, convert_whence(whence)) == 0 as c_int; } - fn tell() -> uint { libc::ftell(self) as uint } - fn flush() -> int { libc::fflush(self) as int } - fn get_type() -> WriterType { - let fd = libc::fileno(self); + fn tell(&self) -> uint { libc::ftell(*self) as uint } + fn flush(&self) -> int { libc::fflush(*self) as int } + fn get_type(&self) -> WriterType { + let fd = libc::fileno(*self); if libc::isatty(fd) == 0 { File } else { Screen } } @@ -589,12 +591,12 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> Writer { } impl fd_t: Writer { - fn write(v: &[const u8]) { + fn write(&self, v: &[const u8]) { let mut count = 0u; do vec::as_const_buf(v) |vbuf, len| { while count < len { let vb = ptr::const_offset(vbuf, count) as *c_void; - let nout = libc::write(self, vb, len as size_t); + let nout = libc::write(*self, vb, len as size_t); if nout < 0 as ssize_t { error!("error writing buffer"); log(error, os::last_os_error()); @@ -604,17 +606,17 @@ impl fd_t: Writer { } } } - fn seek(_offset: int, _whence: SeekStyle) { + fn seek(&self, _offset: int, _whence: SeekStyle) { error!("need 64-bit foreign calls for seek, sorry"); fail; } - fn tell() -> uint { + fn tell(&self) -> uint { error!("need 64-bit foreign calls for tell, sorry"); fail; } - fn flush() -> int { 0 } - fn get_type() -> WriterType { - if libc::isatty(self) == 0 { File } else { Screen } + fn flush(&self) -> int { 0 } + fn get_type(&self) -> WriterType { + if libc::isatty(*self) == 0 { File } else { Screen } } } @@ -752,145 +754,145 @@ pub fn u64_from_be_bytes(data: &[const u8], pub trait WriterUtil { /// Write a single utf-8 encoded char. - fn write_char(ch: char); + fn write_char(&self, ch: char); /// Write every char in the given str, encoded as utf-8. - fn write_str(s: &str); + fn write_str(&self, s: &str); /// Write the given str, as utf-8, followed by '\n'. - fn write_line(s: &str); + fn write_line(&self, s: &str); /// Write the result of passing n through `int::to_str_bytes`. - fn write_int(n: int); + fn write_int(&self, n: int); /// Write the result of passing n through `uint::to_str_bytes`. - fn write_uint(n: uint); + fn write_uint(&self, n: uint); /// Write a little-endian uint (number of bytes depends on system). - fn write_le_uint(n: uint); + fn write_le_uint(&self, n: uint); /// Write a little-endian int (number of bytes depends on system). - fn write_le_int(n: int); + fn write_le_int(&self, n: int); /// Write a big-endian uint (number of bytes depends on system). - fn write_be_uint(n: uint); + fn write_be_uint(&self, n: uint); /// Write a big-endian int (number of bytes depends on system). - fn write_be_int(n: int); + fn write_be_int(&self, n: int); /// Write a big-endian u64 (8 bytes). - fn write_be_u64(n: u64); + fn write_be_u64(&self, n: u64); /// Write a big-endian u32 (4 bytes). - fn write_be_u32(n: u32); + fn write_be_u32(&self, n: u32); /// Write a big-endian u16 (2 bytes). - fn write_be_u16(n: u16); + fn write_be_u16(&self, n: u16); /// Write a big-endian i64 (8 bytes). - fn write_be_i64(n: i64); + fn write_be_i64(&self, n: i64); /// Write a big-endian i32 (4 bytes). - fn write_be_i32(n: i32); + fn write_be_i32(&self, n: i32); /// Write a big-endian i16 (2 bytes). - fn write_be_i16(n: i16); + fn write_be_i16(&self, n: i16); /// Write a little-endian u64 (8 bytes). - fn write_le_u64(n: u64); + fn write_le_u64(&self, n: u64); /// Write a little-endian u32 (4 bytes). - fn write_le_u32(n: u32); + fn write_le_u32(&self, n: u32); /// Write a little-endian u16 (2 bytes). - fn write_le_u16(n: u16); + fn write_le_u16(&self, n: u16); /// Write a little-endian i64 (8 bytes). - fn write_le_i64(n: i64); + fn write_le_i64(&self, n: i64); /// Write a little-endian i32 (4 bytes). - fn write_le_i32(n: i32); + fn write_le_i32(&self, n: i32); /// Write a little-endian i16 (2 bytes). - fn write_le_i16(n: i16); + fn write_le_i16(&self, n: i16); /// Write a u8 (1 byte). - fn write_u8(n: u8); + fn write_u8(&self, n: u8); /// Write a i8 (1 byte). - fn write_i8(n: i8); + fn write_i8(&self, n: i8); } impl T : WriterUtil { - fn write_char(ch: char) { + fn write_char(&self, ch: char) { if ch as uint < 128u { self.write(&[ch as u8]); } else { self.write_str(str::from_char(ch)); } } - fn write_str(s: &str) { str::byte_slice(s, |v| self.write(v)) } - fn write_line(s: &str) { + fn write_str(&self, s: &str) { str::byte_slice(s, |v| self.write(v)) } + fn write_line(&self, s: &str) { self.write_str(s); self.write_str(&"\n"); } - fn write_int(n: int) { + fn write_int(&self, n: int) { int::to_str_bytes(n, 10u, |bytes| self.write(bytes)) } - fn write_uint(n: uint) { + fn write_uint(&self, n: uint) { uint::to_str_bytes(false, n, 10u, |bytes| self.write(bytes)) } - fn write_le_uint(n: uint) { + fn write_le_uint(&self, n: uint) { u64_to_le_bytes(n as u64, uint::bytes, |v| self.write(v)) } - fn write_le_int(n: int) { + fn write_le_int(&self, n: int) { u64_to_le_bytes(n as u64, int::bytes, |v| self.write(v)) } - fn write_be_uint(n: uint) { + fn write_be_uint(&self, n: uint) { u64_to_be_bytes(n as u64, uint::bytes, |v| self.write(v)) } - fn write_be_int(n: int) { + fn write_be_int(&self, n: int) { u64_to_be_bytes(n as u64, int::bytes, |v| self.write(v)) } - fn write_be_u64(n: u64) { + fn write_be_u64(&self, n: u64) { u64_to_be_bytes(n, 8u, |v| self.write(v)) } - fn write_be_u32(n: u32) { + fn write_be_u32(&self, n: u32) { u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) } - fn write_be_u16(n: u16) { + fn write_be_u16(&self, n: u16) { u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) } - fn write_be_i64(n: i64) { + fn write_be_i64(&self, n: i64) { u64_to_be_bytes(n as u64, 8u, |v| self.write(v)) } - fn write_be_i32(n: i32) { + fn write_be_i32(&self, n: i32) { u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) } - fn write_be_i16(n: i16) { + fn write_be_i16(&self, n: i16) { u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) } - fn write_le_u64(n: u64) { + fn write_le_u64(&self, n: u64) { u64_to_le_bytes(n, 8u, |v| self.write(v)) } - fn write_le_u32(n: u32) { + fn write_le_u32(&self, n: u32) { u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) } - fn write_le_u16(n: u16) { + fn write_le_u16(&self, n: u16) { u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) } - fn write_le_i64(n: i64) { + fn write_le_i64(&self, n: i64) { u64_to_le_bytes(n as u64, 8u, |v| self.write(v)) } - fn write_le_i32(n: i32) { + fn write_le_i32(&self, n: i32) { u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) } - fn write_le_i16(n: i16) { + fn write_le_i16(&self, n: i16) { u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) } - fn write_u8(n: u8) { self.write([n]) } - fn write_i8(n: i8) { self.write([n as u8]) } + fn write_u8(&self, n: u8) { self.write([n]) } + fn write_i8(&self, n: i8) { self.write([n as u8]) } } #[allow(non_implicitly_copyable_typarams)] @@ -926,7 +928,7 @@ pub struct BytesWriter { } impl BytesWriter: Writer { - fn write(v: &[const u8]) { + fn write(&self, v: &[const u8]) { do self.bytes.swap |bytes| { let mut bytes = move bytes; let v_len = v.len(); @@ -946,22 +948,14 @@ impl BytesWriter: Writer { move bytes } } - fn seek(offset: int, whence: SeekStyle) { + fn seek(&self, offset: int, whence: SeekStyle) { let pos = self.pos; let len = self.bytes.len(); self.pos = seek_in_buf(offset, pos, len, whence); } - fn tell() -> uint { self.pos } - fn flush() -> int { 0 } - fn get_type() -> WriterType { File } -} - -impl @BytesWriter : Writer { - fn write(v: &[const u8]) { (*self).write(v) } - fn seek(offset: int, whence: SeekStyle) { (*self).seek(offset, whence) } - fn tell() -> uint { (*self).tell() } - fn flush() -> int { (*self).flush() } - fn get_type() -> WriterType { (*self).get_type() } + fn tell(&self) -> uint { self.pos } + fn flush(&self) -> int { 0 } + fn get_type(&self) -> WriterType { File } } pub pure fn BytesWriter() -> BytesWriter { @@ -1091,7 +1085,7 @@ pub mod fsync { } // Type of objects that may want to fsync - pub trait FSyncable { fn fsync(l: Level) -> int; } + pub trait FSyncable { fn fsync(&self, l: Level) -> int; } // Call o.fsync after executing blk pub fn obj_sync(o: FSyncable, opt_level: Option, diff --git a/src/libstd/flatpipes.rs b/src/libstd/flatpipes.rs index 52037969d24c..1617641afe36 100644 --- a/src/libstd/flatpipes.rs +++ b/src/libstd/flatpipes.rs @@ -646,19 +646,19 @@ mod util { } impl BufReader: Reader { - fn read(bytes: &[mut u8], len: uint) -> uint { + fn read(&self, bytes: &[mut u8], len: uint) -> uint { self.as_bytes_reader(|r| r.read(bytes, len) ) } - fn read_byte() -> int { + fn read_byte(&self) -> int { self.as_bytes_reader(|r| r.read_byte() ) } - fn eof() -> bool { + fn eof(&self) -> bool { self.as_bytes_reader(|r| r.eof() ) } - fn seek(offset: int, whence: io::SeekStyle) { + fn seek(&self, offset: int, whence: io::SeekStyle) { self.as_bytes_reader(|r| r.seek(offset, whence) ) } - fn tell() -> uint { + fn tell(&self) -> uint { self.as_bytes_reader(|r| r.tell() ) } } diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index c94a7fd11259..c888b457356b 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -788,7 +788,7 @@ impl TcpSocket { /// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket` impl TcpSocketBuf: io::Reader { - fn read(buf: &[mut u8], len: uint) -> uint { + fn read(&self, buf: &[mut u8], len: uint) -> uint { // Loop until our buffer has enough data in it for us to read from. while self.data.buf.len() < len { let read_result = read(&self.data.sock, 0u); @@ -821,7 +821,7 @@ impl TcpSocketBuf: io::Reader { count } - fn read_byte() -> int { + fn read_byte(&self) -> int { let mut bytes = ~[0]; if self.read(bytes, 1u) == 0 { if self.end_of_stream { @@ -833,21 +833,21 @@ impl TcpSocketBuf: io::Reader { bytes[0] as int } } - fn eof() -> bool { + fn eof(&self) -> bool { self.end_of_stream } - fn seek(dist: int, seek: io::SeekStyle) { + fn seek(&self, dist: int, seek: io::SeekStyle) { log(debug, fmt!("tcp_socket_buf seek stub %? %?", dist, seek)); // noop } - fn tell() -> uint { + fn tell(&self) -> uint { 0u // noop } } /// Implementation of `io::reader` trait for a buffered `net::tcp::tcp_socket` impl TcpSocketBuf: io::Writer { - pub fn write(data: &[const u8]) unsafe { + pub fn write(&self, data: &[const u8]) unsafe { let socket_data_ptr = ptr::addr_of(&(*((*(self.data)).sock).socket_data)); let w_result = write_common_impl(socket_data_ptr, @@ -858,17 +858,17 @@ impl TcpSocketBuf: io::Writer { err_data.err_name, err_data.err_msg)); } } - fn seek(dist: int, seek: io::SeekStyle) { + fn seek(&self, dist: int, seek: io::SeekStyle) { log(debug, fmt!("tcp_socket_buf seek stub %? %?", dist, seek)); // noop } - fn tell() -> uint { + fn tell(&self) -> uint { 0u } - fn flush() -> int { + fn flush(&self) -> int { 0 } - fn get_type() -> io::WriterType { + fn get_type(&self) -> io::WriterType { io::File } } From 6dbb0252678717704930aa36dfbf3777511c16d5 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 24 Dec 2012 12:37:18 -0800 Subject: [PATCH 19/21] Fix wayward search and replace; unbreak build --- src/libcore/float.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libcore/float.rs b/src/libcore/float.rs index d7d68582aefd..02ba4419bcc3 100644 --- a/src/libcore/float.rs +++ b/src/libcore/float.rs @@ -466,9 +466,9 @@ pub fn test_from_str() { assert from_str(~".e-1") == Some(0.); assert from_str(~"5.") == Some(5.); assert from_str(~".5") == Some(0.5); - assert from_str(~"0.6") == Some(0.5); - assert from_str(~"0.6") == Some(0.5); - assert from_str(~"0.6") == Some(0.5); + assert from_str(~"0.5") == Some(0.5); + assert from_str(~"0.5") == Some(0.5); + assert from_str(~"0.5") == Some(0.5); assert from_str(~"-.5") == Some(-0.5); assert from_str(~"-.5") == Some(-0.5); assert from_str(~"-5") == Some(-5.); From c4720a73bbe69db14c574555a423c1045086241d Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 24 Dec 2012 13:29:36 -0800 Subject: [PATCH 20/21] Update shootout-mandelbrot to work with the new io::Writer --- src/test/bench/shootout-mandelbrot.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index b6c1baac4125..f85d6f6fdaaa 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -99,11 +99,11 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan) -> () type devnull = {dn: int}; impl devnull: io::Writer { - fn write(_b: &[const u8]) {} - fn seek(_i: int, _s: io::SeekStyle) {} - fn tell() -> uint {0_u} - fn flush() -> int {0} - fn get_type() -> io::WriterType { io::File } + fn write(&self, _b: &[const u8]) {} + fn seek(&self, _i: int, _s: io::SeekStyle) {} + fn tell(&self) -> uint {0_u} + fn flush(&self) -> int {0} + fn get_type(&self) -> io::WriterType { io::File } } fn writer(path: ~str, writech: oldcomm::Chan>, size: uint) From 09bb07bed9166105ea961a42b5fff7739ae0d2e9 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Mon, 24 Dec 2012 14:07:37 -0800 Subject: [PATCH 21/21] Unfortunately, we can't embed cross-crate tests in the tutorial... ...as far as I know, anyway, so I xfailed this tutorial test. --- doc/tutorial.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorial.md b/doc/tutorial.md index 1add1054cc55..d20ce43c3d2c 100644 --- a/doc/tutorial.md +++ b/doc/tutorial.md @@ -2419,7 +2419,7 @@ these two files: pub fn explore() -> &str { "world" } ~~~~ -~~~~ +~~~~ {.xfail-test} // main.rs extern mod world; fn main() { io::println(~"hello " + world::explore()); }