Skip to content

Commit c765a8e

Browse files
committed
Fixing remaining warnings and errors throughout
1 parent f9a32cd commit c765a8e

File tree

22 files changed

+185
-277
lines changed

22 files changed

+185
-277
lines changed

src/doc/guide-conditions.md

+14-21
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ An example program that does this task reads like this:
4747
# #[allow(unused_imports)];
4848
use std::io::{BufferedReader, File};
4949
# mod BufferedReader {
50-
# use std::io::File;
50+
# use std::io::{File, IoResult};
5151
# use std::io::MemReader;
5252
# use std::io::BufferedReader;
5353
# static s : &'static [u8] = bytes!("1 2\n\
5454
# 34 56\n\
5555
# 789 123\n\
5656
# 45 67\n\
5757
# ");
58-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
58+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
5959
# BufferedReader::new(MemReader::new(s.to_owned()))
6060
# }
6161
# }
@@ -71,7 +71,6 @@ fn read_int_pairs() -> ~[(int,int)] {
7171
let mut pairs = ~[];
7272
7373
// Path takes a generic by-value, rather than by reference
74-
# let _g = std::io::ignore_io_error();
7574
let path = Path::new(&"foo.txt");
7675
let mut reader = BufferedReader::new(File::open(&path));
7776
@@ -245,15 +244,15 @@ and trapping its exit status using `task::try`:
245244
use std::io::{BufferedReader, File};
246245
use std::task;
247246
# mod BufferedReader {
248-
# use std::io::File;
247+
# use std::io::{File, IoResult};
249248
# use std::io::MemReader;
250249
# use std::io::BufferedReader;
251250
# static s : &'static [u8] = bytes!("1 2\n\
252251
# 34 56\n\
253252
# 789 123\n\
254253
# 45 67\n\
255254
# ");
256-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
255+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
257256
# BufferedReader::new(MemReader::new(s.to_owned()))
258257
# }
259258
# }
@@ -277,7 +276,6 @@ fn main() {
277276
278277
fn read_int_pairs() -> ~[(int,int)] {
279278
let mut pairs = ~[];
280-
# let _g = std::io::ignore_io_error();
281279
let path = Path::new(&"foo.txt");
282280
283281
let mut reader = BufferedReader::new(File::open(&path));
@@ -347,15 +345,15 @@ but similarly clear as the version that used `fail!` in the logic where the erro
347345
# #[allow(unused_imports)];
348346
use std::io::{BufferedReader, File};
349347
# mod BufferedReader {
350-
# use std::io::File;
348+
# use std::io::{File, IoResult};
351349
# use std::io::MemReader;
352350
# use std::io::BufferedReader;
353351
# static s : &'static [u8] = bytes!("1 2\n\
354352
# 34 56\n\
355353
# 789 123\n\
356354
# 45 67\n\
357355
# ");
358-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
356+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
359357
# BufferedReader::new(MemReader::new(s.to_owned()))
360358
# }
361359
# }
@@ -374,7 +372,6 @@ fn main() {
374372
375373
fn read_int_pairs() -> ~[(int,int)] {
376374
let mut pairs = ~[];
377-
# let _g = std::io::ignore_io_error();
378375
let path = Path::new(&"foo.txt");
379376
380377
let mut reader = BufferedReader::new(File::open(&path));
@@ -415,15 +412,15 @@ and replaces bad input lines with the pair `(-1,-1)`:
415412
# #[allow(unused_imports)];
416413
use std::io::{BufferedReader, File};
417414
# mod BufferedReader {
418-
# use std::io::File;
415+
# use std::io::{File, IoResult};
419416
# use std::io::MemReader;
420417
# use std::io::BufferedReader;
421418
# static s : &'static [u8] = bytes!("1 2\n\
422419
# 34 56\n\
423420
# 789 123\n\
424421
# 45 67\n\
425422
# ");
426-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
423+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
427424
# BufferedReader::new(MemReader::new(s.to_owned()))
428425
# }
429426
# }
@@ -447,7 +444,6 @@ fn main() {
447444
448445
fn read_int_pairs() -> ~[(int,int)] {
449446
let mut pairs = ~[];
450-
# let _g = std::io::ignore_io_error();
451447
let path = Path::new(&"foo.txt");
452448
453449
let mut reader = BufferedReader::new(File::open(&path));
@@ -489,15 +485,15 @@ Changing the condition's return type from `(int,int)` to `Option<(int,int)>` wil
489485
# #[allow(unused_imports)];
490486
use std::io::{BufferedReader, File};
491487
# mod BufferedReader {
492-
# use std::io::File;
488+
# use std::io::{IoResult, File};
493489
# use std::io::MemReader;
494490
# use std::io::BufferedReader;
495491
# static s : &'static [u8] = bytes!("1 2\n\
496492
# 34 56\n\
497493
# 789 123\n\
498494
# 45 67\n\
499495
# ");
500-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
496+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
501497
# BufferedReader::new(MemReader::new(s.to_owned()))
502498
# }
503499
# }
@@ -522,7 +518,6 @@ fn main() {
522518
523519
fn read_int_pairs() -> ~[(int,int)] {
524520
let mut pairs = ~[];
525-
# let _g = std::io::ignore_io_error();
526521
let path = Path::new(&"foo.txt");
527522
528523
let mut reader = BufferedReader::new(File::open(&path));
@@ -573,15 +568,15 @@ This can be encoded in the handler API by introducing a helper type: `enum Malfo
573568
# #[allow(unused_imports)];
574569
use std::io::{BufferedReader, File};
575570
# mod BufferedReader {
576-
# use std::io::File;
571+
# use std::io::{File, IoResult};
577572
# use std::io::MemReader;
578573
# use std::io::BufferedReader;
579574
# static s : &'static [u8] = bytes!("1 2\n\
580575
# 34 56\n\
581576
# 789 123\n\
582577
# 45 67\n\
583578
# ");
584-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
579+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
585580
# BufferedReader::new(MemReader::new(s.to_owned()))
586581
# }
587582
# }
@@ -615,7 +610,6 @@ fn main() {
615610
616611
fn read_int_pairs() -> ~[(int,int)] {
617612
let mut pairs = ~[];
618-
# let _g = std::io::ignore_io_error();
619613
let path = Path::new(&"foo.txt");
620614
621615
let mut reader = BufferedReader::new(File::open(&path));
@@ -696,15 +690,15 @@ a second condition and a helper function will suffice:
696690
# #[allow(unused_imports)];
697691
use std::io::{BufferedReader, File};
698692
# mod BufferedReader {
699-
# use std::io::File;
693+
# use std::io::{File, IoResult};
700694
# use std::io::MemReader;
701695
# use std::io::BufferedReader;
702696
# static s : &'static [u8] = bytes!("1 2\n\
703697
# 34 56\n\
704698
# 789 123\n\
705699
# 45 67\n\
706700
# ");
707-
# pub fn new(_inner: Option<File>) -> BufferedReader<MemReader> {
701+
# pub fn new(_inner: IoResult<File>) -> BufferedReader<MemReader> {
708702
# BufferedReader::new(MemReader::new(s.to_owned()))
709703
# }
710704
# }
@@ -752,7 +746,6 @@ fn parse_int(x: &str) -> int {
752746
753747
fn read_int_pairs() -> ~[(int,int)] {
754748
let mut pairs = ~[];
755-
# let _g = std::io::ignore_io_error();
756749
let path = Path::new(&"foo.txt");
757750
758751
let mut reader = BufferedReader::new(File::open(&path));

src/etc/combine-tests.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def scrub(b):
6969
use run_pass_stage2::*;
7070
use std::io;
7171
use std::io::Writer;
72+
#[allow(warnings)]
7273
fn main() {
7374
let mut out = io::stdout();
7475
"""

src/libnative/io/file.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
561561
}
562562
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
563563
}
564-
FindClose(find_handle);
564+
assert!(FindClose(find_handle) != 0);
565565
free(wfd_ptr as *mut c_void);
566566
Ok(paths)
567567
} else {
@@ -683,7 +683,9 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
683683
ptr::mut_null())
684684
})
685685
};
686-
if handle == ptr::mut_null() { return Err(super::last_error()) }
686+
if handle as int == libc::INVALID_HANDLE_VALUE as int {
687+
return Err(super::last_error())
688+
}
687689
let ret = fill_utf16_buf_and_decode(|buf, sz| {
688690
unsafe {
689691
libc::GetFinalPathNameByHandleW(handle, buf as *u16, sz,
@@ -694,7 +696,7 @@ pub fn readlink(p: &CString) -> IoResult<Path> {
694696
Some(s) => Ok(Path::new(s)),
695697
None => Err(super::last_error()),
696698
};
697-
unsafe { libc::CloseHandle(handle) };
699+
assert!(unsafe { libc::CloseHandle(handle) } != 0);
698700
return ret;
699701

700702
}

src/libnative/io/process.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,8 @@ impl rtio::RtioProcess for Process {
149149
unsafe fn killpid(pid: pid_t, signal: int) -> Result<(), io::IoError> {
150150
match signal {
151151
io::process::PleaseExitSignal | io::process::MustDieSignal => {
152-
libc::funcs::extra::kernel32::TerminateProcess(
153-
cast::transmute(pid), 1);
154-
Ok(())
152+
let ret = libc::TerminateProcess(pid as libc::HANDLE, 1);
153+
super::mkerr_winbool(ret)
155154
}
156155
_ => Err(io::IoError {
157156
kind: io::OtherIoError,
@@ -255,9 +254,9 @@ fn spawn_process_os(prog: &str, args: &[~str],
255254
})
256255
});
257256

258-
CloseHandle(si.hStdInput);
259-
CloseHandle(si.hStdOutput);
260-
CloseHandle(si.hStdError);
257+
assert!(CloseHandle(si.hStdInput) != 0);
258+
assert!(CloseHandle(si.hStdOutput) != 0);
259+
assert!(CloseHandle(si.hStdError) != 0);
261260

262261
match create_err {
263262
Some(err) => return Err(err),
@@ -269,7 +268,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
269268
// able to close it later. We don't close the process handle however
270269
// because std::we want the process id to stay valid at least until the
271270
// calling code closes the process handle.
272-
CloseHandle(pi.hThread);
271+
assert!(CloseHandle(pi.hThread) != 0);
273272

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

577576
#[cfg(windows)]
578577
fn free_handle(handle: *()) {
579-
unsafe {
580-
libc::funcs::extra::kernel32::CloseHandle(cast::transmute(handle));
581-
}
578+
assert!(unsafe {
579+
libc::CloseHandle(cast::transmute(handle)) != 0
580+
})
582581
}
583582

584583
#[cfg(unix)]
@@ -629,15 +628,15 @@ fn waitpid(pid: pid_t) -> p::ProcessExit {
629628
loop {
630629
let mut status = 0;
631630
if GetExitCodeProcess(process, &mut status) == FALSE {
632-
CloseHandle(process);
631+
assert!(CloseHandle(process) != 0);
633632
fail!("failure in GetExitCodeProcess: {}", os::last_os_error());
634633
}
635634
if status != STILL_ACTIVE {
636-
CloseHandle(process);
635+
assert!(CloseHandle(process) != 0);
637636
return p::ExitStatus(status as int);
638637
}
639638
if WaitForSingleObject(process, INFINITE) == WAIT_FAILED {
640-
CloseHandle(process);
639+
assert!(CloseHandle(process) != 0);
641640
fail!("failure in WaitForSingleObject: {}", os::last_os_error());
642641
}
643642
}

src/libnative/io/timer_helper.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ mod imp {
126126
}
127127

128128
pub fn signal(handle: HANDLE) {
129-
unsafe { SetEvent(handle); }
129+
assert!(unsafe { SetEvent(handle) != 0 });
130130
}
131131

132132
pub fn close(handle: HANDLE) {
133-
unsafe { CloseHandle(handle); }
133+
assert!(unsafe { CloseHandle(handle) != 0 });
134134
}
135135

136136
extern "system" {

src/libnative/io/timer_win32.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
6262
c.send(());
6363
match objs.iter().position(|&o| o == obj) {
6464
Some(i) => {
65-
objs.remove(i);
66-
chans.remove(i - 1);
65+
drop(objs.remove(i));
66+
drop(chans.remove(i - 1));
6767
}
6868
None => {}
6969
}
@@ -83,8 +83,8 @@ fn helper(input: libc::HANDLE, messages: Port<Req>) {
8383
}
8484
};
8585
if remove {
86-
objs.remove(idx as uint);
87-
chans.remove(idx as uint - 1);
86+
drop(objs.remove(idx as uint));
87+
drop(chans.remove(idx as uint - 1));
8888
}
8989
}
9090
}
@@ -133,7 +133,7 @@ impl rtio::RtioTimer for Timer {
133133
ptr::mut_null(), 0)
134134
}, 1);
135135

136-
unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE); }
136+
let _ = unsafe { imp::WaitForSingleObject(self.obj, libc::INFINITE) };
137137
}
138138

139139
fn oneshot(&mut self, msecs: u64) -> Port<()> {
@@ -173,7 +173,7 @@ impl rtio::RtioTimer for Timer {
173173
impl Drop for Timer {
174174
fn drop(&mut self) {
175175
self.remove();
176-
unsafe { libc::CloseHandle(self.obj); }
176+
assert!(unsafe { libc::CloseHandle(self.obj) != 0 });
177177
}
178178
}
179179

src/librustc/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
241241
1u => {
242242
let ifile = matches.free[0].as_slice();
243243
if ifile == "-" {
244-
let src =
245-
str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
244+
let contents = io::stdin().read_to_end().unwrap();
245+
let src = str::from_utf8_owned(contents).unwrap();
246246
(d::StrInput(src), None)
247247
} else {
248248
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))

src/librustc/metadata/decoder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1160,12 +1160,12 @@ fn list_crate_deps(data: &[u8], out: &mut io::Writer) -> io::IoResult<()> {
11601160
let r = get_crate_deps(data);
11611161
for dep in r.iter() {
11621162
let string = token::get_ident(dep.name.name);
1163-
write!(out,
1164-
"{} {}-{}-{}\n",
1165-
dep.cnum,
1166-
string.get(),
1167-
dep.hash,
1168-
dep.vers);
1163+
if_ok!(write!(out,
1164+
"{} {}-{}-{}\n",
1165+
dep.cnum,
1166+
string.get(),
1167+
dep.hash,
1168+
dep.vers));
11691169
}
11701170

11711171
if_ok!(write!(out, "\n"));

src/librustdoc/html/format.rs

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ impl PuritySpace {
4848
}
4949

5050
impl fmt::Show for clean::Generics {
51-
impl fmt::Default for clean::Generics {
5251
fn fmt(g: &clean::Generics, f: &mut fmt::Formatter) -> fmt::Result {
5352
if g.lifetimes.len() == 0 && g.type_params.len() == 0 { return Ok(()) }
5453
if_ok!(f.buf.write("&lt;".as_bytes()));

src/librustdoc/html/render.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,13 +804,13 @@ impl<'a> fmt::Show for Item<'a> {
804804
fn fmt(it: &Item<'a>, fmt: &mut fmt::Formatter) -> fmt::Result {
805805
match attr::find_stability(it.item.attrs.iter()) {
806806
Some(ref stability) => {
807-
write!(fmt.buf,
807+
if_ok!(write!(fmt.buf,
808808
"<a class='stability {lvl}' title='{reason}'>{lvl}</a>",
809809
lvl = stability.level.to_str(),
810810
reason = match stability.text {
811811
Some(ref s) => (*s).clone(),
812812
None => InternedString::new(""),
813-
});
813+
}));
814814
}
815815
None => {}
816816
}

0 commit comments

Comments
 (0)