From 7a661358ad5fd668cb35df7a5886308a2fc37602 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 15 Mar 2011 18:45:56 -0400 Subject: [PATCH 1/3] Remove usages of case(_) { fail; } since the compiler does this automatically --- src/comp/middle/trans.rs | 3 --- src/comp/middle/typeck.rs | 6 ------ src/lib/deque.rs | 1 - src/lib/map.rs | 1 - 4 files changed, 11 deletions(-) diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index d4cd399228951..e81d5a091e48e 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -1753,7 +1753,6 @@ fn variant_types(@crate_ctxt cx, &ast.variant v) -> vec[@ty.t] { } } case (ty.ty_tag(_, _)) { /* nothing */ } - case (_) { fail; } } ret tys; } @@ -1966,7 +1965,6 @@ fn iter_structural_ty_full(@block_ctxt cx, j += 1; } } - case (_) { fail; } } variant_cx.build.Br(next_cx.llbb); @@ -2133,7 +2131,6 @@ fn iter_sequence(@block_ctxt cx, auto et = plain_ty(ty.ty_machine(common.ty_u8)); ret iter_sequence_body(cx, v, et, f, true); } - case (_) { fail; } } cx.fcx.ccx.sess.bug("bad type in trans.iter_sequence"); fail; diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index c849483e8addd..75d6a8fff6101 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1861,9 +1861,6 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr { case (ty.ty_chan(?it)) { item_t = it; } - case (_) { - fail; - } } auto rhs_1 = demand_expr(fcx, item_t, rhs_0); @@ -1884,9 +1881,6 @@ fn check_expr(&@fn_ctxt fcx, @ast.expr expr) -> @ast.expr { case (ty.ty_port(?it)) { item_t = it; } - case (_) { - fail; - } } auto lhs_1 = demand_expr(fcx, item_t, lhs_0); diff --git a/src/lib/deque.rs b/src/lib/deque.rs index 776f82e99fe8f..704e674930076 100644 --- a/src/lib/deque.rs +++ b/src/lib/deque.rs @@ -47,7 +47,6 @@ fn create[T]() -> t[T] { fn get[T](vec[cell[T]] elts, uint i) -> T { alt (elts.(i)) { case (option.some[T](?t)) { ret t; } - case (_) { fail; } } fail; // FIXME: remove me when exhaustiveness checking works } diff --git a/src/lib/map.rs b/src/lib/map.rs index f22faaca7194a..d8e2431408640 100644 --- a/src/lib/map.rs +++ b/src/lib/map.rs @@ -176,7 +176,6 @@ fn mk_hashmap[K, V](&hashfn[K] hasher, &eqfn[K] eqer) -> hashmap[K, V] { fn get(&K key) -> V { alt (find_common[K, V](hasher, eqer, bkts, nbkts, key)) { case (option.some[V](?val)) { ret val; } - case (_) { fail; } } fail; // FIXME: remove me when exhaustiveness checking works } From 1cae322aa236761eaa4d26ed98a56eca261eebfd Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 16 Mar 2011 22:28:00 -0400 Subject: [PATCH 2/3] Update docs for if statements --- doc/rust.texi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/doc/rust.texi b/doc/rust.texi index 48a639ddcd17f..4b92fa94d3ec0 100644 --- a/doc/rust.texi +++ b/doc/rust.texi @@ -3310,11 +3310,14 @@ for each (str s in _str.split(txt, "\n")) @{ An @code{if} statement is a conditional branch in program control. The form of an @code{if} statement is a parenthesized condition expression, followed by a -consequent block, and an optional trailing @code{else} block. The condition -expression must have type @code{bool}. If the condition expression evaluates -to @code{true}, the consequent block is executed and any @code{else} block is -skipped. If the condition expression evaluates to @code{false}, the consequent -block is skipped and any @code{else} block is executed. +consequent block, any number of @code{else if} conditions and blocks, and an +optional trailing @code{else} block. The condition expressions must have type +@code{bool}. If a condition expression evaluates to @code{true}, the +consequent block is executed and any subsequent @code{else if} or @code{else} +block is skipped. If a condition expression evaluates to @code{false}, the +consequent block is skipped and any subsequent @code{else if} condition is +evaluated. If all @code{if} and @code{else if} conditions evaluate to @code{false} +then any @code{else} block is executed. @node Ref.Stmt.Alt @subsection Ref.Stmt.Alt From 87323573772619a99b07b4610639c6ec9c69c670 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 14 Mar 2011 19:57:12 -0400 Subject: [PATCH 3/3] Add some nesting to the else-if test case --- src/test/run-pass/else-if.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/test/run-pass/else-if.rs b/src/test/run-pass/else-if.rs index 9e3eac149fd80..d9e5b8690250f 100644 --- a/src/test/run-pass/else-if.rs +++ b/src/test/run-pass/else-if.rs @@ -16,4 +16,27 @@ fn main() { check(true); } -} \ No newline at end of file + if (1 == 2) { + check(false); + } else if (2 == 2) { + if (1 == 1) { + check(true); + } else { + if (2 == 1) { + check(false); + } else { + check(false); + } + } + } + + if (1 == 2) { + check(false); + } else { + if (1 == 2) { + check(false); + } else { + check(true); + } + } +}