Skip to content

Commit

Permalink
Fixing remaining warnings and errors throughout
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcrichton committed Feb 3, 2014
1 parent f9a32cd commit c765a8e
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 277 deletions.
35 changes: 14 additions & 21 deletions src/doc/guide-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ An example program that does this task reads like this:
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand All @@ -71,7 +71,6 @@ fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
// Path takes a generic by-value, rather than by reference
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -245,15 +244,15 @@ and trapping its exit status using `task::try`:
use std::io::{BufferedReader, File};
use std::task;
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand All @@ -277,7 +276,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -347,15 +345,15 @@ but similarly clear as the version that used `fail!` in the logic where the erro
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand All @@ -374,7 +372,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -415,15 +412,15 @@ and replaces bad input lines with the pair `(-1,-1)`:
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand All @@ -447,7 +444,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -489,15 +485,15 @@ Changing the condition's return type from `(int,int)` to `Option<(int,int)>` wil
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{IoResult, File};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand All @@ -522,7 +518,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -573,15 +568,15 @@ This can be encoded in the handler API by introducing a helper type: `enum Malfo
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand Down Expand Up @@ -615,7 +610,6 @@ fn main() {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down Expand Up @@ -696,15 +690,15 @@ a second condition and a helper function will suffice:
# #[allow(unused_imports)];
use std::io::{BufferedReader, File};
# mod BufferedReader {
# use std::io::File;
# use std::io::{File, IoResult};
# use std::io::MemReader;
# use std::io::BufferedReader;
# static s : &'static [u8] = bytes!("1 2\n\
# 34 56\n\
# 789 123\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()))
# }
# }
Expand Down Expand Up @@ -752,7 +746,6 @@ fn parse_int(x: &str) -> int {
fn read_int_pairs() -> ~[(int,int)] {
let mut pairs = ~[];
# let _g = std::io::ignore_io_error();
let path = Path::new(&"foo.txt");
let mut reader = BufferedReader::new(File::open(&path));
Expand Down
1 change: 1 addition & 0 deletions src/etc/combine-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def scrub(b):
use run_pass_stage2::*;
use std::io;
use std::io::Writer;
#[allow(warnings)]
fn main() {
let mut out = io::stdout();
"""
Expand Down
8 changes: 5 additions & 3 deletions src/libnative/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
}
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
}
FindClose(find_handle);
assert!(FindClose(find_handle) != 0);
free(wfd_ptr as *mut c_void);
Ok(paths)
} else {
Expand Down Expand Up @@ -683,7 +683,9 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
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| {
unsafe {
libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz,
Expand All @@ -694,7 +696,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
Some(s) => Ok(Path::new(s)),
None => Err(super::last_error()),
};
unsafe { libc::CloseHandle(handle) };
assert!(unsafe { libc::CloseHandle(handle) } != 0);
return ret;

}
Expand Down
25 changes: 12 additions & 13 deletions src/libnative/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,8 @@ impl rtio::RtioProcess for Process {
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
match signal {
io::process::PleaseExitSignal | io::process::MustDieSignal => {
libc::funcs::extra::kernel32::TerminateProcess(
cast::transmute(pid), 1);
Ok(())
let ret = libc::TerminateProcess(pid as libc::HANDLE, 1);
super::mkerr_winbool(ret)
}
_ => Err(io::IoError {
kind: io::OtherIoError,
Expand Down Expand Up @@ -255,9 +254,9 @@ fn spawn_process_os(prog: &str, args: &[~str],
})
});

CloseHandle(si.hStdInput);
CloseHandle(si.hStdOutput);
CloseHandle(si.hStdError);
assert!(CloseHandle(si.hStdInput) != 0);
assert!(CloseHandle(si.hStdOutput) != 0);
assert!(CloseHandle(si.hStdError) != 0);

match create_err {
Some(err) => return Err(err),
Expand All @@ -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
// because std::we want the process id to stay valid at least until the
// calling code closes the process handle.
CloseHandle(pi.hThread);
assert!(CloseHandle(pi.hThread) != 0);

Ok(SpawnProcessResult {
pid: pi.dwProcessId as pid_t,
Expand Down Expand Up @@ -576,9 +575,9 @@ fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {

#[cfg(windows)]
fn free_handle(handle: *()) {
unsafe {
libc::funcs::extra::kernel32::CloseHandle(cast::transmute(handle));
}
assert!(unsafe {
libc::CloseHandle(cast::transmute(handle)) != 0
})
}

#[cfg(unix)]
Expand Down Expand Up @@ -629,15 +628,15 @@ fn waitpid(pid: pid_t) -> p::ProcessExit {
loop {
let mut status = 0;
if GetExitCodeProcess(process, &mut status) == FALSE {
CloseHandle(process);
assert!(CloseHandle(process) != 0);
fail!("failure in GetExitCodeProcess: {}", os::last_os_error());
}
if status != STILL_ACTIVE {
CloseHandle(process);
assert!(CloseHandle(process) != 0);
return p::ExitStatus(status as int);
}
if WaitForSingleObject(process, INFINITE) == WAIT_FAILED {
CloseHandle(process);
assert!(CloseHandle(process) != 0);
fail!("failure in WaitForSingleObject: {}", os::last_os_error());
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/timer_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ mod imp {
}

pub fn signal(handle: HANDLE) {
unsafe { SetEvent(handle); }
assert!(unsafe { SetEvent(handle) != 0 });
}

pub fn close(handle: HANDLE) {
unsafe { CloseHandle(handle); }
assert!(unsafe { CloseHandle(handle) != 0 });
}

extern "system" {
Expand Down
12 changes: 6 additions & 6 deletions src/libnative/io/timer_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
c.send(());
match objs.iter().position(|&o| o == obj) {
Some(i) => {
objs.remove(i);
chans.remove(i - 1);
drop(objs.remove(i));
drop(chans.remove(i - 1));
}
None => {}
}
Expand All @@ -83,8 +83,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
}
};
if remove {
objs.remove(idx as uint);
chans.remove(idx as uint - 1);
drop(objs.remove(idx as uint));
drop(chans.remove(idx as uint - 1));
}
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ impl rtio::RtioTimer for Timer {
ptr::mut_null(), 0)
}, 1);

unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE); }
let _ = unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE) };
}

fn oneshot(&mut self, msecs: u64) -> Port<()> {
Expand Down Expand Up @@ -173,7 +173,7 @@ impl rtio::RtioTimer for Timer {
impl Drop for Timer {
fn drop(&mut self) {
self.remove();
unsafe { libc::CloseHandle(self.obj); }
assert!(unsafe { libc::CloseHandle(self.obj) != 0 });
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
1u => {
let ifile = matches.free[0].as_slice();
if ifile == "-" {
let src =
str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
let contents = io::stdin().read_to_end().unwrap();
let src = str::from_utf8_owned(contents).unwrap();
(d::StrInput(src), None)
} else {
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))
Expand Down
12 changes: 6 additions & 6 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,12 +1160,12 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
let r = get_crate_deps(data);
for dep in r.iter() {
let string = token::get_ident(dep.name.name);
write!(out,
"{} {}-{}-{}\n",
dep.cnum,
string.get(),
dep.hash,
dep.vers);
if_ok!(write!(out,
"{} {}-{}-{}\n",
dep.cnum,
string.get(),
dep.hash,
dep.vers));
}

if_ok!(write!(out, "\n"));
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl PuritySpace {
}

impl fmt::Show for clean::Generics {
impl fmt::Default for clean::Generics {
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
if_ok!(f.buf.write("&lt;".as_bytes()));
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,13 +804,13 @@ impl<'a> fmt::Show for Item<'a> {
fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
match attr::find_stability(it.item.attrs.iter()) {
Some(ref stability) => {
write!(fmt.buf,
if_ok!(write!(fmt.buf,
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
lvl = stability.level.to_str(),
reason = match stability.text {
Some(ref s) => (*s).clone(),
None => InternedString::new(""),
});
}));
}
None => {}
}
Expand Down
Loading

5 comments on commit c765a8e

@bors
Copy link
Contributor

@bors bors commented on c765a8e Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at alexcrichton@c765a8e

@bors
Copy link
Contributor

@bors bors commented on c765a8e Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging alexcrichton/rust/no-io-error = c765a8e into auto

@bors
Copy link
Contributor

@bors bors commented on c765a8e Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alexcrichton/rust/no-io-error = c765a8e merged ok, testing candidate = cb40eba

@bors
Copy link
Contributor

@bors bors commented on c765a8e Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on c765a8e Feb 3, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = cb40eba

Please sign in to comment.