about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2014-10-09 15:17:22 -0400
committerSteve Klabnik <steve@steveklabnik.com>2014-10-29 11:43:07 -0400
commit7828c3dd2858d8f3a0448484d8093e22719dbda0 (patch)
tree2d2b106b02526219463d877d480782027ffe1f3f /src/libcoretest
parent3bc545373df4c81ba223a8bece14cbc27eb85a4d (diff)
downloadrust-7828c3dd2858d8f3a0448484d8093e22719dbda0.tar.gz
rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.zip
Rename fail! to panic!
https://github.com/rust-lang/rfcs/pull/221

The current terminology of "task failure" often causes problems when
writing or speaking about code. You often want to talk about the
possibility of an operation that returns a Result "failing", but cannot
because of the ambiguity with task failure. Instead, you have to speak
of "the failing case" or "when the operation does not succeed" or other
circumlocutions.

Likewise, we use a "Failure" header in rustdoc to describe when
operations may fail the task, but it would often be helpful to separate
out a section describing the "Err-producing" case.

We have been steadily moving away from task failure and toward Result as
an error-handling mechanism, so we should optimize our terminology
accordingly: Result-producing functions should be easy to describe.

To update your code, rename any call to `fail!` to `panic!` instead.
Assuming you have not created your own macro named `panic!`, this
will work on UNIX based systems:

    grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g'

You can of course also do this by hand.

[breaking-change]
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/any.rs16
-rw-r--r--src/libcoretest/finally.rs2
-rw-r--r--src/libcoretest/iter.rs12
-rw-r--r--src/libcoretest/option.rs6
-rw-r--r--src/libcoretest/result.rs8
5 files changed, 22 insertions, 22 deletions
diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs
index 9656a6caba0..7c832e90ed9 100644
--- a/src/libcoretest/any.rs
+++ b/src/libcoretest/any.rs
@@ -56,12 +56,12 @@ fn any_downcast_ref() {
 
     match a.downcast_ref::<uint>() {
         Some(&5) => {}
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match a.downcast_ref::<Test>() {
         None => {}
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 }
 
@@ -79,7 +79,7 @@ fn any_downcast_mut() {
             assert_eq!(*x, 5u);
             *x = 612;
         }
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match b_r.downcast_mut::<uint>() {
@@ -87,27 +87,27 @@ fn any_downcast_mut() {
             assert_eq!(*x, 7u);
             *x = 413;
         }
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match a_r.downcast_mut::<Test>() {
         None => (),
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match b_r.downcast_mut::<Test>() {
         None => (),
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match a_r.downcast_mut::<uint>() {
         Some(&612) => {}
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 
     match b_r.downcast_mut::<uint>() {
         Some(&413) => {}
-        x => fail!("Unexpected value {}", x)
+        x => panic!("Unexpected value {}", x)
     }
 }
 
diff --git a/src/libcoretest/finally.rs b/src/libcoretest/finally.rs
index 5da004086d2..032f5f71941 100644
--- a/src/libcoretest/finally.rs
+++ b/src/libcoretest/finally.rs
@@ -35,7 +35,7 @@ fn test_fail() {
         &mut i, (),
         |i, ()| {
             *i = 10;
-            fail!();
+            panic!();
         },
         |i| {
             assert!(failing());
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index 476a2b50fcc..98db377b0d5 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -373,7 +373,7 @@ fn test_all() {
     assert!(v.iter().all(|&x| x < 10));
     assert!(!v.iter().all(|&x| x % 2 == 0));
     assert!(!v.iter().all(|&x| x > 100));
-    assert!(v.slice_or_fail(&0, &0).iter().all(|_| fail!()));
+    assert!(v.slice_or_fail(&0, &0).iter().all(|_| panic!()));
 }
 
 #[test]
@@ -382,7 +382,7 @@ fn test_any() {
     assert!(v.iter().any(|&x| x < 10));
     assert!(v.iter().any(|&x| x % 2 == 0));
     assert!(!v.iter().any(|&x| x > 100));
-    assert!(!v.slice_or_fail(&0, &0).iter().any(|_| fail!()));
+    assert!(!v.slice_or_fail(&0, &0).iter().any(|_| panic!()));
 }
 
 #[test]
@@ -528,13 +528,13 @@ fn test_rposition() {
 
 #[test]
 #[should_fail]
-fn test_rposition_fail() {
+fn test_rposition_panic() {
     let v = [(box 0i, box 0i), (box 0i, box 0i),
              (box 0i, box 0i), (box 0i, box 0i)];
     let mut i = 0i;
     v.iter().rposition(|_elt| {
         if i == 2 {
-            fail!()
+            panic!()
         }
         i += 1;
         false
@@ -678,12 +678,12 @@ fn test_random_access_cycle() {
 fn test_double_ended_range() {
     assert!(range(11i, 14).rev().collect::<Vec<int>>() == vec![13i, 12, 11]);
     for _ in range(10i, 0).rev() {
-        fail!("unreachable");
+        panic!("unreachable");
     }
 
     assert!(range(11u, 14).rev().collect::<Vec<uint>>() == vec![13u, 12, 11]);
     for _ in range(10u, 0).rev() {
-        fail!("unreachable");
+        panic!("unreachable");
     }
 }
 
diff --git a/src/libcoretest/option.rs b/src/libcoretest/option.rs
index 71e9270fe4b..18444fc4240 100644
--- a/src/libcoretest/option.rs
+++ b/src/libcoretest/option.rs
@@ -139,14 +139,14 @@ fn test_unwrap() {
 
 #[test]
 #[should_fail]
-fn test_unwrap_fail1() {
+fn test_unwrap_panic1() {
     let x: Option<int> = None;
     x.unwrap();
 }
 
 #[test]
 #[should_fail]
-fn test_unwrap_fail2() {
+fn test_unwrap_panic2() {
     let x: Option<String> = None;
     x.unwrap();
 }
@@ -233,7 +233,7 @@ fn test_collect() {
     assert!(v == None);
 
     // test that it does not take more elements than it needs
-    let mut functions = [|| Some(()), || None, || fail!()];
+    let mut functions = [|| Some(()), || None, || panic!()];
 
     let v: Option<Vec<()>> = functions.iter_mut().map(|f| (*f)()).collect();
 
diff --git a/src/libcoretest/result.rs b/src/libcoretest/result.rs
index 1cb72bd9eac..92124e2f299 100644
--- a/src/libcoretest/result.rs
+++ b/src/libcoretest/result.rs
@@ -81,7 +81,7 @@ fn test_collect() {
     assert!(v == Err(2));
 
     // test that it does not take more elements than it needs
-    let mut functions = [|| Ok(()), || Err(1i), || fail!()];
+    let mut functions = [|| Ok(()), || Err(1i), || panic!()];
 
     let v: Result<Vec<()>, int> = functions.iter_mut().map(|f| (*f)()).collect();
     assert!(v == Err(1));
@@ -113,7 +113,7 @@ pub fn test_unwrap_or_else() {
         if msg == "I got this." {
             50i
         } else {
-            fail!("BadBad")
+            panic!("BadBad")
         }
     }
 
@@ -126,12 +126,12 @@ pub fn test_unwrap_or_else() {
 
 #[test]
 #[should_fail]
-pub fn test_unwrap_or_else_failure() {
+pub fn test_unwrap_or_else_panic() {
     fn handler(msg: &'static str) -> int {
         if msg == "I got this." {
             50i
         } else {
-            fail!("BadBad")
+            panic!("BadBad")
         }
     }