Skip to content

Commit 7868b6b

Browse files
author
Nick Desaulniers
committed
Remove fail keyword from lexer & parser and clean up remaining calls to
fail Fix merge conflicts - Issue 4524
1 parent 6fb4239 commit 7868b6b

37 files changed

+109
-145
lines changed

doc/lib/codemirror-rust.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CodeMirror.defineMode("rust", function() {
22
var indentUnit = 4, altIndentUnit = 2;
33
var valKeywords = {
44
"if": "if-style", "while": "if-style", "loop": "if-style", "else": "else-style",
5-
"do": "else-style", "return": "else-style", "fail": "else-style",
5+
"do": "else-style", "return": "else-style",
66
"break": "atom", "cont": "atom", "const": "let", "resource": "fn",
77
"let": "let", "fn": "fn", "for": "for", "match": "match", "trait": "trait",
88
"impl": "impl", "type": "type", "enum": "enum", "struct": "atom", "mod": "mod",

doc/rust.md

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ break
216216
const copy
217217
do drop
218218
else enum extern
219-
fail false fn for
219+
false fn for
220220
if impl
221221
let log loop
222222
match mod move mut
@@ -692,15 +692,15 @@ mod math {
692692
type complex = (f64, f64);
693693
fn sin(f: f64) -> f64 {
694694
...
695-
# fail;
695+
# die!();
696696
}
697697
fn cos(f: f64) -> f64 {
698698
...
699-
# fail;
699+
# die!();
700700
}
701701
fn tan(f: f64) -> f64 {
702702
...
703-
# fail;
703+
# die!();
704704
}
705705
}
706706
~~~~~~~~
@@ -989,13 +989,13 @@ output slot type would normally be. For example:
989989
~~~~
990990
fn my_err(s: &str) -> ! {
991991
log(info, s);
992-
fail;
992+
die!();
993993
}
994994
~~~~
995995

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

10091009
~~~~
1010-
# fn my_err(s: &str) -> ! { fail }
1010+
# fn my_err(s: &str) -> ! { die!() }
10111011
10121012
fn f(i: int) -> int {
10131013
if i == 42 {
@@ -2291,9 +2291,9 @@ enum List<X> { Nil, Cons(X, @List<X>) }
22912291
let x: List<int> = Cons(10, @Cons(11, @Nil));
22922292
22932293
match x {
2294-
Cons(_, @Nil) => fail ~"singleton list",
2294+
Cons(_, @Nil) => die!(~"singleton list"),
22952295
Cons(*) => return,
2296-
Nil => fail ~"empty list"
2296+
Nil => die!(~"empty list")
22972297
}
22982298
~~~~
22992299

@@ -2330,7 +2330,7 @@ match x {
23302330
return;
23312331
}
23322332
_ => {
2333-
fail;
2333+
die!();
23342334
}
23352335
}
23362336
~~~~
@@ -2418,23 +2418,10 @@ guard may refer to the variables bound within the pattern they follow.
24182418
let message = match maybe_digit {
24192419
Some(x) if x < 10 => process_digit(x),
24202420
Some(x) => process_other(x),
2421-
None => fail
2421+
None => die!()
24222422
};
24232423
~~~~
24242424

2425-
2426-
### Fail expressions
2427-
2428-
~~~~~~~~{.ebnf .gram}
2429-
fail_expr : "fail" expr ? ;
2430-
~~~~~~~~
2431-
2432-
Evaluating a `fail` expression causes a task to enter the *failing* state. In
2433-
the *failing* state, a task unwinds its stack, destroying all frames and
2434-
running all destructors until it reaches its entry frame, at which point it
2435-
halts execution in the *dead* state.
2436-
2437-
24382425
### Return expressions
24392426

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

31553142
A task may transition to the *failing* state at any time, due being
31563143
killed by some external event or internally, from the evaluation of a
3157-
`fail` expression. Once *failing*, a task unwinds its stack and
3144+
`fail!()` macro. Once *failing*, a task unwinds its stack and
31583145
transitions to the *dead* state. Unwinding the stack of a task is done by
31593146
the task itself, on its own control stack. If a value with a destructor is
31603147
freed during unwinding, the code for the destructor is run, also on the task's

doc/tutorial-macros.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ match x {
218218
// complicated stuff goes here
219219
return result + val;
220220
},
221-
_ => fail ~"Didn't get good_2"
221+
_ => die!(~"Didn't get good_2")
222222
}
223223
}
224224
_ => return 0 // default value
@@ -260,7 +260,7 @@ macro_rules! biased_match (
260260
biased_match!((x) ~ (good_1(g1, val)) else { return 0 };
261261
binds g1, val )
262262
biased_match!((g1.body) ~ (good_2(result) )
263-
else { fail ~"Didn't get good_2" };
263+
else { die!(~"Didn't get good_2") };
264264
binds result )
265265
// complicated stuff goes here
266266
return result + val;
@@ -362,7 +362,7 @@ macro_rules! biased_match (
362362
# fn f(x: t1) -> uint {
363363
biased_match!(
364364
(x) ~ (good_1(g1, val)) else { return 0 };
365-
(g1.body) ~ (good_2(result) ) else { fail ~"Didn't get good_2" };
365+
(g1.body) ~ (good_2(result) ) else { die!(~"Didn't get good_2") };
366366
binds val, result )
367367
// complicated stuff goes here
368368
return result + val;

doc/tutorial-tasks.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cheaper to create than traditional threads, Rust can create hundreds of
1313
thousands of concurrent tasks on a typical 32-bit system.
1414

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

297297
# Handling task failure
298298

299-
Rust has a built-in mechanism for raising exceptions. The `fail` construct
300-
(which can also be written with an error string as an argument: `fail
301-
~reason`) and the `assert` construct (which effectively calls `fail` if a
299+
Rust has a built-in mechanism for raising exceptions. The `fail!()` macro
300+
(which can also be written with an error string as an argument: `fail!(
301+
~reason)`) and the `assert` construct (which effectively calls `fail!()` if a
302302
boolean expression is false) are both ways to raise exceptions. When a task
303303
raises an exception the task unwinds its stack---running destructors and
304304
freeing memory along the way---and then exits. Unlike exceptions in C++,
@@ -313,7 +313,7 @@ of all tasks are intertwined: if one fails, so do all the others.
313313
# fn do_some_work() { loop { task::yield() } }
314314
# do task::try {
315315
// Create a child task that fails
316-
do spawn { fail }
316+
do spawn { die!() }
317317
318318
// This will also fail because the task we spawned failed
319319
do_some_work();
@@ -337,7 +337,7 @@ let result: Result<int, ()> = do task::try {
337337
if some_condition() {
338338
calculate_result()
339339
} else {
340-
fail ~"oops!";
340+
die!(~"oops!");
341341
}
342342
};
343343
assert result.is_err();
@@ -354,7 +354,7 @@ an `Error` result.
354354
> ***Note:*** A failed task does not currently produce a useful error
355355
> value (`try` always returns `Err(())`). In the
356356
> future, it may be possible for tasks to intercept the value passed to
357-
> `fail`.
357+
> `fail!()`.
358358
359359
TODO: Need discussion of `future_result` in order to make failure
360360
modes useful.
@@ -377,7 +377,7 @@ either task dies, it kills the other one.
377377
# do task::try {
378378
do task::spawn {
379379
do task::spawn {
380-
fail; // All three tasks will die.
380+
die!(); // All three tasks will die.
381381
}
382382
sleep_forever(); // Will get woken up by force, then fail
383383
}
@@ -432,7 +432,7 @@ do task::spawn_supervised {
432432
// Intermediate task immediately exits
433433
}
434434
wait_for_a_while();
435-
fail; // Will kill grandchild even if child has already exited
435+
die!(); // Will kill grandchild even if child has already exited
436436
# };
437437
~~~
438438

@@ -446,10 +446,10 @@ other at all, using `task::spawn_unlinked` for _isolated failure_.
446446
let (time1, time2) = (random(), random());
447447
do task::spawn_unlinked {
448448
sleep_for(time2); // Won't get forced awake
449-
fail;
449+
die!();
450450
}
451451
sleep_for(time1); // Won't get forced awake
452-
fail;
452+
die!();
453453
// It will take MAX(time1,time2) for the program to finish.
454454
# };
455455
~~~

src/libcore/pipes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
549549
//unsafe { forget(p); }
550550
return true;
551551
}
552-
Full => fail ~"duplicate send",
552+
Full => die!(~"duplicate send"),
553553
Blocked => {
554554
debug!("waking up task for %?", p_);
555555
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());

src/libcore/private/finally.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn test_fail() {
7171
let mut i = 0;
7272
do (|| {
7373
i = 10;
74-
fail;
74+
die!();
7575
}).finally {
7676
assert failing();
7777
assert i == 10;
@@ -95,4 +95,4 @@ fn test_compact() {
9595
fn but_always_run_this_function() { }
9696
do_some_fallible_work.finally(
9797
but_always_run_this_function);
98-
}
98+
}

src/libcore/private/global.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ fn test_modify() {
269269
Some(~shared_mutable_state(10))
270270
}
271271
}
272-
_ => fail
272+
_ => die!()
273273
}
274274
}
275275

@@ -280,7 +280,7 @@ fn test_modify() {
280280
assert *v == 10;
281281
None
282282
},
283-
_ => fail
283+
_ => die!()
284284
}
285285
}
286286

@@ -291,7 +291,7 @@ fn test_modify() {
291291
Some(~shared_mutable_state(10))
292292
}
293293
}
294-
_ => fail
294+
_ => die!()
295295
}
296296
}
297297
}

src/libcore/private/weak_task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn run_weak_task_service(port: Port<ServiceMsg>) {
112112
// nobody will receive this
113113
shutdown_chan.send(());
114114
}
115-
None => fail
115+
None => die!()
116116
}
117117
}
118118
Shutdown => break
@@ -195,7 +195,7 @@ fn test_select_stream_and_oneshot() {
195195
do weaken_task |signal| {
196196
match select2i(&port, &signal) {
197197
Left(*) => (),
198-
Right(*) => fail
198+
Right(*) => die!()
199199
}
200200
}
201201
}

src/libcore/repr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ impl ReprVisitor : TyVisitor {
594594
}
595595

596596
// Type no longer exists, vestigial function.
597-
fn visit_str(&self) -> bool { fail; }
597+
fn visit_str(&self) -> bool { die!(); }
598598

599599
fn visit_estr_box(&self) -> bool {
600600
do self.get::<@str> |s| {
@@ -616,7 +616,7 @@ impl ReprVisitor : TyVisitor {
616616

617617
// Type no longer exists, vestigial function.
618618
fn visit_estr_fixed(&self, _n: uint, _sz: uint,
619-
_align: uint) -> bool { fail; }
619+
_align: uint) -> bool { die!(); }
620620

621621
fn visit_box(&self, mtbl: uint, inner: *TyDesc) -> bool {
622622
self.writer.write_char('@');
@@ -652,7 +652,7 @@ impl ReprVisitor : TyVisitor {
652652
}
653653

654654
// Type no longer exists, vestigial function.
655-
fn visit_vec(&self, _mtbl: uint, _inner: *TyDesc) -> bool { fail; }
655+
fn visit_vec(&self, _mtbl: uint, _inner: *TyDesc) -> bool { die!(); }
656656

657657

658658
fn visit_unboxed_vec(&self, mtbl: uint, inner: *TyDesc) -> bool {
@@ -859,7 +859,7 @@ impl ReprVisitor : TyVisitor {
859859
}
860860

861861
// Type no longer exists, vestigial function.
862-
fn visit_constr(&self, _inner: *TyDesc) -> bool { fail; }
862+
fn visit_constr(&self, _inner: *TyDesc) -> bool { die!(); }
863863

864864
fn visit_closure_ptr(&self, _ck: uint) -> bool { true }
865865
}

src/libfuzzer/fuzzer.rc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ pub fn common_exprs() -> ~[ast::expr] {
8484

8585
~[dse(ast::expr_break(option::None)),
8686
dse(ast::expr_again(option::None)),
87-
dse(ast::expr_fail(option::None)),
88-
dse(ast::expr_fail(option::Some(
89-
@dse(ast::expr_lit(@dsl(ast::lit_str(@~"boo"))))))),
9087
dse(ast::expr_ret(option::None)),
9188
dse(ast::expr_lit(@dsl(ast::lit_nil))),
9289
dse(ast::expr_lit(@dsl(ast::lit_bool(false)))),
@@ -117,11 +114,10 @@ pub pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
117114
ast::expr_binary(*) | ast::expr_assign(*) |
118115
ast::expr_assign_op(*) => { false }
119116

120-
ast::expr_fail(option::None) |
121117
ast::expr_ret(option::None) => { false }
122118

123119
// https://github.com/mozilla/rust/issues/953
124-
ast::expr_fail(option::Some(_)) => { false }
120+
//ast::expr_fail(option::Some(_)) => { false }
125121

126122
// https://github.com/mozilla/rust/issues/928
127123
//ast::expr_cast(_, _) { false }

src/librustc/middle/liveness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ fn visit_expr(expr: @expr, &&self: @IrMaps, vt: vt<@IrMaps>) {
610610
expr_tup(*) | expr_log(*) | expr_binary(*) |
611611
expr_assert(*) | expr_addr_of(*) | expr_copy(*) |
612612
expr_loop_body(*) | expr_do_body(*) | expr_cast(*) |
613-
expr_unary(*) | expr_fail(*) |
613+
expr_unary(*) |
614614
expr_break(_) | expr_again(_) | expr_lit(_) | expr_ret(*) |
615615
expr_block(*) | expr_assign(*) |
616616
expr_swap(*) | expr_assign_op(*) | expr_mac(*) | expr_struct(*) |
@@ -1191,7 +1191,7 @@ impl Liveness {
11911191
self.propagate_through_expr(e, ln)
11921192
}
11931193

1194-
expr_ret(o_e) | expr_fail(o_e) => {
1194+
expr_ret(o_e) => {
11951195
// ignore succ and subst exit_ln:
11961196
self.propagate_through_opt_expr(o_e, self.s.exit_ln)
11971197
}
@@ -1608,7 +1608,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
16081608
expr_log(*) | expr_binary(*) |
16091609
expr_assert(*) | expr_copy(*) |
16101610
expr_loop_body(*) | expr_do_body(*) |
1611-
expr_cast(*) | expr_unary(*) | expr_fail(*) |
1611+
expr_cast(*) | expr_unary(*) |
16121612
expr_ret(*) | expr_break(*) | expr_again(*) | expr_lit(_) |
16131613
expr_block(*) | expr_swap(*) | expr_mac(*) | expr_addr_of(*) |
16141614
expr_struct(*) | expr_repeat(*) | expr_paren(*) => {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ pub impl &mem_categorization_ctxt {
387387
ast::expr_assert(*) | ast::expr_ret(*) |
388388
ast::expr_loop_body(*) | ast::expr_do_body(*) |
389389
ast::expr_unary(*) | ast::expr_method_call(*) |
390-
ast::expr_copy(*) | ast::expr_cast(*) | ast::expr_fail(*) |
390+
ast::expr_copy(*) | ast::expr_cast(*) |
391391
ast::expr_vstore(*) | ast::expr_vec(*) | ast::expr_tup(*) |
392392
ast::expr_if(*) | ast::expr_log(*) |
393393
ast::expr_binary(*) | ast::expr_while(*) |

0 commit comments

Comments
 (0)