about summary refs log tree commit diff
path: root/src/libgreen
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2014-10-09 15:17:22 -0400
committerSteve Klabnik <steve@steveklabnik.com>2014-10-29 11:43:07 -0400
commit7828c3dd2858d8f3a0448484d8093e22719dbda0 (patch)
tree2d2b106b02526219463d877d480782027ffe1f3f /src/libgreen
parent3bc545373df4c81ba223a8bece14cbc27eb85a4d (diff)
downloadrust-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/libgreen')
-rw-r--r--src/libgreen/basic.rs4
-rw-r--r--src/libgreen/context.rs4
-rw-r--r--src/libgreen/lib.rs4
-rw-r--r--src/libgreen/sched.rs10
-rw-r--r--src/libgreen/simple.rs14
-rw-r--r--src/libgreen/stack.rs8
-rw-r--r--src/libgreen/task.rs12
7 files changed, 28 insertions, 28 deletions
diff --git a/src/libgreen/basic.rs b/src/libgreen/basic.rs
index b592ba477c2..b476f46833b 100644
--- a/src/libgreen/basic.rs
+++ b/src/libgreen/basic.rs
@@ -73,13 +73,13 @@ impl BasicLoop {
             RunRemote(i) => {
                 match self.remotes.iter_mut().find(|& &(id, _)| id == i) {
                     Some(&(_, ref mut f)) => f.call(),
-                    None => fail!("bad remote: {}", i),
+                    None => panic!("bad remote: {}", i),
                 }
             }
             RemoveRemote(i) => {
                 match self.remotes.iter().position(|&(id, _)| id == i) {
                     Some(i) => { self.remotes.remove(i).unwrap(); }
-                    None => fail!("bad remote: {}", i),
+                    None => panic!("bad remote: {}", i),
                 }
             }
         }
diff --git a/src/libgreen/context.rs b/src/libgreen/context.rs
index a665d41aadf..2d3e85cc833 100644
--- a/src/libgreen/context.rs
+++ b/src/libgreen/context.rs
@@ -102,14 +102,14 @@ impl Context {
             // Right before we switch to the new context, set the new context's
             // stack limit in the OS-specified TLS slot. This also  means that
             // we cannot call any more rust functions after record_stack_bounds
-            // returns because they would all likely fail due to the limit being
+            // returns because they would all likely panic due to the limit being
             // invalid for the current task. Lucky for us `rust_swap_registers`
             // is a C function so we don't have to worry about that!
             match in_context.stack_bounds {
                 Some((lo, hi)) => stack::record_rust_managed_stack_bounds(lo, hi),
                 // If we're going back to one of the original contexts or
                 // something that's possibly not a "normal task", then reset
-                // the stack limit to 0 to make morestack never fail
+                // the stack limit to 0 to make morestack never panic
                 None => stack::record_rust_managed_stack_bounds(0, uint::MAX),
             }
             rust_swap_registers(out_regs, in_regs);
diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs
index 5435a6f74d3..fcebfeac292 100644
--- a/src/libgreen/lib.rs
+++ b/src/libgreen/lib.rs
@@ -168,7 +168,7 @@
 //! drop(handle);
 //!
 //! // Required to shut down this scheduler pool.
-//! // The task will fail if `shutdown` is not called.
+//! // The task will panic if `shutdown` is not called.
 //! pool.shutdown();
 //! # }
 //! ```
@@ -511,7 +511,7 @@ impl TaskState {
 impl Drop for SchedPool {
     fn drop(&mut self) {
         if self.threads.len() > 0 {
-            fail!("dropping a M:N scheduler pool that wasn't shut down");
+            panic!("dropping a M:N scheduler pool that wasn't shut down");
         }
     }
 }
diff --git a/src/libgreen/sched.rs b/src/libgreen/sched.rs
index c465aad3e3b..b1c2695ac7d 100644
--- a/src/libgreen/sched.rs
+++ b/src/libgreen/sched.rs
@@ -761,7 +761,7 @@ impl Scheduler {
         // task-local lock around this block. The resumption of the task in
         // context switching will bounce on the lock, thereby waiting for this
         // block to finish, eliminating the race mentioned above.
-        // fail!("should never return!");
+        // panic!("should never return!");
         //
         // To actually maintain a handle to the lock, we use an unsafe pointer
         // to it, but we're guaranteed that the task won't exit until we've
@@ -806,7 +806,7 @@ impl Scheduler {
             coroutine.recycle(&mut sched.stack_pool);
             sched.task_state.decrement();
         });
-        fail!("should never return!");
+        panic!("should never return!");
     }
 
     pub fn run_task(self: Box<Scheduler>,
@@ -1054,7 +1054,7 @@ mod test {
                 task.put_runtime(green);
                 return ret;
             }
-            None => fail!()
+            None => panic!()
         }
     }
 
@@ -1202,8 +1202,8 @@ mod test {
                     }))) => {
                         *id == sched_id
                     }
-                    TypeGreen(None) => { fail!("task without home"); }
-                    TypeSched => { fail!("expected green task"); }
+                    TypeGreen(None) => { panic!("task without home"); }
+                    TypeSched => { panic!("expected green task"); }
                 };
                 task.put();
                 ret
diff --git a/src/libgreen/simple.rs b/src/libgreen/simple.rs
index 686a039d6d6..6c33e7cc619 100644
--- a/src/libgreen/simple.rs
+++ b/src/libgreen/simple.rs
@@ -67,23 +67,23 @@ impl Runtime for SimpleTask {
         }
     }
 
-    // These functions are all unimplemented and fail as a result. This is on
+    // These functions are all unimplemented and panic as a result. This is on
     // purpose. A "simple task" is just that, a very simple task that can't
     // really do a whole lot. The only purpose of the task is to get us off our
     // feet and running.
-    fn yield_now(self: Box<SimpleTask>, _cur_task: Box<Task>) { fail!() }
-    fn maybe_yield(self: Box<SimpleTask>, _cur_task: Box<Task>) { fail!() }
+    fn yield_now(self: Box<SimpleTask>, _cur_task: Box<Task>) { panic!() }
+    fn maybe_yield(self: Box<SimpleTask>, _cur_task: Box<Task>) { panic!() }
     fn spawn_sibling(self: Box<SimpleTask>,
                      _cur_task: Box<Task>,
                      _opts: TaskOpts,
                      _f: proc():Send) {
-        fail!()
+        panic!()
     }
     fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> { None }
-    fn stack_bounds(&self) -> (uint, uint) { fail!() }
-    fn stack_guard(&self) -> Option<uint> { fail!() }
+    fn stack_bounds(&self) -> (uint, uint) { panic!() }
+    fn stack_guard(&self) -> Option<uint> { panic!() }
     fn can_block(&self) -> bool { true }
-    fn wrap(self: Box<SimpleTask>) -> Box<Any+'static> { fail!() }
+    fn wrap(self: Box<SimpleTask>) -> Box<Any+'static> { panic!() }
 }
 
 pub fn task() -> Box<Task> {
diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs
index cccf0ec6987..7d6c82cb0c3 100644
--- a/src/libgreen/stack.rs
+++ b/src/libgreen/stack.rs
@@ -24,7 +24,7 @@ pub struct Stack {
 // Try to use MAP_STACK on platforms that support it (it's what we're doing
 // anyway), but some platforms don't support it at all. For example, it appears
 // that there's a bug in freebsd that MAP_STACK implies MAP_FIXED (so it always
-// fails): http://lists.freebsd.org/pipermail/freebsd-bugs/2011-July/044840.html
+// panics): http://lists.freebsd.org/pipermail/freebsd-bugs/2011-July/044840.html
 //
 // DragonFly BSD also seems to suffer from the same problem. When MAP_STACK is
 // used, it returns the same `ptr` multiple times.
@@ -37,7 +37,7 @@ static STACK_FLAGS: libc::c_int = libc::MAP_PRIVATE | libc::MAP_ANON;
 static STACK_FLAGS: libc::c_int = 0;
 
 impl Stack {
-    /// Allocate a new stack of `size`. If size = 0, this will fail. Use
+    /// Allocate a new stack of `size`. If size = 0, this will panic. Use
     /// `dummy_stack` if you want a zero-sized stack.
     pub fn new(size: uint) -> Stack {
         // Map in a stack. Eventually we might be able to handle stack
@@ -47,7 +47,7 @@ impl Stack {
         let stack = match MemoryMap::new(size, [MapReadable, MapWritable,
                                          MapNonStandardFlags(STACK_FLAGS)]) {
             Ok(map) => map,
-            Err(e) => fail!("mmap for stack of size {} failed: {}", size, e)
+            Err(e) => panic!("mmap for stack of size {} failed: {}", size, e)
         };
 
         // Change the last page to be inaccessible. This is to provide safety;
@@ -55,7 +55,7 @@ impl Stack {
         // page. It isn't guaranteed, but that's why FFI is unsafe. buf.data is
         // guaranteed to be aligned properly.
         if !protect_last_page(&stack) {
-            fail!("Could not memory-protect guard page. stack={}, errno={}",
+            panic!("Could not memory-protect guard page. stack={}, errno={}",
                   stack.data(), errno());
         }
 
diff --git a/src/libgreen/task.rs b/src/libgreen/task.rs
index f151e00f56d..0c549fa66c1 100644
--- a/src/libgreen/task.rs
+++ b/src/libgreen/task.rs
@@ -443,7 +443,7 @@ impl Runtime for GreenTask {
         self.put_task(cur_task);
 
         // First, set up a bomb which when it goes off will restore the local
-        // task unless its disarmed. This will allow us to gracefully fail from
+        // task unless its disarmed. This will allow us to gracefully panic from
         // inside of `configure` which allocates a new task.
         struct Bomb { inner: Option<Box<GreenTask>> }
         impl Drop for Bomb {
@@ -529,11 +529,11 @@ mod tests {
     }
 
     #[test]
-    fn smoke_fail() {
+    fn smoke_panic() {
         let (tx, rx) = channel::<int>();
         spawn_opts(TaskOpts::new(), proc() {
             let _tx = tx;
-            fail!()
+            panic!()
         });
         assert_eq!(rx.recv_opt(), Err(()));
     }
@@ -550,11 +550,11 @@ mod tests {
     }
 
     #[test]
-    fn smoke_opts_fail() {
+    fn smoke_opts_panic() {
         let mut opts = TaskOpts::new();
         let (tx, rx) = channel();
         opts.on_exit = Some(proc(r) tx.send(r));
-        spawn_opts(opts, proc() { fail!() });
+        spawn_opts(opts, proc() { panic!() });
         assert!(rx.recv().is_err());
     }
 
@@ -597,7 +597,7 @@ mod tests {
                     Some(ops) => {
                         task.put_runtime(ops);
                     }
-                    None => fail!(),
+                    None => panic!(),
                 }
                 Local::put(task);
                 tx.send(());