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 committed by Manish Goregaokar
parent 9e9a8b5237
commit 79ac8f5110
1 changed files with 22 additions and 22 deletions

View File

@ -818,15 +818,15 @@ mod math {
type Complex = (f64, f64);
fn sin(f: f64) -> f64 {
/* ... */
# fail!();
# panic!();
}
fn cos(f: f64) -> f64 {
/* ... */
# fail!();
# panic!();
}
fn tan(f: f64) -> f64 {
/* ... */
# fail!();
# panic!();
}
}
```
@ -1195,12 +1195,12 @@ output slot type would normally be. For example:
```
fn my_err(s: &str) -> ! {
println!("{}", s);
fail!();
panic!();
}
```
We call such functions "diverging" because they never return a value to the
caller. Every control path in a diverging function must end with a `fail!()` or
caller. Every control path in a diverging function must end with a `panic!()` or
a call to another diverging function on every control path. The `!` annotation
does *not* denote a type. Rather, the result type of a diverging function is a
special type called $\bot$ ("bottom") that unifies with any type. Rust has no
@ -1213,7 +1213,7 @@ were declared without the `!` annotation, the following code would not
typecheck:
```
# fn my_err(s: &str) -> ! { fail!() }
# fn my_err(s: &str) -> ! { panic!() }
fn f(i: int) -> int {
if i == 42 {
@ -2260,7 +2260,7 @@ These types help drive the compiler's analysis
: Allocate memory on the exchange heap.
* `closure_exchange_malloc`
: ___Needs filling in___
* `fail_`
* `panic`
: Abort the program with an error.
* `fail_bounds_check`
: Abort the program with a bounds check error.
@ -2867,11 +2867,11 @@ be assigned to.
Indices are zero-based, and may be of any integral type. Vector access is
bounds-checked at run-time. When the check fails, it will put the task in a
_failing state_.
_panicked state_.
```{should-fail}
([1, 2, 3, 4])[0];
(["a", "b"])[10]; // fails
(["a", "b"])[10]; // panics
```
### Unary operator expressions
@ -3301,9 +3301,9 @@ enum List<X> { Nil, Cons(X, Box<List<X>>) }
let x: List<int> = Cons(10, box Cons(11, box Nil));
match x {
Cons(_, box Nil) => fail!("singleton list"),
Cons(_, box Nil) => panic!("singleton list"),
Cons(..) => return,
Nil => fail!("empty list")
Nil => panic!("empty list")
}
```
@ -3374,7 +3374,7 @@ match x {
return;
}
_ => {
fail!();
panic!();
}
}
```
@ -3396,7 +3396,7 @@ fn is_sorted(list: &List) -> bool {
Cons(x, ref r @ box Cons(_, _)) => {
match *r {
box Cons(y, _) => (x <= y) && is_sorted(&**r),
_ => fail!()
_ => panic!()
}
}
}
@ -3460,7 +3460,7 @@ may refer to the variables bound within the pattern they follow.
let message = match maybe_digit {
Some(x) if x < 10 => process_digit(x),
Some(x) => process_other(x),
None => fail!()
None => panic!()
};
```
@ -4092,7 +4092,7 @@ cause transitions between the states. The lifecycle states of a task are:
* running
* blocked
* failing
* panicked
* dead
A task begins its lifecycle &mdash; once it has been spawned &mdash; in the
@ -4104,21 +4104,21 @@ it makes a blocking communication call. When the call can be completed &mdash;
when a message arrives at a sender, or a buffer opens to receive a message
&mdash; then the blocked task will unblock and transition back to *running*.
A task may transition to the *failing* state at any time, due being killed by
some external event or internally, from the evaluation of a `fail!()` macro.
Once *failing*, a task unwinds its stack and transitions to the *dead* state.
A task may transition to the *panicked* state at any time, due being killed by
some external event or internally, from the evaluation of a `panic!()` macro.
Once *panicking*, a task unwinds its stack and transitions to the *dead* state.
Unwinding the stack of a task is done by the task itself, on its own control
stack. If a value with a destructor is freed during unwinding, the code for the
destructor is run, also on the task's control stack. Running the destructor
code causes a temporary transition to a *running* state, and allows the
destructor code to cause any subsequent state transitions. The original task
of unwinding and failing thereby may suspend temporarily, and may involve
of unwinding and panicking thereby may suspend temporarily, and may involve
(recursive) unwinding of the stack of a failed destructor. Nonetheless, the
outermost unwinding activity will continue until the stack is unwound and the
task transitions to the *dead* state. There is no way to "recover" from task
failure. Once a task has temporarily suspended its unwinding in the *failing*
state, failure occurring from within this destructor results in *hard* failure.
A hard failure currently results in the process aborting.
panics. Once a task has temporarily suspended its unwinding in the *panicking*
state, a panic occurring from within this destructor results in *hard* panic.
A hard panic currently results in the process aborting.
A task in the *dead* state cannot transition to other states; it exists only to
have its termination status inspected by other tasks, and/or to await