From 3244416b19ea8e424055761087f7f5f951b00d94 Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Thu, 30 Oct 2014 10:06:47 +0100 Subject: [PATCH] fail! -> panic! --- mkmain.rs | 2 +- mkuutils.rs | 2 +- src/base64/base64.rs | 8 ++++---- src/cat/cat.rs | 4 ++-- src/cksum/cksum.rs | 2 +- src/comm/comm.rs | 2 +- src/common/util.rs | 12 ++++++------ src/cp/cp.rs | 16 ++++++++-------- src/cut/buffer.rs | 4 ++-- src/cut/cut.rs | 6 +++--- src/dirname/dirname.rs | 2 +- src/echo/echo.rs | 2 +- src/fmt/parasplit.rs | 4 ++-- src/hostname/hostname.rs | 2 +- src/link/link.rs | 2 +- src/mkfifo/mkfifo.rs | 2 +- src/tail/tail.rs | 6 +++--- src/touch/touch.rs | 18 +++++++++--------- src/tr/tr.rs | 4 ++-- src/users/users.rs | 2 +- test/cat.rs | 2 +- test/mkdir.rs | 2 +- test/mv.rs | 2 +- test/sort.rs | 6 +++--- test/tr.rs | 2 +- test/truncate.rs | 10 +++++----- test/unexpand.rs | 2 +- 27 files changed, 64 insertions(+), 64 deletions(-) diff --git a/mkmain.rs b/mkmain.rs index b7946ec1c..7117cc191 100644 --- a/mkmain.rs +++ b/mkmain.rs @@ -35,7 +35,7 @@ fn main() { let mut out = File::open_mode(&Path::new(outfile), Truncate, ReadWrite); match out.write(main.as_bytes()) { - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), _ => (), } } diff --git a/mkuutils.rs b/mkuutils.rs index c6491b78a..72c9b20a4 100644 --- a/mkuutils.rs +++ b/mkuutils.rs @@ -52,7 +52,7 @@ fn main() { let main = input.read_to_string().unwrap().replace("@CRATES@", crates.as_slice()).replace("@UTIL_MAP@", util_map.as_slice()); match out.write(main.as_bytes()) { - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), _ => (), } } diff --git a/src/base64/base64.rs b/src/base64/base64.rs index 480c52de4..466aedb0c 100644 --- a/src/base64/base64.rs +++ b/src/base64/base64.rs @@ -48,7 +48,7 @@ pub fn uumain(args: Vec) -> int { Ok(m) => m, Err(e) => { error!("error: {}", e); - fail!() + panic!() } }; @@ -69,7 +69,7 @@ pub fn uumain(args: Vec) -> int { Some(s) => s, None => { error!("error: {:s}", "Argument to option 'wrap' improperly formatted."); - fail!() + panic!() } }, None => 76 @@ -98,7 +98,7 @@ pub fn uumain(args: Vec) -> int { fn decode(input: &mut Reader, ignore_garbage: bool) { let mut to_decode = match input.read_to_string() { Ok(m) => m, - Err(f) => fail!(f) + Err(f) => panic!(f) }; let slice = @@ -134,7 +134,7 @@ fn decode(input: &mut Reader, ignore_garbage: bool) { } Err(s) => { error!("error: {}", s); - fail!() + panic!() } } } diff --git a/src/cat/cat.rs b/src/cat/cat.rs index 0a5737597..b84444a5c 100644 --- a/src/cat/cat.rs +++ b/src/cat/cat.rs @@ -38,7 +38,7 @@ pub fn uumain(args: Vec) -> int { ]; let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(f) => fail!("Invalid options\n{}", f) + Err(f) => panic!("Invalid options\n{}", f) }; if matches.opt_present("help") { println!("cat 1.0.0"); @@ -328,7 +328,7 @@ impl<'a, W: Writer> UnsafeWriter<'a, W> { #[inline(never)] fn fail() -> ! { - fail!("assertion failed"); + panic!("assertion failed"); } impl<'a, W: Writer> Writer for UnsafeWriter<'a, W> { diff --git a/src/cksum/cksum.rs b/src/cksum/cksum.rs index 0e855c8aa..4afa4db60 100644 --- a/src/cksum/cksum.rs +++ b/src/cksum/cksum.rs @@ -82,7 +82,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; if matches.opt_present("help") { diff --git a/src/comm/comm.rs b/src/comm/comm.rs index 98960e0c7..60a2b6beb 100644 --- a/src/comm/comm.rs +++ b/src/comm/comm.rs @@ -105,7 +105,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; if matches.opt_present("version") { diff --git a/src/common/util.rs b/src/common/util.rs index 2b75e8407..88e5add24 100644 --- a/src/common/util.rs +++ b/src/common/util.rs @@ -94,7 +94,7 @@ macro_rules! pipe_print( if f.kind == ::std::io::BrokenPipe { false } else { - fail!("{}", f) + panic!("{}", f) } } } @@ -110,7 +110,7 @@ macro_rules! pipe_println( if f.kind == ::std::io::BrokenPipe { false } else { - fail!("{}", f) + panic!("{}", f) } } } @@ -126,7 +126,7 @@ macro_rules! pipe_write( if f.kind == ::std::io::BrokenPipe { false } else { - fail!("{}", f) + panic!("{}", f) } } } @@ -142,7 +142,7 @@ macro_rules! pipe_writeln( if f.kind == ::std::io::BrokenPipe { false } else { - fail!("{}", f) + panic!("{}", f) } } } @@ -154,7 +154,7 @@ macro_rules! safe_write( ($fd:expr, $($args:expr),+) => ( match write!($fd, $($args),+) { Ok(_) => {} - Err(f) => fail!(f.to_string()) + Err(f) => panic!(f.to_string()) } ) ) @@ -164,7 +164,7 @@ macro_rules! safe_writeln( ($fd:expr, $($args:expr),+) => ( match writeln!($fd, $($args),+) { Ok(_) => {} - Err(f) => fail!(f.to_string()) + Err(f) => panic!(f.to_string()) } ) ) diff --git a/src/cp/cp.rs b/src/cp/cp.rs index 386652548..df4ed6b3e 100644 --- a/src/cp/cp.rs +++ b/src/cp/cp.rs @@ -40,7 +40,7 @@ pub fn uumain(args: Vec) -> int { Ok(m) => m, Err(e) => { error!("error: {}", e); - fail!() + panic!() }, }; @@ -79,7 +79,7 @@ fn help(progname: &str, usage: &str) { fn copy(matches: getopts::Matches) { let sources : Vec = if matches.free.len() < 1 { error!("error: Missing SOURCE argument. Try --help."); - fail!() + panic!() } else { // All but the last argument: matches.free.slice(0, matches.free.len() - 1).iter() @@ -87,7 +87,7 @@ fn copy(matches: getopts::Matches) { }; let dest = if matches.free.len() < 2 { error!("error: Missing DEST argument. Try --help."); - fail!() + panic!() } else { // Only the last argument: Path::new(matches.free[matches.free.len() - 1].as_slice()) @@ -103,7 +103,7 @@ fn copy(matches: getopts::Matches) { false } else { error!("error: {:s}", e.to_string()); - fail!() + panic!() } }; @@ -111,7 +111,7 @@ fn copy(matches: getopts::Matches) { error!("error: \"{:s}\" and \"{:s}\" are the same file", source.display().to_string(), dest.display().to_string()); - fail!(); + panic!(); } let io_result = fs::copy(source, &dest); @@ -119,12 +119,12 @@ fn copy(matches: getopts::Matches) { if io_result.is_err() { let err = io_result.unwrap_err(); error!("error: {:s}", err.to_string()); - fail!(); + panic!(); } } else { if fs::stat(&dest).unwrap().kind != io::TypeDirectory { error!("error: TARGET must be a directory"); - fail!(); + panic!(); } for source in sources.iter() { @@ -144,7 +144,7 @@ fn copy(matches: getopts::Matches) { if io_result.is_err() { let err = io_result.unwrap_err(); error!("error: {:s}", err.to_string()); - fail!() + panic!() } } } diff --git a/src/cut/buffer.rs b/src/cut/buffer.rs index 4006782af..77e9a4e67 100644 --- a/src/cut/buffer.rs +++ b/src/cut/buffer.rs @@ -68,7 +68,7 @@ impl BufReader { match self.maybe_fill_buf() { Ok(0) | Err(IoError { kind: std::io::EndOfFile, .. }) if self.start == self.end => return bytes_consumed, - Err(err) => fail!("read error: {}", err.desc), + Err(err) => panic!("read error: {}", err.desc), _ => () } @@ -94,7 +94,7 @@ impl Bytes::Select for BufReader { fn select<'a>(&'a mut self, bytes: uint) -> Bytes::Selected<'a> { match self.maybe_fill_buf() { Err(IoError { kind: std::io::EndOfFile, .. }) => (), - Err(err) => fail!("read error: {}", err.desc), + Err(err) => panic!("read error: {}", err.desc), _ => () } diff --git a/src/cut/cut.rs b/src/cut/cut.rs index d3e663022..64ea51032 100644 --- a/src/cut/cut.rs +++ b/src/cut/cut.rs @@ -142,7 +142,7 @@ fn cut_characters(reader: R, let line = match buf_in.read_line() { Ok(line) => line, Err(std::io::IoError { kind: std::io::EndOfFile, .. }) => break, - _ => fail!(), + _ => panic!(), }; let mut char_pos = 0; @@ -248,7 +248,7 @@ fn cut_fields_delimiter(reader: R, let line = match buf_in.read_until(b'\n') { Ok(line) => line, Err(std::io::IoError { kind: std::io::EndOfFile, .. }) => break, - _ => fail!(), + _ => panic!(), }; let mut fields_pos = 1; @@ -330,7 +330,7 @@ fn cut_fields(reader: R, let line = match buf_in.read_until(b'\n') { Ok(line) => line, Err(std::io::IoError { kind: std::io::EndOfFile, .. }) => break, - _ => fail!(), + _ => panic!(), }; let mut fields_pos = 1; diff --git a/src/dirname/dirname.rs b/src/dirname/dirname.rs index 5406b263f..75db84529 100644 --- a/src/dirname/dirname.rs +++ b/src/dirname/dirname.rs @@ -25,7 +25,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(f) => fail!("Invalid options\n{}", f) + Err(f) => panic!("Invalid options\n{}", f) }; if matches.opt_present("help") { diff --git a/src/echo/echo.rs b/src/echo/echo.rs index 956f25a3a..7d19c7aff 100644 --- a/src/echo/echo.rs +++ b/src/echo/echo.rs @@ -55,7 +55,7 @@ fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) { let (max_digits, is_legal_digit) = match base { 8u => (3, isodigit), 16u => (2, isxdigit), - _ => fail!(), + _ => panic!(), }; let mut bytes = vec!(); diff --git a/src/fmt/parasplit.rs b/src/fmt/parasplit.rs index 7478615e0..bac590cdb 100644 --- a/src/fmt/parasplit.rs +++ b/src/fmt/parasplit.rs @@ -41,7 +41,7 @@ impl Line { fn get_formatline(self) -> FileLine { match self { FormatLine(fl) => fl, - NoFormatLine(..) => fail!("Found NoFormatLine when expecting FormatLine") + NoFormatLine(..) => panic!("Found NoFormatLine when expecting FormatLine") } } @@ -49,7 +49,7 @@ impl Line { fn get_noformatline(self) -> (String, bool) { match self { NoFormatLine(s, b) => (s, b), - FormatLine(..) => fail!("Found FormatLine when expecting NoFormatLine") + FormatLine(..) => panic!("Found FormatLine when expecting NoFormatLine") } } } diff --git a/src/hostname/hostname.rs b/src/hostname/hostname.rs index 35360b90d..322fd1062 100644 --- a/src/hostname/hostname.rs +++ b/src/hostname/hostname.rs @@ -139,7 +139,7 @@ fn xgethostname() -> String { }; if err != 0 { - fail!("Cannot determine hostname"); + panic!("Cannot determine hostname"); } let last_char = name.iter().position(|byte| *byte == 0).unwrap_or(namelen); diff --git a/src/link/link.rs b/src/link/link.rs index ed20dd1a4..81f6360b7 100644 --- a/src/link/link.rs +++ b/src/link/link.rs @@ -29,7 +29,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; if matches.opt_present("version") { diff --git a/src/mkfifo/mkfifo.rs b/src/mkfifo/mkfifo.rs index cdb7d2281..b53b64df5 100644 --- a/src/mkfifo/mkfifo.rs +++ b/src/mkfifo/mkfifo.rs @@ -32,7 +32,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; if matches.opt_present("version") { diff --git a/src/tail/tail.rs b/src/tail/tail.rs index ec1a6c164..99533d515 100644 --- a/src/tail/tail.rs +++ b/src/tail/tail.rs @@ -196,7 +196,7 @@ fn tail(reader: &mut BufferedReader, line_count: uint, byte_count: for io_line in reader.lines() { match io_line { Ok(line) => print!("{}", line), - Err(err) => fail!(err) + Err(err) => panic!(err) } } } @@ -225,7 +225,7 @@ fn tail_lines(reader: &mut BufferedReader, mut line_count: uint, b } ringbuf.push(line); } - Err(err) => fail!(err) + Err(err) => panic!(err) } } for line in ringbuf.iter() { @@ -253,7 +253,7 @@ fn tail_bytes(reader: &mut BufferedReader, mut byte_count: uint, b } ringbuf.push(byte); } - Err(err) => fail!(err) + Err(err) => panic!(err) } } for byte in ringbuf.iter() { diff --git a/src/touch/touch.rs b/src/touch/touch.rs index 9c13cb7dc..9752200e9 100644 --- a/src/touch/touch.rs +++ b/src/touch/touch.rs @@ -41,7 +41,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(e) => fail!("Invalid options\n{}", e) + Err(e) => panic!("Invalid options\n{}", e) }; if matches.opt_present("version") { @@ -65,7 +65,7 @@ pub fn uumain(args: Vec) -> int { if matches.opt_present("date") && matches.opts_present(["reference".to_string(), "t".to_string()]) || matches.opt_present("reference") && matches.opts_present(["date".to_string(), "t".to_string()]) || matches.opt_present("t") && matches.opts_present(["date".to_string(), "reference".to_string()]) { - fail!("Invalid options: cannot specify reference time from more than one source"); + panic!("Invalid options: cannot specify reference time from more than one source"); } let (mut atime, mut mtime) = @@ -97,7 +97,7 @@ pub fn uumain(args: Vec) -> int { match File::create(&path) { Ok(fd) => fd, - Err(e) => fail!("Unable to create file: {}\n{}", filename, e.desc) + Err(e) => panic!("Unable to create file: {}\n{}", filename, e.desc) }; // Minor optimization: if no reference time was specified, we're done. @@ -128,7 +128,7 @@ pub fn uumain(args: Vec) -> int { match std::io::fs::change_file_times(&path, atime, mtime) { Ok(t) => t, - Err(e) => fail!("Unable to modify times\n{}", e.desc) + Err(e) => panic!("Unable to modify times\n{}", e.desc) } } @@ -139,12 +139,12 @@ fn stat(path: &Path, follow: bool) -> std::io::FileStat { if follow { match std::io::fs::stat(path) { Ok(stat) => stat, - Err(e) => fail!("Unable to open file\n{}", e.desc) + Err(e) => panic!("Unable to open file\n{}", e.desc) } } else { match std::io::fs::lstat(path) { Ok(stat) => stat, - Err(e) => fail!("Unable to open file\n{}", e.desc) + Err(e) => panic!("Unable to open file\n{}", e.desc) } } } @@ -156,7 +156,7 @@ fn parse_date(str: &str) -> u64 { // http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;f=lib/parse-datetime.y match time::strptime(str, "%c") { Ok(tm) => (tm.to_timespec().sec * 1000) as u64, - Err(e) => fail!("Unable to parse date\n{}", e) + Err(e) => panic!("Unable to parse date\n{}", e) } } @@ -168,12 +168,12 @@ fn parse_timestamp(str: &str) -> u64 { 10 => "%y%m%d%H%M", 11 => "%m%d%H%M.%S", 8 => "%m%d%H%M", - _ => fail!("Unknown timestamp format") + _ => panic!("Unknown timestamp format") }; match time::strptime(str, format) { Ok(tm) => (tm.to_timespec().sec * 1000) as u64, - Err(e) => fail!("Unable to parse timestamp\n{}", e) + Err(e) => panic!("Unable to parse timestamp\n{}", e) } } diff --git a/src/tr/tr.rs b/src/tr/tr.rs index bb111aa31..791b962fe 100644 --- a/src/tr/tr.rs +++ b/src/tr/tr.rs @@ -103,7 +103,7 @@ fn delete(set: Vec, complement: bool) { match c { Ok(c) if is_allowed(c) => out.write_char(c).unwrap(), Ok(_) => (), - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; } } @@ -130,7 +130,7 @@ fn tr(set1: &[char], set2: &[char]) { out.write_char(trc).unwrap(); } Err(err) => { - fail!("{}", err); + panic!("{}", err); } } } diff --git a/src/users/users.rs b/src/users/users.rs index 7062cbd99..ba9914b14 100644 --- a/src/users/users.rs +++ b/src/users/users.rs @@ -61,7 +61,7 @@ pub fn uumain(args: Vec) -> int { let matches = match getopts::getopts(args.tail(), opts) { Ok(m) => m, - Err(f) => fail!("{}", f), + Err(f) => panic!("{}", f), }; if matches.opt_present("help") { diff --git a/test/cat.rs b/test/cat.rs index 96f31681e..61b997383 100644 --- a/test/cat.rs +++ b/test/cat.rs @@ -12,7 +12,7 @@ fn test_output_multi_files_print_all_chars() { .arg("-n").output() { Ok(p) => p, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; let out = str::from_utf8(po.output.as_slice()).unwrap(); diff --git a/test/mkdir.rs b/test/mkdir.rs index 402608292..be0bb743d 100644 --- a/test/mkdir.rs +++ b/test/mkdir.rs @@ -32,7 +32,7 @@ fn test_mkdir_dup_dir() { let exit_success = prog.unwrap().success(); if !exit_success { cleanup(TEST_DIR2); - fail!(); + panic!(); } let prog2 = Command::new(EXE).arg(TEST_DIR2).status(); let exit_success2 = prog2.unwrap().success(); diff --git a/test/mv.rs b/test/mv.rs index 143e50b92..eb688d8df 100644 --- a/test/mv.rs +++ b/test/mv.rs @@ -14,7 +14,7 @@ static EXE: &'static str = "./mv"; macro_rules! assert_empty_stderr( ($cond:expr) => ( if $cond.stderr.len() > 0 { - fail!(format!("stderr: {}", $cond.stderr)) + panic!(format!("stderr: {}", $cond.stderr)) } ); ) diff --git a/test/sort.rs b/test/sort.rs index bbc1f6c1f..292a63e44 100644 --- a/test/sort.rs +++ b/test/sort.rs @@ -34,13 +34,13 @@ fn numeric_helper(test_num: int) { cmd.arg("-n"); let po = match cmd.clone().arg(format!("{}{}{}", "numeric", test_num, ".txt")).output() { Ok(p) => p, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; let answer = match File::open(&Path::new(format!("{}{}{}", "numeric", test_num, ".ans"))) .read_to_end() { Ok(answer) => answer, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; assert_eq!(String::from_utf8(po.output), String::from_utf8(answer)); -} \ No newline at end of file +} diff --git a/test/tr.rs b/test/tr.rs index 4c7e7d706..281286d81 100644 --- a/test/tr.rs +++ b/test/tr.rs @@ -9,7 +9,7 @@ fn run(input: &str, args: &[&'static str]) -> Vec { let po = match process.wait_with_output() { Ok(p) => p, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; po.output } diff --git a/test/truncate.rs b/test/truncate.rs index 23ab29af1..a4eaf6c51 100644 --- a/test/truncate.rs +++ b/test/truncate.rs @@ -8,7 +8,7 @@ static TFILE2: &'static str = "truncate_test_2"; fn make_file(name: &str) -> io::File { match io::File::create(&Path::new(name)) { Ok(f) => f, - Err(_) => fail!() + Err(_) => panic!() } } @@ -16,11 +16,11 @@ fn make_file(name: &str) -> io::File { fn test_increase_file_size() { let mut file = make_file(TFILE1); if !Command::new(PROGNAME).args(["-s", "+5K", TFILE1]).status().unwrap().success() { - fail!(); + panic!(); } file.seek(0, io::SeekEnd).unwrap(); if file.tell().unwrap() != 5 * 1024 { - fail!(); + panic!(); } io::fs::unlink(&Path::new(TFILE1)).unwrap(); } @@ -30,12 +30,12 @@ fn test_decrease_file_size() { let mut file = make_file(TFILE2); file.write(b"1234567890").unwrap(); if !Command::new(PROGNAME).args(["--size=-4", TFILE2]).status().unwrap().success() { - fail!(); + panic!(); } file.seek(0, io::SeekEnd).unwrap(); if file.tell().unwrap() != 6 { println!("{}", file.tell()); - fail!(); + panic!(); } io::fs::unlink(&Path::new(TFILE2)).unwrap(); } diff --git a/test/unexpand.rs b/test/unexpand.rs index caf70ffad..4d7e660d1 100644 --- a/test/unexpand.rs +++ b/test/unexpand.rs @@ -9,7 +9,7 @@ fn run(input: &str, args: &[&'static str]) -> Vec { let po = match process.wait_with_output() { Ok(p) => p, - Err(err) => fail!("{}", err), + Err(err) => panic!("{}", err), }; po.output }