From 7828c3dd2858d8f3a0448484d8093e22719dbda0 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 9 Oct 2014 15:17:22 -0400 Subject: 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] --- src/libcoretest/any.rs | 16 ++++++++-------- src/libcoretest/finally.rs | 2 +- src/libcoretest/iter.rs | 12 ++++++------ src/libcoretest/option.rs | 6 +++--- src/libcoretest/result.rs | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) (limited to 'src/libcoretest') 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::() { Some(&5) => {} - x => fail!("Unexpected value {}", x) + x => panic!("Unexpected value {}", x) } match a.downcast_ref::() { 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::() { @@ -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::() { None => (), - x => fail!("Unexpected value {}", x) + x => panic!("Unexpected value {}", x) } match b_r.downcast_mut::() { None => (), - x => fail!("Unexpected value {}", x) + x => panic!("Unexpected value {}", x) } match a_r.downcast_mut::() { Some(&612) => {} - x => fail!("Unexpected value {}", x) + x => panic!("Unexpected value {}", x) } match b_r.downcast_mut::() { 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![13i, 12, 11]); for _ in range(10i, 0).rev() { - fail!("unreachable"); + panic!("unreachable"); } assert!(range(11u, 14).rev().collect::>() == 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 = None; x.unwrap(); } #[test] #[should_fail] -fn test_unwrap_fail2() { +fn test_unwrap_panic2() { let x: Option = 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> = 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, 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") } } -- cgit 1.4.1-3-g733a5