Fixing remaining warnings and errors throughout

This commit is contained in:
Alex Crichton 2014-02-01 11:24:42 -08:00
parent f9a32cdabc
commit c765a8e7ad
22 changed files with 185 additions and 277 deletions

View File

@ -47,7 +47,7 @@ An example program that does this task reads like this:
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -55,7 +55,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -71,7 +71,6 @@ fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
// Path takes a generic by-value, rather than by reference // Path takes a generic by-value, rather than by reference
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -245,7 +244,7 @@ and trapping its exit status using `task::try`:
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
use std::task; use std::task;
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -253,7 +252,7 @@ use std::task;
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -277,7 +276,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -347,7 +345,7 @@ but similarly clear as the version that used `fail!` in the logic where the erro
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -355,7 +353,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -374,7 +372,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -415,7 +412,7 @@ and replaces bad input lines with the pair `(-1,-1)`:
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -423,7 +420,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -447,7 +444,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -489,7 +485,7 @@ Changing the condition's return type from `(int,int)` to `Option<(int,int)>` wil
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{IoResult, File};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -497,7 +493,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -522,7 +518,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -573,7 +568,7 @@ This can be encoded in the handler API by introducing a helper type: `enum Malfo
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -581,7 +576,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -615,7 +610,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));
@ -696,7 +690,7 @@ a second condition and a helper function will suffice:
# #[allow(unused_imports)]; # #[allow(unused_imports)];
use std::io::{BufferedReader, File}; use std::io::{BufferedReader, File};
# mod BufferedReader { # mod BufferedReader {
# use std::io::File; # use std::io::{File, IoResult};
# use std::io::MemReader; # use std::io::MemReader;
# use std::io::BufferedReader; # use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\ # static s : &'static [u8] = bytes!("1 2\n\
@ -704,7 +698,7 @@ use std::io::{BufferedReader, File};
# 789 123\n\ # 789 123\n\
# 45 67\n\ # 45 67\n\
# "); # ");
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> { # pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
# BufferedReader::new(MemReader::new(s.to_owned())) # BufferedReader::new(MemReader::new(s.to_owned()))
# } # }
# } # }
@ -752,7 +746,6 @@ fn parse_int(x: &str) -> int {
fn read_int_pairs() -> ~[(int,int)] { fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[]; let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt"); let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path)); let mut reader = BufferedReader::new(File::open(&path));

View File

@ -69,6 +69,7 @@ extern mod run_pass_stage2;
use run_pass_stage2::*; use run_pass_stage2::*;
use std::io; use std::io;
use std::io::Writer; use std::io::Writer;
#[allow(warnings)]
fn main() { fn main() {
let mut out = io::stdout(); let mut out = io::stdout();
""" """

View File

@ -561,7 +561,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
} }
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE); more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
} }
FindClose(find_handle); assert!(FindClose(find_handle) != 0);
free(wfd_ptr as *mut c_void); free(wfd_ptr as *mut c_void);
Ok(paths) Ok(paths)
} else { } else {
@ -683,7 +683,9 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
ptr::mut_null()) ptr::mut_null())
}) })
}; };
if handle == ptr::mut_null() { return Err(super::last_error()) } if handle as int == libc::INVALID_HANDLE_VALUE as int {
return Err(super::last_error())
}
let ret = fill_utf16_buf_and_decode(|buf, sz| { let ret = fill_utf16_buf_and_decode(|buf, sz| {
unsafe { unsafe {
libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz, libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz,
@ -694,7 +696,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
Some(s) => Ok(Path::new(s)), Some(s) => Ok(Path::new(s)),
None => Err(super::last_error()), None => Err(super::last_error()),
}; };
unsafe { libc::CloseHandle(handle) }; assert!(unsafe { libc::CloseHandle(handle) } != 0);
return ret; return ret;
} }

View File

@ -149,9 +149,8 @@ impl rtio::RtioProcess for Process {
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> { unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
match signal { match signal {
io::process::PleaseExitSignal | io::process::MustDieSignal => { io::process::PleaseExitSignal | io::process::MustDieSignal => {
libc::funcs::extra::kernel32::TerminateProcess( let ret = libc::TerminateProcess(pid as libc::HANDLE, 1);
cast::transmute(pid), 1); super::mkerr_winbool(ret)
Ok(())
} }
_ => Err(io::IoError { _ => Err(io::IoError {
kind: io::OtherIoError, kind: io::OtherIoError,
@ -255,9 +254,9 @@ fn spawn_process_os(prog: &str, args: &[~str],
}) })
}); });
CloseHandle(si.hStdInput); assert!(CloseHandle(si.hStdInput) != 0);
CloseHandle(si.hStdOutput); assert!(CloseHandle(si.hStdOutput) != 0);
CloseHandle(si.hStdError); assert!(CloseHandle(si.hStdError) != 0);
match create_err { match create_err {
Some(err) => return Err(err), Some(err) => return Err(err),
@ -269,7 +268,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
// able to close it later. We don't close the process handle however // able to close it later. We don't close the process handle however
// because std::we want the process id to stay valid at least until the // because std::we want the process id to stay valid at least until the
// calling code closes the process handle. // calling code closes the process handle.
CloseHandle(pi.hThread); assert!(CloseHandle(pi.hThread) != 0);
Ok(SpawnProcessResult { Ok(SpawnProcessResult {
pid: pi.dwProcessId as pid_t, pid: pi.dwProcessId as pid_t,
@ -576,9 +575,9 @@ fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {
#[cfg(windows)] #[cfg(windows)]
fn free_handle(handle: *()) { fn free_handle(handle: *()) {
unsafe { assert!(unsafe {
libc::funcs::extra::kernel32::CloseHandle(cast::transmute(handle)); libc::CloseHandle(cast::transmute(handle)) != 0
} })
} }
#[cfg(unix)] #[cfg(unix)]
@ -629,15 +628,15 @@ fn waitpid(pid: pid_t) -> p::ProcessExit {
loop { loop {
let mut status = 0; let mut status = 0;
if GetExitCodeProcess(process, &mut status) == FALSE { if GetExitCodeProcess(process, &mut status) == FALSE {
CloseHandle(process); assert!(CloseHandle(process) != 0);
fail!("failure in GetExitCodeProcess: {}", os::last_os_error()); fail!("failure in GetExitCodeProcess: {}", os::last_os_error());
} }
if status != STILL_ACTIVE { if status != STILL_ACTIVE {
CloseHandle(process); assert!(CloseHandle(process) != 0);
return p::ExitStatus(status as int); return p::ExitStatus(status as int);
} }
if WaitForSingleObject(process, INFINITE) == WAIT_FAILED { if WaitForSingleObject(process, INFINITE) == WAIT_FAILED {
CloseHandle(process); assert!(CloseHandle(process) != 0);
fail!("failure in WaitForSingleObject: {}", os::last_os_error()); fail!("failure in WaitForSingleObject: {}", os::last_os_error());
} }
} }

View File

@ -126,11 +126,11 @@ mod imp {
} }
pub fn signal(handle: HANDLE) { pub fn signal(handle: HANDLE) {
unsafe { SetEvent(handle); } assert!(unsafe { SetEvent(handle) != 0 });
} }
pub fn close(handle: HANDLE) { pub fn close(handle: HANDLE) {
unsafe { CloseHandle(handle); } assert!(unsafe { CloseHandle(handle) != 0 });
} }
extern "system" { extern "system" {

View File

@ -62,8 +62,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
c.send(()); c.send(());
match objs.iter().position(|&o| o == obj) { match objs.iter().position(|&o| o == obj) {
Some(i) => { Some(i) => {
objs.remove(i); drop(objs.remove(i));
chans.remove(i - 1); drop(chans.remove(i - 1));
} }
None => {} None => {}
} }
@ -83,8 +83,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
} }
}; };
if remove { if remove {
objs.remove(idx as uint); drop(objs.remove(idx as uint));
chans.remove(idx as uint - 1); drop(chans.remove(idx as uint - 1));
} }
} }
} }
@ -133,7 +133,7 @@ impl rtio::RtioTimer for Timer {
ptr::mut_null(), 0) ptr::mut_null(), 0)
}, 1); }, 1);
unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE); } let _ = unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE) };
} }
fn oneshot(&mut self, msecs: u64) -> Port<()> { fn oneshot(&mut self, msecs: u64) -> Port<()> {
@ -173,7 +173,7 @@ impl rtio::RtioTimer for Timer {
impl Drop for Timer { impl Drop for Timer {
fn drop(&mut self) { fn drop(&mut self) {
self.remove(); self.remove();
unsafe { libc::CloseHandle(self.obj); } assert!(unsafe { libc::CloseHandle(self.obj) != 0 });
} }
} }

View File

@ -241,8 +241,8 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
1u => { 1u => {
let ifile = matches.free[0].as_slice(); let ifile = matches.free[0].as_slice();
if ifile == "-" { if ifile == "-" {
let src = let contents = io::stdin().read_to_end().unwrap();
str::from_utf8_owned(io::stdin().read_to_end()).unwrap(); let src = str::from_utf8_owned(contents).unwrap();
(d::StrInput(src), None) (d::StrInput(src), None)
} else { } else {
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile))) (d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))

View File

@ -1160,12 +1160,12 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
let r = get_crate_deps(data); let r = get_crate_deps(data);
for dep in r.iter() { for dep in r.iter() {
let string = token::get_ident(dep.name.name); let string = token::get_ident(dep.name.name);
write!(out, if_ok!(write!(out,
"{} {}-{}-{}\n", "{} {}-{}-{}\n",
dep.cnum, dep.cnum,
string.get(), string.get(),
dep.hash, dep.hash,
dep.vers); dep.vers));
} }
if_ok!(write!(out, "\n")); if_ok!(write!(out, "\n"));

View File

@ -48,7 +48,6 @@ impl PuritySpace {
} }
impl fmt::Show for clean::Generics { impl fmt::Show for clean::Generics {
impl fmt::Default for clean::Generics {
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) } if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
if_ok!(f.buf.write("&lt;".as_bytes())); if_ok!(f.buf.write("&lt;".as_bytes()));

View File

@ -804,13 +804,13 @@ impl<'a> fmt::Show for Item<'a> {
fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
match attr::find_stability(it.item.attrs.iter()) { match attr::find_stability(it.item.attrs.iter()) {
Some(ref stability) => { Some(ref stability) => {
write!(fmt.buf, if_ok!(write!(fmt.buf,
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>", "<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
lvl = stability.level.to_str(), lvl = stability.level.to_str(),
reason = match stability.text { reason = match stability.text {
Some(ref s) => (*s).clone(), Some(ref s) => (*s).clone(),
None => InternedString::new(""), None => InternedString::new(""),
}); }));
} }
None => {} None => {}
} }

View File

@ -477,16 +477,20 @@ will look like `"\\{"`.
*/ */
#[cfg(not(stage0))]
use prelude::*;
use cast; use cast;
use char::Char; use char::Char;
use container::Container;
use io::MemWriter; use io::MemWriter;
use io; use io;
use str; use iter::{Iterator, range};
use num::Signed;
use option::{Option,Some,None};
use repr; use repr;
use result::{Ok, Err};
use str::StrSlice;
use str;
use util; use util;
use vec::ImmutableVector;
use vec; use vec;
// NOTE this is just because the `prelude::*` import above includes // NOTE this is just because the `prelude::*` import above includes
@ -494,19 +498,6 @@ use vec;
#[cfg(stage0)] #[cfg(stage0)]
pub use Default = fmt::Show; // export required for `format!()` etc. pub use Default = fmt::Show; // export required for `format!()` etc.
#[cfg(stage0)]
use container::Container;
#[cfg(stage0)]
use iter::{Iterator, range};
#[cfg(stage0)]
use option::{Option,Some,None};
#[cfg(stage0)]
use vec::ImmutableVector;
#[cfg(stage0)]
use str::StrSlice;
#[cfg(stage0)]
use num::Signed;
pub mod parse; pub mod parse;
pub mod rt; pub mod rt;
@ -628,7 +619,7 @@ macro_rules! uniform_fn_call_workaround {
($( $name: ident, $trait_: ident; )*) => { ($( $name: ident, $trait_: ident; )*) => {
$( $(
#[doc(hidden)] #[doc(hidden)]
pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) { pub fn $name<T: $trait_>(x: &T, fmt: &mut Formatter) -> Result {
$trait_::fmt(x, fmt) $trait_::fmt(x, fmt)
} }
)* )*

View File

@ -46,6 +46,7 @@ Some examples of obvious things you might want to do
* Write a line to a file * Write a line to a file
```rust ```rust
# #[allow(unused_must_use)];
use std::io::File; use std::io::File;
let mut file = File::create(&Path::new("message.txt")); let mut file = File::create(&Path::new("message.txt"));
@ -83,6 +84,7 @@ Some examples of obvious things you might want to do
`write_str` and `write_line` methods. `write_str` and `write_line` methods.
```rust,should_fail ```rust,should_fail
# #[allow(unused_must_use)];
use std::io::net::ip::SocketAddr; use std::io::net::ip::SocketAddr;
use std::io::net::tcp::TcpStream; use std::io::net::tcp::TcpStream;
@ -188,6 +190,7 @@ be an error.
If you wanted to handle the error though you might write: If you wanted to handle the error though you might write:
```rust ```rust
# #[allow(unused_must_use)];
use std::io::File; use std::io::File;
match File::create(&Path::new("diary.txt")).write(bytes!("Met a girl.\n")) { match File::create(&Path::new("diary.txt")).write(bytes!("Met a girl.\n")) {
@ -360,7 +363,7 @@ pub struct IoError {
detail: Option<~str> detail: Option<~str>
} }
impl fmt::Default for IoError { impl fmt::Show for IoError {
fn fmt(err: &IoError, fmt: &mut fmt::Formatter) -> fmt::Result { fn fmt(err: &IoError, fmt: &mut fmt::Formatter) -> fmt::Result {
if_ok!(fmt.buf.write_str(err.desc)); if_ok!(fmt.buf.write_str(err.desc));
match err.detail { match err.detail {
@ -515,14 +518,13 @@ pub trait Reader {
/// Returns any non-EOF error immediately. Previously read bytes are /// Returns any non-EOF error immediately. Previously read bytes are
/// discarded when an error is returned. /// discarded when an error is returned.
/// ///
/// When EOF is encountered, all bytes read up to that point are returned, /// When EOF is encountered, all bytes read up to that point are returned.
/// but if 0 bytes have been read then the EOF error is returned.
fn read_to_end(&mut self) -> IoResult<~[u8]> { fn read_to_end(&mut self) -> IoResult<~[u8]> {
let mut buf = vec::with_capacity(DEFAULT_BUF_SIZE); let mut buf = vec::with_capacity(DEFAULT_BUF_SIZE);
loop { loop {
match self.push_bytes(&mut buf, DEFAULT_BUF_SIZE) { match self.push_bytes(&mut buf, DEFAULT_BUF_SIZE) {
Ok(()) => {} Ok(()) => {}
Err(ref e) if buf.len() > 0 && e.kind == EndOfFile => break, Err(ref e) if e.kind == EndOfFile => break,
Err(e) => return Err(e) Err(e) => return Err(e)
} }
} }

View File

@ -192,9 +192,10 @@ mod test {
match stream.read(buf) { match stream.read(buf) {
Ok(..) => fail!(), Ok(..) => fail!(),
Err(ref e) if cfg!(windows) => assert_eq!(e.kind, NotConnected), Err(ref e) => {
Err(ref e) if cfg!(unix) => assert_eq!(e.kind, EndOfFile), assert!(e.kind == NotConnected || e.kind == EndOfFile,
Err(..) => fail!(), "unknown kind: {:?}", e.kind);
}
} }
}) })
@ -217,9 +218,10 @@ mod test {
match stream.read(buf) { match stream.read(buf) {
Ok(..) => fail!(), Ok(..) => fail!(),
Err(ref e) if cfg!(windows) => assert_eq!(e.kind, NotConnected), Err(ref e) => {
Err(ref e) if cfg!(unix) => assert_eq!(e.kind, EndOfFile), assert!(e.kind == NotConnected || e.kind == EndOfFile,
Err(..) => fail!(), "unknown kind: {:?}", e.kind);
}
} }
}) })

View File

@ -203,6 +203,7 @@ mod test {
fn test_io_signal_invalid_signum() { fn test_io_signal_invalid_signum() {
use io; use io;
use super::User1; use super::User1;
use result::{Ok, Err};
let mut s = Listener::new(); let mut s = Listener::new();
let mut called = false; let mut called = false;
match s.register(User1) { match s.register(User1) {

View File

@ -1535,6 +1535,7 @@ mod tests {
assert!(*chunk.data == 0xbe); assert!(*chunk.data == 0xbe);
close(fd); close(fd);
} }
drop(chunk);
fs::unlink(&path).unwrap(); fs::unlink(&path).unwrap();
} }

View File

@ -533,7 +533,7 @@ pub struct Display<'a, P> {
} }
impl<'a, P: GenericPath> fmt::Show for Display<'a, P> { impl<'a, P: GenericPath> fmt::Show for Display<'a, P> {
fn fmt(d: &Display<P>, f: &mut fmt::Formatter) -> fmt::Display { fn fmt(d: &Display<P>, f: &mut fmt::Formatter) -> fmt::Result {
d.with_str(|s| f.pad(s)) d.with_str(|s| f.pad(s))
} }
} }

View File

@ -588,8 +588,8 @@ impl BytesContainer for InternedString {
} }
impl fmt::Show for InternedString { impl fmt::Show for InternedString {
fn fmt(obj: &InternedString, f: &mut fmt::Formatter) { fn fmt(obj: &InternedString, f: &mut fmt::Formatter) -> fmt::Result {
write!(f.buf, "{}", obj.string.as_slice()); write!(f.buf, "{}", obj.string.as_slice())
} }
} }

View File

@ -299,19 +299,34 @@ impl Printer {
if !self.scan_stack_empty { if !self.scan_stack_empty {
self.check_stack(0); self.check_stack(0);
let left = self.token[self.left].clone(); let left = self.token[self.left].clone();
self.advance_left(left, self.size[self.left]); if_ok!(self.advance_left(left, self.size[self.left]));
} }
Begin(b) => { self.indent(0);
if self.scan_stack_empty { Ok(())
self.left_total = 1; }
self.right_total = 1; Begin(b) => {
self.left = 0u; if self.scan_stack_empty {
self.right = 0u; self.left_total = 1;
} else { self.advance_right(); } self.right_total = 1;
debug!("pp Begin({})/buffer ~[{},{}]", self.left = 0u;
b.offset, self.left, self.right); self.right = 0u;
} else { self.advance_right(); }
debug!("pp Begin({})/buffer ~[{},{}]",
b.offset, self.left, self.right);
self.token[self.right] = t;
self.size[self.right] = -self.right_total;
self.scan_push(self.right);
Ok(())
}
End => {
if self.scan_stack_empty {
debug!("pp End/print ~[{},{}]", self.left, self.right);
self.print(t, 0)
} else {
debug!("pp End/buffer ~[{},{}]", self.left, self.right);
self.advance_right();
self.token[self.right] = t; self.token[self.right] = t;
self.size[self.right] = -self.right_total; self.size[self.right] = -1;
self.scan_push(self.right); self.scan_push(self.right);
Ok(()) Ok(())
} }
@ -330,12 +345,13 @@ impl Printer {
self.token[self.right] = t; self.token[self.right] = t;
self.size[self.right] = -self.right_total; self.size[self.right] = -self.right_total;
self.right_total += b.blank_space; self.right_total += b.blank_space;
Ok(())
} }
String(ref s, len) => { String(ref s, len) => {
if self.scan_stack_empty { if self.scan_stack_empty {
debug!("pp String('{}')/print ~[{},{}]", debug!("pp String('{}')/print ~[{},{}]",
*s, self.left, self.right); *s, self.left, self.right);
self.print(t.clone(), len); self.print(t.clone(), len)
} else { } else {
debug!("pp String('{}')/buffer ~[{},{}]", debug!("pp String('{}')/buffer ~[{},{}]",
*s, self.left, self.right); *s, self.left, self.right);
@ -343,8 +359,9 @@ impl Printer {
self.token[self.right] = t.clone(); self.token[self.right] = t.clone();
self.size[self.right] = len; self.size[self.right] = len;
self.right_total += len; self.right_total += len;
self.check_stream(); self.check_stream()
} }
}
} }
} }
pub fn check_stream(&mut self) -> io::IoResult<()> { pub fn check_stream(&mut self) -> io::IoResult<()> {
@ -360,8 +377,10 @@ impl Printer {
} }
} }
let left = self.token[self.left].clone(); let left = self.token[self.left].clone();
self.advance_left(left, self.size[self.left]); if_ok!(self.advance_left(left, self.size[self.left]));
if self.left != self.right { self.check_stream(); } if self.left != self.right {
if_ok!(self.check_stream());
}
} }
Ok(()) Ok(())
} }
@ -405,7 +424,7 @@ impl Printer {
debug!("advnce_left ~[{},{}], sizeof({})={}", self.left, self.right, debug!("advnce_left ~[{},{}], sizeof({})={}", self.left, self.right,
self.left, L); self.left, L);
if L >= 0 { if L >= 0 {
self.print(x.clone(), L); let ret = self.print(x.clone(), L);
match x { match x {
Break(b) => self.left_total += b.blank_space, Break(b) => self.left_total += b.blank_space,
String(_, len) => { String(_, len) => {
@ -417,7 +436,7 @@ impl Printer {
self.left += 1u; self.left += 1u;
self.left %= self.buf_len; self.left %= self.buf_len;
let left = self.token[self.left].clone(); let left = self.token[self.left].clone();
self.advance_left(left, self.size[self.left]); if_ok!(self.advance_left(left, self.size[self.left]));
} }
ret ret
} else { } else {
@ -477,7 +496,7 @@ impl Printer {
} }
write!(self.out, "{}", s) write!(self.out, "{}", s)
} }
pub fn print(&mut self, x: Token, L: int) { pub fn print(&mut self, x: Token, L: int) -> io::IoResult<()> {
debug!("print {} {} (remaining line space={})", tok_str(x.clone()), L, debug!("print {} {} (remaining line space={})", tok_str(x.clone()), L,
self.space); self.space);
debug!("{}", buf_str(self.token.clone(), debug!("{}", buf_str(self.token.clone(),
@ -587,16 +606,16 @@ pub fn end(p: &mut Printer) -> io::IoResult<()> { p.pretty_print(End) }
pub fn eof(p: &mut Printer) -> io::IoResult<()> { p.pretty_print(Eof) } pub fn eof(p: &mut Printer) -> io::IoResult<()> { p.pretty_print(Eof) }
pub fn word(p: &mut Printer, wrd: &str) { pub fn word(p: &mut Printer, wrd: &str) -> io::IoResult<()> {
p.pretty_print(String(/* bad */ wrd.to_str(), wrd.len() as int)); p.pretty_print(String(/* bad */ wrd.to_str(), wrd.len() as int))
} }
pub fn huge_word(p: &mut Printer, wrd: &str) { pub fn huge_word(p: &mut Printer, wrd: &str) -> io::IoResult<()> {
p.pretty_print(String(/* bad */ wrd.to_str(), SIZE_INFINITY)); p.pretty_print(String(/* bad */ wrd.to_str(), SIZE_INFINITY))
} }
pub fn zero_word(p: &mut Printer, wrd: &str) { pub fn zero_word(p: &mut Printer, wrd: &str) -> io::IoResult<()> {
p.pretty_print(String(/* bad */ wrd.to_str(), 0)); p.pretty_print(String(/* bad */ wrd.to_str(), 0))
} }
pub fn spaces(p: &mut Printer, n: uint) -> io::IoResult<()> { pub fn spaces(p: &mut Printer, n: uint) -> io::IoResult<()> {

View File

@ -964,11 +964,7 @@ pub fn print_attribute(s: &mut State, attr: &ast::Attribute) -> io::IoResult<()>
if_ok!(maybe_print_comment(s, attr.span.lo)); if_ok!(maybe_print_comment(s, attr.span.lo));
if attr.node.is_sugared_doc { if attr.node.is_sugared_doc {
let comment = attr.value_str().unwrap(); let comment = attr.value_str().unwrap();
<<<<<<< HEAD if_ok!(word(&mut s.s, comment.get()));
word(&mut s.s, comment.get());
=======
if_ok!(word(&mut s.s, comment));
>>>>>>> syntax: Remove io_error usage
} else { } else {
if_ok!(word(&mut s.s, "#[")); if_ok!(word(&mut s.s, "#["));
if_ok!(print_meta_item(s, attr.meta())); if_ok!(print_meta_item(s, attr.meta()));
@ -1139,24 +1135,7 @@ pub fn print_mac(s: &mut State, m: &ast::Mac) -> io::IoResult<()> {
} }
} }
<<<<<<< HEAD
pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) {
=======
pub fn print_vstore(s: &mut State, t: ast::Vstore) -> io::IoResult<()> {
match t {
ast::VstoreFixed(Some(i)) => word(&mut s.s, format!("{}", i)),
ast::VstoreFixed(None) => word(&mut s.s, "_"),
ast::VstoreUniq => word(&mut s.s, "~"),
ast::VstoreBox => word(&mut s.s, "@"),
ast::VstoreSlice(ref r) => {
if_ok!(word(&mut s.s, "&"));
print_opt_lifetime(s, r)
}
}
}
pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()> { pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()> {
>>>>>>> syntax: Remove io_error usage
match t { match t {
ast::ExprVstoreUniq => word(&mut s.s, "~"), ast::ExprVstoreUniq => word(&mut s.s, "~"),
ast::ExprVstoreSlice => word(&mut s.s, "&"), ast::ExprVstoreSlice => word(&mut s.s, "&"),
@ -1557,51 +1536,27 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> {
} else { } else {
if_ok!(word(&mut s.s, "asm!")); if_ok!(word(&mut s.s, "asm!"));
} }
<<<<<<< HEAD
popen(s);
print_string(s, a.asm.get(), a.asm_str_style);
word_space(s, ":");
for &(ref co, o) in a.outputs.iter() {
print_string(s, co.get(), ast::CookedStr);
popen(s);
print_expr(s, o);
pclose(s);
word_space(s, ",");
}
word_space(s, ":");
for &(ref co, o) in a.inputs.iter() {
print_string(s, co.get(), ast::CookedStr);
popen(s);
print_expr(s, o);
pclose(s);
word_space(s, ",");
}
word_space(s, ":");
print_string(s, a.clobbers.get(), ast::CookedStr);
pclose(s);
=======
if_ok!(popen(s)); if_ok!(popen(s));
if_ok!(print_string(s, a.asm, a.asm_str_style)); if_ok!(print_string(s, a.asm.get(), a.asm_str_style));
if_ok!(word_space(s, ":")); if_ok!(word_space(s, ":"));
for &(co, o) in a.outputs.iter() { for &(ref co, o) in a.outputs.iter() {
if_ok!(print_string(s, co, ast::CookedStr)); if_ok!(print_string(s, co.get(), ast::CookedStr));
if_ok!(popen(s)); if_ok!(popen(s));
if_ok!(print_expr(s, o)); if_ok!(print_expr(s, o));
if_ok!(pclose(s)); if_ok!(pclose(s));
if_ok!(word_space(s, ",")); if_ok!(word_space(s, ","));
} }
if_ok!(word_space(s, ":")); if_ok!(word_space(s, ":"));
for &(co, o) in a.inputs.iter() { for &(ref co, o) in a.inputs.iter() {
if_ok!(print_string(s, co, ast::CookedStr)); if_ok!(print_string(s, co.get(), ast::CookedStr));
if_ok!(popen(s)); if_ok!(popen(s));
if_ok!(print_expr(s, o)); if_ok!(print_expr(s, o));
if_ok!(pclose(s)); if_ok!(pclose(s));
if_ok!(word_space(s, ",")); if_ok!(word_space(s, ","));
} }
if_ok!(word_space(s, ":")); if_ok!(word_space(s, ":"));
if_ok!(print_string(s, a.clobbers, ast::CookedStr)); if_ok!(print_string(s, a.clobbers.get(), ast::CookedStr));
if_ok!(pclose(s)); if_ok!(pclose(s));
>>>>>>> syntax: Remove io_error usage
} }
ast::ExprMac(ref m) => if_ok!(print_mac(s, m)), ast::ExprMac(ref m) => if_ok!(print_mac(s, m)),
ast::ExprParen(e) => { ast::ExprParen(e) => {
@ -1659,23 +1614,14 @@ pub fn print_decl(s: &mut State, decl: &ast::Decl) -> io::IoResult<()> {
} }
} }
<<<<<<< HEAD
pub fn print_ident(s: &mut State, ident: ast::Ident) {
let string = token::get_ident(ident.name);
word(&mut s.s, string.get());
}
pub fn print_name(s: &mut State, name: ast::Name) {
let string = token::get_ident(name);
word(&mut s.s, string.get());
=======
pub fn print_ident(s: &mut State, ident: ast::Ident) -> io::IoResult<()> { pub fn print_ident(s: &mut State, ident: ast::Ident) -> io::IoResult<()> {
word(&mut s.s, ident_to_str(&ident)) let string = token::get_ident(ident.name);
word(&mut s.s, string.get())
} }
pub fn print_name(s: &mut State, name: ast::Name) -> io::IoResult<()> { pub fn print_name(s: &mut State, name: ast::Name) -> io::IoResult<()> {
word(&mut s.s, interner_get(name)) let string = token::get_ident(name);
>>>>>>> syntax: Remove io_error usage word(&mut s.s, string.get())
} }
pub fn print_for_decl(s: &mut State, loc: &ast::Local, pub fn print_for_decl(s: &mut State, loc: &ast::Local,
@ -2088,38 +2034,23 @@ pub fn print_generics(s: &mut State,
pub fn print_meta_item(s: &mut State, item: &ast::MetaItem) -> io::IoResult<()> { pub fn print_meta_item(s: &mut State, item: &ast::MetaItem) -> io::IoResult<()> {
if_ok!(ibox(s, indent_unit)); if_ok!(ibox(s, indent_unit));
match item.node { match item.node {
<<<<<<< HEAD ast::MetaWord(ref name) => {
ast::MetaWord(ref name) => word(&mut s.s, name.get()), if_ok!(word(&mut s.s, name.get()));
ast::MetaNameValue(ref name, ref value) => { }
word_space(s, name.get()); ast::MetaNameValue(ref name, ref value) => {
word_space(s, "="); if_ok!(word_space(s, name.get()));
print_literal(s, value); if_ok!(word_space(s, "="));
} if_ok!(print_literal(s, value));
ast::MetaList(ref name, ref items) => { }
word(&mut s.s, name.get()); ast::MetaList(ref name, ref items) => {
popen(s); if_ok!(word(&mut s.s, name.get()));
commasep(s, if_ok!(popen(s));
Consistent, if_ok!(commasep(s,
items.as_slice(), Consistent,
|p, &i| print_meta_item(p, i)); items.as_slice(),
pclose(s); |p, &i| print_meta_item(p, i)));
======= if_ok!(pclose(s));
ast::MetaWord(name) => { if_ok!(word(&mut s.s, name)); } }
ast::MetaNameValue(name, value) => {
if_ok!(word_space(s, name));
if_ok!(word_space(s, "="));
if_ok!(print_literal(s, &value));
}
ast::MetaList(name, ref items) => {
if_ok!(word(&mut s.s, name));
if_ok!(popen(s));
if_ok!(commasep(s,
Consistent,
items.as_slice(),
|p, &i| print_meta_item(p, i)));
if_ok!(pclose(s));
>>>>>>> syntax: Remove io_error usage
}
} }
end(s) end(s)
} }
@ -2171,17 +2102,10 @@ pub fn print_view_item(s: &mut State, item: &ast::ViewItem) -> io::IoResult<()>
if_ok!(head(s, "extern mod")); if_ok!(head(s, "extern mod"));
if_ok!(print_ident(s, id)); if_ok!(print_ident(s, id));
for &(ref p, style) in optional_path.iter() { for &(ref p, style) in optional_path.iter() {
<<<<<<< HEAD
space(&mut s.s);
word(&mut s.s, "=");
space(&mut s.s);
print_string(s, p.get(), style);
=======
if_ok!(space(&mut s.s)); if_ok!(space(&mut s.s));
if_ok!(word(&mut s.s, "=")); if_ok!(word(&mut s.s, "="));
if_ok!(space(&mut s.s)); if_ok!(space(&mut s.s));
if_ok!(print_string(s, *p, style)); if_ok!(print_string(s, p.get(), style));
>>>>>>> syntax: Remove io_error usage
} }
} }
@ -2373,88 +2297,54 @@ pub fn print_literal(s: &mut State, lit: &ast::Lit) -> io::IoResult<()> {
_ => () _ => ()
} }
match lit.node { match lit.node {
<<<<<<< HEAD
ast::LitStr(ref st, style) => print_string(s, st.get(), style), ast::LitStr(ref st, style) => print_string(s, st.get(), style),
ast::LitChar(ch) => { ast::LitChar(ch) => {
let mut res = ~"'"; let mut res = ~"'";
char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c)); char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c));
res.push_char('\''); res.push_char('\'');
word(&mut s.s, res); word(&mut s.s, res)
} }
ast::LitInt(i, t) => { ast::LitInt(i, t) => {
if i < 0_i64 { if i < 0_i64 {
word(&mut s.s, word(&mut s.s,
~"-" + (-i as u64).to_str_radix(10u) ~"-" + (-i as u64).to_str_radix(10u)
+ ast_util::int_ty_to_str(t)); + ast_util::int_ty_to_str(t))
} else { } else {
word(&mut s.s, word(&mut s.s,
(i as u64).to_str_radix(10u) (i as u64).to_str_radix(10u)
+ ast_util::int_ty_to_str(t)); + ast_util::int_ty_to_str(t))
=======
ast::LitStr(st, style) => print_string(s, st, style),
ast::LitChar(ch) => {
let mut res = ~"'";
char::from_u32(ch).unwrap().escape_default(|c| res.push_char(c));
res.push_char('\'');
word(&mut s.s, res)
} }
ast::LitInt(i, t) => {
if i < 0_i64 {
word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u)
+ ast_util::int_ty_to_str(t))
} else {
word(&mut s.s, (i as u64).to_str_radix(10u)
+ ast_util::int_ty_to_str(t))
}
>>>>>>> syntax: Remove io_error usage
}
ast::LitUint(u, t) => {
word(&mut s.s, u.to_str_radix(10u) + ast_util::uint_ty_to_str(t))
}
ast::LitIntUnsuffixed(i) => {
if i < 0_i64 {
word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u))
} else {
word(&mut s.s, (i as u64).to_str_radix(10u))
}
}
ast::LitFloat(f, t) => {
word(&mut s.s, f.to_owned() + ast_util::float_ty_to_str(t))
}
ast::LitFloatUnsuffixed(f) => word(&mut s.s, f),
ast::LitNil => word(&mut s.s, "()"),
ast::LitBool(val) => {
if val { word(&mut s.s, "true") } else { word(&mut s.s, "false") }
}
ast::LitBinary(arr) => {
if_ok!(ibox(s, indent_unit));
if_ok!(word(&mut s.s, "["));
if_ok!(commasep_cmnt(s, Inconsistent, arr,
|s, u| word(&mut s.s, format!("{}", *u)),
|_| lit.span));
if_ok!(word(&mut s.s, "]"));
end(s)
}
<<<<<<< HEAD
} }
ast::LitUint(u, t) => {
word(&mut s.s,
u.to_str_radix(10u)
+ ast_util::uint_ty_to_str(t))
}
ast::LitIntUnsuffixed(i) => {
if i < 0_i64 {
word(&mut s.s, ~"-" + (-i as u64).to_str_radix(10u))
} else {
word(&mut s.s, (i as u64).to_str_radix(10u))
}
}
ast::LitFloat(ref f, t) => { ast::LitFloat(ref f, t) => {
word(&mut s.s, f.get() + ast_util::float_ty_to_str(t)); word(&mut s.s, f.get() + ast_util::float_ty_to_str(t))
} }
ast::LitFloatUnsuffixed(ref f) => word(&mut s.s, f.get()), ast::LitFloatUnsuffixed(ref f) => word(&mut s.s, f.get()),
ast::LitNil => word(&mut s.s, "()"), ast::LitNil => word(&mut s.s, "()"),
ast::LitBool(val) => { ast::LitBool(val) => {
if val { word(&mut s.s, "true"); } else { word(&mut s.s, "false"); } if val { word(&mut s.s, "true") } else { word(&mut s.s, "false") }
} }
ast::LitBinary(ref arr) => { ast::LitBinary(ref arr) => {
ibox(s, indent_unit); if_ok!(ibox(s, indent_unit));
word(&mut s.s, "["); if_ok!(word(&mut s.s, "["));
commasep_cmnt(s, Inconsistent, *arr.borrow(), |s, u| word(&mut s.s, format!("{}", *u)), if_ok!(commasep_cmnt(s, Inconsistent, *arr.borrow(),
|_| lit.span); |s, u| word(&mut s.s, format!("{}", *u)),
word(&mut s.s, "]"); |_| lit.span));
end(s); if_ok!(word(&mut s.s, "]"));
end(s)
} }
=======
>>>>>>> syntax: Remove io_error usage
} }
} }

View File

@ -19,15 +19,21 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://static.rust-lang.org/doc/master")]; html_root_url = "http://static.rust-lang.org/doc/master")];
#[feature(macro_rules)];
#[deny(non_camel_case_types)]; #[deny(non_camel_case_types)];
#[allow(missing_doc)]; #[allow(missing_doc)];
use std::os; use std::os;
use std::io;
use terminfo::TermInfo; use terminfo::TermInfo;
use terminfo::searcher::open; use terminfo::searcher::open;
use terminfo::parser::compiled::{parse, msys_terminfo}; use terminfo::parser::compiled::{parse, msys_terminfo};
use terminfo::parm::{expand, Number, Variables}; use terminfo::parm::{expand, Number, Variables};
macro_rules! if_ok (
($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
)
pub mod terminfo; pub mod terminfo;
// FIXME (#2807): Windows support. // FIXME (#2807): Windows support.

View File

@ -8,11 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::io;
use std::io::BufferedWriter; use std::io::BufferedWriter;
struct DummyWriter; struct DummyWriter;
impl Writer for DummyWriter { impl Writer for DummyWriter {
fn write(&mut self, _: &[u8]) {} fn write(&mut self, _: &[u8]) -> io::IoResult<()> { Ok(()) }
} }
static ITER: int = 50; static ITER: int = 50;

View File

@ -36,11 +36,12 @@ fn make_complements() -> [u8, ..256] {
fn main() { fn main() {
let complements = make_complements(); let complements = make_complements();
let mut data = if std::os::getenv("RUST_BENCH").is_some() { let data = if std::os::getenv("RUST_BENCH").is_some() {
File::open(&Path::new("shootout-k-nucleotide.data")).read_to_end() File::open(&Path::new("shootout-k-nucleotide.data")).read_to_end()
} else { } else {
stdin().read_to_end() stdin().read_to_end()
}; };
let mut data = data.unwrap();
for seq in data.mut_split(|c| *c == '>' as u8) { for seq in data.mut_split(|c| *c == '>' as u8) {
// skip header and last \n // skip header and last \n