Skip to content

Commit ae1c418

Browse files
committed
Rename fail! to panic!
rust-lang/rfcs#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]
1 parent 21e0fa0 commit ae1c418

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

distributions/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, T: Clone> WeightedChoice<'a, T> {
129129
for item in items.iter_mut() {
130130
running_total = match running_total.checked_add(&item.weight) {
131131
Some(n) => n,
132-
None => fail!("WeightedChoice::new called with a total weight \
132+
None => panic!("WeightedChoice::new called with a total weight \
133133
larger than a uint can contain")
134134
};
135135

lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub trait Rng {
9292
/// not be relied upon.
9393
///
9494
/// This method should guarantee that `dest` is entirely filled
95-
/// with new data, and may fail if this is impossible
95+
/// with new data, and may panic if this is impossible
9696
/// (e.g. reading past the end of a file that is being used as the
9797
/// source of randomness).
9898
///
@@ -375,7 +375,7 @@ impl Rng for XorShiftRng {
375375
}
376376

377377
impl SeedableRng<[u32, .. 4]> for XorShiftRng {
378-
/// Reseed an XorShiftRng. This will fail if `seed` is entirely 0.
378+
/// Reseed an XorShiftRng. This will panic if `seed` is entirely 0.
379379
fn reseed(&mut self, seed: [u32, .. 4]) {
380380
assert!(!seed.iter().all(|&x| x == 0),
381381
"XorShiftRng.reseed called with an all zero seed.");
@@ -386,7 +386,7 @@ impl SeedableRng<[u32, .. 4]> for XorShiftRng {
386386
self.w = seed[3];
387387
}
388388

389-
/// Create a new XorShiftRng. This will fail if `seed` is entirely 0.
389+
/// Create a new XorShiftRng. This will panic if `seed` is entirely 0.
390390
fn from_seed(seed: [u32, .. 4]) -> XorShiftRng {
391391
assert!(!seed.iter().all(|&x| x == 0),
392392
"XorShiftRng::from_seed called with an all zero seed.");
@@ -446,7 +446,7 @@ pub struct Closed01<F>(pub F);
446446

447447
#[cfg(not(test))]
448448
mod std {
449-
pub use core::{option, fmt}; // fail!()
449+
pub use core::{option, fmt}; // panic!()
450450
}
451451

452452
#[cfg(test)]

0 commit comments

Comments
 (0)