Skip to content

removal of fail keyword Issue #4524 #4721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion doc/lib/codemirror-rust.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CodeMirror.defineMode("rust", function() {
var indentUnit = 4, altIndentUnit = 2;
var valKeywords = {
"if": "if-style", "while": "if-style", "loop": "if-style", "else": "else-style",
"do": "else-style", "return": "else-style", "fail": "else-style",
"do": "else-style", "return": "else-style",
"break": "atom", "cont": "atom", "const": "let", "resource": "fn",
"let": "let", "fn": "fn", "for": "for", "match": "match", "trait": "trait",
"impl": "impl", "type": "type", "enum": "enum", "struct": "atom", "mod": "mod",
Expand Down
37 changes: 12 additions & 25 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ break
const copy
do drop
else enum extern
fail false fn for
false fn for
if impl
let log loop
match mod move mut
Expand Down Expand Up @@ -692,15 +692,15 @@ mod math {
type complex = (f64, f64);
fn sin(f: f64) -> f64 {
...
# fail;
# die!();
}
fn cos(f: f64) -> f64 {
...
# fail;
# die!();
}
fn tan(f: f64) -> f64 {
...
# fail;
# die!();
}
}
~~~~~~~~
Expand Down Expand Up @@ -989,13 +989,13 @@ output slot type would normally be. For example:
~~~~
fn my_err(s: &str) -> ! {
log(info, s);
fail;
die!();
}
~~~~

We call such functions "diverging" because they never return a value to the
caller. Every control path in a diverging function must end with a
[`fail`](#fail-expressions) or a call to another diverging function on every
`fail!()` or a call to another diverging function on every
control path. The `!` annotation does *not* denote a type. Rather, the result
type of a diverging function is a special type called $\bot$ ("bottom") that
unifies with any type. Rust has no syntax for $\bot$.
Expand All @@ -1007,7 +1007,7 @@ were declared without the `!` annotation, the following code would not
typecheck:

~~~~
# fn my_err(s: &str) -> ! { fail }
# fn my_err(s: &str) -> ! { die!() }

fn f(i: int) -> int {
if i == 42 {
Expand Down Expand Up @@ -2291,9 +2291,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
let x: List<int> = Cons(10, @Cons(11, @Nil));

match x {
Cons(_, @Nil) => fail ~"singleton list",
Cons(_, @Nil) => die!(~"singleton list"),
Cons(*) => return,
Nil => fail ~"empty list"
Nil => die!(~"empty list")
}
~~~~

Expand Down Expand Up @@ -2330,7 +2330,7 @@ match x {
return;
}
_ => {
fail;
die!();
}
}
~~~~
Expand Down Expand Up @@ -2418,23 +2418,10 @@ 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 => fail
None => die!()
};
~~~~


### Fail expressions

~~~~~~~~{.ebnf .gram}
fail_expr : "fail" expr ? ;
~~~~~~~~

Evaluating a `fail` expression causes a task to enter the *failing* state. In
the *failing* state, a task unwinds its stack, destroying all frames and
running all destructors until it reaches its entry frame, at which point it
halts execution in the *dead* state.


### Return expressions

~~~~~~~~{.ebnf .gram}
Expand Down Expand Up @@ -3154,7 +3141,7 @@ unblock and transition back to *running*.

A task may transition to the *failing* state at any time, due being
killed by some external event or internally, from the evaluation of a
`fail` expression. Once *failing*, a task unwinds its stack and
`fail!()` macro. Once *failing*, a task unwinds its stack and
transitions to the *dead* state. Unwinding the stack of a task is done by
the task itself, on its own control stack. If a value with a destructor is
freed during unwinding, the code for the destructor is run, also on the task's
Expand Down
6 changes: 3 additions & 3 deletions doc/tutorial-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ match x {
// complicated stuff goes here
return result + val;
},
_ => fail ~"Didn't get good_2"
_ => die!(~"Didn't get good_2")
}
}
_ => return 0 // default value
Expand Down Expand Up @@ -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 { fail ~"Didn't get good_2" };
else { die!(~"Didn't get good_2") };
binds result )
// complicated stuff goes here
return result + val;
Expand Down Expand Up @@ -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 { fail ~"Didn't get good_2" };
(g1.body) ~ (good_2(result) ) else { die!(~"Didn't get good_2") };
binds val, result )
// complicated stuff goes here
return result + val;
Expand Down
22 changes: 11 additions & 11 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cheaper to create than traditional threads, Rust can create hundreds of
thousands of concurrent tasks on a typical 32-bit system.

Tasks provide failure isolation and recovery. When an exception occurs in Rust
code (as a result of an explicit call to `fail`, an assertion failure, or
code (as a result of an explicit call to `fail!()`, an assertion failure, or
another invalid operation), the runtime system destroys the entire
task. Unlike in languages such as Java and C++, there is no way to `catch` an
exception. Instead, tasks may monitor each other for failure.
Expand Down Expand Up @@ -296,9 +296,9 @@ let result = ports.foldl(0, |accum, port| *accum + port.recv() );

# Handling task failure

Rust has a built-in mechanism for raising exceptions. The `fail` construct
(which can also be written with an error string as an argument: `fail
~reason`) and the `assert` construct (which effectively calls `fail` if a
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
(which can also be written with an error string as an argument: `fail!(
~reason)`) and the `assert` construct (which effectively calls `fail!()` if a
boolean expression is false) are both ways to raise exceptions. When a task
raises an exception the task unwinds its stack---running destructors and
freeing memory along the way---and then exits. Unlike exceptions in C++,
Expand All @@ -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 { fail }
do spawn { die!() }

// This will also fail because the task we spawned failed
do_some_work();
Expand All @@ -337,7 +337,7 @@ let result: Result<int, ()> = do task::try {
if some_condition() {
calculate_result()
} else {
fail ~"oops!";
die!(~"oops!");
}
};
assert result.is_err();
Expand All @@ -354,7 +354,7 @@ an `Error` result.
> ***Note:*** A failed task does not currently produce a useful error
> value (`try` always returns `Err(())`). In the
> future, it may be possible for tasks to intercept the value passed to
> `fail`.
> `fail!()`.

TODO: Need discussion of `future_result` in order to make failure
modes useful.
Expand All @@ -377,7 +377,7 @@ either task dies, it kills the other one.
# do task::try {
do task::spawn {
do task::spawn {
fail; // All three tasks will die.
die!(); // All three tasks will die.
}
sleep_forever(); // Will get woken up by force, then fail
}
Expand Down Expand Up @@ -432,7 +432,7 @@ do task::spawn_supervised {
// Intermediate task immediately exits
}
wait_for_a_while();
fail; // Will kill grandchild even if child has already exited
die!(); // Will kill grandchild even if child has already exited
# };
~~~

Expand All @@ -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
fail;
die!();
}
sleep_for(time1); // Won't get forced awake
fail;
die!();
// It will take MAX(time1,time2) for the program to finish.
# };
~~~
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn parse_config(args: ~[~str]) -> config {
let matches =
&match getopts::getopts(args_, opts) {
Ok(m) => m,
Err(f) => fail getopts::fail_str(f)
Err(f) => die!(getopts::fail_str(f))
};

fn opt_path(m: &getopts::Matches, nm: ~str) -> Path {
Expand Down Expand Up @@ -137,7 +137,7 @@ fn str_mode(s: ~str) -> mode {
~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass,
~"pretty" => mode_pretty,
_ => fail ~"invalid mode"
_ => die!(~"invalid mode")
}
}

Expand All @@ -154,7 +154,7 @@ fn run_tests(config: config) {
let opts = test_opts(config);
let tests = make_tests(config);
let res = test::run_tests_console(&opts, tests);
if !res { fail ~"Some tests failed"; }
if !res { die!(~"Some tests failed"); }
}

fn test_opts(config: config) -> test::TestOpts {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn parse_exec_env(line: ~str) -> Option<(~str, ~str)> {
match strs.len() {
1u => (strs[0], ~""),
2u => (strs[0], strs[1]),
n => fail fmt!("Expected 1 or 2 strings, not %u", n)
n => die!(fmt!("Expected 1 or 2 strings, not %u", n))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn run(lib_path: ~str,
os::close(pipe_in.out);
os::close(pipe_out.in);
os::close(pipe_err.in);
fail;
die!();
}


Expand Down Expand Up @@ -101,7 +101,7 @@ fn run(lib_path: ~str,
(2, s) => {
errs = s;
}
_ => { fail }
_ => { die!() }
};
count -= 1;
};
Expand Down
8 changes: 4 additions & 4 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ actual:\n\
\n",
expected, actual);
io::stdout().write_str(msg);
fail;
die!();
}
}

Expand Down Expand Up @@ -469,7 +469,7 @@ fn compose_and_run_compiler(
fn ensure_dir(path: &Path) {
if os::path_is_dir(path) { return; }
if !os::make_dir(path, 0x1c0i32) {
fail fmt!("can't make dir %s", path.to_str());
die!(fmt!("can't make dir %s", path.to_str()));
}
}

Expand Down Expand Up @@ -619,7 +619,7 @@ fn maybe_dump_to_stdout(config: config, out: ~str, err: ~str) {

fn error(err: ~str) { io::stdout().write_line(fmt!("\nerror: %s", err)); }

fn fatal(err: ~str) -> ! { error(err); fail; }
fn fatal(err: ~str) -> ! { error(err); die!(); }

fn fatal_procres(err: ~str, procres: procres) -> ! {
let msg =
Expand All @@ -637,5 +637,5 @@ stderr:\n\
\n",
err, procres.cmdline, procres.stdout, procres.stderr);
io::stdout().write_str(msg);
fail;
die!();
}
Loading