diff options
| author | Steve Klabnik <steve@steveklabnik.com> | 2014-10-09 15:17:22 -0400 |
|---|---|---|
| committer | Steve Klabnik <steve@steveklabnik.com> | 2014-10-29 11:43:07 -0400 |
| commit | 7828c3dd2858d8f3a0448484d8093e22719dbda0 (patch) | |
| tree | 2d2b106b02526219463d877d480782027ffe1f3f /src/libstd/collections | |
| parent | 3bc545373df4c81ba223a8bece14cbc27eb85a4d (diff) | |
| download | rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.tar.gz rust-7828c3dd2858d8f3a0448484d8093e22719dbda0.zip | |
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]
Diffstat (limited to 'src/libstd/collections')
| -rw-r--r-- | src/libstd/collections/hashmap/map.rs | 21 | ||||
| -rw-r--r-- | src/libstd/collections/hashmap/table.rs | 2 |
2 files changed, 11 insertions, 12 deletions
diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index ac0d117e02a..6562a644988 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -120,8 +120,7 @@ impl DefaultResizePolicy { // is also memory and cache pressure that this would entail that would be very // difficult to properly see in a microbenchmark. // -// Future Improvements (FIXME!) -// ============================ +// ## Future Improvements (FIXME!) // // Allow the load factor to be changed dynamically and/or at initialization. // @@ -129,8 +128,7 @@ impl DefaultResizePolicy { // underlying table? This is exactly the use case for 'realloc', and may // be worth exploring. // -// Future Optimizations (FIXME!) -// ============================= +// ## Future Optimizations (FIXME!) // // Another possible design choice that I made without any real reason is // parameterizing the raw table over keys and values. Technically, all we need @@ -473,7 +471,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { }; buckets.next(); } - fail!("Internal HashMap error: Out of space."); + panic!("Internal HashMap error: Out of space."); } } @@ -829,7 +827,8 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { } /// Retrieves a mutable value for the given key. - /// See [`find_mut`](../trait.MutableMap.html#tymethod.find_mut) for a non-failing alternative. + /// See [`find_mut`](../trait.MutableMap.html#tymethod.find_mut) for a non-panicking + /// alternative. /// /// # Failure /// @@ -856,7 +855,7 @@ impl<K: Eq + Hash<S>, V, S, H: Hasher<S>> HashMap<K, V, H> { pub fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V { match self.find_mut(k) { Some(v) => v, - None => fail!("no entry found for key") + None => panic!("no entry found for key") } } @@ -1625,7 +1624,7 @@ mod test_map { assert!(m.insert(5i, 14i)); let new = 100; match m.find_mut(&5) { - None => fail!(), Some(x) => *x = new + None => panic!(), Some(x) => *x = new } assert_eq!(m.find(&5), Some(&new)); } @@ -1746,7 +1745,7 @@ mod test_map { assert!(m.find(&1i).is_none()); m.insert(1i, 2i); match m.find(&1) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(*v, 2) } } @@ -1759,12 +1758,12 @@ mod test_map { for i in range(1i, 10000) { m.insert(i, i + 7); match m.find_copy(&i) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(v, i + 7) } for j in range(1i, i/100) { match m.find_copy(&j) { - None => fail!(), + None => panic!(), Some(v) => assert_eq!(v, j + 7) } } diff --git a/src/libstd/collections/hashmap/table.rs b/src/libstd/collections/hashmap/table.rs index ee64a7931c0..ca20c3ddb74 100644 --- a/src/libstd/collections/hashmap/table.rs +++ b/src/libstd/collections/hashmap/table.rs @@ -470,7 +470,7 @@ impl<K, V, M> BucketState<K, V, M> { pub fn expect_full(self) -> FullBucket<K, V, M> { match self { Full(full) => full, - Empty(..) => fail!("Expected full bucket") + Empty(..) => panic!("Expected full bucket") } } } |
