auto merge of #4941 : nickdesaulniers/rust/issue4524cleanup, r=catamorphism

review? @brson
Issue #4524
This commit is contained in:
bors 2013-02-14 21:12:06 -08:00
commit 172c29fe0a
4 changed files with 20 additions and 29 deletions

View File

@ -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<X> { Nil, Cons(X, @List<X>) }
let x: List<int> = 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!()
};
~~~~

View File

@ -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;

View File

@ -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<int, ()> = 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.
# };
~~~

View File

@ -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!())