From 13fe167dbb5a89f9cfad8b71e2c30e3b836aeb48 Mon Sep 17 00:00:00 2001 From: Nick Desaulniers Date: Thu, 14 Feb 2013 17:33:16 -0800 Subject: [PATCH] remove die definition and use in doc tests --- doc/rust.md | 18 +++++++++--------- doc/tutorial-macros.md | 6 +++--- doc/tutorial-tasks.md | 16 ++++++++-------- src/libsyntax/ext/expand.rs | 9 --------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index 30896307aee..23035b3b34a 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -686,15 +686,15 @@ mod math { type complex = (f64, f64); fn sin(f: f64) -> f64 { ... -# die!(); +# fail!(); } fn cos(f: f64) -> f64 { ... -# die!(); +# fail!(); } fn tan(f: f64) -> f64 { ... -# die!(); +# fail!(); } } ~~~~~~~~ @@ -986,7 +986,7 @@ output slot type would normally be. For example: ~~~~ fn my_err(s: &str) -> ! { log(info, s); - die!(); + fail!(); } ~~~~ @@ -1004,7 +1004,7 @@ were declared without the `!` annotation, the following code would not typecheck: ~~~~ -# fn my_err(s: &str) -> ! { die!() } +# fn my_err(s: &str) -> ! { fail!() } fn f(i: int) -> int { if i == 42 { @@ -2284,9 +2284,9 @@ enum List { Nil, Cons(X, @List) } let x: List = Cons(10, @Cons(11, @Nil)); match x { - Cons(_, @Nil) => die!(~"singleton list"), + Cons(_, @Nil) => fail!(~"singleton list"), Cons(*) => return, - Nil => die!(~"empty list") + Nil => fail!(~"empty list") } ~~~~ @@ -2323,7 +2323,7 @@ match x { return; } _ => { - die!(); + fail!(); } } ~~~~ @@ -2411,7 +2411,7 @@ guard 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 => die!() + None => fail!() }; ~~~~ diff --git a/doc/tutorial-macros.md b/doc/tutorial-macros.md index e2813e0809f..42bd319a2a4 100644 --- a/doc/tutorial-macros.md +++ b/doc/tutorial-macros.md @@ -218,7 +218,7 @@ match x { // complicated stuff goes here return result + val; }, - _ => die!(~"Didn't get good_2") + _ => fail!(~"Didn't get good_2") } } _ => return 0 // default value @@ -260,7 +260,7 @@ macro_rules! biased_match ( biased_match!((x) ~ (good_1(g1, val)) else { return 0 }; binds g1, val ) biased_match!((g1.body) ~ (good_2(result) ) - else { die!(~"Didn't get good_2") }; + else { fail!(~"Didn't get good_2") }; binds result ) // complicated stuff goes here return result + val; @@ -362,7 +362,7 @@ macro_rules! biased_match ( # fn f(x: t1) -> uint { biased_match!( (x) ~ (good_1(g1, val)) else { return 0 }; - (g1.body) ~ (good_2(result) ) else { die!(~"Didn't get good_2") }; + (g1.body) ~ (good_2(result) ) else { fail!(~"Didn't get good_2") }; binds val, result ) // complicated stuff goes here return result + val; diff --git a/doc/tutorial-tasks.md b/doc/tutorial-tasks.md index f814970375a..5900fc1a9ff 100644 --- a/doc/tutorial-tasks.md +++ b/doc/tutorial-tasks.md @@ -313,7 +313,7 @@ of all tasks are intertwined: if one fails, so do all the others. # fn do_some_work() { loop { task::yield() } } # do task::try { // Create a child task that fails -do spawn { die!() } +do spawn { fail!() } // This will also fail because the task we spawned failed do_some_work(); @@ -337,7 +337,7 @@ let result: Result = do task::try { if some_condition() { calculate_result() } else { - die!(~"oops!"); + fail!(~"oops!"); } }; assert result.is_err(); @@ -370,14 +370,14 @@ proceed). Hence, you will need different _linked failure modes_. ## Failure modes By default, task failure is _bidirectionally linked_, which means that if -either task dies, it kills the other one. +either task fails, it kills the other one. ~~~ # fn sleep_forever() { loop { task::yield() } } # do task::try { do task::spawn { do task::spawn { - die!(); // All three tasks will die. + fail!(); // All three tasks will fail. } sleep_forever(); // Will get woken up by force, then fail } @@ -386,7 +386,7 @@ sleep_forever(); // Will get woken up by force, then fail ~~~ If you want parent tasks to be able to kill their children, but do not want a -parent to die automatically if one of its child task dies, you can call +parent to fail automatically if one of its child task fails, you can call `task::spawn_supervised` for _unidirectionally linked_ failure. The function `task::try`, which we saw previously, uses `spawn_supervised` internally, with additional logic to wait for the child task to finish @@ -432,7 +432,7 @@ do task::spawn_supervised { // Intermediate task immediately exits } wait_for_a_while(); -die!(); // Will kill grandchild even if child has already exited +fail!(); // Will kill grandchild even if child has already exited # }; ~~~ @@ -446,10 +446,10 @@ other at all, using `task::spawn_unlinked` for _isolated failure_. let (time1, time2) = (random(), random()); do task::spawn_unlinked { sleep_for(time2); // Won't get forced awake - die!(); + fail!(); } sleep_for(time1); // Won't get forced awake -die!(); +fail!(); // It will take MAX(time1,time2) for the program to finish. # }; ~~~ diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 17197f64c55..85821ae6d82 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -287,15 +287,6 @@ pub fn core_macros() -> ~str { macro_rules! debug ( ($( $arg:expr ),+) => ( log(::core::debug, fmt!( $($arg),+ )) )) - macro_rules! die( - ($msg: expr) => ( - ::core::sys::begin_unwind($msg, file!().to_owned(), line!()) - ); - () => ( - fail!(~\"explicit failure\") - ) - ) - macro_rules! fail( ($msg: expr) => ( ::core::sys::begin_unwind($msg, file!().to_owned(), line!())