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/libserialize/base64.rs | 2 +- src/libserialize/json.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/libserialize') diff --git a/src/libserialize/base64.rs b/src/libserialize/base64.rs index 19dcc3c132c..c999157b89a 100644 --- a/src/libserialize/base64.rs +++ b/src/libserialize/base64.rs @@ -144,7 +144,7 @@ impl<'a> ToBase64 for &'a [u8] { v.push(b'='); } } - _ => fail!("Algebra is broken, please alert the math police") + _ => panic!("Algebra is broken, please alert the math police") } unsafe { diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 73b4773fb3f..99c60dde0ac 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1229,7 +1229,7 @@ impl Stack { let len = self.stack.len(); let idx = match *self.stack.last().unwrap() { InternalIndex(i) => { i + 1 } - _ => { fail!(); } + _ => { panic!(); } }; *self.stack.get_mut(len - 1) = InternalIndex(idx); } @@ -1814,7 +1814,7 @@ impl> Builder { match self.token { None => {} Some(Error(e)) => { return Err(e); } - ref tok => { fail!("unexpected token {}", tok.clone()); } + ref tok => { panic!("unexpected token {}", tok.clone()); } } result } @@ -1874,7 +1874,7 @@ impl> Builder { } let key = match self.parser.stack().top() { Some(Key(k)) => { k.to_string() } - _ => { fail!("invalid state"); } + _ => { panic!("invalid state"); } }; match self.build_value() { Ok(value) => { values.insert(key, value); } @@ -3015,9 +3015,9 @@ mod tests { Ok(json) => Decodable::decode(&mut Decoder::new(json)) }; match res { - Ok(_) => fail!("`{}` parsed & decoded ok, expecting error `{}`", + Ok(_) => panic!("`{}` parsed & decoded ok, expecting error `{}`", to_parse, expected), - Err(ParseError(e)) => fail!("`{}` is not valid json: {}", + Err(ParseError(e)) => panic!("`{}` is not valid json: {}", to_parse, e), Err(e) => { assert_eq!(e, expected); @@ -3226,7 +3226,7 @@ mod tests { let bytes = mem_buf.unwrap(); let json_str = from_utf8(bytes.as_slice()).unwrap(); match from_str(json_str) { - Err(_) => fail!("Unable to parse json_str: {}", json_str), + Err(_) => panic!("Unable to parse json_str: {}", json_str), _ => {} // it parsed and we are good to go } } @@ -3247,7 +3247,7 @@ mod tests { let bytes = mem_buf.unwrap(); let json_str = from_utf8(bytes.as_slice()).unwrap(); match from_str(json_str) { - Err(_) => fail!("Unable to parse json_str: {}", json_str), + Err(_) => panic!("Unable to parse json_str: {}", json_str), _ => {} // it parsed and we are good to go } } @@ -3315,7 +3315,7 @@ mod tests { use Decodable; let json_str = "{\"1\":true}"; let json_obj = match from_str(json_str) { - Err(_) => fail!("Unable to parse json_str: {}", json_str), + Err(_) => panic!("Unable to parse json_str: {}", json_str), Ok(o) => o }; let mut decoder = Decoder::new(json_obj); @@ -3328,7 +3328,7 @@ mod tests { use Decodable; let json_str = "{\"a\":true}"; let json_obj = match from_str(json_str) { - Err(_) => fail!("Unable to parse json_str: {}", json_str), + Err(_) => panic!("Unable to parse json_str: {}", json_str), Ok(o) => o }; let mut decoder = Decoder::new(json_obj); @@ -3347,7 +3347,7 @@ mod tests { }; let (ref expected_evt, ref expected_stack) = expected[i]; if !parser.stack().is_equal_to(expected_stack.as_slice()) { - fail!("Parser stack is not equal to {}", expected_stack); + panic!("Parser stack is not equal to {}", expected_stack); } assert_eq!(&evt, expected_evt); i+=1; -- cgit 1.4.1-3-g733a5