Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert alt to match. Stop parsing alt

  • Loading branch information...
commit ecaf9e39c9435fa2de4fe393c4b263be36eb2d99 1 parent d3a9bb1
@brson brson authored
Showing with 2,849 additions and 2,826 deletions.
  1. +20 −20 doc/rust.md
  2. +17 −17 doc/tutorial.md
  3. +67 −67 src/cargo/cargo.rs
  4. +7 −7 src/compiletest/compiletest.rs
  5. +1 −1  src/compiletest/errors.rs
  6. +4 −4 src/compiletest/header.rs
  7. +1 −1  src/compiletest/procsrv.rs
  8. +5 −5 src/compiletest/runtest.rs
  9. +1 −1  src/compiletest/util.rs
  10. +9 −9 src/fuzzer/fuzzer.rs
  11. +1 −1  src/libcore/bool.rs
  12. +2 −2 src/libcore/char.rs
  13. +1 −1  src/libcore/comm.rs
  14. +10 −10 src/libcore/dlist.rs
  15. +1 −1  src/libcore/dvec.rs
  16. +8 −8 src/libcore/either.rs
  17. +12 −12 src/libcore/extfmt.rs
  18. +7 −7 src/libcore/float.rs
  19. +2 −2 src/libcore/future.rs
  20. +1 −1  src/libcore/int-template.rs
  21. +9 −9 src/libcore/io.rs
  22. +2 −2 src/libcore/iter-trait/option.rs
  23. +4 −4 src/libcore/iter.rs
  24. +9 −9 src/libcore/option.rs
  25. +4 −4 src/libcore/os.rs
  26. +1 −1  src/libcore/path.rs
  27. +21 −21 src/libcore/pipes.rs
  28. +1 −1  src/libcore/priv.rs
  29. +20 −20 src/libcore/result.rs
  30. +4 −4 src/libcore/run.rs
  31. +6 −6 src/libcore/send_map.rs
  32. +8 −8 src/libcore/str.rs
  33. +14 −14 src/libcore/task.rs
  34. +2 −2 src/libcore/uint-template.rs
  35. +32 −32 src/libcore/unicode.rs
  36. +5 −5 src/libcore/vec.rs
  37. +2 −2 src/libstd/base64.rs
  38. +16 −16 src/libstd/bitv.rs
  39. +1 −1  src/libstd/c_vec.rs
  40. +9 −9 src/libstd/deque.rs
  41. +4 −4 src/libstd/ebml.rs
  42. +3 −3 src/libstd/fun_treemap.rs
  43. +54 −52 src/libstd/getopts.rs
  44. +28 −28 src/libstd/json.rs
  45. +7 −7 src/libstd/list.rs
  46. +8 −8 src/libstd/map.rs
  47. +8 −8 src/libstd/net_ip.rs
  48. +33 −33 src/libstd/net_tcp.rs
  49. +36 −36 src/libstd/rope.rs
  50. +2 −2 src/libstd/serialization.rs
  51. +4 −4 src/libstd/smallintmap.rs
  52. +1 −1  src/libstd/tempfile.rs
  53. +1 −1  src/libstd/term.rs
  54. +12 −11 src/libstd/test.rs
  55. +39 −35 src/libstd/time.rs
  56. +2 −2 src/libstd/timer.rs
  57. +3 −3 src/libstd/treemap.rs
  58. +1 −1  src/libstd/uv_global_loop.rs
  59. +1 −1  src/libstd/uv_iotask.rs
  60. +1 −1  src/libstd/uv_ll.rs
  61. +1 −1  src/libsyntax/ast.rs
  62. +10 −10 src/libsyntax/ast_map.rs
  63. +40 −40 src/libsyntax/ast_util.rs
  64. +16 −16 src/libsyntax/attr.rs
  65. +3 −3 src/libsyntax/codemap.rs
  66. +6 −6 src/libsyntax/diagnostic.rs
  67. +7 −7 src/libsyntax/ext/auto_serialize.rs
  68. +11 −11 src/libsyntax/ext/base.rs
  69. +1 −1  src/libsyntax/ext/env.rs
  70. +13 −13 src/libsyntax/ext/expand.rs
  71. +20 −20 src/libsyntax/ext/fmt.rs
  72. +1 −1  src/libsyntax/ext/pipes/check.rs
  73. +3 −3 src/libsyntax/ext/pipes/parse_proto.rs
  74. +11 −11 src/libsyntax/ext/pipes/pipec.rs
  75. +6 −6 src/libsyntax/ext/pipes/proto.rs
  76. +12 −12 src/libsyntax/ext/qquote.rs
  77. +56 −56 src/libsyntax/ext/simplext.rs
  78. +2 −2 src/libsyntax/ext/source_util.rs
  79. +13 −13 src/libsyntax/ext/tt/earley_parser.rs
  80. +6 −5 src/libsyntax/ext/tt/macro_rules.rs
  81. +12 −12 src/libsyntax/ext/tt/transcribe.rs
  82. +17 −17 src/libsyntax/fold.rs
  83. +1 −1  src/libsyntax/parse.rs
  84. +5 −5 src/libsyntax/parse/attr.rs
  85. +7 −7 src/libsyntax/parse/classify.rs
  86. +7 −7 src/libsyntax/parse/common.rs
  87. +4 −4 src/libsyntax/parse/eval.rs
  88. +12 −12 src/libsyntax/parse/lexer.rs
  89. +70 −70 src/libsyntax/parse/parser.rs
  90. +1 −1  src/libsyntax/parse/prec.rs
  91. +11 −11 src/libsyntax/parse/token.rs
  92. +6 −6 src/libsyntax/print/pp.rs
  93. +76 −76 src/libsyntax/print/pprust.rs
  94. +1 −1  src/libsyntax/util/interner.rs
  95. +16 −16 src/libsyntax/visit.rs
  96. +12 −12 src/rustc/back/link.rs
  97. +2 −2 src/rustc/back/rpath.rs
  98. +2 −2 src/rustc/back/x86.rs
  99. +2 −2 src/rustc/back/x86_64.rs
  100. +25 −25 src/rustc/driver/driver.rs
  101. +6 −6 src/rustc/driver/rustc.rs
  102. +4 −4 src/rustc/driver/session.rs
  103. +2 −2 src/rustc/front/config.rs
  104. +1 −1  src/rustc/front/intrinsic_inject.rs
  105. +4 −4 src/rustc/front/test.rs
  106. +3 −3 src/rustc/lib/llvm.rs
  107. +8 −8 src/rustc/metadata/creader.rs
  108. +1 −1  src/rustc/metadata/csearch.rs
  109. +1 −1  src/rustc/metadata/cstore.rs
  110. +27 −27 src/rustc/metadata/decoder.rs
  111. +30 −30 src/rustc/metadata/encoder.rs
  112. +6 −6 src/rustc/metadata/filesearch.rs
  113. +8 −8 src/rustc/metadata/loader.rs
  114. +17 −17 src/rustc/metadata/tydecode.rs
  115. +19 −19 src/rustc/metadata/tyencode.rs
  116. +10 −10 src/rustc/middle/astencode.rs
  117. +2 −2 src/rustc/middle/block_use.rs
  118. +14 −14 src/rustc/middle/borrowck.rs
  119. +20 −20 src/rustc/middle/borrowck/categorization.rs
  120. +32 −32 src/rustc/middle/borrowck/check_loans.rs
  121. +16 −16 src/rustc/middle/borrowck/gather_loans.rs
  122. +3 −3 src/rustc/middle/borrowck/loan.rs
  123. +10 −10 src/rustc/middle/borrowck/preserve.rs
  124. +2 −2 src/rustc/middle/capture.rs
  125. +39 −37 src/rustc/middle/check_alt.rs
  126. +9 −9 src/rustc/middle/check_const.rs
  127. +1 −1  src/rustc/middle/check_loop.rs
  128. +21 −21 src/rustc/middle/const_eval.rs
  129. +4 −4 src/rustc/middle/freevars.rs
  130. +21 −21 src/rustc/middle/kind.rs
  131. +6 −6 src/rustc/middle/lang_items.rs
  132. +18 −18 src/rustc/middle/lint.rs
  133. +47 −47 src/rustc/middle/liveness.rs
  134. +3 −3 src/rustc/middle/pat_util.rs
  135. +16 −16 src/rustc/middle/region.rs
  136. +161 −156 src/rustc/middle/resolve3.rs
  137. +37 −35 src/rustc/middle/trans/alt.rs
  138. +166 −166 src/rustc/middle/trans/base.rs
  139. +1 −1  src/rustc/middle/trans/build.rs
  140. +16 −16 src/rustc/middle/trans/closure.rs
  141. +19 −19 src/rustc/middle/trans/common.rs
  142. +12 −10 src/rustc/middle/trans/consts.rs
  143. +31 −31 src/rustc/middle/trans/debuginfo.rs
  144. +23 −23 src/rustc/middle/trans/foreign.rs
  145. +12 −12 src/rustc/middle/trans/impl.rs
  146. +12 −12 src/rustc/middle/trans/reachable.rs
  147. +8 −8 src/rustc/middle/trans/reflect.rs
  148. +8 −8 src/rustc/middle/trans/shape.rs
  149. +8 −8 src/rustc/middle/trans/tvec.rs
  150. +5 −5 src/rustc/middle/trans/type_of.rs
  151. +12 −12 src/rustc/middle/trans/type_use.rs
  152. +1 −1  src/rustc/middle/trans/uniq.rs
  153. +1 −1  src/rustc/middle/tstate/ann.rs
  154. +1 −1  src/rustc/middle/tstate/annotate.rs
  155. +29 −29 src/rustc/middle/tstate/auxiliary.rs
  156. +2 −2 src/rustc/middle/tstate/collect_locals.rs
  157. +25 −25 src/rustc/middle/tstate/pre_post_conditions.rs
  158. +23 −23 src/rustc/middle/tstate/states.rs
  159. +10 −10 src/rustc/middle/tstate/tritv.rs
  160. +107 −107 src/rustc/middle/ty.rs
  161. +9 −9 src/rustc/middle/typeck.rs
  162. +14 −14 src/rustc/middle/typeck/astconv.rs
  163. +92 −92 src/rustc/middle/typeck/check.rs
  164. +10 −10 src/rustc/middle/typeck/check/alt.rs
  165. +3 −3 src/rustc/middle/typeck/check/demand.rs
  166. +19 −17 src/rustc/middle/typeck/check/method.rs
  167. +9 −9 src/rustc/middle/typeck/check/regionck.rs
  168. +8 −8 src/rustc/middle/typeck/check/regionmanip.rs
  169. +18 −18 src/rustc/middle/typeck/check/vtable.rs
  170. +7 −7 src/rustc/middle/typeck/check/writeback.rs
  171. +22 −20 src/rustc/middle/typeck/coherence.rs
  172. +19 −19 src/rustc/middle/typeck/collect.rs
  173. +56 −56 src/rustc/middle/typeck/infer.rs
  174. +4 −4 src/rustc/util/common.rs
  175. +17 −17 src/rustc/util/ppaux.rs
  176. +1 −1  src/rustdoc/astsrv.rs
  177. +3 −3 src/rustdoc/attr_parser.rs
  178. +4 −4 src/rustdoc/attr_pass.rs
  179. +5 −5 src/rustdoc/config.rs
  180. +2 −2 src/rustdoc/desc_to_brief_pass.rs
  181. +18 −18 src/rustdoc/doc.rs
  182. +3 −3 src/rustdoc/extract.rs
  183. +2 −2 src/rustdoc/fold.rs
  184. +1 −1  src/rustdoc/markdown_index_pass.rs
  185. +11 −11 src/rustdoc/markdown_pass.rs
  186. +6 −6 src/rustdoc/markdown_writer.rs
  187. +1 −1  src/rustdoc/page_pass.rs
  188. +1 −1  src/rustdoc/prune_hidden_pass.rs
  189. +1 −1  src/rustdoc/rustdoc.rs
  190. +3 −3 src/rustdoc/sectionalize_pass.rs
  191. +1 −1  src/rustdoc/sort_item_type_pass.rs
  192. +10 −10 src/rustdoc/tystr_pass.rs
  193. +1 −1  src/test/auxiliary/issue2378a.rs
  194. +1 −1  src/test/bench/core-std.rs
  195. +6 −6 src/test/bench/graph500-bfs.rs
  196. +1 −1  src/test/bench/msgsend-pipes-shared.rs
  197. +1 −1  src/test/bench/msgsend-pipes.rs
  198. +1 −1  src/test/bench/msgsend-ring-pipes.rs
  199. +1 −1  src/test/bench/msgsend.rs
  200. +2 −2 src/test/bench/pingpong.rs
  201. +1 −1  src/test/bench/shootout-binarytrees.rs
  202. +4 −4 src/test/bench/shootout-chameneos-redux.rs
  203. +5 −5 src/test/bench/shootout-k-nucleotide-pipes.rs
  204. +5 −5 src/test/bench/shootout-k-nucleotide.rs
  205. +1 −1  src/test/bench/shootout-mandelbrot.rs
  206. +1 −1  src/test/bench/shootout-pfib.rs
  207. +1 −1  src/test/bench/shootout-threadring.rs
  208. +1 −1  src/test/bench/task-perf-alloc-unwind.rs
  209. +5 −5 src/test/bench/task-perf-one-million.rs
  210. +8 −8 src/test/bench/task-perf-word-count-generic.rs
  211. +1 −1  src/test/compile-fail/alt-arrows-block-then-binop.rs
  212. +1 −1  src/test/compile-fail/alt-join.rs
  213. +1 −1  src/test/compile-fail/alt-pattern-field-mismatch-2.rs
  214. +1 −1  src/test/compile-fail/alt-pattern-field-mismatch.rs
  215. +5 −5 src/test/compile-fail/alt-range-fail-dominate.rs
  216. +3 −3 src/test/compile-fail/alt-range-fail.rs
  217. +1 −1  src/test/compile-fail/alt-tag-nullary.rs
  218. +1 −1  src/test/compile-fail/alt-tag-unary.rs
  219. +1 −1  src/test/compile-fail/bad-alt.rs
  220. +1 −1  src/test/compile-fail/bad-record-pat-2.rs
  221. +1 −1  src/test/compile-fail/bad-record-pat.rs
  222. +1 −1  src/test/compile-fail/bogus-tag.rs
  223. +1 −1  src/test/compile-fail/borrowck-binding-mutbl.rs
  224. +1 −1  src/test/compile-fail/borrowck-issue-2657-1.rs
  225. +1 −1  src/test/compile-fail/borrowck-issue-2657-2.rs
  226. +1 −1  src/test/compile-fail/borrowck-no-cycle-in-exchange-heap.rs
  227. +4 −4 src/test/compile-fail/borrowck-pat-enum-in-box.rs
  228. +6 −6 src/test/compile-fail/borrowck-pat-enum.rs
  229. +1 −1  src/test/compile-fail/borrowck-pat-reassign-binding.rs
  230. +1 −1  src/test/compile-fail/borrowck-pat-reassign-sometimes-binding.rs
  231. +2 −2 src/test/compile-fail/borrowck-unchecked-with-borrow.rs
  232. +1 −1  src/test/compile-fail/deref-non-pointer.rs
  233. +1 −1  src/test/compile-fail/issue-1193.rs
  234. +1 −1  src/test/compile-fail/issue-2111.rs
  235. +1 −1  src/test/compile-fail/issue-2354.rs
  236. +1 −1  src/test/compile-fail/issue-2848.rs
  237. +1 −1  src/test/compile-fail/issue-2849.rs
  238. +3 −3 src/test/compile-fail/issue-3038.rs
  239. +2 −2 src/test/compile-fail/liveness-missing-ret2.rs
  240. +1 −1  src/test/compile-fail/liveness-unused.rs
  241. +1 −1  src/test/compile-fail/non-exhaustive-match-nested.rs
  242. +7 −7 src/test/compile-fail/non-exhaustive-match.rs
  243. +1 −1  src/test/compile-fail/occurs-check-3.rs
  244. +1 −1  src/test/compile-fail/or-patter-mismatch.rs
  245. +1 −1  src/test/compile-fail/pattern-tyvar-2.rs
  246. +1 −1  src/test/compile-fail/pattern-tyvar.rs
  247. +2 −2 src/test/compile-fail/regions-creating-enums.rs
  248. +1 −1  src/test/compile-fail/restricted-keyword1.rs
  249. +1 −1  src/test/compile-fail/unreachable-arm.rs
  250. +1 −1  src/test/pretty/alt-naked-expr-long.rs
  251. +1 −1  src/test/pretty/alt-naked-expr-medium.rs
  252. +1 −1  src/test/pretty/alt-naked-expr.rs
  253. +5 −5 src/test/pretty/block-disambig.rs
  254. +2 −2 src/test/pretty/unary-op-disambig.rs
  255. +1 −1  src/test/run-fail/alt-bot-fail.rs
  256. +1 −1  src/test/run-fail/alt-disc-bot.rs
  257. +1 −1  src/test/run-fail/alt-wildcards.rs
  258. +1 −1  src/test/run-fail/expr-alt-fail-fn.rs
  259. +1 −1  src/test/run-fail/expr-alt-fail.rs
  260. +1 −1  src/test/run-fail/fail-parens.rs
  261. +1 −1  src/test/run-fail/issue-2156.rs
  262. +1 −1  src/test/run-fail/unwind-alt.rs
  263. +4 −4 src/test/run-pass/alt-arrows-blocky-commas.rs
  264. +1 −1  src/test/run-pass/alt-bot-2.rs
  265. +1 −1  src/test/run-pass/alt-bot.rs
  266. +1 −1  src/test/run-pass/alt-implicit-copy-unique.rs
  267. +1 −1  src/test/run-pass/alt-implicit-copy.rs
  268. +1 −1  src/test/run-pass/alt-join.rs
  269. +1 −1  src/test/run-pass/alt-naked-record-expr.rs
  270. +1 −1  src/test/run-pass/alt-naked-record.rs
  271. +1 −1  src/test/run-pass/alt-path.rs
  272. +1 −1  src/test/run-pass/alt-pattern-drop.rs
  273. +1 −1  src/test/run-pass/alt-pattern-lit.rs
  274. +1 −1  src/test/run-pass/alt-pattern-no-type-params.rs
  275. +1 −1  src/test/run-pass/alt-pattern-simple.rs
  276. +1 −1  src/test/run-pass/alt-phi.rs
  277. +7 −7 src/test/run-pass/alt-range.rs
  278. +4 −4 src/test/run-pass/alt-str.rs
  279. +1 −1  src/test/run-pass/alt-tag.rs
  280. +1 −1  src/test/run-pass/alt-type-simple.rs
  281. +1 −1  src/test/run-pass/alt-unique-bind.rs
  282. +1 −1  src/test/run-pass/alt-with-ret-arm.rs
  283. +1 −1  src/test/run-pass/binary-minus-without-space.rs
  284. +2 −2 src/test/run-pass/block-arg.rs
  285. +1 −1  src/test/run-pass/borrowck-pat-reassign-no-binding.rs
  286. +1 −1  src/test/run-pass/borrowck-preserve-box-in-arm-not-taken.rs
  287. +1 −1  src/test/run-pass/borrowck-preserve-box-in-discr.rs
  288. +1 −1  src/test/run-pass/borrowck-preserve-box-in-pat.rs
  289. +1 −1  src/test/run-pass/borrowck-preserve-box-sometimes-needed.rs
  290. +1 −1  src/test/run-pass/borrowck-univariant-enum.rs
  291. +1 −1  src/test/run-pass/box-pattern.rs
  292. +2 −2 src/test/run-pass/class-impl-very-parameterized-trait.rs
  293. +1 −1  src/test/run-pass/drop-on-empty-block-exit.rs
  294. +3 −3 src/test/run-pass/expr-alt-box.rs
  295. +4 −4 src/test/run-pass/expr-alt-fail-all.rs
  296. +2 −2 src/test/run-pass/expr-alt-fail.rs
  297. +1 −1  src/test/run-pass/expr-alt-generic-box1.rs
  298. +1 −1  src/test/run-pass/expr-alt-generic-box2.rs
  299. +1 −1  src/test/run-pass/expr-alt-generic-unique1.rs
  300. +1 −1  src/test/run-pass/expr-alt-generic-unique2.rs
Sorry, we could not display the entire diff because too many files (359) changed.
View
40 doc/rust.md
@@ -209,7 +209,7 @@ import export use mod
The keywords in [source files](#source-files) are the following strings:
~~~~~~~~ {.keyword}
-alt again assert
+again assert
break
check class const copy
drop
@@ -217,7 +217,7 @@ else enum export extern
fail false fn for
if impl import
let log loop
-mod mut
+match mod mut
pure
return
true trait type
@@ -956,7 +956,7 @@ An example of a predicate that uses an unchecked block:
# import std::list::*;
fn pure_foldl<T, U: copy>(ls: list<T>, u: U, f: fn(&&T, &&U) -> U) -> U {
- alt ls {
+ match ls {
nil => u,
cons(hd, tl) => f(hd, pure_foldl(*tl, f(hd, u), f))
}
@@ -1156,7 +1156,7 @@ class file_descriptor {
let mut name: option<~str>;
}
fn get_name() -> ~str {
- alt self.name {
+ match self.name {
none => fail ~"File has no name!",
some(n) => n
}
@@ -2171,21 +2171,21 @@ evaluated. If all `if` and `else if` conditions evaluate to `false`
then any `else` block is executed.
-### Alternative expressions
+### Match expressions
~~~~~~~~{.ebnf .gram}
-alt_expr : "alt" expr '{' alt_arm [ '|' alt_arm ] * '}' ;
+match_expr : "match" expr '{' match_arm [ '|' match_arm ] * '}' ;
-alt_arm : alt_pat '=>' expr_or_blockish ;
+match_arm : match_pat '=>' expr_or_blockish ;
-alt_pat : pat [ "to" pat ] ? [ "if" expr ] ;
+match_pat : pat [ "to" pat ] ? [ "if" expr ] ;
~~~~~~~~
-An `alt` expression branches on a *pattern*. The exact form of matching that
+A `match` expression branches on a *pattern*. The exact form of matching that
occurs depends on the pattern. Patterns consist of some combination of
literals, destructured enum constructors, records and tuples, variable binding
-specifications, wildcards (`*`), and placeholders (`_`). An `alt` expression has a *head
+specifications, wildcards (`*`), and placeholders (`_`). A `match` expression has a *head
expression*, which is the value to compare to the patterns. The type of the
patterns must equal the type of the head expression.
@@ -2198,7 +2198,7 @@ enum list<X> { nil, cons(X, @list<X>) }
let x: list<int> = cons(10, @cons(11, @nil));
-alt x {
+match x {
cons(_, @nil) => fail ~"singleton list",
cons(*) => return,
nil => fail ~"empty list"
@@ -2210,13 +2210,13 @@ tail value of `@nil`. The second pattern matches `any` list constructed with `co
ignoring the values of its arguments. The difference between `_` and `*` is that the pattern `C(_)` is only type-correct if
`C` has exactly one argument, while the pattern `C(*)` is type-correct for any enum variant `C`, regardless of how many arguments `C` has.
-To execute an `alt` expression, first the head expression is evaluated, then
+To execute an `match` expression, first the head expression is evaluated, then
its value is sequentially compared to the patterns in the arms until a match
is found. The first arm with a matching pattern is chosen as the branch target
-of the `alt`, any variables bound by the pattern are assigned to local
+of the `match`, any variables bound by the pattern are assigned to local
variables in the arm's block, and control enters the block.
-An example of an `alt` expression:
+An example of an `match` expression:
~~~~
@@ -2227,7 +2227,7 @@ enum list<X> { nil, cons(X, @list<X>) }
let x: list<int> = cons(10, @cons(11, @nil));
-alt x {
+match x {
cons(a, @cons(b, _)) => {
process_pair(a,b);
}
@@ -2264,7 +2264,7 @@ fn main() {
}
};
- alt r {
+ match r {
{options: {choose: true, _}, _} => {
choose_player(r)
}
@@ -2278,20 +2278,20 @@ fn main() {
}
~~~~
-Multiple alternative patterns may be joined with the `|` operator. A
+Multiple match patterns may be joined with the `|` operator. A
range of values may be specified with `to`. For example:
~~~~
# let x = 2;
-let message = alt x {
+let message = match x {
0 | 1 => ~"not many",
2 to 9 => ~"a few",
_ => ~"lots"
};
~~~~
-Finally, alt patterns can accept *pattern guards* to further refine the
+Finally, match patterns can accept *pattern guards* to further refine the
criteria for matching a case. Pattern guards appear after the pattern and
consist of a bool-typed expression following the `if` keyword. A pattern
guard may refer to the variables bound within the pattern they follow.
@@ -2301,7 +2301,7 @@ guard may refer to the variables bound within the pattern they follow.
# fn process_digit(i: int) { }
# fn process_other(i: int) { }
-let message = alt maybe_digit {
+let message = match maybe_digit {
some(x) if x < 10 => process_digit(x),
some(x) => process_other(x),
none => fail
View
34 doc/tutorial.md
@@ -116,7 +116,7 @@ fn main() {
let pick = || (~[rock, paper, scissors])[rng.gen_uint() % 3];
// Pick two gestures and decide the result
- alt (pick(), pick()) {
+ match (pick(), pick()) {
(rock, scissors) | (paper, rock) | (scissors, paper) => copy player1,
(scissors, rock) | (rock, paper) | (paper, scissors) => copy player2,
_ => ~"tie"
@@ -707,14 +707,14 @@ have type `int`, because control doesn't reach the end of that arm
## Pattern matching
-Rust's `alt` construct is a generalized, cleaned-up version of C's
+Rust's `match` construct is a generalized, cleaned-up version of C's
`switch` construct. You provide it with a value and a number of arms,
each labelled with a pattern, and it will execute the arm that matches
the value.
~~~~
# let my_number = 1;
-alt my_number {
+match my_number {
0 => io::println(~"zero"),
1 | 2 => io::println(~"one or two"),
3 to 10 => io::println(~"three to ten"),
@@ -732,14 +732,14 @@ valid patterns, and will match only their own value. The pipe operator
of numeric literal patterns can be expressed with `to`. The underscore
(`_`) is a wildcard pattern that matches everything.
-The patterns in an alt arm are followed by a fat arrow, `=>`, then an
+The patterns in an match arm are followed by a fat arrow, `=>`, then an
expression to evaluate. Each case is separated by commas. It's often
convenient to use a block expression for a case, in which case the
commas are optional.
~~~
# let my_number = 1;
-alt my_number {
+match my_number {
0 => {
io::println(~"zero")
}
@@ -750,9 +750,9 @@ alt my_number {
~~~
If the arm with the wildcard pattern was left off in the above
-example, the typechecker would reject it at compile time. `alt`
+example, the typechecker would reject it at compile time. `match`
constructs must be exhaustive: they must have an arm covering every
-possible case. (You may use the `alt check` construct to write a
+possible case. (You may use the `match check` construct to write a
non-exhaustive match, but it's highly undesirable to do so. You may
reason that the missing cases will never occur, but the typechecker
provides you with no assurance that your reasoning is correct.)
@@ -763,7 +763,7 @@ that `(float, float)` is a tuple of two floats:
~~~~
fn angle(vec: (float, float)) -> float {
- alt vec {
+ match vec {
(0f, y) if y < 0f => 1.5 * float::consts::pi,
(0f, y) => 0.5 * float::consts::pi,
(x, y) => float::atan(y / x)
@@ -777,7 +777,7 @@ y)` matches any tuple whose first element is zero, and binds `y` to
the second element. `(x, y)` matches any tuple, and binds both
elements to a variable.
-Any `alt` arm can have a guard clause (written `if EXPR`), which is
+Any `match` arm can have a guard clause (written `if EXPR`), which is
an expression of type `bool` that determines, after the pattern is
found to match, whether the arm is taken or not. The variables bound
by the pattern are available in this guard expression.
@@ -851,7 +851,7 @@ task failure:
* Accessing an out-of-bounds element of a vector.
-* Having no clauses match when evaluating an `alt check` expression.
+* Having no clauses match when evaluating an `match check` expression.
* An assertion failure.
@@ -1044,14 +1044,14 @@ not an actual new type.)
## Record patterns
-Records can be destructured in `alt` patterns. The basic syntax is
+Records can be destructured in `match` patterns. The basic syntax is
`{fieldname: pattern, ...}`, but the pattern for a field can be
omitted as a shorthand for simply binding the variable with the same
name as the field.
~~~~
# let mypoint = {x: 0f, y: 0f};
-alt mypoint {
+match mypoint {
{x: 0f, y: y_name} => { /* Provide sub-patterns for fields */ }
{x, y} => { /* Simply bind the fields */ }
}
@@ -1157,7 +1157,7 @@ patterns, as in this definition of `area`:
# type point = {x: float, y: float};
# enum shape { circle(point, float), rectangle(point, point) }
fn area(sh: shape) -> float {
- alt sh {
+ match sh {
circle(_, size) => float::consts::pi * size * size,
rectangle({x, y}, {x: x2, y: y2}) => (x2 - x) * (y2 - y)
}
@@ -1170,7 +1170,7 @@ Another example, matching nullary enum variants:
# type point = {x: float, y: float};
# enum direction { north, east, south, west }
fn point_from_direction(dir: direction) -> point {
- alt dir {
+ match dir {
north => {x: 0f, y: 1f},
east => {x: 1f, y: 0f},
south => {x: 0f, y: -1f},
@@ -1188,7 +1188,7 @@ nil, `()`, as the empty tuple if you like).
~~~~
let mytup: (int, int, float) = (10, 20, 30.0);
-alt mytup {
+match mytup {
(a, b, c) => log(info, a + b + (c as int))
}
~~~~
@@ -1922,7 +1922,7 @@ gets access to them.
## Other uses of safe references
Safe references are not only used for argument passing. When you
-destructure on a value in an `alt` expression, or loop over a vector
+destructure on a value in a `match` expression, or loop over a vector
with `for`, variables bound to the inside of the given data structure
will use safe references, not copies. This means such references are
very cheap, but you'll occasionally have to copy them to ensure
@@ -1930,7 +1930,7 @@ safety.
~~~~
let mut my_rec = {a: 4, b: ~[1, 2, 3]};
-alt my_rec {
+match my_rec {
{a, b} => {
log(info, b); // This is okay
my_rec = {a: a + 1, b: b + ~[a]};
View
134 src/cargo/cargo.rs
@@ -128,7 +128,7 @@ fn is_uuid(id: ~str) -> bool {
return false;
}
- alt i {
+ match i {
0u => {
if str::len(part) == 8u {
correct += 1u;
@@ -192,7 +192,7 @@ fn is_archive_url(u: ~str) -> bool {
// FIXME (#2661): this requires the protocol bit - if we had proper
// url parsing, we wouldn't need it
- alt str::find_str(u, ~"://") {
+ match str::find_str(u, ~"://") {
option::some(i) => has_archive_extension(u),
_ => false
}
@@ -223,9 +223,9 @@ fn load_link(mis: ~[@ast::meta_item]) -> (option<~str>,
let mut vers = none;
let mut uuid = none;
for mis.each |a| {
- alt a.node {
+ match a.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
- alt *v {
+ match *v {
~"name" => name = some(*s),
~"vers" => vers = some(*s),
~"uuid" => uuid = some(*s),
@@ -250,9 +250,9 @@ fn load_crate(filename: ~str) -> option<crate> {
let mut crate_type = none;
for c.node.attrs.each |a| {
- alt a.node.value.node {
+ match a.node.value.node {
ast::meta_name_value(v, {node: ast::lit_str(s), span: _}) => {
- alt *v {
+ match *v {
~"desc" => desc = some(*v),
~"sigs" => sigs = some(*v),
~"crate_type" => crate_type = some(*v),
@@ -279,7 +279,7 @@ fn load_crate(filename: ~str) -> option<crate> {
};
fn goto_view_item(e: env, i: @ast::view_item) {
- alt i.node {
+ match i.node {
ast::view_item_use(ident, metas, id) => {
let name_items =
attr::find_meta_items_by_name(metas, ~"name");
@@ -293,11 +293,11 @@ fn load_crate(filename: ~str) -> option<crate> {
let mut attr_from = ~"";
for m.each |item| {
- alt attr::get_meta_item_value_str(item) {
+ match attr::get_meta_item_value_str(item) {
some(value) => {
let name = attr::get_meta_item_name(item);
- alt *name {
+ match *name {
~"vers" => attr_vers = *value,
~"from" => attr_from = *value,
_ => ()
@@ -315,7 +315,7 @@ fn load_crate(filename: ~str) -> option<crate> {
} else { *attr_name }
};
- alt *attr_name {
+ match *attr_name {
~"std" | ~"core" => (),
_ => vec::push(e.deps, query)
}
@@ -339,7 +339,7 @@ fn load_crate(filename: ~str) -> option<crate> {
let deps = copy e.deps;
- alt (name, vers, uuid) {
+ match (name, vers, uuid) {
(some(name0), some(vers0), some(uuid0)) => {
some({
name: name0,
@@ -390,21 +390,21 @@ fn parse_source(name: ~str, j: json::json) -> source {
fail fmt!{"'%s' is an invalid source name", name};
}
- alt j {
+ match j {
json::dict(j) => {
- let mut url = alt j.find(~"url") {
+ let mut url = match j.find(~"url") {
some(json::string(u)) => *u,
_ => fail ~"needed 'url' field in source"
};
- let method = alt j.find(~"method") {
+ let method = match j.find(~"method") {
some(json::string(u)) => *u,
_ => assume_source_method(url)
};
- let key = alt j.find(~"key") {
+ let key = match j.find(~"key") {
some(json::string(u)) => some(*u),
_ => none
};
- let keyfp = alt j.find(~"keyfp") {
+ let keyfp = match j.find(~"keyfp") {
some(json::string(u)) => some(*u),
_ => none
};
@@ -426,7 +426,7 @@ fn parse_source(name: ~str, j: json::json) -> source {
fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
if !os::path_exists(filename) { return; }
let c = io::read_whole_file_str(filename);
- alt json::from_str(result::get(c)) {
+ match json::from_str(result::get(c)) {
ok(json::dict(j)) => {
for j.each |k, v| {
sources.insert(k, parse_source(k, v));
@@ -439,7 +439,7 @@ fn try_parse_sources(filename: ~str, sources: map::hashmap<~str, source>) {
}
fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
- let name = alt p.find(~"name") {
+ let name = match p.find(~"name") {
some(json::string(n)) => {
if !valid_pkg_name(*n) {
warn(~"malformed source json: "
@@ -456,7 +456,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
}
};
- let uuid = alt p.find(~"uuid") {
+ let uuid = match p.find(~"uuid") {
some(json::string(n)) => {
if !is_uuid(*n) {
warn(~"malformed source json: "
@@ -472,7 +472,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
}
};
- let url = alt p.find(~"url") {
+ let url = match p.find(~"url") {
some(json::string(n)) => *n,
_ => {
warn(~"malformed source json: " + src.name + ~" (missing url)");
@@ -480,7 +480,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
}
};
- let method = alt p.find(~"method") {
+ let method = match p.find(~"method") {
some(json::string(n)) => *n,
_ => {
warn(~"malformed source json: "
@@ -489,16 +489,16 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
}
};
- let reference = alt p.find(~"ref") {
+ let reference = match p.find(~"ref") {
some(json::string(n)) => some(*n),
_ => none
};
let mut tags = ~[];
- alt p.find(~"tags") {
+ match p.find(~"tags") {
some(json::list(js)) => {
for (*js).each |j| {
- alt j {
+ match j {
json::string(j) => vec::grow(tags, 1u, *j),
_ => ()
}
@@ -507,7 +507,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
_ => ()
}
- let description = alt p.find(~"description") {
+ let description = match p.find(~"description") {
some(json::string(n)) => *n,
_ => {
warn(~"malformed source json: " + src.name
@@ -527,7 +527,7 @@ fn load_one_source_package(src: source, p: map::hashmap<~str, json::json>) {
versions: ~[]
};
- alt vec::position(src.packages, |pkg| pkg.uuid == uuid) {
+ match vec::position(src.packages, |pkg| pkg.uuid == uuid) {
some(idx) => {
src.packages[idx] = newpkg;
log(debug, ~" updated package: " + src.name + ~"/" + name);
@@ -545,7 +545,7 @@ fn load_source_info(c: cargo, src: source) {
let srcfile = path::connect(dir, ~"source.json");
if !os::path_exists(srcfile) { return; }
let srcstr = io::read_whole_file_str(srcfile);
- alt json::from_str(result::get(srcstr)) {
+ match json::from_str(result::get(srcstr)) {
ok(json::dict(s)) => {
let o = parse_source(src.name, json::dict(s));
@@ -567,10 +567,10 @@ fn load_source_packages(c: cargo, src: source) {
let pkgfile = path::connect(dir, ~"packages.json");
if !os::path_exists(pkgfile) { return; }
let pkgstr = io::read_whole_file_str(pkgfile);
- alt json::from_str(result::get(pkgstr)) {
+ match json::from_str(result::get(pkgstr)) {
ok(json::list(js)) => {
for (*js).each |j| {
- alt j {
+ match j {
json::dict(p) => {
load_one_source_package(src, p);
}
@@ -592,7 +592,7 @@ fn load_source_packages(c: cargo, src: source) {
}
fn build_cargo_options(argv: ~[~str]) -> options {
- let matches = alt getopts::getopts(argv, opts()) {
+ let matches = match getopts::getopts(argv, opts()) {
result::ok(m) => m,
result::err(f) => {
fail fmt!{"%s", getopts::fail_str(f)};
@@ -623,12 +623,12 @@ fn build_cargo_options(argv: ~[~str]) -> options {
}
fn configure(opts: options) -> cargo {
- let home = alt get_cargo_root() {
+ let home = match get_cargo_root() {
ok(home) => home,
err(_err) => result::get(get_cargo_sysroot())
};
- let get_cargo_dir = alt opts.mode {
+ let get_cargo_dir = match opts.mode {
system_mode => get_cargo_sysroot,
user_mode => get_cargo_root,
local_mode => get_cargo_root_nearest
@@ -716,7 +716,7 @@ fn run_in_buildpath(what: ~str, path: ~str, subdir: ~str, cf: ~str,
}
fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
- let buildpath = alt run_in_buildpath(~"testing", path, ~"/test", cf,
+ let buildpath = match run_in_buildpath(~"testing", path, ~"/test", cf,
~[ ~"--test"]) {
none => return,
some(bp) => bp
@@ -725,7 +725,7 @@ fn test_one_crate(_c: cargo, path: ~str, cf: ~str) {
}
fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
- let buildpath = alt run_in_buildpath(~"installing", path,
+ let buildpath = match run_in_buildpath(~"installing", path,
~"/build", cf, ~[]) {
none => return,
some(bp) => bp
@@ -752,7 +752,7 @@ fn install_one_crate(c: cargo, path: ~str, cf: ~str) {
fn rustc_sysroot() -> ~str {
- alt os::self_exe_path() {
+ match os::self_exe_path() {
some(path) => {
let path = ~[path, ~"..", ~"bin", ~"rustc"];
let rustc = path::normalize(path::connect_many(path));
@@ -779,7 +779,7 @@ fn install_source(c: cargo, path: ~str) {
}
for cratefiles.each |cf| {
- alt load_crate(cf) {
+ match load_crate(cf) {
none => again,
some(crate) => {
for crate.deps.each |query| {
@@ -788,7 +788,7 @@ fn install_source(c: cargo, path: ~str) {
// condition")
let wd_base = c.workdir + path::path_sep();
- let wd = alt tempfile::mkdtemp(wd_base, ~"") {
+ let wd = match tempfile::mkdtemp(wd_base, ~"") {
some(wd) => wd,
none => fail fmt!{"needed temp dir: %s", wd_base}
};
@@ -838,7 +838,7 @@ fn install_file(c: cargo, wd: ~str, path: ~str) {
fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
let url = copy pkg.url;
- let method = alt pkg.method {
+ let method = match pkg.method {
~"git" => ~"git",
~"file" => ~"file",
_ => ~"curl"
@@ -846,7 +846,7 @@ fn install_package(c: cargo, src: ~str, wd: ~str, pkg: package) {
info(fmt!{"installing %s/%s via %s...", src, pkg.name, method});
- alt method {
+ match method {
~"git" => install_git(c, wd, url, copy pkg.reference),
~"file" => install_file(c, wd, url),
~"curl" => install_curl(c, wd, copy url),
@@ -913,7 +913,7 @@ fn install_named(c: cargo, wd: ~str, name: ~str) {
}
fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
- alt c.sources.find(src) {
+ match c.sources.find(src) {
some(s) => {
let packages = copy s.packages;
if vec::any(packages, |p| {
@@ -929,7 +929,7 @@ fn install_uuid_specific(c: cargo, wd: ~str, src: ~str, uuid: ~str) {
}
fn install_named_specific(c: cargo, wd: ~str, src: ~str, name: ~str) {
- alt c.sources.find(src) {
+ match c.sources.find(src) {
some(s) => {
let packages = copy s.packages;
if vec::any(packages, |p| {
@@ -960,7 +960,7 @@ fn cmd_uninstall(c: cargo) {
// name only)
if is_uuid(target) {
for os::list_dir(lib).each |file| {
- alt str::find_str(file, ~"-" + target + ~"-") {
+ match str::find_str(file, ~"-" + target + ~"-") {
some(idx) => {
let full = path::normalize(path::connect(lib, file));
if os::remove_file(full) {
@@ -977,7 +977,7 @@ fn cmd_uninstall(c: cargo) {
error(~"can't find package with uuid: " + target);
} else {
for os::list_dir(lib).each |file| {
- alt str::find_str(file, ~"lib" + target + ~"-") {
+ match str::find_str(file, ~"lib" + target + ~"-") {
some(idx) => {
let full = path::normalize(path::connect(lib,
file));
@@ -992,7 +992,7 @@ fn cmd_uninstall(c: cargo) {
}
}
for os::list_dir(bin).each |file| {
- alt str::find_str(file, target) {
+ match str::find_str(file, target) {
some(idx) => {
let full = path::normalize(path::connect(bin, file));
if os::remove_file(full) {
@@ -1011,7 +1011,7 @@ fn cmd_uninstall(c: cargo) {
}
fn install_query(c: cargo, wd: ~str, target: ~str) {
- alt c.dep_cache.find(target) {
+ match c.dep_cache.find(target) {
some(inst) => {
if inst {
return;
@@ -1038,7 +1038,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
} else {
let mut ps = copy target;
- alt str::find_char(ps, '/') {
+ match str::find_char(ps, '/') {
option::some(idx) => {
let source = str::slice(ps, 0u, idx);
ps = str::slice(ps, idx + 1u, str::len(ps));
@@ -1072,7 +1072,7 @@ fn install_query(c: cargo, wd: ~str, target: ~str) {
fn cmd_install(c: cargo) unsafe {
let wd_base = c.workdir + path::path_sep();
- let wd = alt tempfile::mkdtemp(wd_base, ~"") {
+ let wd = match tempfile::mkdtemp(wd_base, ~"") {
some(wd) => wd,
none => fail fmt!{"needed temp dir: %s", wd_base}
};
@@ -1129,7 +1129,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
os::copy_file(path::connect(url, ~"source.json.sig"), srcsigfile);
os::copy_file(path::connect(url, ~"packages.json.sig"), sigfile);
- alt copy src.key {
+ match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
@@ -1141,7 +1141,7 @@ fn sync_one_file(c: cargo, dir: ~str, src: source) -> bool {
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
@@ -1238,7 +1238,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
let has_src_file = os::path_exists(srcfile);
- alt copy src.key {
+ match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
@@ -1251,7 +1251,7 @@ fn sync_one_git(c: cargo, dir: ~str, src: source) -> bool {
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
@@ -1318,7 +1318,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
}
}
- alt copy src.key {
+ match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
@@ -1330,7 +1330,7 @@ fn sync_one_curl(c: cargo, dir: ~str, src: source) -> bool {
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
if smart {
url = src.url + ~"/packages.json.sig";
@@ -1403,7 +1403,7 @@ fn sync_one(c: cargo, src: source) {
need_dir(dir);
- let result = alt src.method {
+ let result = match src.method {
~"git" => sync_one_git(c, dir, src),
~"file" => sync_one_file(c, dir, src),
_ => sync_one_curl(c, dir, src)
@@ -1490,7 +1490,7 @@ fn cmd_list(c: cargo) {
if !valid_pkg_name(name) {
error(fmt!{"'%s' is an invalid source name", name});
} else {
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
print_source(source);
}
@@ -1562,7 +1562,7 @@ fn dump_sources(c: cargo) {
copy_warn(out, path::connect(c.root, ~"sources.json.old"));
}
- alt io::buffered_file_writer(out) {
+ match io::buffered_file_writer(out) {
result::ok(writer) => {
let hash = map::str_hash();
let root = json::dict(hash);
@@ -1574,13 +1574,13 @@ fn dump_sources(c: cargo) {
chash.insert(~"url", json::string(@v.url));
chash.insert(~"method", json::string(@v.method));
- alt copy v.key {
+ match copy v.key {
some(key) => {
chash.insert(~"key", json::string(@key));
}
_ => ()
}
- alt copy v.keyfp {
+ match copy v.keyfp {
some(keyfp) => {
chash.insert(~"keyfp", json::string(@keyfp));
}
@@ -1615,7 +1615,7 @@ fn cmd_sources(c: cargo) {
let action = c.opts.free[2u];
- alt action {
+ match action {
~"clear" => {
for c.sources.each_key |k| {
c.sources.remove(k);
@@ -1637,7 +1637,7 @@ fn cmd_sources(c: cargo) {
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
error(fmt!{"source already exists: %s", name});
}
@@ -1667,7 +1667,7 @@ fn cmd_sources(c: cargo) {
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
c.sources.remove(name);
info(fmt!{"removed source: %s", name});
@@ -1691,7 +1691,7 @@ fn cmd_sources(c: cargo) {
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
let old = copy source.url;
let method = assume_source_method(url);
@@ -1722,11 +1722,11 @@ fn cmd_sources(c: cargo) {
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
let old = copy source.method;
- source.method = alt method {
+ source.method = match method {
~"git" => ~"git",
~"file" => ~"file",
_ => ~"curl"
@@ -1760,7 +1760,7 @@ fn cmd_sources(c: cargo) {
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
c.sources.remove(name);
c.sources.insert(newn, source);
@@ -1874,7 +1874,7 @@ fn main(argv: ~[~str]) {
return;
}
if o.help {
- alt o.free[1] {
+ match o.free[1] {
~"init" => cmd_usage_init(),
~"install" => cmd_usage_install(),
~"uninstall" => cmd_usage_uninstall(),
@@ -1901,7 +1901,7 @@ fn main(argv: ~[~str]) {
c = configure(o);
}
- alt o.free[1] {
+ match o.free[1] {
~"init" => cmd_init(c),
~"install" => cmd_install(c),
~"uninstall" => cmd_uninstall(c),
View
14 src/compiletest/compiletest.rs
@@ -37,7 +37,7 @@ fn parse_config(args: ~[~str]) -> config {
assert (vec::is_not_empty(args));
let args_ = vec::tail(args);
let matches =
- alt getopts::getopts(args_, opts) {
+ match getopts::getopts(args_, opts) {
ok(m) => m,
err(f) => fail getopts::fail_str(f)
};
@@ -80,7 +80,7 @@ fn log_config(config: config) {
}
fn opt_str(maybestr: option<~str>) -> ~str {
- alt maybestr { option::some(s) => s, option::none => ~"(none)" }
+ match maybestr { option::some(s) => s, option::none => ~"(none)" }
}
fn str_opt(maybestr: ~str) -> option<~str> {
@@ -88,7 +88,7 @@ fn str_opt(maybestr: ~str) -> option<~str> {
}
fn str_mode(s: ~str) -> mode {
- alt s {
+ match s {
~"compile-fail" => mode_compile_fail,
~"run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass,
@@ -98,7 +98,7 @@ fn str_mode(s: ~str) -> mode {
}
fn mode_str(mode: mode) -> ~str {
- alt mode {
+ match mode {
mode_compile_fail => ~"compile-fail",
mode_run_fail => ~"run-fail",
mode_run_pass => ~"run-pass",
@@ -115,13 +115,13 @@ fn run_tests(config: config) {
fn test_opts(config: config) -> test::test_opts {
{filter:
- alt config.filter {
+ match config.filter {
option::some(s) => option::some(s),
option::none => option::none
},
run_ignored: config.run_ignored,
logfile:
- alt config.logfile {
+ match config.logfile {
option::some(s) => option::some(s),
option::none => option::none
}
@@ -144,7 +144,7 @@ fn make_tests(config: config) -> ~[test::test_desc] {
fn is_test(config: config, testfile: ~str) -> bool {
// Pretty-printer does not work with .rc files yet
let valid_extensions =
- alt config.mode {
+ match config.mode {
mode_pretty => ~[~".rs"],
_ => ~[~".rc", ~".rs"]
};
View
2  src/compiletest/errors.rs
@@ -23,7 +23,7 @@ fn load_errors(testfile: ~str) -> ~[expected_error] {
fn parse_expected(line_num: uint, line: ~str) -> ~[expected_error] unsafe {
let error_tag = ~"//~";
let mut idx;
- alt str::find_str(line, error_tag) {
+ match str::find_str(line, error_tag) {
option::none => return ~[],
option::some(nn) => { idx = (nn as uint) + str::len(error_tag); }
}
View
8 src/compiletest/header.rs
@@ -30,7 +30,7 @@ fn load_props(testfile: ~str) -> test_props {
let mut compile_flags = option::none;
let mut pp_exact = option::none;
for iter_header(testfile) |ln| {
- alt parse_error_pattern(ln) {
+ match parse_error_pattern(ln) {
option::some(ep) => vec::push(error_patterns, ep),
option::none => ()
};
@@ -107,7 +107,7 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
do parse_name_value_directive(line, ~"exec-env").map |nv| {
// nv is either FOO or FOO=BAR
let strs = str::splitn_char(nv, '=', 1u);
- alt strs.len() {
+ match strs.len() {
1u => (strs[0], ~""),
2u => (strs[0], strs[1]),
n => fail fmt!{"Expected 1 or 2 strings, not %u", n}
@@ -116,7 +116,7 @@ fn parse_exec_env(line: ~str) -> option<(~str, ~str)> {
}
fn parse_pp_exact(line: ~str, testfile: ~str) -> option<~str> {
- alt parse_name_value_directive(line, ~"pp-exact") {
+ match parse_name_value_directive(line, ~"pp-exact") {
option::some(s) => option::some(s),
option::none => {
if parse_name_directive(line, ~"pp-exact") {
@@ -135,7 +135,7 @@ fn parse_name_directive(line: ~str, directive: ~str) -> bool {
fn parse_name_value_directive(line: ~str,
directive: ~str) -> option<~str> unsafe {
let keycolon = directive + ~":";
- alt str::find_str(line, keycolon) {
+ match str::find_str(line, keycolon) {
option::some(colon) => {
let value = str::slice(line, colon + str::len(keycolon),
str::len(line));
View
2  src/compiletest/procsrv.rs
@@ -76,7 +76,7 @@ fn run(lib_path: ~str,
let mut outs = ~"";
let mut count = 2;
while count > 0 {
- alt p.recv() {
+ match p.recv() {
(1, s) => {
outs = s;
}
View
10 src/compiletest/runtest.rs
@@ -18,7 +18,7 @@ fn run(config: config, testfile: ~str) {
}
debug!{"running %s", testfile};
let props = load_props(testfile);
- alt config.mode {
+ match config.mode {
mode_compile_fail => run_cfail_test(config, props, testfile),
mode_run_fail => run_rfail_test(config, props, testfile),
mode_run_pass => run_rpass_test(config, props, testfile),
@@ -90,7 +90,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
} else { logv(config, ~"testing for converging pretty-printing"); }
let rounds =
- alt props.pp_exact { option::some(_) => 1, option::none => 2 };
+ match props.pp_exact { option::some(_) => 1, option::none => 2 };
let mut srcs = ~[result::get(io::read_whole_file_str(testfile))];
@@ -109,7 +109,7 @@ fn run_pretty_test(config: config, props: test_props, testfile: ~str) {
}
let mut expected =
- alt props.pp_exact {
+ match props.pp_exact {
option::some(file) => {
let filepath = path::connect(path::dirname(testfile), file);
result::get(io::read_whole_file_str(filepath))
@@ -383,7 +383,7 @@ fn make_run_args(config: config, _props: test_props, testfile: ~str) ->
// If we've got another tool to run under (valgrind),
// then split apart its command
let runtool =
- alt config.runtool {
+ match config.runtool {
option::some(s) => option::some(s),
option::none => option::none
};
@@ -402,7 +402,7 @@ fn split_maybe_args(argstr: option<~str>) -> ~[~str] {
vec::filter_map(v, flt)
}
- alt argstr {
+ match argstr {
option::some(s) => rm_whitespace(str::split_char(s, ' ')),
option::none => ~[]
}
View
2  src/compiletest/util.rs
@@ -7,7 +7,7 @@ fn make_new_path(path: ~str) -> ~str {
// Windows just uses PATH as the library search path, so we have to
// maintain the current value while adding our own
- alt getenv(lib_path_env_var()) {
+ match getenv(lib_path_env_var()) {
option::some(curr) => {
fmt!{"%s%s%s", path, path_div(), curr}
}
View
18 src/fuzzer/fuzzer.rs
@@ -62,9 +62,9 @@ pure fn safe_to_steal_expr(e: @ast::expr, tm: test_mode) -> bool {
}
pure fn safe_to_use_expr(e: ast::expr, tm: test_mode) -> bool {
- alt tm {
+ match tm {
tm_converge => {
- alt e.node {
+ match e.node {
// If the fuzzer moves a block-ending-in-semicolon into callee
// position, the pretty-printer can't preserve this even by
// parenthesizing!! See email to marijn.
@@ -139,7 +139,7 @@ fn steal(crate: ast::crate, tm: test_mode) -> stolen_stuff {
fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
- alt e {
+ match e {
// https://github.com/mozilla/rust/issues/652
ast::expr_if(*) => { false }
ast::expr_block(_) => { false }
@@ -152,7 +152,7 @@ fn safe_to_replace_expr(e: ast::expr_, _tm: test_mode) -> bool {
}
fn safe_to_replace_ty(t: ast::ty_, _tm: test_mode) -> bool {
- alt t {
+ match t {
ast::ty_infer => { false } // always implicit, always top level
ast::ty_bot => { false } // in source, can only appear
// as the out type of a function
@@ -272,7 +272,7 @@ fn check_variants_T<T: copy>(
io::str_reader(~""), a,
pprust::no_ann(),
false));
- alt cx.mode {
+ match cx.mode {
tm_converge => {
check_roundtrip_convergence(str3, 1u);
}
@@ -314,12 +314,12 @@ fn check_whole_compiler(code: ~str, suggested_filename_prefix: ~str,
let compile_result = check_compiling(filename);
- let run_result = alt (compile_result, allow_running) {
+ let run_result = match (compile_result, allow_running) {
(passed, true) => { check_running(suggested_filename_prefix) }
(h, _) => { h }
};
- alt run_result {
+ match run_result {
passed | cleanly_rejected(_) | known_bug(_) => {
removeIfExists(suggested_filename_prefix);
removeIfExists(suggested_filename_prefix + ~".rs");
@@ -364,7 +364,7 @@ fn check_running(exe_filename: ~str) -> happiness {
} else if contains(comb, ~"malloc") {
failed(~"Mentioned malloc")
} else {
- alt p.status {
+ match p.status {
0 => { passed }
100 => { cleanly_rejected(~"running: explicit fail") }
101 | 247 => { cleanly_rejected(~"running: timed out") }
@@ -441,7 +441,7 @@ fn parse_and_print(code: @~str) -> ~str {
fn has_raw_pointers(c: ast::crate) -> bool {
let has_rp = @mut false;
fn visit_ty(flag: @mut bool, t: @ast::ty) {
- alt t.node {
+ match t.node {
ast::ty_ptr(_) => { *flag = true; }
_ => { }
}
View
2  src/libcore/bool.rs
@@ -39,7 +39,7 @@ pure fn is_false(v: bool) -> bool { !v }
/// Parse logic value from `s`
pure fn from_str(s: ~str) -> option<bool> {
- alt check s {
+ match check s {
~"true" => some(true),
~"false" => some(false),
_ => none
View
4 src/libcore/char.rs
@@ -113,7 +113,7 @@ pure fn is_digit(c: char) -> bool {
* refer to a digit in the given radix.
*/
pure fn to_digit(c: char, radix: uint) -> option<uint> {
- let val = alt c {
+ let val = match c {
'0' to '9' => c as uint - ('0' as uint),
'a' to 'z' => c as uint + 10u - ('a' as uint),
'A' to 'Z' => c as uint + 10u - ('A' as uint),
@@ -158,7 +158,7 @@ fn escape_unicode(c: char) -> ~str {
* - Any other chars are given hex unicode escapes; see `escape_unicode`.
*/
fn escape_default(c: char) -> ~str {
- alt c {
+ match c {
'\t' => ~"\\t",
'\r' => ~"\\r",
'\n' => ~"\\n",
View
2  src/libcore/comm.rs
@@ -409,7 +409,7 @@ fn test_select2_stress() {
let mut as = 0;
let mut bs = 0;
for iter::repeat(msgs * times * 2u) {
- alt check select2(po_a, po_b) {
+ match check select2(po_a, po_b) {
either::left(~"a") => as += 1,
either::right(~"b") => bs += 1
}
View
20 src/libcore/dlist.rs
@@ -26,8 +26,8 @@ enum dlist<T> = @{
impl private_methods<T> for dlist_node<T> {
pure fn assert_links() {
- alt self.next {
- some(neighbour) => alt neighbour.prev {
+ match self.next {
+ some(neighbour) => match neighbour.prev {
some(me) => if !box::ptr_eq(*self, *me) {
fail ~"Asymmetric next-link in dlist node."
}
@@ -35,8 +35,8 @@ impl private_methods<T> for dlist_node<T> {
}
none => ()
}
- alt self.prev {
- some(neighbour) => alt neighbour.next {
+ match self.prev {
+ some(neighbour) => match neighbour.next {
some(me) => if !box::ptr_eq(*me, *self) {
fail ~"Asymmetric prev-link in dlist node."
}
@@ -55,7 +55,7 @@ impl extensions<T> for dlist_node<T> {
}
/// Get the next node in the list, failing if there isn't one.
pure fn next_node() -> dlist_node<T> {
- alt self.next_link() {
+ match self.next_link() {
some(nobe) => nobe,
none => fail ~"This dlist node has no next neighbour."
}
@@ -67,7 +67,7 @@ impl extensions<T> for dlist_node<T> {
}
/// Get the previous node in the list, failing if there isn't one.
pure fn prev_node() -> dlist_node<T> {
- alt self.prev_link() {
+ match self.prev_link() {
some(nobe) => nobe,
none => fail ~"This dlist node has no previous neighbour."
}
@@ -138,11 +138,11 @@ impl private_methods<T> for dlist<T> {
// the head and/or tail pointers appropriately.
#[inline(always)]
fn link(+before: dlist_link<T>, +after: dlist_link<T>) {
- alt before {
+ match before {
some(neighbour) => neighbour.next = after,
none => self.hd = after
}
- alt after {
+ match after {
some(neighbour) => neighbour.prev = before,
none => self.tl = before
}
@@ -286,14 +286,14 @@ impl extensions<T> for dlist<T> {
/// Get the node at the list's head, failing if empty. O(1).
pure fn head_n() -> dlist_node<T> {
- alt self.hd {
+ match self.hd {
some(nobe) => nobe,
none => fail ~"Attempted to get the head of an empty dlist."
}
}
/// Get the node at the list's tail, failing if empty. O(1).
pure fn tail_n() -> dlist_node<T> {
- alt self.tl {
+ match self.tl {
some(nobe) => nobe,
none => fail ~"Attempted to get the tail of an empty dlist."
}
View
2  src/libcore/dvec.rs
@@ -222,7 +222,7 @@ impl extensions<A:copy> for dvec<A> {
*/
fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
do self.swap |v| {
- let mut v = alt ts.size_hint() {
+ let mut v = match ts.size_hint() {
none { v }
some(h) {
let len = v.len() + h;
View
16 src/libcore/either.rs
@@ -18,7 +18,7 @@ fn either<T, U, V>(f_left: fn(T) -> V,
* result is returned.
*/
- alt value {
+ match value {
left(l) => f_left(l),
right(r) => f_right(r)
}
@@ -29,7 +29,7 @@ fn lefts<T: copy, U>(eithers: ~[either<T, U>]) -> ~[T] {
let mut result: ~[T] = ~[];
for vec::each(eithers) |elt| {
- alt elt {
+ match elt {
left(l) => vec::push(result, l),
_ => { /* fallthrough */ }
}
@@ -42,7 +42,7 @@ fn rights<T, U: copy>(eithers: ~[either<T, U>]) -> ~[U] {
let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| {
- alt elt {
+ match elt {
right(r) => vec::push(result, r),
_ => { /* fallthrough */ }
}
@@ -62,7 +62,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
let mut lefts: ~[T] = ~[];
let mut rights: ~[U] = ~[];
for vec::each(eithers) |elt| {
- alt elt {
+ match elt {
left(l) => vec::push(lefts, l),
right(r) => vec::push(rights, r)
}
@@ -73,7 +73,7 @@ fn partition<T: copy, U: copy>(eithers: ~[either<T, U>])
pure fn flip<T: copy, U: copy>(eith: either<T, U>) -> either<U, T> {
//! Flips between left and right of a given either
- alt eith {
+ match eith {
right(r) => left(r),
left(l) => right(l)
}
@@ -88,7 +88,7 @@ pure fn to_result<T: copy, U: copy>(
* an ok result, and the "left" choice a fail
*/
- alt eith {
+ match eith {
right(r) => result::ok(r),
left(l) => result::err(l)
}
@@ -97,13 +97,13 @@ pure fn to_result<T: copy, U: copy>(
pure fn is_left<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a left
- alt eith { left(_) => true, _ => false }
+ match eith { left(_) => true, _ => false }
}
pure fn is_right<T, U>(eith: either<T, U>) -> bool {
//! Checks whether the given value is a right
- alt eith { right(_) => true, _ => false }
+ match eith { right(_) => true, _ => false }
}
#[test]
View
24 src/libcore/extfmt.rs
@@ -122,7 +122,7 @@ mod ct {
let c = s[i];
if !('0' as u8 <= c && c <= '9' as u8) { return option::none; }
let n = (c - ('0' as u8)) as uint;
- return alt peek_num(s, i + 1u, lim) {
+ return match peek_num(s, i + 1u, lim) {
none => some({num: n, next: i + 1u}),
some(next) => {
let m = next.num;
@@ -150,7 +150,7 @@ mod ct {
{param: option<int>, next: uint} {
if i >= lim { return {param: none, next: i}; }
let num = peek_num(s, i, lim);
- return alt num {
+ return match num {
none => {param: none, next: i},
some(t) => {
let n = t.num;
@@ -195,13 +195,13 @@ mod ct {
} else if s[i] == '*' as u8 {
let param = parse_parameter(s, i + 1u, lim);
let j = param.next;
- alt param.param {
+ match param.param {
none => {count: count_is_next_param, next: j},
some(n) => {count: count_is_param(n), next: j}
}
} else {
let num = peek_num(s, i, lim);
- alt num {
+ match num {
none => {count: count_implied, next: i},
some(num) => {
count: count_is(num.num as int),
@@ -220,7 +220,7 @@ mod ct {
// If there were no digits specified, i.e. the precision
// was ".", then the precision is 0
- alt count.count {
+ match count.count {
count_implied => {count: count_is(0), next: count.next},
_ => count
}
@@ -294,7 +294,7 @@ mod rt {
pure fn conv_uint(cv: conv, u: uint) -> ~str {
let prec = get_int_precision(cv);
let mut rs =
- alt cv.ty {
+ match cv.ty {
ty_default => uint_to_str_prec(u, 10u, prec),
ty_hex_lower => uint_to_str_prec(u, 16u, prec),
ty_hex_upper => str::to_upper(uint_to_str_prec(u, 16u, prec)),
@@ -316,7 +316,7 @@ mod rt {
pure fn conv_str(cv: conv, s: &str) -> ~str {
// For strings, precision is the maximum characters
// displayed
- let mut unpadded = alt cv.precision {
+ let mut unpadded = match cv.precision {
count_implied => s.to_unique(),
count_is(max) => if max as uint < str::char_len(s) {
str::substr(s, 0u, max as uint)
@@ -327,7 +327,7 @@ mod rt {
return unchecked { pad(cv, unpadded, pad_nozero) };
}
pure fn conv_float(cv: conv, f: float) -> ~str {
- let (to_str, digits) = alt cv.precision {
+ let (to_str, digits) = match cv.precision {
count_is(c) => (float::to_str_exact, c as uint),
count_implied => (float::to_str, 6u)
};
@@ -371,14 +371,14 @@ mod rt {
};
}
pure fn get_int_precision(cv: conv) -> uint {
- return alt cv.precision {
+ return match cv.precision {
count_is(c) => c as uint,
count_implied => 1u
};
}
enum pad_mode { pad_signed, pad_unsigned, pad_nozero, pad_float }
fn pad(cv: conv, &s: ~str, mode: pad_mode) -> ~str {
- let uwidth : uint = alt cv.width {
+ let uwidth : uint = match cv.width {
count_implied => return s,
count_is(width) => {
// FIXME: width should probably be uint (see Issue #1996)
@@ -393,14 +393,14 @@ mod rt {
let padstr = str::from_chars(vec::from_elem(diff, padchar));
return s + padstr;
}
- let {might_zero_pad, signed} = alt mode {
+ let {might_zero_pad, signed} = match mode {
pad_nozero => {might_zero_pad:false, signed:false},
pad_signed => {might_zero_pad:true, signed:true },
pad_float => {might_zero_pad:true, signed:true},
pad_unsigned => {might_zero_pad:true, signed:false}
};
pure fn have_precision(cv: conv) -> bool {
- return alt cv.precision { count_implied => false, _ => true };
+ return match cv.precision { count_implied => false, _ => true };
}
let zero_padding = {
if might_zero_pad && have_flag(cv.flags, flag_left_zero_pad) &&
View
14 src/libcore/float.rs
@@ -256,14 +256,14 @@ fn from_str(num: ~str) -> option<float> {
let mut c = 'z'; //Latest char.
//The string must start with one of the following characters.
- alt str::char_at(num, 0u) {
+ match str::char_at(num, 0u) {
'-' | '+' | '0' to '9' | '.' => (),
_ => return none
}
//Determine if first char is '-'/'+'. Set [pos] and [neg] accordingly.
let mut neg = false; //Sign of the result
- alt str::char_at(num, 0u) {
+ match str::char_at(num, 0u) {
'-' => {
neg = true;
pos = 1u;
@@ -279,7 +279,7 @@ fn from_str(num: ~str) -> option<float> {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
pos = char_range.next;
- alt c {
+ match c {
'0' to '9' => {
total = total * 10f;
total += ((c as int) - ('0' as int)) as float;
@@ -295,7 +295,7 @@ fn from_str(num: ~str) -> option<float> {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
pos = char_range.next;
- alt c {
+ match c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
decimal /= 10f;
total += (((c as int) - ('0' as int)) as float)*decimal;
@@ -312,7 +312,7 @@ fn from_str(num: ~str) -> option<float> {
if(pos < len) {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
- alt c {
+ match c {
'+' => {
pos = char_range.next;
}
@@ -325,7 +325,7 @@ fn from_str(num: ~str) -> option<float> {
while(pos < len) {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
- alt c {
+ match c {
'0' | '1' | '2' | '3' | '4' | '5' | '6'| '7' | '8' | '9' => {
exponent *= 10u;
exponent += ((c as uint) - ('0' as uint));
@@ -447,7 +447,7 @@ fn test_from_str() {
assert from_str(~"inf") == some(infinity);
assert from_str(~"-inf") == some(neg_infinity);
// note: NaN != NaN, hence this slightly complex test
- alt from_str(~"NaN") {
+ match from_str(~"NaN") {
some(f) => assert is_NaN(f),
none => fail
}
View
4 src/libcore/future.rs
@@ -77,7 +77,7 @@ fn from_port<A:send>(-port: future_pipe::client::waiting<A>) -> future<A> {
let mut port_ = none;
port_ <-> *port;
let port = option::unwrap(port_);
- alt recv(port) {
+ match recv(port) {
future_pipe::completed(data) => move_it!{data}
}
}
@@ -119,7 +119,7 @@ fn get<A:copy>(future: future<A>) -> A {
fn with<A,B>(future: future<A>, blk: fn(A) -> B) -> B {
//! Work with the value without copying it
- let v = alt copy future.v {
+ let v = match copy future.v {
either::left(v) => v,
either::right(f) => {
let v = @f();
View
2  src/libcore/int-template.rs
@@ -144,7 +144,7 @@ fn parse_buf(buf: ~[u8], radix: uint) -> option<T> {
}
let mut n = 0 as T;
loop {
- alt char::to_digit(buf[i] as char, radix) {
+ match char::to_digit(buf[i] as char, radix) {
some(d) => n += (d as T) * power,
none => return none
}
View
18 src/libcore/io.rs
@@ -196,7 +196,7 @@ impl reader_util for reader {
// Reader implementations
fn convert_whence(whence: seek_style) -> i32 {