1
Fork 0

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]
This commit is contained in:
Steve Klabnik 2014-10-09 15:17:22 -04:00
parent 3bc545373d
commit 7828c3dd28
505 changed files with 1623 additions and 1618 deletions

View file

@ -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();