diff options
| author | bors <bors@rust-lang.org> | 2014-10-29 20:16:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-29 20:16:57 +0000 |
| commit | 77f44d4a7bf14805fda5fc41310a6aeffda30fd4 (patch) | |
| tree | aea7012d4afbf278ae64ce92cff06c3d2a7e00cc /src/libstd | |
| parent | 4769bca1483839ff9c0ad8353c206d6ee06c50e1 (diff) | |
| parent | 6ac7fc73f5acfe30c698ea4f8bfc37b30473977e (diff) | |
| download | rust-77f44d4a7bf14805fda5fc41310a6aeffda30fd4.tar.gz rust-77f44d4a7bf14805fda5fc41310a6aeffda30fd4.zip | |
auto merge of #17894 : steveklabnik/rust/fail_to_panic, r=aturon
This in-progress PR implements https://github.com/rust-lang/rust/issues/17489. I made the code changes in this commit, next is to go through alllllllll the documentation and fix various things. - Rename column headings as appropriate, `# Panics` for panic conditions and `# Errors` for `Result`s. - clean up usage of words like 'fail' in error messages Anything else to add to the list, @aturon ? I think I should leave the actual functions with names like `slice_or_fail` alone, since you'll get to those in your conventions work? I'm submitting just the code bits now so that we can see it separately, and I also don't want to have to keep re-building rust over and over again if I don't have to :wink: Listing all the bits so I can remember as I go: - [x] compiler-rt - [x] compiletest - [x] doc - [x] driver - [x] etc - [x] grammar - [x] jemalloc - [x] liballoc - [x] libarena - [x] libbacktrace - [x] libcollections - [x] libcore - [x] libcoretest - [x] libdebug - [x] libflate - [x] libfmt_macros - [x] libfourcc - [x] libgetopts - [x] libglob - [x] libgraphviz - [x] libgreen - [x] libhexfloat - [x] liblibc - [x] liblog - [x] libnative - [x] libnum - [x] librand - [x] librbml - [x] libregex - [x] libregex_macros - [x] librlibc - [x] librustc - [x] librustc_back - [x] librustc_llvm - [x] librustdoc - [x] librustrt - [x] libsemver - [x] libserialize - [x] libstd - [x] libsync - [x] libsyntax - [x] libterm - [x] libtest - [x] libtime - [x] libunicode - [x] liburl - [x] libuuid - [x] llvm - [x] rt - [x] test
Diffstat (limited to 'src/libstd')
35 files changed, 239 insertions, 239 deletions
diff --git a/src/libstd/ascii.rs b/src/libstd/ascii.rs index 6b6b08c5e6e..33c8e94e32b 100644 --- a/src/libstd/ascii.rs +++ b/src/libstd/ascii.rs @@ -138,7 +138,7 @@ impl<'a> fmt::Show for Ascii { /// Trait for converting into an ascii type. pub trait AsciiCast<T> { - /// Convert to an ascii type, fail on non-ASCII input. + /// Convert to an ascii type, panic on non-ASCII input. #[inline] fn to_ascii(&self) -> T { assert!(self.is_ascii()); @@ -649,16 +649,16 @@ mod tests { } #[test] #[should_fail] - fn test_ascii_vec_fail_u8_slice() { (&[127u8, 128u8, 255u8]).to_ascii(); } + fn test_ascii_vec_panic_u8_slice() { (&[127u8, 128u8, 255u8]).to_ascii(); } #[test] #[should_fail] - fn test_ascii_vec_fail_str_slice() { "zoä华".to_ascii(); } + fn test_ascii_vec_panic_str_slice() { "zoä华".to_ascii(); } #[test] #[should_fail] - fn test_ascii_fail_u8_slice() { 255u8.to_ascii(); } + fn test_ascii_panic_u8_slice() { 255u8.to_ascii(); } #[test] #[should_fail] - fn test_ascii_fail_char_slice() { 'λ'.to_ascii(); } + fn test_ascii_panic_char_slice() { 'λ'.to_ascii(); } #[test] fn test_opt() { diff --git a/src/libstd/c_vec.rs b/src/libstd/c_vec.rs index 7ec25acb173..bb7de168898 100644 --- a/src/libstd/c_vec.rs +++ b/src/libstd/c_vec.rs @@ -169,7 +169,7 @@ mod tests { fn malloc(n: uint) -> CVec<u8> { unsafe { let mem = libc::malloc(n as libc::size_t); - if mem.is_null() { fail!("out of memory") } + if mem.is_null() { panic!("out of memory") } CVec::new_with_dtor(mem as *mut u8, n, proc() { libc::free(mem as *mut libc::c_void); }) @@ -189,7 +189,7 @@ mod tests { #[test] #[should_fail] - fn test_fail_at_null() { + fn test_panic_at_null() { unsafe { CVec::new(ptr::null_mut::<u8>(), 9); } @@ -213,7 +213,7 @@ mod tests { fn test_unwrap() { unsafe { let cv = CVec::new_with_dtor(1 as *mut int, 0, - proc() { fail!("Don't run this destructor!") }); + proc() { panic!("Don't run this destructor!") }); let p = cv.unwrap(); assert_eq!(p, 1 as *mut int); } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index ac0d117e02a..6562a644988 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -120,8 +120,7 @@ impl DefaultResizePolicy { // is also memory and cache pressure that this would entail that would be very // difficult to properly see in a microbenchmark. // -// Future Improvements (FIXME!) -// ============================ +// ## Future Improvements (FIXME!) // // Allow the load factor to be changed dynamically and/or at initialization. // @@ -129,8 +128,7 @@ impl DefaultResizePolicy { // underlying table? This is exactly the use case for 'realloc', and may // be worth exploring. // -// Future Optimizations (FIXME!) -// ============================= +// ## Future Optimizations (FIXME!) // // Another possible design choice that I made without any real reason is // parameterizing the raw table over keys and values. Technically, all we need @@ -473,7 +471,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { }; buckets.next(); } - fail!("Internal HashMap error: Out of space."); + panic!("Internal HashMap error: Out of space."); } } @@ -829,7 +827,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { } /// Retrieves a mutable value for the given key. - /// See [`find_mut`](../trait.MutableMap.html#tymethod.find_mut) for a non-failing alternative. + /// See [`find_mut`](../trait.MutableMap.html#tymethod.find_mut) for a non-panicking + /// alternative. /// /// # Failure /// @@ -856,7 +855,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { pub fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V { match self.find_mut(k) { Some(v) => v, - None => fail!("no entry found for key") + None => panic!("no entry found for key") } } @@ -1625,7 +1624,7 @@ mod test_map { assert!(m.insert(5i, 14i)); let new = 100; match m.find_mut(&5) { - None => fail!(), Some(x) => *x = new + None => panic!(), Some(x) => *x = new } assert_eq!(m.find(&5), Some(&new)); } @@ -1746,7 +1745,7 @@ mod test_map { assert!(m.find(&1i).is_none()); m.insert(1i, 2i); match m.find(&1) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(*v, 2) } } @@ -1759,12 +1758,12 @@ mod test_map { for i in range(1i, 10000) { m.insert(i, i + 7); match m.find_copy(&i) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(v, i + 7) } for j in range(1i, i/100) { match m.find_copy(&j) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(v, j + 7) } } diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index ee64a7931c0..ca20c3ddb74 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -470,7 +470,7 @@ impl<K, V, M> BucketState<K, V, M> { pub fn expect_full(self) -> FullBucket<K, V, M> { match self { Full(full) => full, - Empty(..) => fail!("Expected full bucket") + Empty(..) => panic!("Expected full bucket") } } } diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index ed8ff821f5c..c2f27caad1d 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -44,7 +44,7 @@ impl Drop for DynamicLibrary { } }) { Ok(()) => {}, - Err(str) => fail!("{}", str) + Err(str) => panic!("{}", str) } } } @@ -168,13 +168,13 @@ mod test { // statically linked in let none: Option<Path> = None; // appease the typechecker let libm = match DynamicLibrary::open(none) { - Err(error) => fail!("Could not load self as module: {}", error), + Err(error) => panic!("Could not load self as module: {}", error), Ok(libm) => libm }; let cosine: extern fn(libc::c_double) -> libc::c_double = unsafe { match libm.symbol("cos") { - Err(error) => fail!("Could not load function cos: {}", error), + Err(error) => panic!("Could not load function cos: {}", error), Ok(cosine) => mem::transmute::<*mut u8, _>(cosine) } }; @@ -183,7 +183,7 @@ mod test { let expected_result = 1.0; let result = cosine(argument); if result != expected_result { - fail!("cos({}) != {} but equaled {} instead", argument, + panic!("cos({}) != {} but equaled {} instead", argument, expected_result, result) } } @@ -199,7 +199,7 @@ mod test { let path = Path::new("/dev/null"); match DynamicLibrary::open(Some(&path)) { Err(_) => {} - Ok(_) => fail!("Successfully opened the empty library.") + Ok(_) => panic!("Successfully opened the empty library.") } } } diff --git a/src/libstd/failure.rs b/src/libstd/failure.rs index a7de84184ff..07759974356 100644 --- a/src/libstd/failure.rs +++ b/src/libstd/failure.rs @@ -51,11 +51,11 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { // all times. This means that this `exists` will return true almost all of // the time. There are border cases, however, when the runtime has // *almost* set up the local task, but hasn't quite gotten there yet. In - // order to get some better diagnostics, we print on failure and + // order to get some better diagnostics, we print on panic and // immediately abort the whole process if there is no local task // available. if !Local::exists(None::<Task>) { - let _ = writeln!(&mut err, "failed at '{}', {}:{}", msg, file, line); + let _ = writeln!(&mut err, "panicked at '{}', {}:{}", msg, file, line); if backtrace::log_enabled() { let _ = backtrace::write(&mut err); } else { @@ -76,9 +76,9 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { match local_stderr.replace(None) { Some(mut stderr) => { - // FIXME: what to do when the task printing fails? + // FIXME: what to do when the task printing panics? let _ = writeln!(stderr, - "task '{}' failed at '{}', {}:{}\n", + "task '{}' panicked at '{}', {}:{}\n", n, msg, file, line); if backtrace::log_enabled() { let _ = backtrace::write(&mut *stderr); @@ -86,7 +86,7 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { local_stderr.replace(Some(stderr)); } None => { - let _ = writeln!(&mut err, "task '{}' failed at '{}', {}:{}", + let _ = writeln!(&mut err, "task '{}' panicked at '{}', {}:{}", n, msg, file, line); if backtrace::log_enabled() { let _ = backtrace::write(&mut err); @@ -94,8 +94,8 @@ pub fn on_fail(obj: &Any + Send, file: &'static str, line: uint) { } } - // If this is a double failure, make sure that we printed a backtrace - // for this failure. + // If this is a double panic, make sure that we printed a backtrace + // for this panic. if unwinding && !backtrace::log_enabled() { let _ = backtrace::write(&mut err); } diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 95c44e6a3fc..9cd8dbcc509 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -183,7 +183,7 @@ impl<W: Writer> BufferedWriter<W> { /// /// The buffer is flushed before returning the writer. pub fn unwrap(mut self) -> W { - // FIXME(#12628): is failing the right thing to do if flushing fails? + // FIXME(#12628): is panicking the right thing to do if flushing panicks? self.flush_buf().unwrap(); self.inner.take().unwrap() } @@ -214,7 +214,7 @@ impl<W: Writer> Writer for BufferedWriter<W> { impl<W: Writer> Drop for BufferedWriter<W> { fn drop(&mut self) { if self.inner.is_some() { - // dtors should not fail, so we ignore a failed flush + // dtors should not panic, so we ignore a panicked flush let _ = self.flush_buf(); } } @@ -612,7 +612,7 @@ mod test { #[test] #[should_fail] - fn dont_fail_in_drop_on_failed_flush() { + fn dont_panic_in_drop_on_panicked_flush() { struct FailFlushWriter; impl Writer for FailFlushWriter { @@ -623,9 +623,8 @@ mod test { let writer = FailFlushWriter; let _writer = BufferedWriter::new(writer); - // Trigger failure. If writer fails *again* due to the flush - // error then the process will abort. - fail!(); + // If writer panics *again* due to the flush error then the process will abort. + panic!(); } #[bench] diff --git a/src/libstd/io/comm_adapters.rs b/src/libstd/io/comm_adapters.rs index bd9577c8cfc..07f4ebda2d4 100644 --- a/src/libstd/io/comm_adapters.rs +++ b/src/libstd/io/comm_adapters.rs @@ -188,14 +188,14 @@ mod test { assert_eq!(a, buf.as_slice()); match reader.read(buf.as_mut_slice()) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } assert_eq!(a, buf.as_slice()); - // Ensure it continues to fail in the same way. + // Ensure it continues to panic in the same way. match reader.read(buf.as_mut_slice()) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } assert_eq!(a, buf.as_slice()); @@ -218,7 +218,7 @@ mod test { assert_eq!(Ok("hello world\n".to_string()), reader.read_line()); assert_eq!(Ok("how are you?".to_string()), reader.read_line()); match reader.read_line() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } } @@ -232,12 +232,12 @@ mod test { let wanted = vec![0u8, 0u8, 0u8, 42u8]; let got = match task::try(proc() { rx.recv() }) { Ok(got) => got, - Err(_) => fail!(), + Err(_) => panic!(), }; assert_eq!(wanted, got); match writer.write_u8(1) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::BrokenPipe), } } diff --git a/src/libstd/io/extensions.rs b/src/libstd/io/extensions.rs index 57741db5ae2..a595921fcf7 100644 --- a/src/libstd/io/extensions.rs +++ b/src/libstd/io/extensions.rs @@ -70,7 +70,7 @@ impl<'r, R: Reader> Iterator<IoResult<u8>> for Bytes<'r, R> { /// /// * `n`: The value to convert. /// * `size`: The size of the value, in bytes. This must be 8 or less, or task -/// failure occurs. If this is less than 8, then a value of that +/// panic occurs. If this is less than 8, then a value of that /// many bytes is produced. For example, if `size` is 4, then a /// 32-bit byte representation is produced. /// * `f`: A callback that receives the value. @@ -109,7 +109,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// /// * `n`: The value to convert. /// * `size`: The size of the value, in bytes. This must be 8 or less, or task -/// failure occurs. If this is less than 8, then a value of that +/// panic occurs. If this is less than 8, then a value of that /// many bytes is produced. For example, if `size` is 4, then a /// 32-bit byte representation is produced. /// * `f`: A callback that receives the value. @@ -146,7 +146,7 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T { /// * `data`: The buffer in which to extract the value. /// * `start`: The offset at which to extract the value. /// * `size`: The size of the value in bytes to extract. This must be 8 or -/// less, or task failure occurs. If this is less than 8, then only +/// less, or task panic occurs. If this is less than 8, then only /// that many bytes are parsed. For example, if `size` is 4, then a /// 32-bit value is parsed. pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { @@ -156,7 +156,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 { assert!(size <= 8u); if data.len() - start < size { - fail!("index out of bounds"); + panic!("index out of bounds"); } let mut buf = [0u8, ..8]; diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index 8632fc63e52..f749d6c823e 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -105,7 +105,7 @@ impl File { /// /// let file = match File::open_mode(&p, Open, ReadWrite) { /// Ok(f) => f, - /// Err(e) => fail!("file error: {}", e), + /// Err(e) => panic!("file error: {}", e), /// }; /// // do some stuff with that file /// @@ -957,13 +957,13 @@ mod test { macro_rules! check( ($e:expr) => ( match $e { Ok(t) => t, - Err(e) => fail!("{} failed with: {}", stringify!($e), e), + Err(e) => panic!("{} failed with: {}", stringify!($e), e), } ) ) macro_rules! error( ($e:expr, $s:expr) => ( match $e { - Ok(val) => fail!("Unexpected success. Should've been: {}", $s), + Ok(val) => panic!("Unexpected success. Should've been: {}", $s), Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()), format!("`{}` did not contain `{}`", err, $s)) } @@ -1013,7 +1013,7 @@ mod test { let mut read_stream = File::open_mode(filename, Open, Read); let mut read_buf = [0, .. 1028]; let read_str = match check!(read_stream.read(read_buf)) { - -1|0 => fail!("shouldn't happen"), + -1|0 => panic!("shouldn't happen"), n => str::from_utf8(read_buf[..n]).unwrap().to_string() }; assert_eq!(read_str.as_slice(), message); @@ -1241,7 +1241,7 @@ mod test { check!(File::open(f).read(mem)); let read_str = str::from_utf8(mem).unwrap(); let expected = match n { - None|Some("") => fail!("really shouldn't happen.."), + None|Some("") => panic!("really shouldn't happen.."), Some(n) => format!("{}{}", prefix, n), }; assert_eq!(expected.as_slice(), read_str); @@ -1371,7 +1371,7 @@ mod test { from.display(), to.display())); match copy(&from, &to) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(..) => { assert!(!from.exists()); assert!(!to.exists()); @@ -1400,7 +1400,7 @@ mod test { check!(File::create(&out)); match copy(&out, tmpdir.path()) { - Ok(..) => fail!(), Err(..) => {} + Ok(..) => panic!(), Err(..) => {} } } @@ -1424,7 +1424,7 @@ mod test { let out = tmpdir.join("out"); match copy(tmpdir.path(), &out) { - Ok(..) => fail!(), Err(..) => {} + Ok(..) => panic!(), Err(..) => {} } assert!(!out.exists()); } @@ -1475,7 +1475,7 @@ mod test { fn readlink_not_symlink() { let tmpdir = tmpdir(); match readlink(tmpdir.path()) { - Ok(..) => fail!("wanted a failure"), + Ok(..) => panic!("wanted a failure"), Err(..) => {} } } @@ -1501,12 +1501,12 @@ mod test { // can't link to yourself match link(&input, &input) { - Ok(..) => fail!("wanted a failure"), + Ok(..) => panic!("wanted a failure"), Err(..) => {} } // can't link to something that doesn't exist match link(&tmpdir.join("foo"), &tmpdir.join("bar")) { - Ok(..) => fail!("wanted a failure"), + Ok(..) => panic!("wanted a failure"), Err(..) => {} } } @@ -1522,7 +1522,7 @@ mod test { assert!(!check!(stat(&file)).perm.contains(io::USER_WRITE)); match chmod(&tmpdir.join("foo"), io::USER_RWX) { - Ok(..) => fail!("wanted a failure"), + Ok(..) => panic!("wanted a panic"), Err(..) => {} } @@ -1580,7 +1580,7 @@ mod test { let tmpdir = tmpdir(); match File::open_mode(&tmpdir.join("a"), io::Open, io::Read) { - Ok(..) => fail!(), Err(..) => {} + Ok(..) => panic!(), Err(..) => {} } // Perform each one twice to make sure that it succeeds the second time @@ -1615,7 +1615,7 @@ mod test { let mut f = check!(File::open_mode(&tmpdir.join("h"), io::Open, io::Read)); match f.write("wut".as_bytes()) { - Ok(..) => fail!(), Err(..) => {} + Ok(..) => panic!(), Err(..) => {} } } assert!(check!(stat(&tmpdir.join("h"))).size == 3, @@ -1653,7 +1653,7 @@ mod test { let tmpdir = tmpdir(); match change_file_times(&tmpdir.join("a"), 100, 200) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(..) => {} } } diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index dd4a3e05935..2f6dd7e4795 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -409,7 +409,7 @@ mod test { writer.write([0]).unwrap(); match writer.write([0, 0]) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::OtherIoError), } } @@ -510,7 +510,7 @@ mod test { let buf = [0xff]; let mut r = BufReader::new(buf); match r.read_to_string() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(..) => {} } } diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 8592d48974a..7826a6dd9c6 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1730,7 +1730,7 @@ pub enum FileType { /// # fn foo() { /// let info = match Path::new("foo.txt").stat() { /// Ok(stat) => stat, -/// Err(e) => fail!("couldn't read foo.txt: {}", e), +/// Err(e) => panic!("couldn't read foo.txt: {}", e), /// }; /// /// println!("byte size: {}", info.size); diff --git a/src/libstd/io/net/pipe.rs b/src/libstd/io/net/pipe.rs index e0cf761fdbd..112094d1d39 100644 --- a/src/libstd/io/net/pipe.rs +++ b/src/libstd/io/net/pipe.rs @@ -269,13 +269,13 @@ mod tests { spawn(proc() { match UnixStream::connect(&path2) { Ok(c) => client(c), - Err(e) => fail!("failed connect: {}", e), + Err(e) => panic!("failed connect: {}", e), } }); match acceptor.accept() { Ok(c) => server(c), - Err(e) => fail!("failed accept: {}", e), + Err(e) => panic!("failed accept: {}", e), } } @@ -283,7 +283,7 @@ mod tests { fn bind_error() { let path = "path/to/nowhere"; match UnixListener::bind(&path) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == PermissionDenied || e.kind == FileNotFound || e.kind == InvalidInput); @@ -299,7 +299,7 @@ mod tests { "path/to/nowhere" }; match UnixStream::connect(&path) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == FileNotFound || e.kind == OtherIoError); } @@ -358,7 +358,7 @@ mod tests { let mut acceptor = match UnixListener::bind(&path1).listen() { Ok(a) => a, - Err(e) => fail!("failed listen: {}", e), + Err(e) => panic!("failed listen: {}", e), }; spawn(proc() { @@ -366,7 +366,7 @@ mod tests { let mut stream = UnixStream::connect(&path2); match stream.write([100]) { Ok(..) => {} - Err(e) => fail!("failed write: {}", e) + Err(e) => panic!("failed write: {}", e) } } }); @@ -376,7 +376,7 @@ mod tests { let mut buf = [0]; match client.read(buf) { Ok(..) => {} - Err(e) => fail!("failed read/accept: {}", e), + Err(e) => panic!("failed read/accept: {}", e), } assert_eq!(buf[0], 100); } @@ -531,10 +531,10 @@ mod tests { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} - Err(e) => fail!("error: {}", e), + Err(e) => panic!("error: {}", e), } ::task::deschedule(); - if i == 1000 { fail!("should have a pending connection") } + if i == 1000 { panic!("should have a pending connection") } } drop(l); @@ -659,9 +659,9 @@ mod tests { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } // I'm not sure as to why, but apparently the write on windows always @@ -687,7 +687,7 @@ mod tests { while amt < 100 * 128 * 1024 { match s.read([0, ..128 * 1024]) { Ok(n) => { amt += n; } - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } } let _ = rx.recv_opt(); @@ -722,9 +722,9 @@ mod tests { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } tx.send(()); diff --git a/src/libstd/io/net/tcp.rs b/src/libstd/io/net/tcp.rs index d6528ce977e..09804ef5703 100644 --- a/src/libstd/io/net/tcp.rs +++ b/src/libstd/io/net/tcp.rs @@ -471,7 +471,7 @@ impl TcpAcceptor { /// match socket { /// Ok(s) => { /* handle s */ } /// Err(ref e) if e.kind == EndOfFile => break, // closed - /// Err(e) => fail!("unexpected error: {}", e), + /// Err(e) => panic!("unexpected error: {}", e), /// } /// } /// }); @@ -532,7 +532,7 @@ mod test { #[test] fn bind_error() { match TcpListener::bind("0.0.0.0", 1) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } } @@ -540,7 +540,7 @@ mod test { #[test] fn connect_error() { match TcpStream::connect("0.0.0.0", 1) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, ConnectionRefused), } } @@ -708,7 +708,7 @@ mod test { assert!(nread.is_err()); match stream.read(buf) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, "unknown kind: {}", e.kind); @@ -734,7 +734,7 @@ mod test { assert!(nread.is_err()); match stream.read(buf) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(ref e) => { assert!(e.kind == NotConnected || e.kind == EndOfFile, "unknown kind: {}", e.kind); @@ -1082,7 +1082,7 @@ mod test { let listener = TcpListener::bind(ip_str.as_slice(), port).unwrap().listen(); assert!(listener.is_ok()); match TcpListener::bind(ip_str.as_slice(), port).listen() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => { assert!(e.kind == ConnectionRefused || e.kind == OtherIoError, "unknown error: {} {}", e, e.kind); @@ -1266,10 +1266,10 @@ mod test { match a.accept() { Ok(..) => break, Err(ref e) if e.kind == TimedOut => {} - Err(e) => fail!("error: {}", e), + Err(e) => panic!("error: {}", e), } ::task::deschedule(); - if i == 1000 { fail!("should have a pending connection") } + if i == 1000 { panic!("should have a pending connection") } } } @@ -1373,9 +1373,9 @@ mod test { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } assert_eq!(s.write([0]).err().unwrap().kind, TimedOut); @@ -1398,7 +1398,7 @@ mod test { while amt < 100 * 128 * 1024 { match s.read([0, ..128 * 1024]) { Ok(n) => { amt += n; } - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } } let _ = rx.recv_opt(); @@ -1435,9 +1435,9 @@ mod test { match s.write([0, .. 128 * 1024]) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("{}", e), + Err(e) => panic!("{}", e), } - if i == 1000 { fail!("should have filled up?!"); } + if i == 1000 { panic!("should have filled up?!"); } } assert_eq!(s.write([0]).err().unwrap().kind, TimedOut); diff --git a/src/libstd/io/net/udp.rs b/src/libstd/io/net/udp.rs index 7d9eea3a732..ad9ed090a5b 100644 --- a/src/libstd/io/net/udp.rs +++ b/src/libstd/io/net/udp.rs @@ -43,7 +43,7 @@ use rt::rtio; /// let addr = SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 34254 }; /// let mut socket = match UdpSocket::bind(addr) { /// Ok(s) => s, -/// Err(e) => fail!("couldn't bind socket: {}", e), +/// Err(e) => panic!("couldn't bind socket: {}", e), /// }; /// /// let mut buf = [0, ..10]; @@ -271,7 +271,7 @@ mod test { fn bind_error() { let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 }; match UdpSocket::bind(addr) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, PermissionDenied), } } @@ -289,7 +289,7 @@ mod test { rx1.recv(); client.send_to([99], server_ip).unwrap() } - Err(..) => fail!() + Err(..) => panic!() } tx2.send(()); }); @@ -304,10 +304,10 @@ mod test { assert_eq!(buf[0], 99); assert_eq!(src, client_ip); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -324,7 +324,7 @@ mod test { rx.recv(); client.send_to([99], server_ip).unwrap() } - Err(..) => fail!() + Err(..) => panic!() } }); @@ -338,10 +338,10 @@ mod test { assert_eq!(buf[0], 99); assert_eq!(src, client_ip); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } } @@ -362,7 +362,7 @@ mod test { let mut stream = client.connect(server_ip); stream.write(val).unwrap(); } - Err(..) => fail!() + Err(..) => panic!() } }; rx1.recv(); @@ -382,10 +382,10 @@ mod test { assert_eq!(nread, 1); assert_eq!(buf[0], 99); } - Err(..) => fail!(), + Err(..) => panic!(), } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -406,7 +406,7 @@ mod test { rx1.recv(); stream.write([99]).unwrap(); } - Err(..) => fail!() + Err(..) => panic!() } tx2.send(()); }); @@ -422,10 +422,10 @@ mod test { assert_eq!(nread, 1); assert_eq!(buf[0], 99); } - Err(..) => fail!() + Err(..) => panic!() } } - Err(..) => fail!() + Err(..) => panic!() } rx2.recv(); } @@ -535,7 +535,7 @@ mod test { rx.recv(); match sock2.recv_from(buf) { Ok(..) => {} - Err(e) => fail!("failed receive: {}", e), + Err(e) => panic!("failed receive: {}", e), } serv_tx.send(()); }); @@ -612,7 +612,7 @@ mod test { match a.send_to([0, ..4*1024], addr2) { Ok(()) | Err(IoError { kind: ShortWrite(..), .. }) => {}, Err(IoError { kind: TimedOut, .. }) => break, - Err(e) => fail!("other error: {}", e), + Err(e) => panic!("other error: {}", e), } } } diff --git a/src/libstd/io/process.rs b/src/libstd/io/process.rs index 88f8434b957..36d23590704 100644 --- a/src/libstd/io/process.rs +++ b/src/libstd/io/process.rs @@ -56,7 +56,7 @@ use std::hash::sip::SipState; /// /// let mut child = match Command::new("/bin/cat").arg("file.txt").spawn() { /// Ok(child) => child, -/// Err(e) => fail!("failed to execute child: {}", e), +/// Err(e) => panic!("failed to execute child: {}", e), /// }; /// /// let contents = child.stdout.as_mut().unwrap().read_to_end(); @@ -145,7 +145,7 @@ pub type EnvMap = HashMap<EnvKey, CString>; /// /// let mut process = match Command::new("sh").arg("-c").arg("echo hello").spawn() { /// Ok(p) => p, -/// Err(e) => fail!("failed to execute process: {}", e), +/// Err(e) => panic!("failed to execute process: {}", e), /// }; /// /// let output = process.stdout.as_mut().unwrap().read_to_end(); @@ -372,7 +372,7 @@ impl Command { /// /// let output = match Command::new("cat").arg("foot.txt").output() { /// Ok(output) => output, - /// Err(e) => fail!("failed to execute process: {}", e), + /// Err(e) => panic!("failed to execute process: {}", e), /// }; /// /// println!("status: {}", output.status); @@ -393,7 +393,7 @@ impl Command { /// /// let status = match Command::new("ls").status() { /// Ok(status) => status, - /// Err(e) => fail!("failed to execute process: {}", e), + /// Err(e) => panic!("failed to execute process: {}", e), /// }; /// /// println!("process exited with: {}", status); @@ -691,7 +691,7 @@ mod tests { #[test] fn smoke_failure() { match Command::new("if-this-is-a-binary-then-the-world-has-ended").spawn() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(..) => {} } } @@ -714,7 +714,7 @@ mod tests { let mut p = p.unwrap(); match p.wait().unwrap() { process::ExitSignal(1) => {}, - result => fail!("not terminated by signal 1 (instead, {})", result), + result => panic!("not terminated by signal 1 (instead, {})", result), } } @@ -815,7 +815,7 @@ mod tests { fn test_process_output_fail_to_start() { match Command::new("/no-binary-by-this-name-should-exist").output() { Err(e) => assert_eq!(e.kind, FileNotFound), - Ok(..) => fail!() + Ok(..) => panic!() } } @@ -1063,7 +1063,7 @@ mod tests { } timer::sleep(Duration::milliseconds(100)); } - fail!("never saw the child go away"); + panic!("never saw the child go away"); } #[test] @@ -1121,7 +1121,7 @@ mod tests { let mut fdes = match file::open(&path.to_c_str(), Truncate, Write) { Ok(f) => f, - Err(_) => fail!("failed to open file descriptor"), + Err(_) => panic!("failed to open file descriptor"), }; let mut cmd = pwd_cmd(); diff --git a/src/libstd/io/result.rs b/src/libstd/io/result.rs index 03637079241..40793d98ee3 100644 --- a/src/libstd/io/result.rs +++ b/src/libstd/io/result.rs @@ -96,11 +96,11 @@ mod test { Err(io::standard_error(io::EndOfFile)); match writer.write([0, 0, 0]) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } match writer.flush() { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } } @@ -122,7 +122,7 @@ mod test { let mut buf = []; match reader.read(buf) { - Ok(..) => fail!(), + Ok(..) => panic!(), Err(e) => assert_eq!(e.kind, io::EndOfFile), } } diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index 93037f765d6..5fd4faff6d2 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -176,8 +176,8 @@ pub fn set_stdout(stdout: Box<Writer + Send>) -> Option<Box<Writer + Send>> { /// Resets the task-local stderr handle to the specified writer /// /// This will replace the current task's stderr handle, returning the old -/// handle. Currently, the stderr handle is used for printing failure messages -/// during task failure. +/// handle. Currently, the stderr handle is used for printing panic messages +/// during task panic. /// /// Note that this does not need to be called for all new tasks; the default /// output handle is to the process's stderr stream. @@ -212,7 +212,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) { }; match result { Ok(()) => {} - Err(e) => fail!("failed printing to stdout: {}", e), + Err(e) => panic!("failed printing to stdout: {}", e), } } @@ -415,7 +415,7 @@ mod tests { let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx)); spawn(proc() { ::realstd::io::stdio::set_stderr(box w); - fail!("my special message"); + panic!("my special message"); }); let s = r.read_to_string().unwrap(); assert!(s.as_slice().contains("my special message")); diff --git a/src/libstd/io/test.rs b/src/libstd/io/test.rs index 9b4333a6d82..6571dc41585 100644 --- a/src/libstd/io/test.rs +++ b/src/libstd/io/test.rs @@ -139,14 +139,14 @@ mod darwin_fd_limit { if sysctl(&mut mib[0], 2, &mut maxfiles as *mut libc::c_int as *mut libc::c_void, &mut size, null_mut(), 0) != 0 { let err = last_os_error(); - fail!("raise_fd_limit: error calling sysctl: {}", err); + panic!("raise_fd_limit: error calling sysctl: {}", err); } // Fetch the current resource limits let mut rlim = rlimit{rlim_cur: 0, rlim_max: 0}; if getrlimit(RLIMIT_NOFILE, &mut rlim) != 0 { let err = last_os_error(); - fail!("raise_fd_limit: error calling getrlimit: {}", err); + panic!("raise_fd_limit: error calling getrlimit: {}", err); } // Bump the soft limit to the smaller of kern.maxfilesperproc and the hard limit @@ -155,7 +155,7 @@ mod darwin_fd_limit { // Set our newly-increased resource limit if setrlimit(RLIMIT_NOFILE, &rlim) != 0 { let err = last_os_error(); - fail!("raise_fd_limit: error calling setrlimit: {}", err); + panic!("raise_fd_limit: error calling setrlimit: {}", err); } } } diff --git a/src/libstd/io/timer.rs b/src/libstd/io/timer.rs index a657989fe12..d16199da77f 100644 --- a/src/libstd/io/timer.rs +++ b/src/libstd/io/timer.rs @@ -340,7 +340,7 @@ mod test { fn oneshot_fail() { let mut timer = Timer::new().unwrap(); let _rx = timer.oneshot(Duration::milliseconds(1)); - fail!(); + panic!(); } #[test] @@ -348,14 +348,14 @@ mod test { fn period_fail() { let mut timer = Timer::new().unwrap(); let _rx = timer.periodic(Duration::milliseconds(1)); - fail!(); + panic!(); } #[test] #[should_fail] fn normal_fail() { let _timer = Timer::new().unwrap(); - fail!(); + panic!(); } #[test] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index c47cd025994..5451d07ab46 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -91,7 +91,7 @@ //! Finally, the [`prelude`](prelude/index.html) defines a //! common set of traits, types, and functions that are made available //! to all code by default. [`macros`](macros/index.html) contains -//! all the standard macros, such as `assert!`, `fail!`, `println!`, +//! all the standard macros, such as `assert!`, `panic!`, `println!`, //! and `format!`, also available to all Rust code. #![crate_name = "std"] @@ -261,7 +261,7 @@ mod std { pub use io; // used for println!() pub use local_data; // used for local_data_key!() pub use option; // used for bitflags!{} - pub use rt; // used for fail!() + pub use rt; // used for panic!() pub use vec; // used for vec![] // The test runner calls ::std::os::args() but really wants realstd diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 1ad3d6eed94..9e0530a76f2 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -17,29 +17,29 @@ #![experimental] #![macro_escape] -/// The entry point for failure of rust tasks. +/// The entry point for panic of Rust tasks. /// -/// This macro is used to inject failure into a rust task, causing the task to -/// unwind and fail entirely. Each task's failure can be reaped as the -/// `Box<Any>` type, and the single-argument form of the `fail!` macro will be +/// This macro is used to inject panic into a Rust task, causing the task to +/// unwind and panic entirely. Each task's panic can be reaped as the +/// `Box<Any>` type, and the single-argument form of the `panic!` macro will be /// the value which is transmitted. /// -/// The multi-argument form of this macro fails with a string and has the +/// The multi-argument form of this macro panics with a string and has the /// `format!` syntax for building a string. /// /// # Example /// /// ```should_fail /// # #![allow(unreachable_code)] -/// fail!(); -/// fail!("this is a terrible mistake!"); -/// fail!(4i); // fail with the value of 4 to be collected elsewhere -/// fail!("this is a {} {message}", "fancy", message = "message"); +/// panic!(); +/// panic!("this is a terrible mistake!"); +/// panic!(4i); // panic with the value of 4 to be collected elsewhere +/// panic!("this is a {} {message}", "fancy", message = "message"); /// ``` #[macro_export] -macro_rules! fail( +macro_rules! panic( () => ({ - fail!("explicit failure") + panic!("explicit panic") }); ($msg:expr) => ({ // static requires less code at runtime, more constant data @@ -57,7 +57,7 @@ macro_rules! fail( // as returning !. We really do want this to be inlined, however, // because it's just a tiny wrapper. Small wins (156K to 149K in size) // were seen when forcing this to be inlined, and that number just goes - // up with the number of calls to fail!() + // up with the number of calls to panic!() // // The leading _'s are to avoid dead code warnings if this is // used inside a dead function. Just `#[allow(dead_code)]` is @@ -74,13 +74,13 @@ macro_rules! fail( /// Ensure that a boolean expression is `true` at runtime. /// -/// This will invoke the `fail!` macro if the provided expression cannot be +/// This will invoke the `panic!` macro if the provided expression cannot be /// evaluated to `true` at runtime. /// /// # Example /// /// ``` -/// // the failure message for these assertions is the stringified value of the +/// // the panic message for these assertions is the stringified value of the /// // expression given. /// assert!(true); /// # fn some_computation() -> bool { true } @@ -96,12 +96,12 @@ macro_rules! fail( macro_rules! assert( ($cond:expr) => ( if !$cond { - fail!(concat!("assertion failed: ", stringify!($cond))) + panic!(concat!("assertion failed: ", stringify!($cond))) } ); ($cond:expr, $($arg:expr),+) => ( if !$cond { - fail!($($arg),+) + panic!($($arg),+) } ); ) @@ -109,7 +109,7 @@ macro_rules! assert( /// Asserts that two expressions are equal to each other, testing equality in /// both directions. /// -/// On failure, this macro will print the values of the expressions. +/// On panic, this macro will print the values of the expressions. /// /// # Example /// @@ -126,7 +126,7 @@ macro_rules! assert_eq( // check both directions of equality.... if !((*given_val == *expected_val) && (*expected_val == *given_val)) { - fail!("assertion failed: `(left == right) && (right == left)` \ + panic!("assertion failed: `(left == right) && (right == left)` \ (left: `{}`, right: `{}`)", *given_val, *expected_val) } } @@ -136,7 +136,7 @@ macro_rules! assert_eq( /// Ensure that a boolean expression is `true` at runtime. /// -/// This will invoke the `fail!` macro if the provided expression cannot be +/// This will invoke the `panic!` macro if the provided expression cannot be /// evaluated to `true` at runtime. /// /// Unlike `assert!`, `debug_assert!` statements can be disabled by passing @@ -147,7 +147,7 @@ macro_rules! assert_eq( /// # Example /// /// ``` -/// // the failure message for these assertions is the stringified value of the +/// // the panic message for these assertions is the stringified value of the /// // expression given. /// debug_assert!(true); /// # fn some_expensive_computation() -> bool { true } @@ -167,7 +167,7 @@ macro_rules! debug_assert( /// Asserts that two expressions are equal to each other, testing equality in /// both directions. /// -/// On failure, this macro will print the values of the expressions. +/// On panic, this macro will print the values of the expressions. /// /// Unlike `assert_eq!`, `debug_assert_eq!` statements can be disabled by /// passing `--cfg ndebug` to the compiler. This makes `debug_assert_eq!` @@ -186,7 +186,7 @@ macro_rules! debug_assert_eq( ($($arg:tt)*) => (if cfg!(not(ndebug)) { assert_eq!($($arg)*); }) ) -/// A utility macro for indicating unreachable code. It will fail if +/// A utility macro for indicating unreachable code. It will panic if /// executed. This is occasionally useful to put after loops that never /// terminate normally, but instead directly return from a function. /// @@ -211,14 +211,14 @@ macro_rules! debug_assert_eq( /// ``` #[macro_export] macro_rules! unreachable( - () => (fail!("internal error: entered unreachable code")) + () => (panic!("internal error: entered unreachable code")) ) -/// A standardised placeholder for marking unfinished code. It fails with the +/// A standardised placeholder for marking unfinished code. It panics with the /// message `"not yet implemented"` when executed. #[macro_export] macro_rules! unimplemented( - () => (fail!("not yet implemented")) + () => (panic!("not yet implemented")) ) /// Use the syntax described in `std::fmt` to create a value of type `String`. diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index af66e6ca934..6e0d81a63c9 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -264,10 +264,10 @@ pub fn float_to_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Float+ assert!(2 <= radix && radix <= 36); match exp_format { ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e' - => fail!("float_to_str_bytes_common: radix {} incompatible with \ + => panic!("float_to_str_bytes_common: radix {} incompatible with \ use of 'e' as decimal exponent", radix), ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p' - => fail!("float_to_str_bytes_common: radix {} incompatible with \ + => panic!("float_to_str_bytes_common: radix {} incompatible with \ use of 'p' as binary exponent", radix), _ => () } @@ -553,19 +553,19 @@ pub fn from_str_bytes_common<T:NumCast+Zero+One+PartialEq+PartialOrd+Div<T,T>+ ) -> Option<T> { match exponent { ExpDec if radix >= DIGIT_E_RADIX // decimal exponent 'e' - => fail!("from_str_bytes_common: radix {} incompatible with \ + => panic!("from_str_bytes_common: radix {} incompatible with \ use of 'e' as decimal exponent", radix), ExpBin if radix >= DIGIT_P_RADIX // binary exponent 'p' - => fail!("from_str_bytes_common: radix {} incompatible with \ + => panic!("from_str_bytes_common: radix {} incompatible with \ use of 'p' as binary exponent", radix), _ if special && radix >= DIGIT_I_RADIX // first digit of 'inf' - => fail!("from_str_bytes_common: radix {} incompatible with \ + => panic!("from_str_bytes_common: radix {} incompatible with \ special values 'inf' and 'NaN'", radix), _ if (radix as int) < 2 - => fail!("from_str_bytes_common: radix {} to low, \ + => panic!("from_str_bytes_common: radix {} to low, \ must lie in the range [2, 36]", radix), _ if (radix as int) > 36 - => fail!("from_str_bytes_common: radix {} to high, \ + => panic!("from_str_bytes_common: radix {} to high, \ must lie in the range [2, 36]", radix), _ => () } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index e758dec6bff..c7994ae84e8 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -96,7 +96,7 @@ pub fn getcwd() -> Path { let mut buf = [0 as c_char, ..BUF_BYTES]; unsafe { if libc::getcwd(buf.as_mut_ptr(), buf.len() as libc::size_t).is_null() { - fail!() + panic!() } Path::new(CString::new(buf.as_ptr(), false)) } @@ -130,7 +130,7 @@ pub fn getcwd() -> Path { let mut buf = [0 as u16, ..BUF_BYTES]; unsafe { if libc::GetCurrentDirectoryW(buf.len() as DWORD, buf.as_mut_ptr()) == 0 as DWORD { - fail!(); + panic!(); } } Path::new(String::from_utf16(::str::truncate_utf16_at_nul(buf)) @@ -238,7 +238,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> { }; let ch = GetEnvironmentStringsW(); if ch as uint == 0 { - fail!("os::env() failure getting env string from OS: {}", + panic!("os::env() failure getting env string from OS: {}", os::last_os_error()); } // Here, we lossily decode the string as UTF16. @@ -280,7 +280,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> { } let mut environ = rust_env_pairs(); if environ as uint == 0 { - fail!("os::env() failure getting env string from OS: {}", + panic!("os::env() failure getting env string from OS: {}", os::last_os_error()); } let mut result = Vec::new(); @@ -1009,7 +1009,7 @@ pub fn error_string(errnum: uint) -> String { let p = buf.as_mut_ptr(); unsafe { if strerror_r(errnum as c_int, p, buf.len() as libc::size_t) < 0 { - fail!("strerror_r failure"); + panic!("strerror_r failure"); } ::string::raw::from_buf(p as *const u8) @@ -1079,9 +1079,9 @@ static EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT; * Sets the process exit code * * Sets the exit code returned by the process if all supervised tasks - * terminate successfully (without failing). If the current root task fails + * terminate successfully (without panicking). If the current root task panics * and is supervised by the scheduler then any user-specified exit status is - * ignored and the process exits with the default failure status. + * ignored and the process exits with the default panic status. * * Note that this is not synchronized against modifications of other threads. */ @@ -1185,7 +1185,7 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> { match rt::args::clone() { Some(args) => args, - None => fail!("process arguments not initialized") + None => panic!("process arguments not initialized") } } @@ -1511,12 +1511,12 @@ impl MemoryMap { #[cfg(unix)] impl Drop for MemoryMap { - /// Unmap the mapping. Fails the task if `munmap` fails. + /// Unmap the mapping. Panics the task if `munmap` panics. fn drop(&mut self) { if self.len == 0 { /* workaround for dummy_stack */ return; } unsafe { - // `munmap` only fails due to logic errors + // `munmap` only panics due to logic errors libc::munmap(self.data as *mut c_void, self.len as libc::size_t); } } @@ -2098,7 +2098,7 @@ mod tests { os::MapWritable ]) { Ok(chunk) => chunk, - Err(msg) => fail!("{}", msg) + Err(msg) => panic!("{}", msg) }; assert!(chunk.len >= 16); @@ -2147,7 +2147,7 @@ mod tests { MapOffset(size / 2) ]) { Ok(chunk) => chunk, - Err(msg) => fail!("{}", msg) + Err(msg) => panic!("{}", msg) }; assert!(chunk.len > 0); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 4456cf96094..1897c8638cc 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1343,7 +1343,7 @@ mod tests { #[test] #[should_fail] - fn test_not_utf8_fail() { + fn test_not_utf8_panics() { Path::new(b"hello\x80.txt"); } diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 29eae0ced54..d1c655cb4d0 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -297,7 +297,7 @@ impl<'a> SeedableRng<&'a [uint]> for StdRng { pub fn weak_rng() -> XorShiftRng { match OsRng::new() { Ok(mut r) => r.gen(), - Err(e) => fail!("weak_rng: failed to create seeded RNG: {}", e) + Err(e) => panic!("weak_rng: failed to create seeded RNG: {}", e) } } @@ -308,7 +308,7 @@ impl reseeding::Reseeder<StdRng> for TaskRngReseeder { fn reseed(&mut self, rng: &mut StdRng) { *rng = match StdRng::new() { Ok(r) => r, - Err(e) => fail!("could not reseed task_rng: {}", e) + Err(e) => panic!("could not reseed task_rng: {}", e) } } } @@ -339,7 +339,7 @@ pub fn task_rng() -> TaskRng { None => { let r = match StdRng::new() { Ok(r) => r, - Err(e) => fail!("could not initialize task_rng: {}", e) + Err(e) => panic!("could not initialize task_rng: {}", e) }; let rng = reseeding::ReseedingRng::new(r, TASK_RNG_RESEED_THRESHOLD, @@ -445,7 +445,7 @@ mod test { // use this to get nicer error messages. for (i, &byte) in v.iter().enumerate() { if byte == 0 { - fail!("byte {} of {} is zero", i, n) + panic!("byte {} of {} is zero", i, n) } } } @@ -472,14 +472,14 @@ mod test { #[test] #[should_fail] - fn test_gen_range_fail_int() { + fn test_gen_range_panic_int() { let mut r = task_rng(); r.gen_range(5i, -2); } #[test] #[should_fail] - fn test_gen_range_fail_uint() { + fn test_gen_range_panic_uint() { let mut r = task_rng(); r.gen_range(5u, 2u); } diff --git a/src/libstd/rand/os.rs b/src/libstd/rand/os.rs index 91308be21ed..424fd039fd4 100644 --- a/src/libstd/rand/os.rs +++ b/src/libstd/rand/os.rs @@ -120,7 +120,7 @@ mod imp { SecRandomCopyBytes(kSecRandomDefault, v.len() as size_t, v.as_mut_ptr()) }; if ret == -1 { - fail!("couldn't generate random bytes: {}", os::last_os_error()); + panic!("couldn't generate random bytes: {}", os::last_os_error()); } } } @@ -208,7 +208,7 @@ mod imp { v.as_mut_ptr()) }; if ret == 0 { - fail!("couldn't generate random bytes: {}", os::last_os_error()); + panic!("couldn't generate random bytes: {}", os::last_os_error()); } } } @@ -219,7 +219,7 @@ mod imp { CryptReleaseContext(self.hcryptprov, 0) }; if ret == 0 { - fail!("couldn't release context: {}", os::last_os_error()); + panic!("couldn't release context: {}", os::last_os_error()); } } } diff --git a/src/libstd/rand/reader.rs b/src/libstd/rand/reader.rs index 8ca1cec3e0a..4f220531237 100644 --- a/src/libstd/rand/reader.rs +++ b/src/libstd/rand/reader.rs @@ -18,7 +18,9 @@ use result::{Ok, Err}; /// An RNG that reads random bytes straight from a `Reader`. This will /// work best with an infinite reader, but this is not required. /// -/// It will fail if it there is insufficient data to fulfill a request. +/// # Panics +/// +/// It will panic if it there is insufficient data to fulfill a request. /// /// # Example /// @@ -65,7 +67,7 @@ impl<R: Reader> Rng for ReaderRng<R> { if v.len() == 0 { return } match self.reader.read_at_least(v.len(), v) { Ok(_) => {} - Err(e) => fail!("ReaderRng.fill_bytes error: {}", e) + Err(e) => panic!("ReaderRng.fill_bytes error: {}", e) } } } diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index e05e533be56..5bd39277275 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Simple backtrace functionality (to print on failure) +//! Simple backtrace functionality (to print on panic) #![allow(non_camel_case_types)] @@ -265,7 +265,7 @@ mod imp { // while it doesn't requires lock for work as everything is // local, it still displays much nicer backtraces when a - // couple of tasks fail simultaneously + // couple of tasks panic simultaneously static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _g = unsafe { LOCK.lock() }; @@ -327,7 +327,7 @@ mod imp { // FindEnclosingFunction on non-osx platforms. In doing so, we get a // slightly more accurate stack trace in the process. // - // This is often because failure involves the last instruction of a + // This is often because panic involves the last instruction of a // function being "call std::rt::begin_unwind", with no ret // instructions after it. This means that the return instruction // pointer points *outside* of the calling function, and by diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index a91c6c572e6..e36d4ce8d4b 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -67,7 +67,7 @@ pub use rustrt::{task, local, mutex, exclusive, stack, args, rtio, thread}; pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt}; pub use rustrt::{bookkeeping, at_exit, unwind, DEFAULT_ERROR_CODE, Runtime}; -// Simple backtrace functionality (to print on failure) +// Simple backtrace functionality (to print on panic) pub mod backtrace; // Just stuff diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index ec301369804..56f2dbf667a 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -62,7 +62,7 @@ pub fn default_sched_threads() -> uint { let opt_n: Option<uint> = FromStr::from_str(nstr.as_slice()); match opt_n { Some(n) if n > 0 => n, - _ => fail!("`RUST_THREADS` is `{}`, should be a positive integer", nstr) + _ => panic!("`RUST_THREADS` is `{}`, should be a positive integer", nstr) } } None => { diff --git a/src/libstd/sync/future.rs b/src/libstd/sync/future.rs index 621c08fe7bc..36070509432 100644 --- a/src/libstd/sync/future.rs +++ b/src/libstd/sync/future.rs @@ -58,7 +58,7 @@ impl<A> Future<A> { let state = replace(&mut self.state, Evaluating); match state { Forced(v) => v, - _ => fail!( "Logic error." ), + _ => panic!( "Logic error." ), } } @@ -70,10 +70,10 @@ impl<A> Future<A> { */ match self.state { Forced(ref v) => return v, - Evaluating => fail!("Recursive forcing of future!"), + Evaluating => panic!("Recursive forcing of future!"), Pending(_) => { match replace(&mut self.state, Evaluating) { - Forced(_) | Evaluating => fail!("Logic error."), + Forced(_) | Evaluating => panic!("Logic error."), Pending(f) => { self.state = Forced(f()); self.get_ref() @@ -132,7 +132,7 @@ impl<A:Send> Future<A> { let (tx, rx) = channel(); spawn(proc() { - // Don't fail if the other end has hung up + // Don't panic if the other end has hung up let _ = tx.send_opt(blk()); }); @@ -193,8 +193,8 @@ mod test { #[test] #[should_fail] - fn test_futurefail() { - let mut f = Future::spawn(proc() fail!()); + fn test_future_panic() { + let mut f = Future::spawn(proc() panic!()); let _x: String = f.get(); } @@ -211,7 +211,7 @@ mod test { } #[test] - fn test_dropped_future_doesnt_fail() { + fn test_dropped_future_doesnt_panic() { struct Bomb(Sender<bool>); local_data_key!(LOCAL: Bomb) @@ -224,13 +224,13 @@ mod test { } // Spawn a future, but drop it immediately. When we receive the result - // later on, we should never view the task as having failed. + // later on, we should never view the task as having panicked. let (tx, rx) = channel(); drop(Future::spawn(proc() { LOCAL.replace(Some(Bomb(tx))); })); - // Make sure the future didn't fail the task. + // Make sure the future didn't panic the task. assert!(!rx.recv()); } } diff --git a/src/libstd/sync/task_pool.rs b/src/libstd/sync/task_pool.rs index a00eeb1f938..d4a60fb5844 100644 --- a/src/libstd/sync/task_pool.rs +++ b/src/libstd/sync/task_pool.rs @@ -42,9 +42,9 @@ impl<T> TaskPool<T> { /// `init_fn_factory` returns a function which, given the index of the /// task, should return local data to be kept around in that task. /// - /// # Failure + /// # Panics /// - /// This function will fail if `n_tasks` is less than 1. + /// This function will panic if `n_tasks` is less than 1. pub fn new(n_tasks: uint, init_fn_factory: || -> proc(uint):Send -> T) -> TaskPool<T> { @@ -96,7 +96,7 @@ fn test_task_pool() { #[test] #[should_fail] -fn test_zero_tasks_failure() { +fn test_zero_tasks_panic() { let f: || -> proc(uint):Send -> uint = || { proc(i) i }; TaskPool::new(0, f); } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 1d1e6ae4feb..c79b8715c06 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -28,12 +28,12 @@ //! using the atomically-reference-counted container, //! [`Arc`](../../std/sync/struct.Arc.html). //! -//! Fatal logic errors in Rust cause *task failure*, during which +//! Fatal logic errors in Rust cause *task panic*, during which //! a task will unwind the stack, running destructors and freeing -//! owned resources. Task failure is unrecoverable from within -//! the failing task (i.e. there is no 'try/catch' in Rust), but -//! failure may optionally be detected from a different task. If -//! the main task fails the application will exit with a non-zero +//! owned resources. Task panic is unrecoverable from within +//! the panicking task (i.e. there is no 'try/catch' in Rust), but +//! panic may optionally be detected from a different task. If +//! the main task panics the application will exit with a non-zero //! exit code. //! //! # Basic task scheduling @@ -123,7 +123,7 @@ impl Spawner for SiblingSpawner { let tb: Option<Box<Task>> = Local::try_take(); match tb { Some(t) => t.spawn_sibling(opts, f), - None => fail!("need a local task to spawn a sibling task"), + None => panic!("need a local task to spawn a sibling task"), }; } } @@ -140,7 +140,7 @@ impl Spawner for SiblingSpawner { // sidestep that whole issue by making builders uncopyable and making // the run function move them in. pub struct TaskBuilder<S = SiblingSpawner> { - // A name for the task-to-be, for identification in failure messages + // A name for the task-to-be, for identification in panic messages name: Option<SendStr>, // The size of the stack for the spawned task stack_size: Option<uint>, @@ -173,7 +173,7 @@ impl TaskBuilder<SiblingSpawner> { impl<S: Spawner> TaskBuilder<S> { /// Name the task-to-be. Currently the name is used for identification - /// only in failure messages. + /// only in panic messages. #[unstable = "IntoMaybeOwned will probably change."] pub fn named<T: IntoMaybeOwned<'static>>(mut self, name: T) -> TaskBuilder<S> { self.name = Some(name.into_maybe_owned()); @@ -269,10 +269,10 @@ impl<S: Spawner> TaskBuilder<S> { /// /// # Return value /// - /// If the child task executes successfully (without failing) then the + /// If the child task executes successfully (without panicking) then the /// future returns `result::Ok` containing the value returned by the - /// function. If the child task fails then the future returns `result::Err` - /// containing the argument to `fail!(...)` as an `Any` trait object. + /// function. If the child task panics then the future returns `result::Err` + /// containing the argument to `panic!(...)` as an `Any` trait object. #[experimental = "Futures are experimental."] pub fn try_future<T:Send>(self, f: proc():Send -> T) -> Future<Result<T, Box<Any + Send>>> { @@ -293,7 +293,7 @@ impl<S: Spawner> TaskBuilder<S> { } /// Execute a function in a newly-spawnedtask and block until the task - /// completes or fails. Equivalent to `.try_future(f).unwrap()`. + /// completes or panics. Equivalent to `.try_future(f).unwrap()`. #[unstable = "Error type may change."] pub fn try<T:Send>(self, f: proc():Send -> T) -> Result<T, Box<Any + Send>> { self.try_future(f).unwrap() @@ -313,7 +313,7 @@ pub fn spawn(f: proc(): Send) { } /// Execute a function in a newly-spawned task and return either the return -/// value of the function or an error if the task failed. +/// value of the function or an error if the task panicked. /// /// This is equivalent to `TaskBuilder::new().try`. #[unstable = "Error type may change."] @@ -355,8 +355,8 @@ pub fn deschedule() { task.yield_now(); } -/// True if the running task is currently failing (e.g. will return `true` inside a -/// destructor that is run while unwinding the stack after a call to `fail!()`). +/// True if the running task is currently panicking (e.g. will return `true` inside a +/// destructor that is run while unwinding the stack after a call to `panic!()`). #[unstable = "May move to a different module."] pub fn failing() -> bool { use rt::task::Task; @@ -420,7 +420,7 @@ mod test { assert!(result.unwrap().is_ok()); let result = TaskBuilder::new().try_future(proc() -> () { - fail!(); + panic!(); }); assert!(result.unwrap().is_err()); } @@ -431,17 +431,17 @@ mod test { "Success!".to_string() }).as_ref().map(|s| s.as_slice()) { result::Ok("Success!") => (), - _ => fail!() + _ => panic!() } } #[test] - fn test_try_fail() { + fn test_try_panic() { match try(proc() { - fail!() + panic!() }) { result::Err(_) => (), - result::Ok(()) => fail!() + result::Ok(()) => panic!() } } @@ -541,37 +541,37 @@ mod test { } #[test] - fn test_try_fail_message_static_str() { + fn test_try_panic_message_static_str() { match try(proc() { - fail!("static string"); + panic!("static string"); }) { Err(e) => { type T = &'static str; assert!(e.is::<T>()); assert_eq!(*e.downcast::<T>().unwrap(), "static string"); } - Ok(()) => fail!() + Ok(()) => panic!() } } #[test] - fn test_try_fail_message_owned_str() { + fn test_try_panic_message_owned_str() { match try(proc() { - fail!("owned string".to_string()); + panic!("owned string".to_string()); }) { Err(e) => { type T = String; assert!(e.is::<T>()); assert_eq!(*e.downcast::<T>().unwrap(), "owned string".to_string()); } - Ok(()) => fail!() + Ok(()) => panic!() } } #[test] - fn test_try_fail_message_any() { + fn test_try_panic_message_any() { match try(proc() { - fail!(box 413u16 as Box<Any + Send>); + panic!(box 413u16 as Box<Any + Send>); }) { Err(e) => { type T = Box<Any + Send>; @@ -580,19 +580,19 @@ mod test { assert!(any.is::<u16>()); assert_eq!(*any.downcast::<u16>().unwrap(), 413u16); } - Ok(()) => fail!() + Ok(()) => panic!() } } #[test] - fn test_try_fail_message_unit_struct() { + fn test_try_panic_message_unit_struct() { struct Juju; match try(proc() { - fail!(Juju) + panic!(Juju) }) { Err(ref e) if e.is::<Juju>() => {} - Err(_) | Ok(()) => fail!() + Err(_) | Ok(()) => panic!() } } diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 751eb00bfae..c8b01ce1055 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -107,7 +107,7 @@ impl Duration { pub fn seconds(seconds: i64) -> Duration { let d = Duration { secs: seconds, nanos: 0 }; if d < MIN || d > MAX { - fail!("Duration::seconds out of bounds"); + panic!("Duration::seconds out of bounds"); } d } |
