The keywords in [source files](#source-files) are the following strings:
~~~~~~~~ {.keyword}
-alt again assert
+again assert
break
check class const copy
drop
fail false fn for
if impl import
let log loop
-mod mut
+match mod mut
pure
return
true trait type
# 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))
}
let mut name: option<~str>;
}
fn get_name() -> ~str {
- alt self.name {
+ match self.name {
none => fail ~"File has no name!",
some(n) => n
}
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.
let x: list<int> = cons(10, @cons(11, @nil));
-alt x {
+match x {
cons(_, @nil) => fail ~"singleton list",
cons(*) => return,
nil => fail ~"empty list"
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:
~~~~
let x: list<int> = cons(10, @cons(11, @nil));
-alt x {
+match x {
cons(a, @cons(b, _)) => {
process_pair(a,b);
}
}
};
- alt r {
+ match r {
{options: {choose: true, _}, _} => {
choose_player(r)
}
}
~~~~
-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.
# 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
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"
## 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"),
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")
}
~~~
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.)
~~~~
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)
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.
* 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.
## 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 */ }
}
# 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)
}
# 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},
~~~~
let mytup: (int, int, float) = (10, 20, 30.0);
-alt mytup {
+match mytup {
(a, b, c) => log(info, a + b + (c as int))
}
~~~~
## 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
~~~~
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]};
return false;
}
- alt i {
+ match i {
0u => {
if str::len(part) == 8u {
correct += 1u;
// 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
}
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),
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),
};
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");
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,
_ => ()
} else { *attr_name }
};
- alt *attr_name {
+ match *attr_name {
~"std" | ~"core" => (),
_ => vec::push(e.deps, query)
}
let deps = copy e.deps;
- alt (name, vers, uuid) {
+ match (name, vers, uuid) {
(some(name0), some(vers0), some(uuid0)) => {
some({
name: name0,
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
};
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));
}
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: "
}
};
- let uuid = alt p.find(~"uuid") {
+ let uuid = match p.find(~"uuid") {
some(json::string(n)) => {
if !is_uuid(*n) {
warn(~"malformed source 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)");
}
};
- let method = alt p.find(~"method") {
+ let method = match p.find(~"method") {
some(json::string(n)) => *n,
_ => {
warn(~"malformed source 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),
_ => ()
}
_ => ()
}
- let description = alt p.find(~"description") {
+ let description = match p.find(~"description") {
some(json::string(n)) => *n,
_ => {
warn(~"malformed source json: " + src.name
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);
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));
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);
}
}
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)};
}
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
}
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
}
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
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));
}
for cratefiles.each |cf| {
- alt load_crate(cf) {
+ match load_crate(cf) {
none => again,
some(crate) => {
for crate.deps.each |query| {
// 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}
};
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"
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),
}
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| {
}
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| {
// 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) {
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));
}
}
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) {
}
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;
} 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));
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}
};
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]);
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
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]);
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
let r = pgp::verify(c.root, pkgfile, sigfile, f);
}
}
- alt copy src.key {
+ match copy src.key {
some(u) => {
let p = run::program_output(~"curl",
~[~"-f", ~"-s", ~"-o", keyfile, u]);
}
_ => ()
}
- alt (src.key, src.keyfp) {
+ match (src.key, src.keyfp) {
(some(_), some(f)) => {
if smart {
url = src.url + ~"/packages.json.sig";
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)
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);
}
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);
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));
}
let action = c.opts.free[2u];
- alt action {
+ match action {
~"clear" => {
for c.sources.each_key |k| {
c.sources.remove(k);
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
error(fmt!{"source already exists: %s", name});
}
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
c.sources.remove(name);
info(fmt!{"removed source: %s", name});
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
let old = copy source.url;
let method = assume_source_method(url);
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"
return;
}
- alt c.sources.find(name) {
+ match c.sources.find(name) {
some(source) => {
c.sources.remove(name);
c.sources.insert(newn, source);
return;
}
if o.help {
- alt o.free[1] {
+ match o.free[1] {
~"init" => cmd_usage_init(),
~"install" => cmd_usage_install(),
~"uninstall" => cmd_usage_uninstall(),
c = configure(o);
}
- alt o.free[1] {
+ match o.free[1] {
~"init" => cmd_init(c),
~"install" => cmd_install(c),
~"uninstall" => cmd_uninstall(c),
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)
};
}
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> {
}
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,
}
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",
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
}
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"]
};
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); }
}
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 => ()
};
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}
}
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") {
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));
let mut outs = ~"";
let mut count = 2;
while count > 0 {
- alt p.recv() {
+ match p.recv() {
(1, s) => {
outs = s;
}
}
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),
} 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))];
}
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))
// 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
};
vec::filter_map(v, flt)
}
- alt argstr {
+ match argstr {
option::some(s) => rm_whitespace(str::split_char(s, ' ')),
option::none => ~[]
}
// 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}
}
}
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.
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 }
}
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
io::str_reader(~""), a,
pprust::no_ann(),
false));
- alt cx.mode {
+ match cx.mode {
tm_converge => {
check_roundtrip_convergence(str3, 1u);
}
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");
} 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") }
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; }
_ => { }
}
/// 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
* 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),
* - 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",
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
}
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."
}
}
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."
}
}
/// 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."
}
}
/// 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."
}
// 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
}
/// 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."
}
*/
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;
* result is returned.
*/
- alt value {
+ match value {
left(l) => f_left(l),
right(r) => f_right(r)
}
let mut result: ~[T] = ~[];
for vec::each(eithers) |elt| {
- alt elt {
+ match elt {
left(l) => vec::push(result, l),
_ => { /* fallthrough */ }
}
let mut result: ~[U] = ~[];
for vec::each(eithers) |elt| {
- alt elt {
+ match elt {
right(r) => vec::push(result, r),
_ => { /* fallthrough */ }
}
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)
}
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)
}
* an ok result, and the "left" choice a fail
*/
- alt eith {
+ match eith {
right(r) => result::ok(r),
left(l) => result::err(l)
}
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]
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;
{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;
} 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),
// 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
}
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)),
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)
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)
};
};
}
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)
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) &&
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;
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;
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;
if(pos < len) {
let char_range = str::char_range_at(num, pos);
c = char_range.ch;
- alt c {
+ match c {
'+' => {
pos = char_range.next;
}
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));
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
}
let mut port_ = none;
port_ <-> *port;
let port = option::unwrap(port_);
- alt recv(port) {
+ match recv(port) {
future_pipe::completed(data) => move_it!{data}
}
}
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();
}
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
}
// Reader implementations
fn convert_whence(whence: seek_style) -> i32 {
- return alt whence {
+ return match whence {
seek_set => 0i32,
seek_cur => 1i32,
seek_end => 2i32
let mut fflags: c_int = wb();
for vec::each(flags) |f| {
- alt f {
+ match f {
append => fflags |= O_APPEND as c_int,
create => fflags |= O_CREAT as c_int,
truncate => fflags |= O_TRUNC as c_int,
fn u64_to_le_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u;
- alt size {
+ match size {
1u => f(&[n as u8]),
2u => f(&[n as u8,
(n >> 8) as u8]),
fn u64_to_be_bytes<T>(n: u64, size: uint, f: fn(v: &[u8]) -> T) -> T {
assert size <= 8u;
- alt size {
+ match size {
1u => f(&[n as u8]),
2u => f(&[(n >> 8) as u8,
n as u8]),
uint {
let mut bpos = pos as int;
let blen = len as int;
- alt whence {
+ match whence {
seek_set => bpos = offset,
seek_cur => bpos += offset,
seek_end => bpos = blen + offset
let arg: arg<t>;
new(-arg: arg<t>) { self.arg <- arg; }
drop {
- alt self.arg.opt_level {
+ match self.arg.opt_level {
option::none => (),
option::some(level) => {
// fail hard if not succesful
#[test]
fn file_reader_not_exist() {
- alt io::file_reader(~"not a file") {
+ match io::file_reader(~"not a file") {
result::err(e) => {
assert e == ~"error opening not a file";
}
#[test]
fn file_writer_bad_name() {
- alt io::file_writer(~"?/?", ~[]) {
+ match io::file_writer(~"?/?", ~[]) {
result::err(e) => {
assert str::starts_with(e, ~"error opening ?/?");
}
#[test]
fn buffered_file_writer_bad_name() {
- alt io::buffered_file_writer(~"?/?") {
+ match io::buffered_file_writer(~"?/?") {
result::err(e) => {
assert e == ~"error opening ?/?";
}
type IMPL_T<A> = option<A>;
pure fn EACH<A>(self: IMPL_T<A>, f: fn(A) -> bool) {
- alt self {
+ match self {
none => (),
some(a) => { f(a); }
}
}
fn SIZE_HINT<A>(self: IMPL_T<A>) -> option<uint> {
- alt self {
+ match self {
none => some(0u),
some(_) => some(1u)
}
}
fn min<A:copy,IA:base_iter<A>>(self: IA) -> A {
- alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
- alt a {
+ match do foldl::<A,option<A>,IA>(self, none) |a, b| {
+ match a {
some(a_) if a_ < b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move
}
fn max<A:copy,IA:base_iter<A>>(self: IA) -> A {
- alt do foldl::<A,option<A>,IA>(self, none) |a, b| {
- alt a {
+ match do foldl::<A,option<A>,IA>(self, none) |a, b| {
+ match a {
some(a_) if a_ > b => {
// FIXME (#2005): Not sure if this is successfully optimized to
// a move.
* Fails if the value equals `none`
*/
- alt opt {
+ match opt {
some(x) => return x,
none => fail ~"option::get none"
}
Fails if the value equals `none`
"];
- alt opt { some(x) => x, none => fail reason }
+ match opt { some(x) => x, none => fail reason }
}
pure fn map<T, U>(opt: option<T>, f: fn(T) -> U) -> option<U> {
//! Maps a `some` value from one type to another
- alt opt { some(x) => some(f(x)), none => none }
+ match opt { some(x) => some(f(x)), none => none }
}
pure fn map_consume<T, U>(-opt: option<T>, f: fn(-T) -> U) -> option<U> {
* function that returns an option.
*/
- alt opt { some(x) => f(x), none => none }
+ match opt { some(x) => f(x), none => none }
}
#[inline(always)]
pure fn is_none<T>(opt: option<T>) -> bool {
//! Returns true if the option equals `none`
- alt opt { none => true, some(_) => false }
+ match opt { none => true, some(_) => false }
}
pure fn is_some<T>(opt: option<T>) -> bool {
pure fn get_default<T: copy>(opt: option<T>, def: T) -> T {
//! Returns the contained value or a default
- alt opt { some(x) => x, none => def }
+ match opt { some(x) => x, none => def }
}
pure fn map_default<T, U>(opt: option<T>, +def: U, f: fn(T) -> U) -> U {
//! Applies a function to the contained value or returns a default
- alt opt { none => def, some(t) => f(t) }
+ match opt { none => def, some(t) => f(t) }
}
pure fn iter<T>(opt: option<T>, f: fn(T)) {
//! Performs an operation on the contained value or does nothing
- alt opt { none => (), some(t) => f(t) }
+ match opt { none => (), some(t) => f(t) }
}
#[inline(always)]
*/
unsafe {
- let addr = alt opt {
+ let addr = match opt {
some(x) => ptr::addr_of(x),
none => fail ~"option::unwrap none"
};
unsafe {
do priv::weaken_task |weak_po| {
loop {
- alt comm::select2(msg_po, weak_po) {
+ match comm::select2(msg_po, weak_po) {
either::left(msg_getenv(n, resp_ch)) => {
comm::send(resp_ch, impl::getenv(n))
}
#[cfg(target_os = "linux")]
fn fsync_fd(fd: c_int, level: io::fsync::level) -> c_int {
import libc::funcs::posix01::unistd::*;
- alt level {
+ match level {
io::fsync::fsync
| io::fsync::fullfsync => return fsync(fd),
io::fsync::fdatasync => return fdatasync(fd)
import libc::consts::os::extra::*;
import libc::funcs::posix88::fcntl::*;
import libc::funcs::posix01::unistd::*;
- alt level {
+ match level {
io::fsync::fsync => return fsync(fd),
_ => {
// According to man fnctl, the ok retval is only specified to be !=-1
* Otherwise, homedir returns option::none.
*/
fn homedir() -> option<path> {
- return alt getenv(~"HOME") {
+ return match getenv(~"HOME") {
some(p) => if !str::is_empty(p) {
some(p)
} else {
fn path_sep() -> ~str { return str::from_char(consts::path_sep); }
fn split_dirname_basename (pp: path) -> {dirname: ~str, basename: ~str} {
- alt str::rfind(pp, |ch|
+ match str::rfind(pp, |ch|
ch == consts::path_sep || ch == consts::alt_path_sep
) {
some(i) => {
unsafe fn unblock() {
let old_task = swap_task(self.blocked_task, ptr::null());
if !old_task.is_null() { rustrt::rust_task_deref(old_task) }
- alt swap_state_acq(self.state, empty) {
+ match swap_state_acq(self.state, empty) {
empty | blocked => (),
terminated => self.state = terminated,
full => self.state = full
assert p.payload == none;
p.payload <- some(payload);
let old_state = swap_state_rel(p.header.state, full);
- alt old_state {
+ match old_state {
empty => {
// Yay, fastpath.
rustrt::task_clear_event_reject(this);
let old_state = swap_state_acq(p.header.state,
blocked);
- alt old_state {
+ match old_state {
empty => {
debug!{"no data available on %?, going to sleep.", p_};
if count == 0 {
/// Returns true if messages are available.
pure fn peek<T: send, Tb: send>(p: recv_packet_buffered<T, Tb>) -> bool {
- alt unsafe {(*p.header()).state} {
+ match unsafe {(*p.header()).state} {
empty => false,
blocked => fail ~"peeking on blocked packet",
full | terminated => true
#[doc(hidden)]
fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { &*p };
- alt swap_state_rel(p.header.state, terminated) {
+ match swap_state_rel(p.header.state, terminated) {
empty => {
assert p.header.blocked_task.is_null();
// The receiver will eventually clean up.
fn receiver_terminate<T: send>(p: *packet<T>) {
let p = unsafe { &*p };
assert p.header.blocked_task.is_null();
- alt swap_state_rel(p.header.state, terminated) {
+ match swap_state_rel(p.header.state, terminated) {
empty => {
// the sender will clean up
//unsafe { forget(p) }
for pkts.eachi |i, p| unsafe {
let p = unsafe { &*p };
let old = p.mark_blocked(this);
- alt old {
+ match old {
full | terminated => {
data_avail = true;
ready_packet = i;
let event = wait_event(this) as *packet_header;
let pos = vec::position(pkts, |p| p == event);
- alt pos {
+ match pos {
some(i) => {
ready_packet = i;
data_avail = true;
let i = wait_many([a.header(), b.header()]/_);
unsafe {
- alt i {
+ match i {
0 => left((try_recv(a), b)),
1 => right((a, try_recv(b))),
_ => fail ~"select2 return an invalid packet"
/// Returns 0 or 1 depending on which endpoint is ready to receive
fn select2i<A: selectable, B: selectable>(a: A, b: B) -> either<(), ()> {
- alt wait_many([a.header(), b.header()]/_) {
+ match wait_many([a.header(), b.header()]/_) {
0 => left(()),
1 => right(()),
_ => fail ~"wait returned unexpected index"
}
pure fn header() -> *packet_header {
- alt self.p {
+ match self.p {
some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(packet.header);
}
pure fn header() -> *packet_header {
- alt self.p {
+ match self.p {
some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(packet.header);
fn try_recv() -> option<T> {
let mut endp = none;
endp <-> self.endp;
- alt move pipes::try_recv(unwrap(endp)) {
+ match move pipes::try_recv(unwrap(endp)) {
some(streamp::data(x, endp)) => {
self.endp = some(move_it!{endp});
some(move_it!{x})
pure fn peek() -> bool unchecked {
let mut endp = none;
endp <-> self.endp;
- let peek = alt endp {
+ let peek = match endp {
some(endp) => pipes::peek(endp),
none => fail ~"peeking empty stream"
};
ports <-> self.ports;
while result == none && ports.len() > 0 {
let i = wait_many(ports.map(|p| p.header()));
- alt move ports[i].try_recv() {
+ match move ports[i].try_recv() {
some(copy m) => {
result = some(move m);
}
impl<T: send> of selectable for port<T> {
pure fn header() -> *packet_header unchecked {
- alt self.endp {
+ match self.endp {
some(endp) => endp.header(),
none => fail ~"peeking empty stream"
}
of select2<T, U> for (Left, Right) {
fn select() -> either<T, U> {
- alt self {
- (lp, rp) => alt select2i(lp, rp) {
+ match self {
+ (lp, rp) => match select2i(lp, rp) {
left(()) => left (lp.recv()),
right(()) => right(rp.recv())
}
}
fn try_select() -> either<option<T>, option<U>> {
- alt self {
- (lp, rp) => alt select2i(lp, rp) {
+ match self {
+ (lp, rp) => match select2i(lp, rp) {
left(()) => left (lp.try_recv()),
right(()) => right(rp.try_recv())
}
c1.send(~"abc");
- alt (p1, p2).select() {
+ match (p1, p2).select() {
right(_) => fail,
_ => ()
}
// Wait to hear if we are the official instance of
// this global task
- alt comm::recv::<msg>(setup_po) {
+ match comm::recv::<msg>(setup_po) {
proceed => f(po),
abort => ()
}
* If the result is an error
*/
pure fn get<T: copy, U>(res: result<T, U>) -> T {
- alt res {
+ match res {
ok(t) => t,
err(the_err) => unchecked {
fail fmt!{"get called on error result: %?", the_err}
* If the result is not an error
*/
pure fn get_err<T, U: copy>(res: result<T, U>) -> U {
- alt res {
+ match res {
err(u) => u,
ok(_) => fail ~"get_error called on ok result"
}
/// Returns true if the result is `ok`
pure fn is_ok<T, U>(res: result<T, U>) -> bool {
- alt res {
+ match res {
ok(_) => true,
err(_) => false
}
* result variants are converted to `either::left`.
*/
pure fn to_either<T: copy, U: copy>(res: result<U, T>) -> either<T, U> {
- alt res {
+ match res {
ok(res) => either::right(res),
err(fail_) => either::left(fail_)
}
*/
fn chain<T, U: copy, V: copy>(res: result<T, V>, op: fn(T) -> result<U, V>)
-> result<U, V> {
- alt res {
+ match res {
ok(t) => op(t),
err(e) => err(e)
}
res: result<T, V>,
op: fn(V) -> result<T, U>)
-> result<T, U> {
- alt res {
+ match res {
ok(t) => ok(t),
err(v) => op(v)
}
* }
*/
fn iter<T, E>(res: result<T, E>, f: fn(T)) {
- alt res {
+ match res {
ok(t) => f(t),
err(_) => ()
}
* handling an error.
*/
fn iter_err<T, E>(res: result<T, E>, f: fn(E)) {
- alt res {
+ match res {
ok(_) => (),
err(e) => f(e)
}
*/
fn map<T, E: copy, U: copy>(res: result<T, E>, op: fn(T) -> U)
-> result<U, E> {
- alt res {
+ match res {
ok(t) => ok(op(t)),
err(e) => err(e)
}
*/
fn map_err<T: copy, E, F: copy>(res: result<T, E>, op: fn(E) -> F)
-> result<T, F> {
- alt res {
+ match res {
ok(t) => ok(t),
err(e) => err(op(e))
}
fn is_err() -> bool { is_err(self) }
fn iter(f: fn(T)) {
- alt self {
+ match self {
ok(t) => f(t),
err(_) => ()
}
}
fn iter_err(f: fn(E)) {
- alt self {
+ match self {
ok(_) => (),
err(e) => f(e)
}
fn get() -> T { get(self) }
fn map_err<F:copy>(op: fn(E) -> F) -> result<T,F> {
- alt self {
+ match self {
ok(t) => ok(t),
err(e) => err(op(e))
}
fn get_err() -> E { get_err(self) }
fn map<U:copy>(op: fn(T) -> U) -> result<U,E> {
- alt self {
+ match self {
ok(t) => ok(op(t)),
err(e) => err(e)
}
let mut vs: ~[V] = ~[];
vec::reserve(vs, vec::len(ts));
for vec::each(ts) |t| {
- alt op(t) {
+ match op(t) {
ok(v) => vec::push(vs, v),
err(u) => return err(u)
}
fn map_opt<T,U:copy,V:copy>(
o_t: option<T>, op: fn(T) -> result<V,U>) -> result<option<V>,U> {
- alt o_t {
+ match o_t {
none => ok(none),
- some(t) => alt op(t) {
+ some(t) => match op(t) {
ok(v) => ok(some(v)),
err(e) => err(e)
}
vec::reserve(vs, n);
let mut i = 0u;
while i < n {
- alt op(ss[i],ts[i]) {
+ match op(ss[i],ts[i]) {
ok(v) => vec::push(vs, v),
err(u) => return err(u)
}
let n = vec::len(ts);
let mut i = 0u;
while i < n {
- alt op(ss[i],ts[i]) {
+ match op(ss[i],ts[i]) {
ok(()) => (),
err(u) => return err(u)
}
/// Unwraps a result, assuming it is an `ok(T)`
fn unwrap<T, U>(-res: result<T, U>) -> T {
unsafe {
- let addr = alt res {
+ let addr = match res {
ok(x) => ptr::addr_of(x),
err(_) => fail ~"error result"
};
cb: fn(*c_void) -> T) -> T {
// On posixy systems we can pass a char** for envp, which is
// a null-terminated array of "k=v\n" strings.
- alt env {
+ match env {
some(es) if !vec::is_empty(es) => {
let mut tmps = ~[];
let mut ptrs = ~[];
// rather a concatenation of null-terminated k=v\0 sequences, with a final
// \0 to terminate.
unsafe {
- alt env {
+ match env {
some(es) if !vec::is_empty(es) => {
let mut blk : ~[u8] = ~[];
for vec::each(es) |e| {
fn with_dirp<T>(d: option<~str>,
cb: fn(*libc::c_char) -> T) -> T {
- alt d {
+ match d {
some(dir) => str::as_c_str(dir, cb),
none => cb(ptr::null())
}
let mut count = 2;
while count > 0 {
let stream = comm::recv(p);
- alt check stream {
+ match check stream {
(1, s) => {
outs = s;
}
k: &K) -> search_result {
let _ = for self.bucket_sequence(hash) |i| {
- alt buckets[i] {
+ match buckets[i] {
some(bkt) => if bkt.hash == hash && self.eqfn(k, &bkt.key) {
return found_entry(i);
}
/// Assumes that there will be a bucket.
/// True if there was no previous entry with that key
fn insert_internal(hash: uint, +k: K, +v: V) -> bool {
- alt self.bucket_for_key_with_hash(self.buckets, hash,
+ match self.bucket_for_key_with_hash(self.buckets, hash,
unsafe{borrow(k)}) {
table_full => {fail ~"Internal logic error";}
found_hole(idx) => {
// I found this explanation elucidating:
// http://www.maths.lse.ac.uk/Courses/MA407/del-hash.pdf
- let mut idx = alt self.bucket_for_key(self.buckets, k) {
+ let mut idx = match self.bucket_for_key(self.buckets, k) {
table_full | found_hole(_) => {
return false;
}
}
fn contains_key(k: &K) -> bool {
- alt self.bucket_for_key(self.buckets, k) {
+ match self.bucket_for_key(self.buckets, k) {
found_entry(_) => {true}
table_full | found_hole(_) => {false}
}
impl public_methods<K,V: copy> for &const linear_map<K,V> {
fn find(k: &K) -> option<V> {
- alt self.bucket_for_key(self.buckets, k) {
+ match self.bucket_for_key(self.buckets, k) {
found_entry(idx) => {
- alt check self.buckets[idx] {
+ match check self.buckets[idx] {
some(bkt) => {some(copy bkt.value)}
}
}
/// Returns a string with leading whitespace removed
pure fn trim_left(s: &str) -> ~str {
- alt find(s, |c| !char::is_whitespace(c)) {
+ match find(s, |c| !char::is_whitespace(c)) {
none => ~"",
some(first) => unsafe { unsafe::slice_bytes(s, first, len(s)) }
}
/// Returns a string with trailing whitespace removed
pure fn trim_right(s: &str) -> ~str {
- alt rfind(s, |c| !char::is_whitespace(c)) {
+ match rfind(s, |c| !char::is_whitespace(c)) {
none => ~"",
some(last) => {
let {next, _} = char_range_at(s, last);
fn test_chars_iter() {
let mut i = 0;
do chars_iter(~"x\u03c0y") |ch| {
- alt check i {
+ match check i {
0 => assert ch == 'x',
1 => assert ch == '\u03c0',
2 => assert ch == 'y'
let mut i = 0;
do bytes_iter(~"xyz") |bb| {
- alt check i {
+ match check i {
0 => assert bb == 'x' as u8,
1 => assert bb == 'y' as u8,
2 => assert bb == 'z' as u8
let mut ii = 0;
do split_char_iter(data, ' ') |xx| {
- alt ii {
+ match ii {
0 => assert ~"\nMary" == xx,
1 => assert ~"had" == xx,
2 => assert ~"a" == xx,
let mut ii = 0;
do splitn_char_iter(data, ' ', 2u) |xx| {
- alt ii {
+ match ii {
0 => assert ~"\nMary" == xx,
1 => assert ~"had" == xx,
2 => assert ~"a little lamb\nLittle lamb\n" == xx,
let mut ii = 0;
do words_iter(data) |ww| {
- alt ii {
+ match ii {
0 => assert ~"Mary" == ww,
1 => assert ~"had" == ww,
2 => assert ~"a" == ww,
let mut ii = 0;
do lines_iter(lf) |x| {
- alt ii {
+ match ii {
0 => assert ~"" == x,
1 => assert ~"Mary had a little lamb" == x,
2 => assert ~"Little lamb" == x,
let ch = comm::chan(po);
blk(do future::from_fn {
- alt comm::recv(po) {
+ match comm::recv(po) {
exit(_, result) => result
}
});
do task().unlinked().future_result(|-r| { result = some(r); }).spawn {
comm::send(ch, f());
}
- alt future::get(option::unwrap(result)) {
+ match future::get(option::unwrap(result)) {
success => result::ok(comm::recv(po)),
failure => result::err(())
}
/*######################################################################*
* Step 1. Get spawner's taskgroup info.
*######################################################################*/
- let spawner_group = alt unsafe { local_get(spawner, taskgroup_key()) } {
+ let spawner_group = match unsafe { local_get(spawner, taskgroup_key()) } {
none => {
// Main task, doing first spawn ever. Lazily initialise here.
let mut members = new_taskset();
// assertion, but initialising it requires locking a mutex. Hence
// it should be enabled only in debug builds.
let new_generation =
- alt *old_ancestors {
+ match *old_ancestors {
some(arc) => access_ancestors(arc, |a| a.generation+1),
none => 0 // the actual value doesn't really matter.
};
fn share_ancestors(ancestors: &mut ancestor_list) -> ancestor_list {
// Appease the borrow-checker. Really this wants to be written as:
- // alt ancestors
+ // match ancestors
// some(ancestor_arc) { ancestor_list(some(ancestor_arc.clone())) }
// none { ancestor_list(none) }
let tmp = util::replace(&mut **ancestors, none);
// Agh. Get move-mode items into the closure. FIXME (#2829)
let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
// Create child task.
- let new_task = alt opts.sched {
+ let new_task = match opts.sched {
none => rustrt::new_task(),
some(sched_opts) => new_task_in_new_sched(sched_opts)
};
fail ~"foreign_stack_size scheduler option unimplemented";
}
- let num_threads = alt opts.mode {
+ let num_threads = match opts.mode {
single_threaded => 1u,
thread_per_core => {
fail ~"thread_per_core scheduling mode unimplemented"
let key_value = key_to_key_value(key);
let map_pos = (*map).position(|entry|
- alt entry {
+ match entry {
some((k,_,_)) => k == key_value,
none => false
}
// Construct new entry to store in the map.
let new_entry = some((keyval, data_ptr, data_box));
// Find a place to put it.
- alt local_data_lookup(map, key) {
+ match local_data_lookup(map, key) {
some((index, _old_data_ptr)) => {
// Key already had a value set, _old_data_ptr, whose reference
// will get dropped when the local_data box is overwritten.
}
none => {
// Find an empty slot. If not, grow the vector.
- alt (*map).position(|x| x == none) {
+ match (*map).position(|x| x == none) {
some(empty_index) => (*map).set_elt(empty_index, new_entry),
none => (*map).push(new_entry)
}
#[test]
fn test_try_success() {
- alt do try {
+ match do try {
~"Success!"
} {
result::ok(~"Success!") => (),
#[test]
#[ignore(cfg(windows))]
fn test_try_fail() {
- alt do try {
+ match do try {
fail
} {
result::err(()) => (),
fn test_tls_modify() unsafe {
fn my_key(+_x: @~str) { }
local_data_modify(my_key, |data| {
- alt data {
+ match data {
some(@val) => fail ~"unwelcome value: " + val,
none => some(@~"first data")
}
});
local_data_modify(my_key, |data| {
- alt data {
+ match data {
some(@~"first data") => some(@~"next data"),
some(@val) => fail ~"wrong value: " + val,
none => fail ~"missing value"
let mut power = 1u as T;
let mut n = 0u 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
}
let mut i = str::len(buf) - 1u;
let mut power = 1u64, n = 0u64;
loop {
- alt char::to_digit(buf[i] as char, radix as uint) {
+ match char::to_digit(buf[i] as char, radix as uint) {
some(d) => n += d as u64 * power,
none => return none
}
mod general_category {
pure fn Cc(c: char) -> bool {
- return alt c {
+ return match c {
'\x00' to '\x1f'
| '\x7f' to '\x9f' => true,
_ => false
}
pure fn Cf(c: char) -> bool {
- return alt c {
+ return match c {
'\xad'
| '\u0600' to '\u0603'
| '\u06dd'
}
pure fn Co(c: char) -> bool {
- return alt c {
+ return match c {
'\ue000' to '\uf8ff' => true,
_ => false
};
}
pure fn Cs(c: char) -> bool {
- return alt c {
+ return match c {
'\ud800' to '\udfff' => true,
_ => false
};
}
pure fn Ll(c: char) -> bool {
- return alt c {
+ return match c {
'\x61' to '\x7a'
| '\xaa'
| '\xb5'
}
pure fn Lm(c: char) -> bool {
- return alt c {
+ return match c {
'\u02b0' to '\u02c1'
| '\u02c6' to '\u02d1'
| '\u02e0' to '\u02e4'
}
pure fn Lo(c: char) -> bool {
- return alt c {
+ return match c {
'\u01bb'
| '\u01c0' to '\u01c3'
| '\u0294'
}
pure fn Lt(c: char) -> bool {
- return alt c {
+ return match c {
'\u01c5'
| '\u01c8'
| '\u01cb'
}
pure fn Lu(c: char) -> bool {
- return alt c {
+ return match c {
'\x41' to '\x5a'
| '\xc0' to '\xd6'
| '\xd8' to '\xde'
}
pure fn Mc(c: char) -> bool {
- return alt c {
+ return match c {
'\u0903'
| '\u093b'
| '\u093e' to '\u0940'
}
pure fn Me(c: char) -> bool {
- return alt c {
+ return match c {
'\u0488' to '\u0489'
| '\u20dd' to '\u20e0'
| '\u20e2' to '\u20e4'
}
pure fn Mn(c: char) -> bool {
- return alt c {
+ return match c {
'\u0300' to '\u036f'
| '\u0483' to '\u0487'
| '\u0591' to '\u05bd'
}
pure fn Nd(c: char) -> bool {
- return alt c {
+ return match c {
'\x30' to '\x39'
| '\u0660' to '\u0669'
| '\u06f0' to '\u06f9'
}
pure fn Nl(c: char) -> bool {
- return alt c {
+ return match c {
'\u16ee' to '\u16f0'
| '\u2160' to '\u2182'
| '\u2185' to '\u2188'
}
pure fn No(c: char) -> bool {
- return alt c {
+ return match c {
'\xb2' to '\xb3'
| '\xb9'
| '\xbc' to '\xbe'
}
pure fn Pc(c: char) -> bool {
- return alt c {
+ return match c {
'\x5f'
| '\u203f' to '\u2040'
| '\u2054'
}
pure fn Pd(c: char) -> bool {
- return alt c {
+ return match c {
'\x2d'
| '\u058a'
| '\u05be'
}
pure fn Pe(c: char) -> bool {
- return alt c {
+ return match c {
'\x29'
| '\x5d'
| '\x7d'
}
pure fn Pf(c: char) -> bool {
- return alt c {
+ return match c {
'\xbb'
| '\u2019'
| '\u201d'
}
pure fn Pi(c: char) -> bool {
- return alt c {
+ return match c {
'\xab'
| '\u2018'
| '\u201b' to '\u201c'
}
pure fn Po(c: char) -> bool {
- return alt c {
+ return match c {
'\x21' to '\x23'
| '\x25' to '\x27'
| '\x2a'
}
pure fn Ps(c: char) -> bool {
- return alt c {
+ return match c {
'\x28'
| '\x5b'
| '\x7b'
}
pure fn Sc(c: char) -> bool {
- return alt c {
+ return match c {
'\x24'
| '\xa2' to '\xa5'
| '\u060b'
}
pure fn Sk(c: char) -> bool {
- return alt c {
+ return match c {
'\x5e'
| '\x60'
| '\xa8'
}
pure fn Sm(c: char) -> bool {
- return alt c {
+ return match c {
'\x2b'
| '\x3c' to '\x3e'
| '\x7c'
}
pure fn So(c: char) -> bool {
- return alt c {
+ return match c {
'\xa6' to '\xa7'
| '\xa9'
| '\xae'
}
pure fn Zl(c: char) -> bool {
- return alt c {
+ return match c {
'\u2028' => true,
_ => false
};
}
pure fn Zp(c: char) -> bool {
- return alt c {
+ return match c {
'\u2029' => true,
_ => false
};
}
pure fn Zs(c: char) -> bool {
- return alt c {
+ return match c {
'\x20'
| '\xa0'
| '\u1680'
mod derived_property {
/// Check if a character has the alphabetic unicode property
pure fn Alphabetic(c: char) -> bool {
- return alt c {
+ return match c {
'\x41' to '\x5a'
| '\x61' to '\x7a'
| '\xaa'
}
pure fn XID_Continue(c: char) -> bool {
- return alt c {
+ return match c {
'\x30' to '\x39'
| '\x41' to '\x5a'
| '\x5f'
}
pure fn XID_Start(c: char) -> bool {
- return alt c {
+ return match c {
'\x41' to '\x5a'
| '\x61' to '\x7a'
| '\xaa'
let mut start = 0u;
let mut result = ~[];
while start < ln {
- alt position_between(v, start, ln, f) {
+ match position_between(v, start, ln, f) {
none => break,
some(i) => {
push(result, slice(v, start, i));
let mut count = n;
let mut result = ~[];
while start < ln && count > 0u {
- alt position_between(v, start, ln, f) {
+ match position_between(v, start, ln, f) {
none => break,
some(i) => {
push(result, slice(v, start, i));
let mut end = ln;
let mut result = ~[];
while end > 0u {
- alt rposition_between(v, 0u, end, f) {
+ match rposition_between(v, 0u, end, f) {
none => break,
some(i) => {
push(result, slice(v, i + 1u, end));
let mut count = n;
let mut result = ~[];
while end > 0u && count > 0u {
- alt rposition_between(v, 0u, end, f) {
+ match rposition_between(v, 0u, end, f) {
none => break,
some(i) => {
push(result, slice(v, i + 1u, end));
-> ~[U] {
let mut result = ~[];
for each(v) |elem| {
- alt f(elem) {
+ match f(elem) {
none => {/* no-op */ }
some(result_elem) => unsafe { push(result, result_elem); }
}
i += 3u;
}
- alt check len % 3u {
+ match check len % 3u {
0u => (),
1u => {
let n = (self[i] as uint) << 16u;
} else if ch == '/' {
n |= 0x3Fu;
} else if ch == '=' {
- alt len - i {
+ match len - i {
1u => {
vec::push(r, ((n >> 16u) & 0xFFu) as u8);
vec::push(r, ((n >> 8u ) & 0xFFu) as u8);
if self.nbits != other.nbits {
self.die();
}
- alt self.rep {
- small(s) => alt other.rep {
- small(s1) => alt op {
+ match self.rep {
+ small(s) => match other.rep {
+ small(s1) => match op {
union => s.union(s1),
intersect => s.intersect(s1),
assign => s.become(s1),
}
big(s1) => self.die()
}
- big(s) => alt other.rep {
+ big(s) => match other.rep {
small(_) => self.die(),
- big(s1) => alt op {
+ big(s1) => match op {
union => s.union(s1),
intersect => s.intersect(s1),
assign => s.become(s1),
/// Makes a copy of a bitvector
#[inline(always)]
fn clone() -> ~bitv {
- ~alt self.rep {
+ ~match self.rep {
small(b) => {
bitv{nbits: self.nbits, rep: small(~small_bitv{bits: b.bits})}
}
#[inline(always)]
pure fn get(i: uint) -> bool {
assert (i < self.nbits);
- alt self.rep {
+ match self.rep {
big(b) => b.get(i),
small(s) => s.get(i)
}
#[inline(always)]
fn set(i: uint, x: bool) {
assert (i < self.nbits);
- alt self.rep {
+ match self.rep {
big(b) => b.set(i, x),
small(s) => s.set(i, x)
}
#[inline(always)]
fn equal(v1: bitv) -> bool {
if self.nbits != v1.nbits { return false; }
- alt self.rep {
- small(b) => alt v1.rep {
+ match self.rep {
+ small(b) => match v1.rep {
small(b1) => b.equals(b1),
_ => false
}
- big(s) => alt v1.rep {
+ big(s) => match v1.rep {
big(s1) => s.equals(s1),
small(_) => return false
}
/// Set all bits to 0
#[inline(always)]
fn clear() {
- alt self.rep {
+ match self.rep {
small(b) => b.clear(),
big(s) => for s.each_storage() |w| { w = 0u }
}
/// Set all bits to 1
#[inline(always)]
fn set_all() {
- alt self.rep {
+ match self.rep {
small(b) => b.set_all(),
big(s) => for s.each_storage() |w| { w = !0u } }
}
/// Invert all bits
#[inline(always)]
fn invert() {
- alt self.rep {
+ match self.rep {
small(b) => b.invert(),
big(s) => for s.each_storage() |w| { w = !w } }
}
/// Returns true if all bits are 1
#[inline(always)]
fn is_true() -> bool {
- alt self.rep {
+ match self.rep {
small(b) => b.is_true(),
_ => {
for self.each() |i| { if !i { return false; } }
/// Returns true if all bits are 0
fn is_false() -> bool {
- alt self.rep {
+ match self.rep {
small(b) => b.is_false(),
big(_) => {
for self.each() |i| { if i { return false; } }
let dtor: option<fn@()>;
new(dtor: option<fn@()>) { self.dtor = dtor; }
drop {
- alt self.dtor {
+ match self.dtor {
option::none => (),
option::some(f) => f()
}
return rv;
}
fn get<T: copy>(elts: dvec<cell<T>>, i: uint) -> T {
- alt elts.get_elt(i) { some(t) => t, _ => fail }
+ match elts.get_elt(i) { some(t) => t, _ => fail }
}
type repr<T> = {mut nelts: uint,
fn inteq(&&a: int, &&b: int) -> bool { return a == b; }
fn intboxeq(&&a: @int, &&b: @int) -> bool { return a == b; }
fn taggyeq(a: taggy, b: taggy) -> bool {
- alt a {
- one(a1) => alt b {
+ match a {
+ one(a1) => match b {
one(b1) => return a1 == b1,
_ => return false
}
- two(a1, a2) => alt b {
+ two(a1, a2) => match b {
two(b1, b2) => return a1 == b1 && a2 == b2,
_ => return false
}
- three(a1, a2, a3) => alt b {
+ three(a1, a2, a3) => match b {
three(b1, b2, b3) => return a1 == b1 && a2 == b2 && a3 == b3,
_ => return false
}
}
}
fn taggypareq<T>(a: taggypar<T>, b: taggypar<T>) -> bool {
- alt a {
- onepar::<T>(a1) => alt b {
+ match a {
+ onepar::<T>(a1) => match b {
onepar::<T>(b1) => return a1 == b1,
_ => return false
}
- twopar::<T>(a1, a2) => alt b {
+ twopar::<T>(a1, a2) => match b {
twopar::<T>(b1, b2) => return a1 == b1 && a2 == b2,
_ => return false
}
- threepar::<T>(a1, a2, a3) => alt b {
+ threepar::<T>(a1, a2, a3) => match b {
threepar::<T>(b1, b2, b3) => {
return a1 == b1 && a2 == b2 && a3 == b3
}
}
fn get_doc(d: doc, tg: uint) -> doc {
- alt maybe_get_doc(d, tg) {
+ match maybe_get_doc(d, tg) {
some(d) => return d,
none => {
error!{"failed to find block with tag %u", tg};
}
fn write_sized_vuint(w: io::writer, n: uint, size: uint) {
- alt size {
+ match size {
1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) {
do s.emit_enum(~"core::option::t") {
- alt v {
+ match v {
none => s.emit_enum_variant(
~"core::option::none", 0u, 0u, || { } ),
some(v0) => {
fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> {
do s.read_enum(~"core::option::t") {
do s.read_enum_variant |i| {
- alt check i {
+ match check i {
0u => none,
1u => {
let v0 = do s.read_enum_variant_arg(0u) {
/// Insert a value into the map
fn insert<K: copy, V: copy>(m: treemap<K, V>, k: K, v: V) -> treemap<K, V> {
- @alt m {
+ @match m {
@empty => node(@k, @v, @empty, @empty),
@node(@kk, vv, left, right) => {
if k < kk {
/// Find a value based on the key
fn find<K, V: copy>(m: treemap<K, V>, k: K) -> option<V> {
- alt *m {
+ match *m {
empty => none,
node(@kk, @v, left, right) => {
if k == kk {
/// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: treemap<K, V>, f: fn(K, V)) {
- alt *m {
+ match *m {
empty => (),
/*
Previously, this had what looked like redundant
* optflag("h"),
* optflag("help")
* ];
- * let matches = alt getopts(vec::tail(args), opts) {
+ * let matches = match getopts(vec::tail(args), opts) {
* result::ok(m) { m }
* result::err(f) { fail fail_str(f) }
* };
}
fn name_str(nm: name) -> ~str {
- return alt nm {
+ return match nm {
short(ch) => str::from_char(ch),
long(s) => s
};
/// Convert a `fail_` enum into an error string
fn fail_str(f: fail_) -> ~str {
- return alt f {
+ return match f {
argument_missing(nm) => ~"Argument to option '" + nm + ~"' missing.",
unrecognized_option(nm) => ~"Unrecognized option: '" + nm + ~"'.",
option_missing(nm) => ~"Required option '" + nm + ~"' missing.",
correctly
*/
- alt find_opt(opts, opt) {
+ match find_opt(opts, opt) {
some(id) => last_valid_opt_id = option::some(id),
none => {
let arg_follows =
option::is_some(last_valid_opt_id) &&
- alt opts[option::get(last_valid_opt_id)].hasarg {
+ match opts[option::get(last_valid_opt_id)]
+ .hasarg {
+
yes | maybe => true,
no => false
};
let mut name_pos = 0u;
for vec::each(names) |nm| {
name_pos += 1u;
- let optid = alt find_opt(opts, nm) {
+ let optid = match find_opt(opts, nm) {
some(id) => id,
none => return err(unrecognized_option(name_str(nm)))
};
- alt opts[optid].hasarg {
+ match opts[optid].hasarg {
no => {
if !option::is_none::<~str>(i_arg) {
return err(unexpected_argument(name_str(nm)));
}
fn opt_vals(m: matches, nm: ~str) -> ~[optval] {
- return alt find_opt(m.opts, mkname(nm)) {
+ return match find_opt(m.opts, mkname(nm)) {
some(id) => m.vals[id],
none => {
error!{"No option '%s' defined", nm};
/// Returns true if any of several options were matched
fn opts_present(m: matches, names: ~[~str]) -> bool {
for vec::each(names) |nm| {
- alt find_opt(m.opts, mkname(nm)) {
+ match find_opt(m.opts, mkname(nm)) {
some(_) => return true,
_ => ()
}
* argument
*/
fn opt_str(m: matches, nm: ~str) -> ~str {
- return alt opt_val(m, nm) { val(s) => s, _ => fail };
+ return match opt_val(m, nm) { val(s) => s, _ => fail };
}
/**
*/
fn opts_str(m: matches, names: ~[~str]) -> ~str {
for vec::each(names) |nm| {
- alt opt_val(m, nm) {
+ match opt_val(m, nm) {
val(s) => return s,
_ => ()
}
fn opt_strs(m: matches, nm: ~str) -> ~[~str] {
let mut acc: ~[~str] = ~[];
for vec::each(opt_vals(m, nm)) |v| {
- alt v { val(s) => vec::push(acc, s), _ => () }
+ match v { val(s) => vec::push(acc, s), _ => () }
}
return acc;
}
fn opt_maybe_str(m: matches, nm: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
- return alt vals[0] { val(s) => some::<~str>(s), _ => none::<~str> };
+ return match vals[0] { val(s) => some::<~str>(s), _ => none::<~str> };
}
fn opt_default(m: matches, nm: ~str, def: ~str) -> option<~str> {
let vals = opt_vals(m, nm);
if vec::len::<optval>(vals) == 0u { return none::<~str>; }
- return alt vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) }
+ return match vals[0] { val(s) => some::<~str>(s), _ => some::<~str>(def) }
}
#[cfg(test)]
}
fn check_fail_type(f: fail_, ft: fail_type) {
- alt f {
+ match f {
argument_missing(_) => assert ft == argument_missing_,
unrecognized_option(_) => assert ft == unrecognized_option_,
option_missing(_) => assert ft == option_missing_,
let args = ~[~"--test=20"];
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
- alt check rs {
+ match check rs {
ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
let args = ~[~"blah"];
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_missing_),
_ => fail
}
let args = ~[~"--test"];
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[reqopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"-t", ~"20"];
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
let args = ~[~"blah"];
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_missing_),
_ => fail
}
let args = ~[~"-t"];
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[reqopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"--test=20"];
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
let args = ~[~"blah"];
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"test")),
_ => fail
}
let args = ~[~"--test"];
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optopt(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"-t", ~"20"];
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
let args = ~[~"blah"];
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"t")),
_ => fail
}
let args = ~[~"-t"];
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optopt(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"--test"];
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (opt_present(m, ~"test")),
_ => fail
}
let args = ~[~"blah"];
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"test")),
_ => fail
}
let args = ~[~"--test=20"];
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => {
log(error, fail_str(f));
check_fail_type(f, unexpected_argument_);
let args = ~[~"--test", ~"--test"];
let opts = ~[optflag(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"-t"];
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (opt_present(m, ~"t")),
_ => fail
}
let args = ~[~"blah"];
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"t")),
_ => fail
}
let args = ~[~"-t", ~"20"];
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
// The next variable after the flag is just a free argument
let args = ~[~"-t", ~"-t"];
let opts = ~[optflag(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, option_duplicated_),
_ => fail
}
let args = ~[~"--test=20"];
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
let args = ~[~"blah"];
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"test")),
_ => fail
}
let args = ~[~"--test"];
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"--test=20", ~"--test=30"];
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"test"));
assert (opt_str(m, ~"test") == ~"20");
let args = ~[~"-t", ~"20"];
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
let args = ~[~"blah"];
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => assert (!opt_present(m, ~"t")),
_ => fail
}
let args = ~[~"-t"];
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, argument_missing_),
_ => fail
}
let args = ~[~"-t", ~"20", ~"-t", ~"30"];
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (opt_present(m, ~"t"));
assert (opt_str(m, ~"t") == ~"20");
let args = ~[~"--untest"];
let opts = ~[optmulti(~"t")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, unrecognized_option_),
_ => fail
}
let args = ~[~"-t"];
let opts = ~[optmulti(~"test")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
err(f) => check_fail_type(f, unrecognized_option_),
_ => fail
}
optflag(~"f"), optmulti(~"m"), optmulti(~"n"),
optopt(~"notpresent")];
let rs = getopts(args, opts);
- alt rs {
+ match rs {
ok(m) => {
assert (m.free[0] == ~"prog");
assert (m.free[1] == ~"free1");
fn test_multi() {
let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"];
let opts = ~[optopt(~"e"), optopt(~"encrypt")];
- let matches = alt getopts(args, opts) {
+ let matches = match getopts(args, opts) {
result::ok(m) => m,
result::err(f) => fail
};
fn test_nospace() {
let args = ~[~"-Lfoo"];
let opts = ~[optmulti(~"L")];
- let matches = alt getopts(args, opts) {
+ let matches = match getopts(args, opts) {
result::ok(m) => m,
result::err(f) => fail
};
/// Serializes a json value into a io::writer
fn to_writer(wr: io::writer, j: json) {
- alt j {
+ match j {
num(n) => wr.write_str(float::to_str(n, 6u)),
string(s) => wr.write_str(escape_str(*s)),
boolean(b) => wr.write_str(if b { ~"true" } else { ~"false" }),
fn escape_str(s: ~str) -> ~str {
let mut escaped = ~"\"";
do str::chars_iter(s) |c| {
- alt c {
+ match c {
'"' => escaped += ~"\\\"",
'\\' => escaped += ~"\\\\",
'\x08' => escaped += ~"\\b",
}
fn parse() -> result<json, error> {
- alt self.parse_value() {
+ match self.parse_value() {
ok(value) => {
// Skip trailing whitespaces.
self.parse_whitespace();
if self.eof() { return self.error(~"EOF while parsing value"); }
- alt self.ch {
+ match self.ch {
'n' => self.parse_ident(~"ull", null),
't' => self.parse_ident(~"rue", boolean(true)),
'f' => self.parse_ident(~"alse", boolean(false)),
'0' to '9' | '-' => self.parse_number(),
- '"' => alt self.parse_str() {
+ '"' => match self.parse_str() {
ok(s) => ok(string(s)),
err(e) => err(e)
}
neg = -1f;
}
- let mut res = alt self.parse_integer() {
+ let mut res = match self.parse_integer() {
ok(res) => res,
err(e) => return err(e)
};
if self.ch == '.' {
- alt self.parse_decimal(res) {
+ match self.parse_decimal(res) {
ok(r) => res = r,
err(e) => return err(e)
}
}
if self.ch == 'e' || self.ch == 'E' {
- alt self.parse_exponent(res) {
+ match self.parse_exponent(res) {
ok(r) => res = r,
err(e) => return err(e)
}
fn parse_integer() -> result<float, error> {
let mut res = 0f;
- alt self.ch {
+ match self.ch {
'0' => {
self.bump();
// There can be only one leading '0'.
- alt self.ch {
+ match self.ch {
'0' to '9' => return self.error(~"invalid number"),
_ => ()
}
}
'1' to '9' => {
while !self.eof() {
- alt self.ch {
+ match self.ch {
'0' to '9' => {
res *= 10f;
res += ((self.ch as int) - ('0' as int)) as float;
self.bump();
// Make sure a digit follows the decimal place.
- alt self.ch {
+ match self.ch {
'0' to '9' => (),
_ => return self.error(~"invalid number")
}
let mut res = res;
let mut dec = 1f;
while !self.eof() {
- alt self.ch {
+ match self.ch {
'0' to '9' => {
dec /= 10f;
res += (((self.ch as int) - ('0' as int)) as float) * dec;
let mut exp = 0u;
let mut neg_exp = false;
- alt self.ch {
+ match self.ch {
'+' => self.bump(),
'-' => { self.bump(); neg_exp = true; }
_ => ()
}
// Make sure a digit follows the exponent place.
- alt self.ch {
+ match self.ch {
'0' to '9' => (),
_ => return self.error(~"invalid number")
}
while !self.eof() {
- alt self.ch {
+ match self.ch {
'0' to '9' => {
exp *= 10u;
exp += (self.ch as uint) - ('0' as uint);
self.bump();
if (escape) {
- alt self.ch {
+ match self.ch {
'"' => str::push_char(res, '"'),
'\\' => str::push_char(res, '\\'),
'/' => str::push_char(res, '/'),
let mut i = 0u;
let mut n = 0u;
while i < 4u {
- alt self.next_char() {
+ match self.next_char() {
'0' to '9' => {
n = n * 10u +
(self.ch as uint) - ('0' as uint);
}
loop {
- alt self.parse_value() {
+ match self.parse_value() {
ok(v) => vec::push(values, v),
e => return e
}
return self.error(~"EOF while parsing list");
}
- alt self.ch {
+ match self.ch {
',' => self.bump(),
']' => { self.bump(); return ok(list(@values)); }
_ => return self.error(~"expected `,` or `]`")
return self.error(~"key must be a string");
}
- let key = alt self.parse_str() {
+ let key = match self.parse_str() {
ok(key) => key,
err(e) => return err(e)
};
}
self.bump();
- alt self.parse_value() {
+ match self.parse_value() {
ok(value) => { values.insert(copy *key, value); }
e => return e
}
self.parse_whitespace();
- alt self.ch {
+ match self.ch {
',' => self.bump(),
'}' => { self.bump(); return ok(dict(values)); }
_ => {
/// Test if two json values are equal
fn eq(value0: json, value1: json) -> bool {
- alt (value0, value1) {
+ match (value0, value1) {
(num(f0), num(f1)) => f0 == f1,
(string(s0), string(s1)) => s0 == s1,
(boolean(b0), boolean(b1)) => b0 == b1,
if d0.size() == d1.size() {
let mut equal = true;
for d0.each |k, v0| {
- alt d1.find(k) {
+ match d1.find(k) {
some(v1) => if !eq(v0, v1) { equal = false },
none => equal = false
}
impl <A: to_json, B: to_json> of to_json for (A, B) {
fn to_json() -> json {
- alt self {
+ match self {
(a, b) => {
list(@~[a.to_json(), b.to_json()])
}
impl <A: to_json, B: to_json, C: to_json>
of to_json for (A, B, C) {
fn to_json() -> json {
- alt self {
+ match self {
(a, b, c) => {
list(@~[a.to_json(), b.to_json(), c.to_json()])
}
impl <A: to_json> of to_json for option<A> {
fn to_json() -> json {
- alt self {
+ match self {
none => null,
some(value) => value.to_json()
}
fn find<T: copy>(ls: @list<T>, f: fn(T) -> bool) -> option<T> {
let mut ls = ls;
loop {
- ls = alt *ls {
+ ls = match *ls {
cons(hd, tl) => {
if f(hd) { return some(hd); }
tl
/// Returns true if the list is empty
pure fn is_empty<T: copy>(ls: @list<T>) -> bool {
- alt *ls {
+ match *ls {
nil => true,
_ => false
}
/// Returns all but the first element of a list
pure fn tail<T: copy>(ls: @list<T>) -> @list<T> {
- alt *ls {
+ match *ls {
cons(_, tl) => return tl,
nil => fail ~"list empty"
}
/// Returns the first element of a list
pure fn head<T: copy>(ls: @list<T>) -> T {
- alt check *ls { cons(hd, _) => hd }
+ match check *ls { cons(hd, _) => hd }
}
/// Appends one list to another
pure fn append<T: copy>(l: @list<T>, m: @list<T>) -> @list<T> {
- alt *l {
+ match *l {
nil => return m,
cons(x, xs) => {
let rest = append(xs, m);
fn iter<T>(l: @list<T>, f: fn(T)) {
let mut cur = l;
loop {
- cur = alt *cur {
+ cur = match *cur {
cons(hd, tl) => {
f(hd);
tl
fn each<T>(l: @list<T>, f: fn(T) -> bool) {
let mut cur = l;
loop {
- cur = alt *cur {
+ cur = match *cur {
cons(hd, tl) => {
if !f(hd) { return; }
tl
let mut e0 = e_root;
let mut comp = 1u; // for logging
loop {
- alt copy e0.next {
+ match copy e0.next {
none => {
debug!{"search_tbl: absent, comp %u, hash %u, idx %u",
comp, h, idx};
fn search_tbl(k: &K, h: uint) -> search_result<K,V> {
let idx = h % vec::len(self.chains);
- alt copy self.chains[idx] {
+ match copy self.chains[idx] {
none => {
debug!{"search_tbl: none, comp %u, hash %u, idx %u",
0u, h, idx};
while i < n {
let mut chain = self.chains[i];
loop {
- chain = alt chain {
+ chain = match chain {
none => break,
some(entry) => {
let next = entry.next;
fn contains_key_ref(k: &K) -> bool {
let hash = self.hasher(k);
- alt self.search_tbl(k, hash) {
+ match self.search_tbl(k, hash) {
not_found => false,
found_first(*) | found_after(*) => true
}
fn insert(+k: K, +v: V) -> bool {
let hash = self.hasher(&k);
- alt self.search_tbl(&k, hash) {
+ match self.search_tbl(&k, hash) {
not_found => {
self.count += 1u;
let idx = hash % vec::len(self.chains);
}
fn find(+k: K) -> option<V> {
- alt self.search_tbl(&k, self.hasher(&k)) {
+ match self.search_tbl(&k, self.hasher(&k)) {
not_found => none,
found_first(_, entry) => some(entry.value),
found_after(_, entry) => some(entry.value)
}
fn remove(+k: K) -> option<V> {
- alt self.search_tbl(&k, self.hasher(&k)) {
+ match self.search_tbl(&k, self.hasher(&k)) {
not_found => none,
found_first(idx, entry) => {
self.count -= 1u;
i = 0u;
while i < num_to_insert {
let v = hm.remove(i);
- alt v {
+ match v {
option::some(u) => assert (u == i * i),
option::none => fail
}
* * ip - a `std::net::ip::ip_addr`
*/
fn format_addr(ip: ip_addr) -> ~str {
- alt ip {
+ match ip {
ipv4(addr) => unsafe {
let result = uv_ip4_name(&addr);
if result == ~"" {
node_ptr,
ptr::null(),
ptr::null());
- alt result {
+ match result {
0i32 => {
set_data_for_req(handle_ptr, handle_data_ptr);
}
* * an `ip_addr` of the `ipv4` variant
*/
fn parse_addr(ip: ~str) -> ip_addr {
- alt try_parse_addr(ip) {
+ match try_parse_addr(ip) {
result::ok(addr) => copy(addr),
result::err(err_data) => fail err_data.err_msg
}
}
fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> {
let parts = vec::map(str::split_char(ip, '.'), |s| {
- alt uint::from_str(s) {
+ match uint::from_str(s) {
some(n) if n <= 255u => n,
_ => 256u
}
* * an `ip_addr` of the `ipv6` variant
*/
fn parse_addr(ip: ~str) -> ip_addr {
- alt try_parse_addr(ip) {
+ match try_parse_addr(ip) {
result::ok(addr) => copy(addr),
result::err(err_data) => fail err_data.err_msg
}
}
#[test]
fn test_ip_ipv4_bad_parse() {
- alt v4::try_parse_addr(~"b4df00d") {
+ match v4::try_parse_addr(~"b4df00d") {
result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info});
assert true;
#[test]
#[ignore(target_os="win32")]
fn test_ip_ipv6_bad_parse() {
- alt v6::try_parse_addr(~"::,~2234k;") {
+ match v6::try_parse_addr(~"::,~2234k;") {
result::err(err_info) => {
log(debug, fmt!{"got error as expected %?", err_info});
assert true;
log(debug, fmt!{"test_get_addr: Number of results for %s: %?",
localhost_name, vec::len(results)});
for vec::each(results) |r| {
- let ipv_prefix = alt r {
+ let ipv_prefix = match r {
ipv4(_) => ~"IPv4",
ipv6(_) => ~"IPv6"
};
log(debug, ~"in interact cb for tcp client connect..");
log(debug, fmt!{"stream_handle_ptr in interact %?",
stream_handle_ptr});
- alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
+ match uv::ll::tcp_init( loop_ptr, stream_handle_ptr) {
0i32 => {
log(debug, ~"tcp_init successful");
- alt input_ip {
+ match input_ip {
ipv4 => {
log(debug, ~"dealing w/ ipv4 connection..");
let connect_req_ptr =
ptr::addr_of((*socket_data_ptr).connect_req);
let addr_str = ip::format_addr(input_ip);
- let connect_result = alt input_ip {
+ let connect_result = match input_ip {
ip::ipv4(addr) => {
// have to "recreate" the sockaddr_in/6
// since the ip_addr discards the port
tcp_connect_on_connect_cb)
}
};
- alt connect_result {
+ match connect_result {
0i32 => {
log(debug, ~"tcp_connect successful");
// reusable data that we'll have for the
}
}
};
- alt comm::recv(result_po) {
+ match comm::recv(result_po) {
conn_success => {
log(debug, ~"tcp::connect - received success on result_po");
result::ok(tcp_socket(socket_data))
// still have to free the malloc'd stream handle..
rustrt::rust_uv_current_kernel_free(stream_handle_ptr
as *libc::c_void);
- let tcp_conn_err = alt err_data.err_name {
+ let tcp_conn_err = match err_data.err_name {
~"ECONNREFUSED" => connection_refused,
_ => generic_connect_err(err_data.err_name, err_data.err_msg)
};
* // do work here
* }
* };
- * alt comm::recv(cont_po) {
+ * match comm::recv(cont_po) {
* // shut down listen()
* some(err_data) { comm::send(kill_chan, some(err_data)) }
* // wait for next connection
fn accept(new_conn: tcp_new_connection)
-> result::result<tcp_socket, tcp_err_data> unsafe {
- alt new_conn{
+ match new_conn{
new_tcp_conn(server_handle_ptr) => {
let server_data_ptr = uv::ll::get_data_for_uv_handle(
server_handle_ptr) as *tcp_listen_fc_data;
log(debug, ~"in interact cb for tcp::accept");
let loop_ptr = uv::ll::get_loop_for_uv_handle(
server_handle_ptr);
- alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) {
+ match uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) {
0i32 => {
log(debug, ~"uv_tcp_init successful for client stream");
- alt uv::ll::accept(
+ match uv::ll::accept(
server_handle_ptr as *libc::c_void,
client_stream_handle_ptr as *libc::c_void) {
0i32 => {
}
}
// UNSAFE LIBUV INTERACTION END
- alt comm::recv(result_po) {
+ match comm::recv(result_po) {
some(err_data) => result::err(err_data),
none => result::ok(tcp_socket(client_socket_data))
}
// nested within a comm::listen block)
let loc_ip = copy(host_ip);
do iotask::interact(iotask) |loop_ptr| {
- alt uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
+ match uv::ll::tcp_init(loop_ptr, server_stream_ptr) {
0i32 => {
uv::ll::set_data_for_uv_handle(
server_stream_ptr,
server_data_ptr);
let addr_str = ip::format_addr(loc_ip);
- let bind_result = alt loc_ip {
+ let bind_result = match loc_ip {
ip::ipv4(addr) => {
log(debug, fmt!{"addr: %?", addr});
let in_addr = uv::ll::ip4_addr(addr_str, port as int);
ptr::addr_of(in_addr))
}
};
- alt bind_result {
+ match bind_result {
0i32 => {
- alt uv::ll::listen(server_stream_ptr,
+ match uv::ll::listen(server_stream_ptr,
backlog as libc::c_int,
tcp_lfc_on_connection_cb) {
0i32 => comm::send(setup_ch, none),
};
setup_ch.recv()
};
- alt setup_result {
+ match setup_result {
some(err_data) => {
do iotask::interact(iotask) |loop_ptr| {
log(debug, fmt!{"tcp::listen post-kill recv hl interact %?",
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
};
stream_closed_po.recv();
- alt err_data.err_name {
+ match err_data.err_name {
~"EACCES" => {
log(debug, ~"Got EACCES error");
result::err(access_denied)
uv::ll::close(server_stream_ptr, tcp_lfc_close_cb);
};
stream_closed_po.recv();
- alt kill_result {
+ match kill_result {
// some failure post bind/listen
some(err_data) => result::err(generic_listen_err(err_data.err_name,
err_data.err_msg)),
some(comm::recv(result::get(rs_result)))
};
log(debug, ~"tcp::read after recv_timeout");
- alt read_result {
+ match read_result {
none => {
log(debug, ~"tcp::read: timed out..");
let err_data = {
let stop_ch = comm::chan(stop_po);
do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, ~"in interact cb for tcp::read_stop");
- alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
+ match uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) {
0i32 => {
log(debug, ~"successfully called uv_read_stop");
comm::send(stop_ch, none);
}
}
};
- alt comm::recv(stop_po) {
+ match comm::recv(stop_po) {
some(err_data) => result::err(err_data.to_tcp_err()),
none => result::ok(())
}
log(debug, ~"in tcp::read_start before interact loop");
do iotask::interact((*socket_data).iotask) |loop_ptr| {
log(debug, fmt!{"in tcp::read_start interact cb %?", loop_ptr});
- alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
+ match uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t,
on_alloc_cb,
on_tcp_read_cb) {
0i32 => {
}
}
};
- alt comm::recv(start_po) {
+ match comm::recv(start_po) {
some(err_data) => result::err(err_data.to_tcp_err()),
none => result::ok((*socket_data).reader_po)
}
let write_data_ptr = ptr::addr_of(write_data);
do iotask::interact((*socket_data_ptr).iotask) |loop_ptr| {
log(debug, fmt!{"in interact cb for tcp::write %?", loop_ptr});
- alt uv::ll::write(write_req_ptr,
+ match uv::ll::write(write_req_ptr,
stream_handle_ptr,
write_buf_vec_ptr,
tcp_write_complete_cb) {
// and waiting here for the write to complete, we should transfer
// ownership of everything to the I/O task and let it deal with the
// aftermath, so we don't have to sit here blocking.
- alt comm::recv(result_po) {
+ match comm::recv(result_po) {
tcp_write_success => result::ok(()),
tcp_write_error(err_data) => result::err(err_data.to_tcp_err())
}
as *tcp_listen_fc_data;
let kill_ch = (*server_data_ptr).kill_ch;
if (*server_data_ptr).active {
- alt status {
+ match status {
0i32 => (*server_data_ptr).on_connect_cb(handle),
_ => {
let loop_ptr = uv::ll::get_loop_for_uv_handle(handle);
let loop_ptr = uv::ll::get_loop_for_uv_handle(stream);
let socket_data_ptr = uv::ll::get_data_for_uv_handle(stream)
as *tcp_socket_data;
- alt nread as int {
+ match nread as int {
// incoming err.. probably eof
-1 => {
let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err();
log(debug, fmt!{"tcp_connect result_ch %?", result_ch});
let tcp_stream_ptr =
uv::ll::get_stream_handle_from_connect_req(connect_req_ptr);
- alt status {
+ match status {
0i32 => {
log(debug, ~"successful tcp connection!");
comm::send(result_ch, conn_success);
client_ch,
hl_loop)
};
- alt actual_resp_result.get_err() {
+ match actual_resp_result.get_err() {
connection_refused => (),
_ => fail ~"unknown error.. expected connection_refused"
}
client_ch,
hl_loop)
};
- alt listen_err {
+ match listen_err {
address_in_use => {
assert true;
}
server_ip,
server_port,
hl_loop);
- alt listen_err {
+ match listen_err {
access_denied => {
assert true;
}
log(debug, ~"SERVER: successfully accepted"+
~"connection!");
let received_req_bytes = read(sock, 0u);
- alt received_req_bytes {
+ match received_req_bytes {
result::ok(data) => {
log(debug, ~"SERVER: got REQ str::from_bytes..");
log(debug, fmt!{"SERVER: REQ data len: %?",
});
// err check on listen_result
if result::is_err(listen_result) {
- alt result::get_err(listen_result) {
+ match result::get_err(listen_result) {
generic_listen_err(name, msg) => {
fail fmt!{"SERVER: exited abnormally name %s msg %s",
name, msg};
/// Concatenate two ropes
fn append_rope(left: rope, right: rope) -> rope {
- alt(left) {
+ match (left) {
node::empty => return right,
node::content(left_content) => {
- alt(right) {
+ match (right) {
node::empty => return left,
node::content(right_content) => {
return node::content(node::concat2(left_content, right_content));
* to rebalance your rope at some point, before using it for other purposes.
*/
fn bal(rope:rope) -> rope {
- alt(rope) {
+ match (rope) {
node::empty => return rope,
- node::content(x) => alt(node::bal(x)) {
+ node::content(x) => match (node::bal(x)) {
option::none => rope,
option::some(y) => node::content(y)
}
*/
fn sub_chars(rope: rope, char_offset: uint, char_len: uint) -> rope {
if char_len == 0u { return node::empty; }
- alt(rope) {
+ match (rope) {
node::empty => fail,
node::content(node) => if char_len > node::char_len(node) {
fail
*/
fn sub_bytes(rope: rope, byte_offset: uint, byte_len: uint) -> rope {
if byte_len == 0u { return node::empty; }
- alt(rope) {
+ match (rope) {
node::empty => fail,
node::content(node) =>if byte_len > node::byte_len(node) {
fail
* value if `left > right`
*/
fn cmp(left: rope, right: rope) -> int {
- alt((left, right)) {
+ match ((left, right)) {
(node::empty, node::empty) => return 0,
(node::empty, _) => return -1,
(_, node::empty) => return 1,
* that is if `it` returned `false` at any point.
*/
fn loop_chars(rope: rope, it: fn(char) -> bool) -> bool {
- alt(rope) {
+ match (rope) {
node::empty => return true,
node::content(x) => return node::loop_chars(x, it)
}
* that is if `it` returned `false` at any point.
*/
fn loop_leaves(rope: rope, it: fn(node::leaf) -> bool) -> bool{
- alt(rope) {
+ match (rope) {
node::empty => return true,
node::content(x) => return node::loop_leaves(x, it)
}
mod iterator {
mod leaf {
fn start(rope: rope) -> node::leaf_iterator::t {
- alt(rope) {
+ match (rope) {
node::empty => return node::leaf_iterator::empty(),
node::content(x) => return node::leaf_iterator::start(x)
}
}
mod char {
fn start(rope: rope) -> node::char_iterator::t {
- alt(rope) {
+ match (rope) {
node::empty => return node::char_iterator::empty(),
node::content(x) => return node::char_iterator::start(x)
}
* Constant time.
*/
fn height(rope: rope) -> uint {
- alt(rope) {
+ match (rope) {
node::empty => return 0u,
node::content(x) => return node::height(x)
}
* Constant time.
*/
pure fn char_len(rope: rope) -> uint {
- alt(rope) {
+ match (rope) {
node::empty => return 0u,
node::content(x) => return node::char_len(x)
}
* Constant time.
*/
pure fn byte_len(rope: rope) -> uint {
- alt(rope) {
+ match (rope) {
node::empty => return 0u,
node::content(x) => return node::byte_len(x)
}
* rope + the (bounded) length of the largest leaf.
*/
fn char_at(rope: rope, pos: uint) -> char {
- alt(rope) {
+ match (rope) {
node::empty => fail,
node::content(x) => return node::char_at(x, pos)
}
pure fn byte_len(node: @node) -> uint {
//FIXME (#2744): Could we do this without the pattern-matching?
- alt(*node) {
+ match (*node) {
leaf(y) => return y.byte_len,
concat(y) => return y.byte_len
}
}
pure fn char_len(node: @node) -> uint {
- alt(*node) {
+ match (*node) {
leaf(y) => return y.char_len,
concat(y) => return y.char_len
}
let mut offset = 0u;//Current position in the buffer
let it = leaf_iterator::start(node);
loop {
- alt(leaf_iterator::next(it)) {
+ match (leaf_iterator::next(it)) {
option::none => break,
option::some(x) => {
//FIXME (#2744): Replace with memcpy or something similar
* This function executes in linear time.
*/
fn flatten(node: @node) -> @node unsafe {
- alt(*node) {
+ match (*node) {
leaf(_) => return node,
concat(x) => {
return @leaf({
let mut forest = ~[mut];
let it = leaf_iterator::start(node);
loop {
- alt (leaf_iterator::next(it)) {
+ match (leaf_iterator::next(it)) {
option::none => break,
option::some(x) => vec::push(forest, @leaf(x))
}
if byte_offset == 0u && byte_len == node::byte_len(node) {
return node;
}
- alt(*node) {
+ match (*node) {
node::leaf(x) => {
let char_len =
str::count_chars(*x.content, byte_offset, byte_len);
let mut node = node;
let mut char_offset = char_offset;
loop {
- alt(*node) {
+ match (*node) {
node::leaf(x) => {
if char_offset == 0u && char_len == x.char_len {
return node;
}
fn height(node: @node) -> uint {
- alt(*node) {
+ match (*node) {
leaf(_) => return 0u,
concat(x) => return x.height
}
let itb = char_iterator::start(b);
let mut result = 0;
while result == 0 {
- alt((char_iterator::next(ita), char_iterator::next(itb))) {
+ match ((char_iterator::next(ita), char_iterator::next(itb))) {
(option::none, option::none) => break,
(option::some(chara), option::some(charb)) => {
result = char::cmp(chara, charb);
fn loop_leaves(node: @node, it: fn(leaf) -> bool) -> bool{
let mut current = node;
loop {
- alt(*current) {
+ match (*current) {
leaf(x) => return it(x),
concat(x) => if loop_leaves(x.left, it) { //non tail call
current = x.right; //tail call
let mut node = node;
let mut pos = pos;
loop {
- alt *node {
+ match *node {
leaf(x) => return str::char_at(*x.content, pos),
concat({left, right, _}) => {
let left_len = char_len(left);
loop {
let current = it.stack[it.stackpos];
it.stackpos -= 1;
- alt(*current) {
+ match (*current) {
concat(x) => {
it.stackpos += 1;
it.stack[it.stackpos] = x.right;
fn next(it: t) -> option<char> {
loop {
- alt(get_current_or_next_leaf(it)) {
+ match (get_current_or_next_leaf(it)) {
option::none => return option::none,
option::some(_) => {
let next_char = get_next_char_in_leaf(it);
- alt(next_char) {
+ match (next_char) {
option::none => again,
option::some(_) => return next_char
}
}
fn get_current_or_next_leaf(it: t) -> option<leaf> {
- alt(it.leaf) {
+ match (it.leaf) {
option::some(_) => return it.leaf,
option::none => {
let next = leaf_iterator::next(it.leaf_iterator);
- alt(next) {
+ match (next) {
option::none => return option::none,
option::some(_) => {
it.leaf = next;
}
fn get_next_char_in_leaf(it: t) -> option<char> {
- alt copy it.leaf {
+ match copy it.leaf {
option::none => return option::none,
option::some(aleaf) => {
if it.leaf_byte_pos >= aleaf.byte_len {
//Utility function, used for sanity check
fn rope_to_string(r: rope) -> ~str {
- alt(r) {
+ match (r) {
node::empty => return ~"",
node::content(x) => {
let str = @mut ~"";
fn aux(str: @mut ~str, node: @node::node) unsafe {
- alt(*node) {
+ match (*node) {
node::leaf(x) => {
*str += str::slice(
*x.content, x.byte_offset,
let rope_iter = iterator::char::start(r);
let mut equal = true;
while equal {
- alt(node::char_iterator::next(rope_iter)) {
+ match (node::char_iterator::next(rope_iter)) {
option::none => {
if string_iter < string_len {
equal = false;
let mut len = 0u;
let it = iterator::char::start(r);
loop {
- alt(node::char_iterator::next(it)) {
+ match (node::char_iterator::next(it)) {
option::none => break,
option::some(_) => len += 1u
}
fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) {
do s.emit_enum(~"option") {
- alt v {
+ match v {
none => do s.emit_enum_variant(~"none", 0u, 0u) {
}
-> option<T> {
do d.read_enum(~"option") {
do d.read_enum_variant |i| {
- alt check i {
+ match check i {
0u => none,
1u => some(d.read_enum_variant_arg(0u, || st() ))
}
* If the key does not exist in the map
*/
pure fn get<T: copy>(self: smallintmap<T>, key: uint) -> T {
- alt find(self, key) {
+ match find(self, key) {
none => {
error!{"smallintmap::get(): key not present"};
fail;
fn size() -> uint {
let mut sz = 0u;
for self.v.each |item| {
- alt item {
+ match item {
some(_) => sz += 1u,
_ => ()
}
fn each(it: fn(+key: uint, +value: V) -> bool) {
let mut idx = 0u, l = self.v.len();
while idx < l {
- alt self.v.get_elt(idx) {
+ match self.v.get_elt(idx) {
some(elt) => if !it(idx, elt) { break }
none => ()
}
fn each_ref(it: fn(key: &uint, value: &V) -> bool) {
let mut idx = 0u, l = self.v.len();
while idx < l {
- alt self.v.get_elt(idx) {
+ match self.v.get_elt(idx) {
some(elt) => if !it(&idx, &elt) { break }
none => ()
}
#[test]
fn test_mkdtemp() {
let r = mkdtemp(~"./", ~"foobar");
- alt r {
+ match r {
some(p) => {
os::remove_dir(p);
assert(str::ends_with(p, ~"foobar"));
fn color_supported() -> bool {
let supported_terms = ~[~"xterm-color", ~"xterm",
~"screen-bce", ~"xterm-256color"];
- return alt os::getenv(~"TERM") {
+ return match os::getenv(~"TERM") {
option::some(env) => {
for vec::each(supported_terms) |term| {
if term == env { return true; }
// arguments and a vector of test_descs (generated at compile time).
fn test_main(args: ~[~str], tests: ~[test_desc]) {
let opts =
- alt parse_opts(args) {
+ match parse_opts(args) {
either::left(o) => o,
either::right(m) => fail m
};
let args_ = vec::tail(args);
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
let matches =
- alt getopts::getopts(args_, opts) {
+ match getopts::getopts(args_, opts) {
ok(m) => m,
err(f) => return either::right(getopts::fail_str(f))
};
tests: ~[test_desc]) -> bool {
fn callback(event: testevent, st: console_test_state) {
- alt event {
+ match event {
te_filtered(filtered_tests) => {
st.total = vec::len(filtered_tests);
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
}
te_wait(test) => st.out.write_str(fmt!{"test %s ... ", test.name}),
te_result(test, result) => {
- alt st.log_out {
+ match st.log_out {
some(f) => write_log(f, result, test),
none => ()
}
- alt result {
+ match result {
tr_ok => {
st.passed += 1u;
write_ok(st.out, st.use_color);
}
}
- let log_out = alt opts.logfile {
- some(path) => alt io::file_writer(path, ~[io::create, io::truncate]) {
+ let log_out = match opts.logfile {
+ some(path) => match io::file_writer(path,
+ ~[io::create, io::truncate]) {
result::ok(w) => some(w),
result::err(s) => {
fail(fmt!{"can't open output file: %s", s})
fn write_log(out: io::writer, result: test_result, test: test_desc) {
out.write_line(fmt!{"%s %s",
- alt result {
+ match result {
tr_ok => ~"ok",
tr_failed => ~"failed",
tr_ignored => ~"ignored"
filtered
} else {
let filter_str =
- alt opts.filter {
+ match opts.filter {
option::some(f) => f,
option::none => ~""
};
#[test]
fn first_free_arg_should_be_a_filter() {
let args = ~[~"progname", ~"filter"];
- let opts = alt parse_opts(args) {
+ let opts = match parse_opts(args) {
either::left(o) => o,
_ => fail ~"Malformed arg in first_free_arg_should_be_a_filter"
};
#[test]
fn parse_ignored_flag() {
let args = ~[~"progname", ~"filter", ~"--ignored"];
- let opts = alt parse_opts(args) {
+ let opts = match parse_opts(args) {
either::left(o) => o,
_ => fail ~"Malformed arg in parse_ignored_flag"
};
let {ch, next} = str::char_range_at(s, pos);
pos = next;
- alt ch {
+ match ch {
'0' to '9' => {
value = value * 10_i32 + (ch as i32 - '0' as i32);
}
fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut)
-> result<uint, ~str> {
- alt ch {
- 'A' => alt match_strs(s, pos, ~[
+ match ch {
+ 'A' => match match_strs(s, pos, ~[
(~"Sunday", 0_i32),
(~"Monday", 1_i32),
(~"Tuesday", 2_i32),
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid day")
}
- 'a' => alt match_strs(s, pos, ~[
+ 'a' => match match_strs(s, pos, ~[
(~"Sun", 0_i32),
(~"Mon", 1_i32),
(~"Tue", 2_i32),
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid day")
}
- 'B' => alt match_strs(s, pos, ~[
+ 'B' => match match_strs(s, pos, ~[
(~"January", 0_i32),
(~"February", 1_i32),
(~"March", 2_i32),
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
none => err(~"Invalid month")
}
- 'b' | 'h' => alt match_strs(s, pos, ~[
+ 'b' | 'h' => match match_strs(s, pos, ~[
(~"Jan", 0_i32),
(~"Feb", 1_i32),
(~"Mar", 2_i32),
some(item) => { let (v, pos) = item; tm.tm_mon = v; ok(pos) }
none => err(~"Invalid month")
}
- 'C' => alt match_digits(s, pos, 2u, false) {
+ 'C' => match match_digits(s, pos, 2u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_year += (v * 100_i32) - 1900_i32;
.chain(|pos| parse_char(s, pos, '/'))
.chain(|pos| parse_type(s, pos, 'y', tm))
}
- 'd' => alt match_digits(s, pos, 2u, false) {
+ 'd' => match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
none => err(~"Invalid day of the month")
}
- 'e' => alt match_digits(s, pos, 2u, true) {
+ 'e' => match match_digits(s, pos, 2u, true) {
some(item) => { let (v, pos) = item; tm.tm_mday = v; ok(pos) }
none => err(~"Invalid day of the month")
}
}
'H' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
none => err(~"Invalid hour")
}
}
'I' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
}
'j' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 3u, false) {
+ match match_digits(s, pos, 3u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_yday = v - 1_i32;
}
'k' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, true) {
+ match match_digits(s, pos, 2u, true) {
some(item) => { let (v, pos) = item; tm.tm_hour = v; ok(pos) }
none => err(~"Invalid hour")
}
}
'l' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, true) {
+ match match_digits(s, pos, 2u, true) {
some(item) => {
let (v, pos) = item;
tm.tm_hour = if v == 12_i32 { 0_i32 } else { v };
}
'M' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => { let (v, pos) = item; tm.tm_min = v; ok(pos) }
none => err(~"Invalid minute")
}
}
'm' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_mon = v - 1_i32;
}
}
'n' => parse_char(s, pos, '\n'),
- 'P' => alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) {
+ 'P' => match match_strs(s, pos,
+ ~[(~"am", 0_i32), (~"pm", 12_i32)]) {
+
some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
none => err(~"Invalid hour")
}
- 'p' => alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
+ 'p' => match match_strs(s, pos,
+ ~[(~"AM", 0_i32), (~"PM", 12_i32)]) {
+
some(item) => { let (v, pos) = item; tm.tm_hour += v; ok(pos) }
none => err(~"Invalid hour")
}
}
'S' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_sec = v;
't' => parse_char(s, pos, '\t'),
'u' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 1u, false) {
+ match match_digits(s, pos, 1u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_wday = v;
//'W' {}
'w' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 1u, false) {
+ match match_digits(s, pos, 1u, false) {
some(item) => { let (v, pos) = item; tm.tm_wday = v; ok(pos) }
none => err(~"Invalid weekday")
}
//'x' {}
'Y' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 4u, false) {
+ match match_digits(s, pos, 4u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_year = v - 1900_i32;
}
'y' => {
// FIXME (#2350): range check.
- alt match_digits(s, pos, 2u, false) {
+ match match_digits(s, pos, 2u, false) {
some(item) => {
let (v, pos) = item;
tm.tm_year = v - 1900_i32;
let {ch, next} = str::char_range_at(s, pos);
if ch == '+' || ch == '-' {
- alt match_digits(s, next, 4u, false) {
+ match match_digits(s, next, 4u, false) {
some(item) => {
let (v, pos) = item;
if v == 0_i32 {
while !rdr.eof() && pos < len {
let {ch, next} = str::char_range_at(s, pos);
- alt rdr.read_char() {
- '%' => alt parse_type(s, pos, rdr.read_char(), tm) {
+ match rdr.read_char() {
+ '%' => match parse_type(s, pos, rdr.read_char(), tm) {
ok(next) => pos = next,
err(e) => { result = err(e); break; }
}
fn strftime(format: ~str, tm: tm) -> ~str {
fn parse_type(ch: char, tm: tm) -> ~str {
//FIXME (#2350): Implement missing types.
- alt check ch {
- 'A' => alt check tm.tm_wday as int {
+ match check ch {
+ 'A' => match check tm.tm_wday as int {
0 => ~"Sunday",
1 => ~"Monday",
2 => ~"Tuesday",
5 => ~"Friday",
6 => ~"Saturday"
}
- 'a' => alt check tm.tm_wday as int {
+ 'a' => match check tm.tm_wday as int {
0 => ~"Sun",
1 => ~"Mon",
2 => ~"Tue",
5 => ~"Fri",
6 => ~"Sat"
}
- 'B' => alt check tm.tm_mon as int {
+ 'B' => match check tm.tm_mon as int {
0 => ~"January",
1 => ~"February",
2 => ~"March",
10 => ~"November",
11 => ~"December"
}
- 'b' | 'h' => alt check tm.tm_mon as int {
+ 'b' | 'h' => match check tm.tm_mon as int {
0 => ~"Jan",
1 => ~"Feb",
2 => ~"Mar",
do io::with_str_reader(format) |rdr| {
while !rdr.eof() {
- alt rdr.read_char() {
+ match rdr.read_char() {
'%' => buf += parse_type(rdr.read_char(), tm),
ch => str::push_char(buf, ch)
}
os::setenv(~"TZ", ~"America/Los_Angeles");
tzset();
- alt strptime(~"", ~"") {
+ match strptime(~"", ~"") {
ok(tm) => {
assert tm.tm_sec == 0_i32;
assert tm.tm_min == 0_i32;
assert strptime(~"Fri Feb 13 15:31:30", format)
== err(~"Invalid time");
- alt strptime(~"Fri Feb 13 15:31:30 2009", format) {
+ match strptime(~"Fri Feb 13 15:31:30 2009", format) {
err(e) => fail e,
ok(tm) => {
assert tm.tm_sec == 30_i32;
}
fn test(s: ~str, format: ~str) -> bool {
- alt strptime(s, format) {
+ match strptime(s, format) {
ok(tm) => tm.strftime(format) == s,
err(e) => fail e
}
delayed_send(hl_loop, 1u, test_ch, expected);
};
- alt recv_timeout(hl_loop, 10u, test_po) {
+ match recv_timeout(hl_loop, 10u, test_po) {
some(val) => {
assert val == expected;
successes += 1;
delayed_send(hl_loop, 1000u, test_ch, expected);
};
- alt recv_timeout(hl_loop, 1u, test_po) {
+ match recv_timeout(hl_loop, 1u, test_po) {
none => successes += 1,
_ => failures += 1
};
/// Insert a value into the map
fn insert<K: copy, V: copy>(m: &mut tree_edge<K, V>, k: K, v: V) {
- alt copy *m {
+ match copy *m {
none => {
*m = some(@tree_node({key: k,
mut value: v,
/// Find a value based on the key
fn find<K: copy, V: copy>(m: &const tree_edge<K, V>, k: K) -> option<V> {
- alt copy *m {
+ match copy *m {
none => none,
// FIXME (#2808): was that an optimization?
/// Visit all pairs in the map in order.
fn traverse<K, V: copy>(m: &const tree_edge<K, V>, f: fn(K, V)) {
- alt copy *m {
+ match copy *m {
none => (),
some(node) => {
traverse(&const node.left, f);
let hl_loop = spawn_loop();
loop {
debug!{"in outer_loop..."};
- alt select2(weak_exit_po, msg_po) {
+ match select2(weak_exit_po, msg_po) {
left(weak_exit) => {
// all normal tasks have ended, tell the
// libuv loop to tear_down, then exit
let msg_po = (*data).msg_po;
while msg_po.peek() {
- alt msg_po.recv() {
+ match msg_po.recv() {
interaction(cb) => cb(loop_ptr),
teardown_loop => begin_teardown(data)
}
src_unsafe_ptr, src});
let result = rustrt::rust_uv_ip6_name(src_unsafe_ptr,
dst_buf, size as libc::size_t);
- alt result {
+ match result {
0i32 => str::unsafe::from_buf(dst_buf),
_ => ~""
}
}
pure fn is_blockish(p: ast::proto) -> bool {
- alt p {
+ match p {
proto_block => true,
proto_bare | proto_uniq | proto_box => false
}
/* FIXMEs that say "bad" are as per #2543 */
fn path_to_str_with_sep(p: path, sep: ~str) -> ~str {
let strs = do vec::map(p) |e| {
- alt e {
+ match e {
path_mod(s) => /* FIXME (#2543) */ copy *s,
path_name(s) => /* FIXME (#2543) */ copy *s
}
// methods get added to the AST map when their impl is visited. Since we
// don't decode and instantiate the impl, but just the method, we have to
// add it to the table now:
- alt ii {
+ match ii {
ii_item(*) | ii_ctor(*) | ii_dtor(*) => { /* fallthrough */ }
ii_foreign(i) => {
cx.map.insert(i.id, node_foreign_item(i, foreign_abi_rust_intrinsic,
copy a, cx.local_id));
cx.local_id += 1u;
}
- alt fk {
+ match fk {
visit::fk_ctor(nm, attrs, tps, self_id, parent_id) => {
let ct = @{node: {id: id,
attrs: attrs,
fn number_pat(cx: ctx, pat: @pat) {
do ast_util::walk_pat(pat) |p| {
- alt p.node {
+ match p.node {
pat_ident(*) => {
cx.map.insert(p.id, node_local(cx.local_id));
cx.local_id += 1u;
fn map_item(i: @item, cx: ctx, v: vt) {
let item_path = @/* FIXME (#2543) */ copy cx.path;
cx.map.insert(i.id, node_item(i, item_path));
- alt i.node {
+ match i.node {
item_impl(_, opt_ir, _, ms) => {
let impl_did = ast_util::local_def(i.id);
for ms.each |m| {
}
}
item_foreign_mod(nm) => {
- let abi = alt attr::foreign_abi(i.attrs) {
+ let abi = match attr::foreign_abi(i.attrs) {
either::left(msg) => cx.diag.span_fatal(i.span, msg),
either::right(abi) => abi
};
}
_ => ()
}
- alt i.node {
+ match i.node {
item_mod(_) | item_foreign_mod(_) => {
vec::push(cx.path, path_mod(i.ident));
}
}
fn map_view_item(vi: @view_item, cx: ctx, _v: vt) {
- alt vi.node {
+ match vi.node {
view_item_export(vps) => for vps.each |vp| {
- let (id, name) = alt vp.node {
+ let (id, name) = match vp.node {
view_path_simple(nm, _, id) => {
(id, /* FIXME (#2543) */ copy nm)
}
}
fn node_id_to_str(map: map, id: node_id) -> ~str {
- alt map.find(id) {
+ match map.find(id) {
none => {
fmt!{"unknown node (id=%d)", id}
}
pure fn is_local(did: ast::def_id) -> bool { did.crate == local_crate }
pure fn stmt_id(s: stmt) -> node_id {
- alt s.node {
+ match s.node {
stmt_decl(_, id) => id,
stmt_expr(_, id) => id,
stmt_semi(_, id) => id
}
fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
- alt d {
+ match d {
def_variant(enum_id, var_id) => {
return {enm: enum_id, var: var_id}
}
}
pure fn def_id_of_def(d: def) -> def_id {
- alt d {
+ match d {
def_fn(id, _) | def_mod(id) |
def_foreign_mod(id) | def_const(id) |
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
}
pure fn binop_to_str(op: binop) -> ~str {
- alt op {
+ match op {
add => return ~"+",
subtract => return ~"-",
mul => return ~"*",
}
pure fn binop_to_method_name(op: binop) -> option<~str> {
- alt op {
+ match op {
add => return some(~"add"),
subtract => return some(~"sub"),
mul => return some(~"mul"),
}
pure fn lazy_binop(b: binop) -> bool {
- alt b {
+ match b {
and => true,
or => true,
_ => false
}
pure fn is_shift_binop(b: binop) -> bool {
- alt b {
+ match b {
shl => true,
shr => true,
_ => false
}
pure fn unop_to_str(op: unop) -> ~str {
- alt op {
+ match op {
box(mt) => if mt == m_mutbl { ~"@mut " } else { ~"@" },
uniq(mt) => if mt == m_mutbl { ~"~mut " } else { ~"~" },
deref => ~"*",
}
pure fn is_path(e: @expr) -> bool {
- return alt e.node { expr_path(_) => true, _ => false };
+ return match e.node { expr_path(_) => true, _ => false };
}
pure fn int_ty_to_str(t: int_ty) -> ~str {
- alt t {
+ match t {
ty_char => ~"u8", // ???
ty_i => ~"",
ty_i8 => ~"i8",
}
pure fn int_ty_max(t: int_ty) -> u64 {
- alt t {
+ match t {
ty_i8 => 0x80u64,
ty_i16 => 0x8000u64,
ty_i | ty_char | ty_i32 => 0x80000000u64, // actually ni about ty_i
}
pure fn uint_ty_to_str(t: uint_ty) -> ~str {
- alt t {
+ match t {
ty_u => ~"u",
ty_u8 => ~"u8",
ty_u16 => ~"u16",
}
pure fn uint_ty_max(t: uint_ty) -> u64 {
- alt t {
+ match t {
ty_u8 => 0xffu64,
ty_u16 => 0xffffu64,
ty_u | ty_u32 => 0xffffffffu64, // actually ni about ty_u
}
pure fn float_ty_to_str(t: float_ty) -> ~str {
- alt t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" }
+ match t { ty_f => ~"f", ty_f32 => ~"f32", ty_f64 => ~"f64" }
}
fn is_exported(i: ident, m: _mod) -> bool {
let mut parent_enum : option<ident> = none;
for m.items.each |it| {
if it.ident == i { local = true; }
- alt it.node {
+ match it.node {
item_enum(variants, _) => for variants.each |v| {
if v.node.name == i {
local = true;
}
let mut has_explicit_exports = false;
for m.view_items.each |vi| {
- alt vi.node {
+ match vi.node {
view_item_export(vps) => {
has_explicit_exports = true;
for vps.each |vp| {
- alt vp.node {
+ match vp.node {
ast::view_path_simple(id, _, _) => {
if id == i { return true; }
- alt parent_enum {
+ match parent_enum {
some(parent_enum_id) => {
if id == parent_enum_id { return true; }
}
}
pure fn is_call_expr(e: @expr) -> bool {
- alt e.node { expr_call(_, _, _) => true, _ => false }
+ match e.node { expr_call(_, _, _) => true, _ => false }
}
pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) }
}
pure fn is_unguarded(&&a: arm) -> bool {
- alt a.guard {
+ match a.guard {
none => true,
_ => false
}
}
pure fn class_item_ident(ci: @class_member) -> ident {
- alt ci.node {
+ match ci.node {
instance_var(i,_,_,_,_) => /* FIXME (#2543) */ copy i,
class_method(it) => /* FIXME (#2543) */ copy it.ident
}
fn public_methods(ms: ~[@method]) -> ~[@method] {
vec::filter(ms,
- |m| alt m.vis {
+ |m| match m.vis {
public => true,
_ => false
})
fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) {
let mut vs = ~[], ms = ~[];
for cs.each |c| {
- alt c.node {
+ match c.node {
instance_var(i, t, cm, id, vis) => {
vec::push(vs, {ident: /* FIXME (#2543) */ copy i,
ty: t,
// extract a ty_method from a trait_method. if the trait_method is
// a default, pull out the useful fields to make a ty_method
fn trait_method_to_ty_method(method: trait_method) -> ty_method {
- alt method {
+ match method {
required(m) => m,
provided(m) => {
{ident: m.ident, attrs: m.attrs,
-> (~[ty_method], ~[@method]) {
let mut reqd = ~[], provd = ~[];
for trait_methods.each |trt_method| {
- alt trt_method {
+ match trt_method {
required(tm) => vec::push(reqd, tm),
provided(m) => vec::push(provd, m)
}
}
pure fn class_member_visibility(ci: @class_member) -> visibility {
- alt ci.node {
+ match ci.node {
instance_var(_, _, _, _, vis) => vis,
class_method(m) => m.vis
}
impl inlined_item_methods of inlined_item_utils for inlined_item {
fn ident() -> ident {
- alt self {
+ match self {
ii_item(i) => /* FIXME (#2543) */ copy i.ident,
ii_foreign(i) => /* FIXME (#2543) */ copy i.ident,
ii_method(_, m) => /* FIXME (#2543) */ copy m.ident,
}
fn id() -> ast::node_id {
- alt self {
+ match self {
ii_item(i) => i.id,
ii_foreign(i) => i.id,
ii_method(_, m) => m.id,
}
fn accept<E>(e: E, v: visit::vt<E>) {
- alt self {
+ match self {
ii_item(i) => v.visit_item(i, e, v),
ii_foreign(i) => v.visit_foreign_item(i, e, v),
ii_method(_, m) => visit::visit_method_helper(m, e, v),
/* True if d is either a def_self, or a chain of def_upvars
referring to a def_self */
fn is_self(d: ast::def) -> bool {
- alt d {
+ match d {
def_self(_) => true,
def_upvar(_, d, _) => is_self(*d),
_ => false
/// Maps a binary operator to its precedence
fn operator_prec(op: ast::binop) -> uint {
- alt op {
+ match op {
mul | div | rem => 12u,
// 'as' sits between here with 11
add | subtract => 10u,
},
visit_view_item: fn@(vi: @view_item) {
- alt vi.node {
+ match vi.node {
view_item_use(_, _, id) => vfn(id),
view_item_import(vps) | view_item_export(vps) => {
do vec::iter(vps) |vp| {
- alt vp.node {
+ match vp.node {
view_path_simple(_, _, id) => vfn(id),
view_path_glob(_, id) => vfn(id),
view_path_list(_, _, id) => vfn(id)
visit_item: fn@(i: @item) {
vfn(i.id);
- alt i.node {
+ match i.node {
item_enum(vs, _) => for vs.each |v| { vfn(v.node.id); }
_ => ()
}
},
visit_ty: fn@(t: @ty) {
- alt t.node {
+ match t.node {
ty_path(_, id) => vfn(id),
_ => { /* fall through */ }
}
_b: ast::blk, _sp: span, id: ast::node_id) {
vfn(id);
- alt fk {
+ match fk {
visit::fk_ctor(nm, _, tps, self_id, parent_id) => {
vec::iter(tps, |tp| vfn(tp.id));
vfn(id);
},
visit_class_item: fn@(c: @class_member) {
- alt c.node {
+ match c.node {
instance_var(_, _, _, id,_) => vfn(id),
class_method(_) => ()
}
}
pure fn is_item_impl(item: @ast::item) -> bool {
- alt item.node {
+ match item.node {
item_impl(*) => true,
_ => false
}
fn walk_pat(pat: @pat, it: fn(@pat)) {
it(pat);
- alt pat.node {
+ match pat.node {
pat_ident(_, pth, some(p)) => walk_pat(p, it),
pat_rec(fields, _) => for fields.each |f| { walk_pat(f.pat, it) }
pat_enum(_, some(s)) | pat_tup(s) => for s.each |p| {
}
fn view_path_id(p: @view_path) -> node_id {
- alt p.node {
+ match p.node {
view_path_simple(_, _, id) | view_path_glob(_, id) |
view_path_list(_, _, id) => id
}
// All "bad" FIXME copies are as per #2543
fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident {
- alt meta.node {
+ match meta.node {
ast::meta_word(n) => /* FIXME (#2543) */ copy n,
ast::meta_name_value(n, _) => /* FIXME (#2543) */ copy n,
ast::meta_list(n, _) => /* FIXME (#2543) */ copy n
* containing a string, otherwise none
*/
fn get_meta_item_value_str(meta: @ast::meta_item) -> option<@~str> {
- alt meta.node {
- ast::meta_name_value(_, v) => alt v.node {
+ match meta.node {
+ ast::meta_name_value(_, v) => match v.node {
ast::lit_str(s) => option::some(s),
_ => option::none
}
/// Gets a list of inner meta items from a list meta_item type
fn get_meta_item_list(meta: @ast::meta_item) -> option<~[@ast::meta_item]> {
- alt meta.node {
+ match meta.node {
ast::meta_list(_, l) => option::some(/* FIXME (#2543) */ copy l),
_ => option::none
}
fn get_name_value_str_pair(
item: @ast::meta_item
) -> option<(ast::ident, @~str)> {
- 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);
some((name, value))
}
fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool {
- return alt a.node {
- ast::meta_word(na) => alt b.node {
+ return match a.node {
+ ast::meta_word(na) => match b.node {
ast::meta_word(nb) => na == nb,
_ => false
}
- ast::meta_name_value(na, va) => alt b.node {
+ ast::meta_name_value(na, va) => match b.node {
ast::meta_name_value(nb, vb) => na == nb && va.node == vb.node,
_ => false
}
items: ~[@ast::meta_item],
+name: ~str
) -> option<@~str> {
- alt last_meta_item_by_name(items, name) {
- some(item) => alt attr::get_meta_item_value_str(item) {
+ match last_meta_item_by_name(items, name) {
+ some(item) => match attr::get_meta_item_value_str(item) {
some(value) => some(value),
none => none
}
items: ~[@ast::meta_item],
+name: ~str
) -> option<~[@ast::meta_item]> {
- alt last_meta_item_by_name(items, name) {
+ match last_meta_item_by_name(items, name) {
some(item) => attr::get_meta_item_list(item),
none => none
}
fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
pure fn key(m: &ast::meta_item) -> ast::ident {
- alt m.node {
+ match m.node {
ast::meta_word(name) => /* FIXME (#2543) */ copy name,
ast::meta_name_value(name, _) => /* FIXME (#2543) */ copy name,
ast::meta_list(name, _) => /* FIXME (#2543) */ copy name
fn find_linkage_attrs(attrs: ~[ast::attribute]) -> ~[ast::attribute] {
let mut found = ~[];
for find_attrs_by_name(attrs, ~"link").each |attr| {
- alt attr.node.value.node {
+ match attr.node.value.node {
ast::meta_list(_, _) => vec::push(found, attr),
_ => debug!{"ignoring link attribute that has incorrect type"}
}
*/
fn find_linkage_metas(attrs: ~[ast::attribute]) -> ~[@ast::meta_item] {
do find_linkage_attrs(attrs).flat_map |attr| {
- alt check attr.node.value.node {
+ match check attr.node.value.node {
ast::meta_list(_, items) => /* FIXME (#2543) */ copy items
}
}
}
fn foreign_abi(attrs: ~[ast::attribute]) -> either<~str, ast::foreign_abi> {
- return alt attr::first_attr_value_str_by_name(attrs, ~"abi") {
+ return match attr::first_attr_value_str_by_name(attrs, ~"abi") {
option::none => {
either::right(ast::foreign_abi_cdecl)
}
fn find_inline_attr(attrs: ~[ast::attribute]) -> inline_attr {
// FIXME (#2809)---validate the usage of #[inline] and #[inline(always)]
do vec::foldl(ia_none, attrs) |ia,attr| {
- alt attr.node.value.node {
+ match attr.node.value.node {
ast::meta_word(@~"inline") => ia_hint,
ast::meta_list(@~"inline", items) => {
if !vec::is_empty(find_meta_items_by_name(items, ~"always")) {
-> {filename: ~str, line: uint, col: uint, file: option<filemap>}
{
let loc = lookup_char_pos(map, pos);
- alt (loc.file.substr) {
+ match (loc.file.substr) {
fss_none => {
{filename: /* FIXME (#2543) */ copy loc.file.name,
line: loc.line,
fn adjust_span(map: codemap, sp: span) -> span {
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let line = lookup_line(map, sp.lo, lookup);
- alt (line.fm.substr) {
+ match (line.fm.substr) {
fss_none => sp,
fss_internal(s) => {
adjust_span(map, {lo: s.lo + (sp.lo - line.fm.start_pos.ch),
fn get_line(fm: filemap, line: int) -> ~str unsafe {
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
- let end = alt str::find_char_from(*fm.src, '\n', begin) {
+ let end = match str::find_char_from(*fm.src, '\n', begin) {
some(e) => e,
none => str::len(*fm.src)
};
fn has_errors() -> bool { self.err_count > 0u }
fn abort_if_errors() {
let s;
- alt self.err_count {
+ match self.err_count {
0u => return,
1u => s = ~"aborting due to previous error",
_ => {
fn mk_handler(emitter: option<emitter>) -> handler {
- let emit = alt emitter {
+ let emit = match emitter {
some(e) => e,
none => {
let f = fn@(cmsp: option<(codemap::codemap, span)>,
}
fn diagnosticstr(lvl: level) -> ~str {
- alt lvl {
+ match lvl {
fatal => ~"error",
error => ~"error",
warning => ~"warning",
}
fn diagnosticcolor(lvl: level) -> u8 {
- alt lvl {
+ match lvl {
fatal => term::color_bright_red,
error => term::color_bright_red,
warning => term::color_bright_yellow,
fn emit(cmsp: option<(codemap::codemap, span)>,
msg: ~str, lvl: level) {
- alt cmsp {
+ match cmsp {
some((cm, sp)) => {
let sp = codemap::adjust_span(cm,sp);
let ss = codemap::span_to_str(sp, cm);
fn expect<T: copy>(diag: span_handler,
opt: option<T>, msg: fn() -> ~str) -> T {
- alt opt {
+ match opt {
some(t) => t,
none => diag.handler().bug(msg())
}
}
do vec::flat_map(in_items) |in_item| {
- alt in_item.node {
+ match in_item.node {
ast::item_ty(ty, tps) => {
vec::append(~[filter_attrs(in_item)],
ty_fns(cx, in_item.ident, ty, tps))
}
fn is_vec_or_str(ty: @ast::ty) -> bool {
- alt ty.node {
+ match ty.node {
ast::ty_vec(_) => true,
// This may be wrong if the user has shadowed (!) str
ast::ty_path(@{span: _, global: _, idents: ids,
let ext_cx = cx; // required for #ast{}
- alt ty.node {
+ match ty.node {
ast::ty_nil => {
~[#ast[stmt]{$(s).emit_nil()}]
}
ast::ty_tup(tys) => {
// Generate code like
//
- // alt v {
+ // match v {
// (v1, v2, v3) {
// .. serialize v1, v2, v3 ..
// }
vec::is_empty(path.types) {
let ident = path.idents[0];
- alt tps.find(*ident) {
+ match tps.find(*ident) {
some(f) => f(v),
none => ser_path(cx, tps, path, s, v)
}
let ext_cx = cx; // required for #ast{}
- alt ty.node {
+ match ty.node {
ast::ty_nil => {
#ast{ $(d).read_nil() }
}
vec::is_empty(path.types) {
let ident = path.idents[0];
- alt tps.find(*ident) {
+ match tps.find(*ident) {
some(f) => f(),
none => deser_path(cx, tps, path, d)
}
fn mod_pop() { vec::pop(self.mod_path); }
fn mod_path() -> ~[ast::ident] { return self.mod_path; }
fn bt_push(ei: codemap::expn_info_) {
- alt ei {
+ match ei {
expanded_from({call_site: cs, callie: callie}) => {
self.backtrace =
some(@expanded_from({
}
}
fn bt_pop() {
- alt self.backtrace {
+ match self.backtrace {
some(@expanded_from({call_site: {expn_info: prev, _}, _})) => {
self.backtrace = prev
}
}
fn expr_to_str(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ~str {
- alt expr.node {
- ast::expr_lit(l) => alt l.node {
+ match expr.node {
+ ast::expr_lit(l) => match l.node {
ast::lit_str(s) => return *s,
_ => cx.span_fatal(l.span, error)
}
}
fn expr_to_ident(cx: ext_ctxt, expr: @ast::expr, error: ~str) -> ast::ident {
- alt expr.node {
+ match expr.node {
ast::expr_path(p) => {
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
cx.span_fatal(expr.span, error);
fn get_mac_args(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
min: uint, max: option<uint>, name: ~str) -> ~[@ast::expr] {
- alt arg {
- some(expr) => alt expr.node {
+ match arg {
+ some(expr) => match expr.node {
ast::expr_vec(elts, _) => {
let elts_len = vec::len(elts);
- alt max {
+ match max {
some(max) if ! (min <= elts_len && elts_len <= max) => {
cx.span_fatal(sp,
fmt!{"#%s takes between %u and %u arguments.",
fn get_mac_body(cx: ext_ctxt, sp: span, args: ast::mac_body)
-> ast::mac_body_
{
- alt (args) {
+ match (args) {
some(body) => body,
none => cx.span_fatal(sp, ~"missing macro body")
}
let arg_reader = new_tt_reader(cx.parse_sess().span_diagnostic,
cx.parse_sess().interner, none, arg);
let args =
- alt parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
+ match parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader as reader,
argument_gram).get(@~"arg") {
@matched_seq(s, _) => do s.map() |lf| {
- alt lf {
+ match lf {
@matched_nonterminal(parse::token::nt_expr(arg)) => {
arg /* whew! list of exprs, here we come! */
}
// option<str> rather than just an maybe-empty string.
let var = expr_to_str(cx, args[0], ~"#env requires a string");
- alt os::getenv(var) {
+ match os::getenv(var) {
option::none => return mk_uniq_str(cx, sp, ~""),
option::some(s) => return mk_uniq_str(cx, sp, s)
}
orig: fn@(expr_, span, ast_fold) -> (expr_, span))
-> (expr_, span)
{
- return alt e {
+ return match e {
// expr_mac should really be expr_ext or something; it's the
// entry-point for all syntax extensions.
expr_mac(mac) => {
// Old-style macros, for compatibility, will erase this whole
// block once we've transitioned.
- alt mac.node {
+ match mac.node {
mac_invoc(pth, args, body) => {
assert (vec::len(pth.idents) > 0u);
let extname = pth.idents[0];
- alt exts.find(*extname) {
+ match exts.find(*extname) {
none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
mac_invoc_tt(pth, tts) => {
assert (vec::len(pth.idents) == 1u);
let extname = pth.idents[0];
- alt exts.find(*extname) {
+ match exts.find(*extname) {
none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
}
some(expr_tt({expander: exp, span: exp_sp})) => {
- let expanded = alt exp(cx, mac.span, tts) {
+ let expanded = match exp(cx, mac.span, tts) {
mr_expr(e) => e,
_ => cx.span_fatal(
pth.span, fmt!{"non-expr macro in expr pos: %s",
// the item into a new set of items.
let new_items = do vec::flat_map(module_.items) |item| {
do vec::foldr(item.attrs, ~[item]) |attr, items| {
- let mname = alt attr.node.value.node {
+ let mname = match attr.node.value.node {
ast::meta_word(n) => n,
ast::meta_name_value(n, _) => n,
ast::meta_list(n, _) => n
};
- alt exts.find(*mname) {
+ match exts.find(*mname) {
none | some(normal(_)) | some(macro_defining(_))
| some(expr_tt(_)) | some(item_tt(*)) => items,
some(item_decorator(dec_fn)) => {
orig: fn@(&&@ast::item, ast_fold) -> option<@ast::item>)
-> option<@ast::item>
{
- let is_mod = alt it.node {
+ let is_mod = match it.node {
ast::item_mod(_) | ast::item_foreign_mod(_) => true,
_ => false
};
- let maybe_it = alt it.node {
+ let maybe_it = match it.node {
ast::item_mac(*) => expand_item_mac(exts, cx, it, fld),
_ => some(it)
};
- alt maybe_it {
+ match maybe_it {
some(it) => {
if is_mod { cx.mod_push(it.ident); }
let ret_val = orig(it, fld);
fn expand_item_mac(exts: hashmap<~str, syntax_extension>,
cx: ext_ctxt, &&it: @ast::item,
fld: ast_fold) -> option<@ast::item> {
- alt it.node {
+ match it.node {
item_mac({node: mac_invoc_tt(pth, tts), span}) => {
let extname = pth.idents[0];
- alt exts.find(*extname) {
+ match exts.find(*extname) {
none => {
cx.span_fatal(pth.span,
fmt!{"macro undefined: '%s'", *extname})
cx.bt_push(expanded_from({call_site: it.span,
callie: {name: *extname,
span: expand.span}}));
- let maybe_it = alt expanded {
+ let maybe_it = match expanded {
mr_item(it) => fld.fold_item(it),
mr_expr(e) => cx.span_fatal(pth.span,
~"expr macro in item position: " +
fn make_flags(cx: ext_ctxt, sp: span, flags: ~[flag]) -> @ast::expr {
let mut tmp_expr = make_rt_path_expr(cx, sp, @~"flag_none");
for flags.each |f| {
- let fstr = alt f {
+ let fstr = match f {
flag_left_justify => ~"flag_left_justify",
flag_left_zero_pad => ~"flag_left_zero_pad",
flag_space_for_sign => ~"flag_space_for_sign",
return tmp_expr;
}
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
- alt cnt {
+ match cnt {
count_implied => {
return make_rt_path_expr(cx, sp, @~"count_implied");
}
}
fn make_ty(cx: ext_ctxt, sp: span, t: ty) -> @ast::expr {
let mut rt_type;
- alt t {
- ty_hex(c) => alt c {
+ match t {
+ ty_hex(c) => match c {
case_upper => rt_type = ~"ty_hex_upper",
case_lower => rt_type = ~"ty_hex_lower"
}
// FIXME: Move validation code into core::extfmt (Issue #2249)
fn is_signed_type(cnv: conv) -> bool {
- alt cnv.ty {
- ty_int(s) => alt s {
+ match cnv.ty {
+ ty_int(s) => match s {
signed => return true,
unsigned => return false
}
}
}
let unsupported = ~"conversion not supported in #fmt string";
- alt cnv.param {
+ match cnv.param {
option::none => (),
_ => cx.span_unimpl(sp, unsupported)
}
for cnv.flags.each |f| {
- alt f {
+ match f {
flag_left_justify => (),
flag_sign_always => {
if !is_signed_type(cnv) {
_ => cx.span_unimpl(sp, unsupported)
}
}
- alt cnv.width {
+ match cnv.width {
count_implied => (),
count_is(_) => (),
_ => cx.span_unimpl(sp, unsupported)
}
- alt cnv.precision {
+ match cnv.precision {
count_implied => (),
count_is(_) => (),
_ => cx.span_unimpl(sp, unsupported)
}
- alt cnv.ty {
+ match cnv.ty {
ty_str => return make_conv_call(cx, arg.span, ~"str", cnv, arg),
- ty_int(sign) => alt sign {
+ ty_int(sign) => match sign {
signed => return make_conv_call(cx, arg.span, ~"int", cnv, arg),
unsigned => {
return make_conv_call(cx, arg.span, ~"uint", cnv, arg)
}
}
fn log_conv(c: conv) {
- alt c.param {
+ match c.param {
some(p) => { log(debug, ~"param: " + int::to_str(p, 10u)); }
_ => debug!{"param: none"}
}
for c.flags.each |f| {
- alt f {
+ match f {
flag_left_justify => debug!{"flag: left justify"},
flag_left_zero_pad => debug!{"flag: left zero pad"},
flag_space_for_sign => debug!{"flag: left space pad"},
flag_alternate => debug!{"flag: alternate"}
}
}
- alt c.width {
+ match c.width {
count_is(i) => log(
debug, ~"width: count is " + int::to_str(i, 10u)),
count_is_param(i) => log(
count_is_next_param => debug!{"width: count is next param"},
count_implied => debug!{"width: count is implied"}
}
- alt c.precision {
+ match c.precision {
count_is(i) => log(
debug, ~"prec: count is " + int::to_str(i, 10u)),
count_is_param(i) => log(
count_is_next_param => debug!{"prec: count is next param"},
count_implied => debug!{"prec: count is implied"}
}
- alt c.ty {
+ match c.ty {
ty_bool => debug!{"type: bool"},
ty_str => debug!{"type: str"},
ty_char => debug!{"type: char"},
- ty_int(s) => alt s {
+ ty_int(s) => match s {
signed => debug!{"type: signed"},
unsigned => debug!{"type: unsigned"}
}
ty_bits => debug!{"type: bits"},
- ty_hex(cs) => alt cs {
+ ty_hex(cs) => match cs {
case_upper => debug!{"type: uhex"},
case_lower => debug!{"type: lhex"},
}
let mut piece_exprs = ~[];
let nargs = args.len();
for pieces.each |pc| {
- alt pc {
+ match pc {
piece_string(s) => {
vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s))
}
fn visit_message(name: ident, _span: span, _tys: &[@ast::ty],
this: state, next: next_state) {
- alt next {
+ match next {
some({state: next, tys: next_tys}) => {
let proto = this.proto;
if !proto.has_state(next) {
fn parse_state(proto: protocol) {
let id = self.parse_ident();
self.expect(token::COLON);
- let dir = alt copy self.token {
+ let dir = match copy self.token {
token::IDENT(n, _) => self.get_str(n),
_ => fail
};
self.bump();
- let dir = alt dir {
+ let dir = match dir {
@~"send" => send,
@~"recv" => recv,
_ => fail
self.expect(token::RARROW);
- let next = alt copy self.token {
+ let next = match copy self.token {
token::IDENT(_, _) => {
let name = self.parse_ident();
let ntys = if self.token == token::LT {
impl compile of gen_send for message {
fn gen_send(cx: ext_ctxt) -> @ast::item {
debug!{"pipec: gen_send"};
- alt self {
+ match self {
message(id, span, tys, this,
some({state: next, tys: next_tys})) => {
debug!{"pipec: next state exists"};
let mut body = ~"{\n";
if this.proto.is_bounded() {
- let (sp, rp) = alt (this.dir, next.dir) {
+ let (sp, rp) = match (this.dir, next.dir) {
(send, send) => (~"c", ~"s"),
(send, recv) => (~"s", ~"c"),
(recv, send) => (~"s", ~"c"),
rp, *next.name};
}
else {
- let pat = alt (this.dir, next.dir) {
+ let pat = match (this.dir, next.dir) {
(send, send) => ~"(c, s)",
(send, recv) => ~"(s, c)",
(recv, send) => ~"(s, c)",
for self.messages.each |m| {
let message(name, _span, tys, this, next) = m;
- let tys = alt next {
+ let tys = match next {
some({state: next, tys: next_tys}) => {
let next = this.proto.get_state(next);
let next_name = next.data_name();
- let dir = alt this.dir {
+ let dir = match this.dir {
send => @~"server",
recv => @~"client"
};
fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
debug!{"pipec: to_endpoint_decls"};
- let dir = alt dir {
+ let dir = match dir {
send => (*self).dir,
recv => (*self).dir.reverse()
};
let start_state = self.states[0];
let body = if !self.is_bounded() {
- alt start_state.dir {
+ match start_state.dir {
send => #ast { pipes::entangle() },
recv => {
#ast {{
}
else {
let body = self.gen_init_bounded(ext_cx);
- alt start_state.dir {
+ match start_state.dir {
send => body,
recv => {
#ast {{
let mut params: ~[ast::ty_param] = ~[];
for (copy self.states).each |s| {
for s.ty_params.each |tp| {
- alt params.find(|tpp| *tp.ident == *tpp.ident) {
+ match params.find(|tpp| *tp.ident == *tpp.ident) {
none => vec::push(params, tp),
_ => ()
}
let mut params: ~[ast::ty_param] = ~[];
let fields = do (copy self.states).map_to_vec |s| {
for s.ty_params.each |tp| {
- alt params.find(|tpp| *tp.ident == *tpp.ident) {
+ match params.find(|tpp| *tp.ident == *tpp.ident) {
none => vec::push(params, tp),
_ => ()
}
self.cfg(),
~[],
self.parse_sess());
- alt res {
+ match res {
some(ast) => ast,
none => {
error!{"Parse error with ```\n%s\n```", s};
impl of to_str for direction {
fn to_str() -> ~str {
- alt self {
+ match self {
send => ~"send",
recv => ~"recv"
}
impl methods for direction {
fn reverse() -> direction {
- alt self {
+ match self {
send => recv,
recv => send
}
impl methods for message {
fn name() -> ident {
- alt self {
+ match self {
message(id, _, _, _, _) => id
}
}
fn span() -> span {
- alt self {
+ match self {
message(_, span, _, _, _) => span
}
}
/// Return the type parameters actually used by this message
fn get_params() -> ~[ast::ty_param] {
- alt self {
+ match self {
message(_, _, _, this, _) => this.ty_params
}
}
/// from this state.
fn reachable(f: fn(state) -> bool) {
for self.messages.each |m| {
- alt m {
+ match m {
message(_, _, _, _, some({state: id, _})) => {
let state = self.proto.get_state(id);
if !f(state) { break }
fn span() -> span {self.span}
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_expr(self, cx, v);}
fn extract_mac() -> option<ast::mac_> {
- alt (self.node) {
+ match (self.node) {
ast::expr_mac({node: mac, _}) => some(mac),
_ => none
}
fn span() -> span {self.span}
fn visit(cx: aq_ctxt, v: vt<aq_ctxt>) {visit_ty(self, cx, v);}
fn extract_mac() -> option<ast::mac_> {
- alt (self.node) {
+ match (self.node) {
ast::ty_mac({node: mac, _}) => some(mac),
_ => none
}
fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
{
- alt (node.extract_mac()) {
+ match (node.extract_mac()) {
some(mac_aq(sp, e)) => {
cx.gather.push(gather_item {
lo: sp.lo - cx.lo,
let mut what = ~"expr";
do option::iter(arg) |arg| {
let args: ~[@ast::expr] =
- alt arg.node {
+ match arg.node {
ast::expr_vec(elts, _) => elts,
_ => {
ecx.span_fatal
if vec::len::<@ast::expr>(args) != 1u {
ecx.span_fatal(_sp, ~"#ast requires exactly one arg");
}
- alt (args[0].node) {
+ match (args[0].node) {
ast::expr_path(@{idents: id, _}) if vec::len(id) == 1u
=> what = *id[0],
_ => ecx.span_fatal(args[0].span, ~"expected an identifier")
}
let body = get_mac_body(ecx,_sp,body);
- return alt what {
+ return match what {
~"crate" => finish(ecx, body, parse_crate),
~"expr" => finish(ecx, body, parse_expr),
~"ty" => finish(ecx, body, parse_ty),
fn parse_pat(p: parser) -> @ast::pat { p.parse_pat(true) }
fn parse_item(p: parser) -> @ast::item {
- alt p.parse_item(~[]) {
+ match p.parse_item(~[]) {
some(item) => item,
none => fail ~"parse_item: parsing an item failed"
}
state = skip(str::char_len(repl));
str2 += repl;
}
- alt copy state {
+ match copy state {
active => str::push_char(str2, ch),
skip(1u) => state = blank,
skip(sk) => state = skip (sk-1u),
orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span))
-> (ast::expr_, span)
{
- alt e {
- ast::expr_mac({node: mac_var(i), _}) => alt (repls[i]) {
+ match e {
+ ast::expr_mac({node: mac_var(i), _}) => match (repls[i]) {
from_expr(r) => (r.node, r.span),
_ => fail /* fixme error message */
}
orig: fn@(ast::ty_, span, ast_fold)->(ast::ty_, span))
-> (ast::ty_, span)
{
- alt e {
- ast::ty_mac({node: mac_var(i), _}) => alt (repls[i]) {
+ match e {
+ ast::ty_mac({node: mac_var(i), _}) => match (repls[i]) {
from_ty(r) => (r.node, r.span),
_ => fail /* fixme error message */
}
/* for when given an incompatible bit of AST */
fn match_error(cx: ext_ctxt, m: matchable, expected: ~str) -> ! {
- alt m {
+ match m {
match_expr(x) => cx.span_fatal(
x.span, ~"this argument is an expr, expected " + expected),
match_path(x) => cx.span_fatal(
let mut idx: uint = 0u;
let mut res = none;
for elts.each |elt| {
- alt elt.node {
- expr_mac(m) => alt m.node {
+ match elt.node {
+ expr_mac(m) => match m.node {
ast::mac_ellipsis => {
if res != none {
cx.span_fatal(m.span, ~"only one ellipsis allowed");
}
idx += 1u;
}
- return alt res {
+ return match res {
some(val) => val,
none => {pre: elts, rep: none, post: ~[]}
}
option<~[U]> {
let mut res = ~[];
for v.each |elem| {
- alt f(elem) {
+ match f(elem) {
none => return none,
some(fv) => vec::push(res, fv)
}
}
fn a_d_map(ad: arb_depth<matchable>, f: selector) -> match_result {
- alt ad {
+ match ad {
leaf(x) => return f(x),
- seq(ads, span) => alt option_flatten_map(|x| a_d_map(x, f), *ads) {
+ seq(ads, span) => match option_flatten_map(|x| a_d_map(x, f), *ads) {
none => return none,
some(ts) => return some(seq(@ts, span))
}
fn compose_sels(s1: selector, s2: selector) -> selector {
fn scomp(s1: selector, s2: selector, m: matchable) -> match_result {
- return alt s1(m) {
+ return match s1(m) {
none => none,
some(matches) => a_d_map(matches, s2)
}
let res = box_str_hash::<arb_depth<matchable>>();
//need to do this first, to check vec lengths.
for b.literal_ast_matchers.each |sel| {
- alt sel(match_expr(e)) { none => return none, _ => () }
+ match sel(match_expr(e)) { none => return none, _ => () }
}
let mut never_mind: bool = false;
for b.real_binders.each |key, val| {
- alt val(match_expr(e)) {
+ match val(match_expr(e)) {
none => never_mind = true,
some(mtc) => { res.insert(key, mtc); }
}
arb_depth<matchable> {
let mut res: arb_depth<matchable> = m;
for vec::each(*idx_path) |idx| {
- res = alt res {
+ res = match res {
leaf(_) => return res,/* end of the line */
seq(new_ms, _) => new_ms[idx]
}
fn follow_for_trans(cx: ext_ctxt, mmaybe: option<arb_depth<matchable>>,
idx_path: @mut ~[uint]) -> option<matchable> {
- alt mmaybe {
+ match mmaybe {
none => return none,
some(m) => {
- return alt follow(m, idx_path) {
+ return match follow(m, idx_path) {
seq(_, sp) => {
cx.span_fatal(sp,
~"syntax matched under ... but not " +
fn transcribe_exprs(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
recur: fn@(&&@expr) -> @expr,
exprs: ~[@expr]) -> ~[@expr] {
- alt elts_to_ell(cx, exprs) {
+ match elts_to_ell(cx, exprs) {
{pre: pre, rep: repeat_me_maybe, post: post} => {
let mut res = vec::map(pre, recur);
- alt repeat_me_maybe {
+ match repeat_me_maybe {
none => (),
some(repeat_me) => {
let mut repeat: option<{rep_count: uint, name: ident}> = none;
the leaves, which are just duplicated */
do free_vars(b, repeat_me) |fv| {
let cur_pos = follow(b.get(fv), idx_path);
- alt cur_pos {
+ match cur_pos {
leaf(_) => (),
seq(ms, _) => {
- alt repeat {
+ match repeat {
none => {
repeat = some({rep_count: vec::len(*ms), name: fv});
}
}
}
};
- alt repeat {
+ match repeat {
none => {
cx.span_fatal(repeat_me.span,
~"'...' surrounds an expression without any" +
// substitute, in a position that's required to be an ident
fn transcribe_ident(cx: ext_ctxt, b: bindings, idx_path: @mut ~[uint],
&&i: ident, _fld: ast_fold) -> ident {
- return alt follow_for_trans(cx, b.find(i), idx_path) {
+ return match follow_for_trans(cx, b.find(i), idx_path) {
some(match_ident(a_id)) => a_id.node,
some(m) => match_error(cx, m, ~"an identifier"),
none => i
p: path, _fld: ast_fold) -> path {
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { return p; }
- alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
+ match follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
some(match_ident(id)) => {
{span: id.span, global: false, idents: ~[id.node],
rp: none, types: ~[]}
orig: fn@(ast::expr_, span, ast_fold)->(ast::expr_, span))
-> (ast::expr_, span)
{
- return alt e {
+ return match e {
expr_path(p) => {
// Don't substitute into qualified names.
if vec::len(p.types) > 0u || vec::len(p.idents) != 1u {
(e, s);
}
- alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
+ match follow_for_trans(cx, b.find(p.idents[0]), idx_path) {
some(match_ident(id)) => {
(expr_path(@{span: id.span,
global: false,
orig: fn@(ast::ty_, span, ast_fold) -> (ast::ty_, span))
-> (ast::ty_, span)
{
- return alt t {
+ return match t {
ast::ty_path(pth, _) => {
- alt path_to_ident(pth) {
+ match path_to_ident(pth) {
some(id) => {
- alt follow_for_trans(cx, b.find(id), idx_path) {
+ match follow_for_trans(cx, b.find(id), idx_path) {
some(match_ty(ty)) => (ty.node, ty.span),
some(m) => match_error(cx, m, ~"a type"),
none => orig(t, s, fld)
orig: fn@(blk_, span, ast_fold) -> (blk_, span))
-> (blk_, span)
{
- return alt block_to_ident(blk) {
+ return match block_to_ident(blk) {
some(id) => {
- alt follow_for_trans(cx, b.find(id), idx_path) {
+ match follow_for_trans(cx, b.find(id), idx_path) {
some(match_block(new_blk)) => (new_blk.node, new_blk.span),
// possibly allow promotion of ident/path/expr to blocks?
fn p_t_s_rec(cx: ext_ctxt, m: matchable, s: selector, b: binders) {
//it might be possible to traverse only exprs, not matchables
- alt m {
+ match m {
match_expr(e) => {
- alt e.node {
+ match e.node {
expr_path(p_pth) => p_t_s_r_path(cx, p_pth, s, b),
expr_vec(p_elts, _) => {
- alt elts_to_ell(cx, p_elts) {
+ match elts_to_ell(cx, p_elts) {
{pre: pre, rep: some(repeat_me), post: post} => {
p_t_s_r_length(cx, vec::len(pre) + vec::len(post), true, s,
b);
_ => {
fn select(cx: ext_ctxt, m: matchable, pat: @expr) ->
match_result {
- return alt m {
+ return match m {
match_expr(e) => {
if e == pat { some(leaf(match_exact)) } else { none }
}
/* make a match more precise */
fn specialize_match(m: matchable) -> matchable {
- return alt m {
+ return match m {
match_expr(e) => {
- alt e.node {
+ match e.node {
expr_path(pth) => {
- alt path_to_ident(pth) {
+ match path_to_ident(pth) {
some(id) => match_ident(respan(pth.span, id)),
none => match_path(pth)
}
/* pattern_to_selectors helper functions */
fn p_t_s_r_path(cx: ext_ctxt, p: @path, s: selector, b: binders) {
- alt path_to_ident(p) {
+ match path_to_ident(p) {
some(p_id) => {
fn select(cx: ext_ctxt, m: matchable) -> match_result {
- return alt m {
+ return match m {
match_expr(e) => some(leaf(specialize_match(m))),
_ => cx.bug(~"broken traversal in p_t_s_r")
}
fn block_to_ident(blk: blk_) -> option<ident> {
if vec::len(blk.stmts) != 0u { return none; }
- return alt blk.expr {
- some(expr) => alt expr.node {
+ return match blk.expr {
+ some(expr) => match expr.node {
expr_path(pth) => path_to_ident(pth),
_ => none
}
fn p_t_s_r_mac(cx: ext_ctxt, mac: ast::mac, _s: selector, _b: binders) {
fn select_pt_1(cx: ext_ctxt, m: matchable,
fn_m: fn(ast::mac) -> match_result) -> match_result {
- return alt m {
- match_expr(e) => alt e.node {
+ return match m {
+ match_expr(e) => match e.node {
expr_mac(mac) => fn_m(mac),
_ => none
}
fn no_des(cx: ext_ctxt, sp: span, syn: ~str) -> ! {
cx.span_fatal(sp, ~"destructuring " + syn + ~" is not yet supported");
}
- alt mac.node {
+ match mac.node {
ast::mac_ellipsis => cx.span_fatal(mac.span, ~"misused `...`"),
ast::mac_invoc(_, _, _) => no_des(cx, mac.span, ~"macro calls"),
ast::mac_invoc_tt(_, _) => no_des(cx, mac.span, ~"macro calls"),
b: binders) {
fn select(cx: ext_ctxt, repeat_me: @expr, offset: uint, m: matchable) ->
match_result {
- return alt m {
+ return match m {
match_expr(e) => {
- alt e.node {
+ match e.node {
expr_vec(arg_elts, _) => {
let mut elts = ~[];
let mut idx = offset;
b: binders) {
fn len_select(_cx: ext_ctxt, m: matchable, at_least: bool, len: uint) ->
match_result {
- return alt m {
+ return match m {
match_expr(e) => {
- alt e.node {
+ match e.node {
expr_vec(arg_elts, _) => {
let actual_len = vec::len(arg_elts);
if at_least && actual_len >= len || actual_len == len {
let mut idx: uint = 0u;
while idx < vec::len(elts) {
fn select(cx: ext_ctxt, m: matchable, idx: uint) -> match_result {
- return alt m {
+ return match m {
match_expr(e) => {
- alt e.node {
+ match e.node {
expr_vec(arg_elts, _) => {
some(leaf(match_expr(arg_elts[idx])))
}
let mut macro_name: option<@~str> = none;
let mut clauses: ~[@clause] = ~[];
for args.each |arg| {
- alt arg.node {
+ match arg.node {
expr_vec(elts, mutbl) => {
if vec::len(elts) != 2u {
cx.span_fatal((*arg).span,
}
- alt elts[0u].node {
+ match elts[0u].node {
expr_mac(mac) => {
- alt mac.node {
+ match mac.node {
mac_invoc(pth, invoc_arg, body) => {
- alt path_to_ident(pth) {
- some(id) => alt macro_name {
+ match path_to_ident(pth) {
+ some(id) => match macro_name {
none => macro_name = some(id),
some(other_id) => if id != other_id {
cx.span_fatal(pth.span,
none => cx.span_fatal(pth.span,
~"macro name must not be a path")
}
- let arg = alt invoc_arg {
+ let arg = match invoc_arg {
some(arg) => arg,
none => cx.span_fatal(mac.span,
~"macro must have arguments")
let ext = |a,b,c,d, move clauses| generic_extension(a,b,c,d,clauses);
return {ident:
- alt macro_name {
+ match macro_name {
some(id) => id,
none => cx.span_fatal(sp, ~"macro definition must have " +
~"at least one clause")
fn generic_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body,
clauses: ~[@clause]) -> @expr {
- let arg = alt arg {
+ let arg = match arg {
some(arg) => arg,
none => cx.span_fatal(sp, ~"macro must have arguments")
};
for clauses.each |c| {
- alt use_selectors_to_bind(c.params, arg) {
+ match use_selectors_to_bind(c.params, arg) {
some(bindings) => return transcribe(cx, bindings, c.body),
none => again
}
let file = expr_to_str(cx, args[0], ~"#include_str requires a string");
let res = io::read_whole_file_str(res_rel_file(cx, sp, file));
- alt res {
+ match res {
result::ok(_) => { /* Continue. */ }
result::err(e) => {
cx.parse_sess().span_diagnostic.handler().fatal(e);
let file = expr_to_str(cx, args[0], ~"#include_bin requires a string");
- alt io::read_whole_file(res_rel_file(cx, sp, file)) {
+ match io::read_whole_file(res_rel_file(cx, sp, file)) {
result::ok(src) => {
let u8_exprs = vec::map(src, |char: u8| {
mk_u8(cx, sp, char)
}
fn is_some(&&mpu: matcher_pos_up) -> bool {
- alt mpu {
+ match mpu {
matcher_pos_up(none) => false,
_ => true
}
};
fn copy_up(&& mpu: matcher_pos_up) -> matcher_pos {
- alt mpu {
+ match mpu {
matcher_pos_up(some(mp)) => copy mp,
_ => fail
}
fn count_names(ms: &[matcher]) -> uint {
vec::foldl(0u, ms, |ct, m| {
- ct + alt m.node {
+ ct + match m.node {
match_tok(_) => 0u,
match_seq(more_ms, _, _, _, _) => count_names(more_ms),
match_nonterminal(_,_,_) => 1u
-> matcher_pos {
let mut match_idx_hi = 0u;
for ms.each() |elt| {
- alt elt.node {
+ match elt.node {
match_tok(_) => (),
match_seq(_,_,_,_,hi) => {
match_idx_hi = hi; // it is monotonic...
-> hashmap<ident,@named_match> {
fn n_rec(p_s: parse_sess, m: matcher, res: ~[@named_match],
ret_val: hashmap<ident, @named_match>) {
- alt m {
+ match m {
{node: match_tok(_), span: _} => (),
{node: match_seq(more_ms, _, _, _, _), span: _} => {
for more_ms.each() |next_m| { n_rec(p_s, next_m, res, ret_val) };
fn parse_or_else(sess: parse_sess, cfg: ast::crate_cfg, rdr: reader,
ms: ~[matcher]) -> hashmap<ident, @named_match> {
- alt parse(sess, cfg, rdr, ms) {
+ match parse(sess, cfg, rdr, ms) {
success(m) => m,
failure(sp, str) => sess.span_diagnostic.span_fatal(sp, str)
}
// can we go around again?
// the *_t vars are workarounds for the lack of unary move
- alt copy ei.sep {
+ match copy ei.sep {
some(t) if idx == len => { // we need a separator
if tok == t { //pass the separator
let ei_t <- ei;
vec::push(eof_eis, ei);
}
} else {
- alt copy ei.elts[idx].node {
+ match copy ei.elts[idx].node {
/* need to descend into sequence */
match_seq(matchers, sep, zero_ok,
match_idx_lo, match_idx_hi) => {
if (bb_eis.len() > 0u && next_eis.len() > 0u)
|| bb_eis.len() > 1u {
let nts = str::connect(vec::map(bb_eis, |ei| {
- alt ei.elts[ei.idx].node {
+ match ei.elts[ei.idx].node {
match_nonterminal(bind,name,_) => {
fmt!{"%s ('%s')", *name, *bind}
}
let rust_parser = parser(sess, cfg, rdr.dup(), SOURCE_FILE);
let ei = vec::pop(bb_eis);
- alt ei.elts[ei.idx].node {
+ match ei.elts[ei.idx].node {
match_nonterminal(_, name, idx) => {
ei.matches[idx].push(@matched_nonterminal(
parse_nt(rust_parser, *name)));
}
fn parse_nt(p: parser, name: ~str) -> nonterminal {
- alt name {
- ~"item" => alt p.parse_item(~[]) {
+ match name {
+ ~"item" => match p.parse_item(~[]) {
some(i) => token::nt_item(i),
none => p.fatal(~"expected an item keyword")
}
~"expr" => token::nt_expr(p.parse_expr()),
~"ty" => token::nt_ty(p.parse_ty(false /* no need to disambiguate*/)),
// this could be handled like a token, since it is one
- ~"ident" => alt copy p.token {
+ ~"ident" => match copy p.token {
token::IDENT(sn,b) => { p.bump(); token::nt_ident(sn,b) }
_ => p.fatal(~"expected ident, found "
+ token::to_str(*p.reader.interner(), copy p.token))
arg_reader as reader, argument_gram);
// Extract the arguments:
- let lhses:~[@named_match] = alt argument_map.get(@~"lhs") {
+ let lhses:~[@named_match] = match argument_map.get(@~"lhs") {
@matched_seq(s, sp) => s,
_ => cx.span_bug(sp, ~"wrong-structured lhs")
};
- let rhses:~[@named_match] = alt argument_map.get(@~"rhs") {
+ let rhses:~[@named_match] = match argument_map.get(@~"rhs") {
@matched_seq(s, sp) => s,
_ => cx.span_bug(sp, ~"wrong-structured rhs")
};
let itr = cx.parse_sess().interner;
for lhses.eachi() |i, lhs| { // try each arm's matchers
- alt lhs {
+ match lhs {
@matched_nonterminal(nt_matchers(mtcs)) => {
// `none` is because we're not interpolating
let arg_rdr = new_tt_reader(s_d, itr, none, arg) as reader;
- alt parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) {
+ match parse(cx.parse_sess(), cx.cfg(), arg_rdr, mtcs) {
success(named_matches) => {
- let rhs = alt rhses[i] { // okay, what's your transcriber?
+ let rhs = match rhses[i] {
+ // okay, what's your transcriber?
@matched_nonterminal(nt_tt(@tt)) => tt,
_ => cx.span_bug(sp, ~"bad thing in rhs")
};
let r = @{sp_diag: sp_diag, interner: itr,
mut cur: @{readme: src, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::none)},
- interpolations: alt interp { /* just a convienience */
+ interpolations: match interp { /* just a convienience */
none => std::map::box_str_hash::<@named_match>(),
some(x) => x
},
pure fn dup_tt_frame(&&f: tt_frame) -> tt_frame {
@{readme: f.readme, mut idx: f.idx, dotdotdoted: f.dotdotdoted,
- sep: f.sep, up: alt f.up {
+ sep: f.sep, up: match f.up {
tt_frame_up(some(up_frame)) => {
tt_frame_up(some(dup_tt_frame(up_frame)))
}
pure fn lookup_cur_matched_by_matched(r: tt_reader,
start: @named_match) -> @named_match {
pure fn red(&&ad: @named_match, &&idx: uint) -> @named_match {
- alt *ad {
+ match *ad {
matched_nonterminal(_) => {
// end of the line; duplicate henceforth
ad
fn lockstep_iter_size(&&t: token_tree, &&r: tt_reader) -> lis {
fn lis_merge(lhs: lis, rhs: lis) -> lis {
- alt lhs {
+ match lhs {
lis_unconstrained => rhs,
lis_contradiction(_) => lhs,
- lis_constraint(l_len, l_id) => alt rhs {
+ lis_constraint(l_len, l_id) => match rhs {
lis_unconstrained => lhs,
lis_contradiction(_) => rhs,
lis_constraint(r_len, _) if l_len == r_len => lhs,
}
}
}
- alt t {
+ match t {
tt_delim(tts) | tt_seq(_, tts, _, _) => {
vec::foldl(lis_unconstrained, tts, {|lis, tt|
lis_merge(lis, lockstep_iter_size(tt, r)) })
}
tt_tok(*) => lis_unconstrained,
- tt_nonterminal(_, name) => alt *lookup_cur_matched(r, name) {
+ tt_nonterminal(_, name) => match *lookup_cur_matched(r, name) {
matched_nonterminal(_) => lis_unconstrained,
matched_seq(ads, _) => lis_constraint(ads.len(), name)
}
if ! r.cur.dotdotdoted
|| r.repeat_idx.last() == r.repeat_len.last() - 1 {
- alt r.cur.up {
+ match r.cur.up {
tt_frame_up(none) => {
r.cur_tok = EOF;
return ret_val;
} else { /* repeat */
r.cur.idx = 0u;
r.repeat_idx[r.repeat_idx.len() - 1u] += 1u;
- alt r.cur.sep {
+ match r.cur.sep {
some(tk) => {
r.cur_tok = tk; /* repeat same span, I guess */
return ret_val;
}
loop { /* because it's easiest, this handles `tt_delim` not starting
with a `tt_tok`, even though it won't happen */
- alt r.cur.readme[r.cur.idx] {
+ match r.cur.readme[r.cur.idx] {
tt_delim(tts) => {
r.cur = @{readme: tts, mut idx: 0u, dotdotdoted: false,
sep: none, up: tt_frame_up(option::some(r.cur)) };
return ret_val;
}
tt_seq(sp, tts, sep, zerok) => {
- alt lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) {
+ match lockstep_iter_size(tt_seq(sp, tts, sep, zerok), r) {
lis_unconstrained => {
r.sp_diag.span_fatal(
sp, /* blame macro writer */
}
// FIXME #2887: think about span stuff here
tt_nonterminal(sp, ident) => {
- alt *lookup_cur_matched(r, ident) {
+ match *lookup_cur_matched(r, ident) {
/* sidestep the interpolation tricks for ident because
(a) idents can be in lots of places, so it'd be a pain
(b) we actually can, since it's a token. */
//used in noop_fold_item and noop_fold_crate and noop_fold_crate_directive
fn fold_meta_item_(&&mi: @meta_item, fld: ast_fold) -> @meta_item {
return @{node:
- alt mi.node {
+ match mi.node {
meta_word(id) => meta_word(fld.fold_ident(id)),
meta_list(id, mis) => {
let fold_meta_item = |x|fold_meta_item_(x, fld);
//used in noop_fold_expr, and possibly elsewhere in the future
fn fold_mac_(m: mac, fld: ast_fold) -> mac {
return {node:
- alt m.node {
+ match m.node {
mac_invoc(pth, arg, body) => {
mac_invoc(fld.fold_path(pth),
option::map(arg, |x| fld.fold_expr(x)), body)
}
fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
- alt tpb {
+ match tpb {
bound_copy | bound_send | bound_const | bound_owned => tpb,
bound_trait(ty) => bound_trait(fld.fold_ty(ty))
}
fn noop_fold_crate_directive(cd: crate_directive_, fld: ast_fold) ->
crate_directive_ {
- return alt cd {
+ return match cd {
cdir_src_mod(id, attrs) => {
cdir_src_mod(fld.fold_ident(id), /* FIXME (#2543) */ copy attrs)
}
return @{ident: fld.fold_ident(ni.ident),
attrs: vec::map(ni.attrs, fold_attribute),
node:
- alt ni.node {
+ match ni.node {
foreign_item_fn(fdec, typms) => {
foreign_item_fn({inputs: vec::map(fdec.inputs, fold_arg),
output: fld.fold_ty(fdec.output),
fn noop_fold_class_item(&&ci: @class_member, fld: ast_fold)
-> @class_member {
- @{node: alt ci.node {
+ @{node: match ci.node {
instance_var(ident, t, cm, id, p) => {
instance_var(/* FIXME (#2543) */ copy ident,
fld.fold_ty(t), cm, id, p)
}
fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
- return alt i {
+ return match i {
item_const(t, e) => item_const(fld.fold_ty(t), fld.fold_expr(e)),
item_fn(decl, typms, body) => {
item_fn(fold_fn_decl(decl, fld),
}
item_class(typms, traits, items, m_ctor, m_dtor) => {
let resulting_optional_constructor;
- alt m_ctor {
+ match m_ctor {
none => {
resulting_optional_constructor = none;
}
}
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
- return alt s {
+ return match s {
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid))
}
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
- return alt p {
+ return match p {
pat_wild => pat_wild,
pat_ident(binding_mode, pth, sub) => {
pat_ident(binding_mode,
}
fn noop_fold_decl(d: decl_, fld: ast_fold) -> decl_ {
- alt d {
+ match d {
decl_local(ls) => decl_local(vec::map(ls, |x| fld.fold_local(x))),
- decl_item(it) => alt fld.fold_item(it) {
+ decl_item(it) => match fld.fold_item(it) {
some(it_folded) => decl_item(it_folded),
none => decl_local(~[])
}
let fold_mac = |x| fold_mac_(x, fld);
- return alt e {
+ return match e {
expr_vstore(e, v) => {
expr_vstore(fld.fold_expr(e), v)
}
mt: fold_mt(f.node.mt, fld)},
span: fld.new_span(f.span)}
}
- alt t {
+ match t {
ty_nil | ty_bot | ty_infer => copy t,
ty_box(mt) => ty_box(fold_mt(mt, fld)),
ty_uniq(mt) => ty_uniq(fold_mt(mt, fld)),
let fold_attribute = |x| fold_attribute_(x, fld);
let attrs = vec::map(v.attrs, fold_attribute);
- let de = alt v.disr_expr {
+ let de = match v.disr_expr {
some(e) => some(fld.fold_expr(e)),
none => none
};
ty: fld.fold_ty(l.ty),
pat: fld.fold_pat(l.pat),
init:
- alt l.init {
+ match l.init {
option::none::<initializer> => l.init,
option::some::<initializer>(init) => {
option::some::<initializer>({op: init.op,
return self.fold_item(i, self as ast_fold);
}
fn fold_class_item(&&ci: @class_member) -> @class_member {
- @{node: alt ci.node {
+ @{node: match ci.node {
instance_var(nm, t, mt, id, p) => {
instance_var(/* FIXME (#2543) */ copy nm,
(self as ast_fold).fold_ty(t), mt, id, p)
+path: ~str, ftype: parser::file_type) ->
(parser, string_reader) {
let res = io::read_whole_file_str(path);
- alt res {
+ match res {
result::ok(_) => { /* Continue. */ }
result::err(e) => sess.span_diagnostic.handler().fatal(e)
}
-> attr_or_ext
{
let expect_item_next = vec::is_not_empty(first_item_attrs);
- alt self.token {
+ match self.token {
token::POUND => {
let lo = self.span.lo;
if self.look_ahead(1u) == token::LBRACKET {
fn parse_outer_attributes() -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[];
loop {
- alt copy self.token {
+ match copy self.token {
token::POUND => {
if self.look_ahead(1u) != token::LBRACKET {
break;
let mut inner_attrs: ~[ast::attribute] = ~[];
let mut next_outer_attrs: ~[ast::attribute] = ~[];
loop {
- alt copy self.token {
+ match copy self.token {
token::POUND => {
if self.look_ahead(1u) != token::LBRACKET {
// This is an extension
fn parse_meta_item() -> @ast::meta_item {
let lo = self.span.lo;
let ident = self.parse_ident();
- alt self.token {
+ match self.token {
token::EQ => {
self.bump();
let lit = self.parse_lit();
}
fn parse_optional_meta() -> ~[@ast::meta_item] {
- alt self.token {
+ match self.token {
token::LPAREN => return self.parse_meta_seq(),
_ => return ~[]
}
import ast_util::operator_prec;
fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
- alt e.node {
+ match e.node {
ast::expr_if(_, _, _) | ast::expr_alt(_, _, _) | ast::expr_block(_)
| ast::expr_while(_, _) | ast::expr_loop(_)
| ast::expr_call(_, _, true) => false,
}
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
- alt stmt.node {
+ match stmt.node {
ast::stmt_decl(d, _) => {
- return alt d.node {
+ return match d.node {
ast::decl_local(_) => true,
ast::decl_item(_) => false
}
}
fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool {
- alt expr.node {
+ match expr.node {
ast::expr_binary(op, _, _) => operator_prec(op) < outer_prec,
ast::expr_cast(_, _) => parse::prec::as_prec < outer_prec,
// This may be too conservative in some cases
}
fn ends_in_lit_int(ex: @ast::expr) -> bool {
- alt ex.node {
- ast::expr_lit(node) => alt node {
+ match ex.node {
+ ast::expr_lit(node) => match node {
@{node: ast::lit_int(_, ast::ty_i), _}
| @{node: ast::lit_int_unsuffixed(_), _} => true,
_ => false
ast::expr_log(_, _, sub) | ast::expr_assert(sub) => {
ends_in_lit_int(sub)
}
- ast::expr_fail(osub) | ast::expr_ret(osub) => alt osub {
+ ast::expr_fail(osub) | ast::expr_ret(osub) => match osub {
some(ex) => ends_in_lit_int(ex),
_ => false
}
}
fn parse_ident() -> ast::ident {
- alt copy self.token {
+ match copy self.token {
token::IDENT(i, _) => { self.bump(); return self.get_str(i); }
token::INTERPOLATED(token::nt_ident(*)) => { self.bug(
~"ident interpolation not converted to real token"); }
}
fn token_is_word(word: ~str, ++tok: token::token) -> bool {
- alt tok {
+ match tok {
token::IDENT(sid, false) => { word == *self.get_str(sid) }
_ => { false }
}
}
fn is_any_keyword(tok: token::token) -> bool {
- alt tok {
+ match tok {
token::IDENT(sid, false) => {
self.keywords.contains_key_ref(self.get_str(sid))
}
self.require_keyword(word);
let mut bump = false;
- let val = alt self.token {
+ let val = match self.token {
token::IDENT(sid, false) => {
if word == *self.get_str(sid) {
bump = true;
}
fn check_restricted_keywords() {
- alt self.token {
+ match self.token {
token::IDENT(_, false) => {
let w = token_to_str(self.reader, self.token);
self.check_restricted_keywords_(w);
let mut v = ~[];
while self.token != token::GT
&& self.token != token::BINOP(token::SHR) {
- alt sep {
+ match sep {
some(t) => {
if first { first = false; }
else { self.expect(t); }
let mut first: bool = true;
let mut v: ~[T] = ~[];
while self.token != ket {
- alt sep.sep {
+ match sep.sep {
some(t) => {
if first { first = false; }
else { self.expect(t); }
-> (~[@ast::view_item], ~[@ast::item], ~[ast::attribute]) {
fn companion_file(+prefix: ~str, suffix: option<~str>) -> ~str {
- return alt suffix {
+ return match suffix {
option::some(s) => path::connect(prefix, s),
option::none => prefix
} + ~".rs";
fn file_exists(path: ~str) -> bool {
// Crude, but there's no lib function for this and I'm not
// up to writing it just now
- alt io::file_reader(path) {
+ match io::file_reader(path) {
result::ok(_) => true,
result::err(_) => false
}
}
fn cdir_path_opt(id: ast::ident, attrs: ~[ast::attribute]) -> @~str {
- alt ::attr::first_attr_value_str_by_name(attrs, ~"path") {
+ match ::attr::first_attr_value_str_by_name(attrs, ~"path") {
some(d) => return d,
none => return id
}
fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: ~str,
&view_items: ~[@ast::view_item],
&items: ~[@ast::item]) {
- alt cdir.node {
+ match cdir.node {
ast::cdir_src_mod(id, attrs) => {
let file_path = cdir_path_opt(@(*id + ~".rs"), attrs);
let full_path =
fn consume_any_line_comment(rdr: string_reader)
-> option<{tok: token::token, sp: span}> {
if rdr.curr == '/' {
- alt nextch(rdr) {
+ match nextch(rdr) {
'/' => {
bump(rdr);
bump(rdr);
loop {
let c = rdr.curr;
if c == '_' { bump(rdr); again; }
- alt char::to_digit(c, radix) {
+ match char::to_digit(c, radix) {
some(d) => {
str::push_char(rslt, c);
bump(rdr);
rdr.fatal(~"no valid digits found for number");
}
let parsed = option::get(u64::from_str_radix(num_str, base as u64));
- alt tp {
+ match tp {
either::left(t) => return token::LIT_INT(parsed as i64, t),
either::right(t) => return token::LIT_UINT(parsed, t)
}
let dec_part = scan_digits(rdr, 10u);
num_str += ~"." + dec_part;
}
- alt scan_exponent(rdr) {
+ match scan_exponent(rdr) {
some(s) => {
is_float = true;
num_str += s;
return token::BINOPEQ(op);
} else { return token::BINOP(op); }
}
- alt c {
+ match c {
}
'<' => {
bump(rdr);
- alt rdr.curr {
+ match rdr.curr {
'=' => { bump(rdr); return token::LE; }
'<' => { return binop(rdr, token::SHL); }
'-' => {
bump(rdr);
- alt rdr.curr {
+ match rdr.curr {
'>' => { bump(rdr); return token::DARROW; }
_ => { return token::LARROW; }
}
}
'>' => {
bump(rdr);
- alt rdr.curr {
+ match rdr.curr {
'=' => { bump(rdr); return token::GE; }
'>' => { return binop(rdr, token::SHR); }
_ => { return token::GT; }
if c2 == '\\' {
let escaped = rdr.curr;
bump(rdr);
- alt escaped {
+ match escaped {
'n' => { c2 = '\n'; }
'r' => { c2 = '\r'; }
't' => { c2 = '\t'; }
let ch = rdr.curr;
bump(rdr);
- alt ch {
+ match ch {
'\\' => {
let escaped = rdr.curr;
bump(rdr);
- alt escaped {
+ match escaped {
'n' => str::push_char(accum_str, '\n'),
'r' => str::push_char(accum_str, '\r'),
't' => str::push_char(accum_str, '\t'),
} else { return binop(rdr, token::AND); }
}
'|' => {
- alt nextch(rdr) {
+ match nextch(rdr) {
'|' => { bump(rdr); bump(rdr); return token::OROR; }
_ => { return binop(rdr, token::OR); }
}
The important thing is to make sure that lookahead doesn't balk
at INTERPOLATED tokens */
macro_rules! maybe_whole_expr {
- {$p:expr} => { alt copy $p.token {
+ {$p:expr} => { match copy $p.token {
INTERPOLATED(token::nt_expr(e)) => {
$p.bump();
return pexpr(e);
}
macro_rules! maybe_whole {
- {$p:expr, $constructor:ident} => { alt copy $p.token {
+ {$p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return x; }
_ => ()
}} ;
- {deref $p:expr, $constructor:ident} => { alt copy $p.token {
+ {deref $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return *x; }
_ => ()
}} ;
- {some $p:expr, $constructor:ident} => { alt copy $p.token {
+ {some $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return some(x); }
_ => ()
}} ;
- {pair_empty $p:expr, $constructor:ident} => { alt copy $p.token {
+ {pair_empty $p:expr, $constructor:ident} => { match copy $p.token {
INTERPOLATED(token::$constructor(x)) => { $p.bump(); return (~[], x); }
_ => ()
}}
debug!{"parse_trait_methods(): trait method signature ends in \
`%s`",
token_to_str(p.reader, p.token)};
- alt p.token {
+ match p.token {
token::SEMI => {
p.bump();
debug!{"parse_trait_methods(): parsing required method"};
}
fn region_from_name(s: option<@~str>) -> @region {
- let r = alt s {
+ let r = match s {
some (string) => re_named(string),
none => re_anon
};
fn parse_region() -> @region {
self.expect(token::BINOP(token::AND));
- alt copy self.token {
+ match copy self.token {
token::IDENT(sid, _) => {
self.bump();
let n = self.get_str(sid);
// Parses something like "&x/" (note the trailing slash)
fn parse_region_with_sep() -> @region {
let name =
- alt copy self.token {
+ match copy self.token {
token::IDENT(sid, _) => {
if self.look_ahead(1u) == token::BINOP(token::SLASH) {
self.bump(); self.bump();
let lo = self.span.lo;
- alt self.maybe_parse_dollar_mac() {
+ match self.maybe_parse_dollar_mac() {
some(e) => {
return @{id: self.get_id(),
node: ty_mac(spanned(lo, self.span.hi, e)),
let sp = mk_sp(lo, self.last_span.hi);
return @{id: self.get_id(),
- node: alt self.maybe_parse_fixed_vstore() {
+ node: match self.maybe_parse_fixed_vstore() {
// Consider a fixed vstore suffix (/N or /_)
none => t,
some(v) => {
}
fn maybe_parse_dollar_mac() -> option<mac_> {
- alt copy self.token {
+ match copy self.token {
token::DOLLAR => {
let lo = self.span.lo;
self.bump();
- alt copy self.token {
+ match copy self.token {
token::LIT_INT_UNSUFFIXED(num) => {
self.bump();
some(mac_var(num as uint))
fn maybe_parse_fixed_vstore() -> option<option<uint>> {
if self.token == token::BINOP(token::SLASH) {
self.bump();
- alt copy self.token {
+ match copy self.token {
token::UNDERSCORE => {
self.bump(); some(none)
}
}
fn lit_from_token(tok: token::token) -> lit_ {
- alt tok {
+ match tok {
token::LIT_INT(i, it) => lit_int(i, it),
token::LIT_UINT(u, ut) => lit_uint(u, ut),
token::LIT_INT_UNSUFFIXED(i) => lit_int_unsuffixed(i),
}
fn to_expr(e: pexpr) -> @expr {
- alt e.node {
+ match e.node {
expr_tup(es) if vec::len(es) == 1u => es[0u],
_ => *e
}
let mut ex: expr_;
- alt self.maybe_parse_dollar_mac() {
+ match self.maybe_parse_dollar_mac() {
some(x) => return pexpr(self.mk_mac_expr(lo, self.span.hi, x)),
_ => ()
}
return pexpr(self.parse_while_expr());
} else if self.eat_keyword(~"loop") {
return pexpr(self.parse_loop_expr());
- } else if self.eat_keyword(~"alt") || self.eat_keyword(~"match") {
+ } else if self.eat_keyword(~"match") {
return pexpr(self.parse_alt_expr());
} else if self.eat_keyword(~"fn") {
let proto = self.parse_fn_ty_proto();
- alt proto {
+ match proto {
proto_bare => self.fatal(~"fn expr are deprecated, use fn@"),
_ => { /* fallthrough */ }
}
/* `!`, as an operator, is prefix, so we know this isn't that */
if self.token == token::NOT {
self.bump();
- let tts = alt self.token {
+ let tts = match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket,
// Vstore is legal following expr_lit(lit_str(...)) and expr_vec(...)
// only.
- alt ex {
+ match ex {
expr_lit(@{node: lit_str(_), span: _}) |
- expr_vec(_, _) => alt self.maybe_parse_fixed_vstore() {
+ expr_vec(_, _) => match self.maybe_parse_fixed_vstore() {
none => (),
some(v) => {
hi = self.span.hi;
}
fn parse_syntax_ext_naked(lo: uint) -> @expr {
- alt self.token {
+ match self.token {
token::IDENT(_, _) => (),
_ => self.fatal(~"expected a syntax expander name")
}
let lo = self.span.lo;
let mut depth = 1u;
while (depth > 0u) {
- alt (self.token) {
+ match (self.token) {
token::LBRACE => depth += 1u,
token::RBRACE => depth -= 1u,
token::EOF => self.fatal(~"unexpected EOF in macro body"),
loop {
// expr.f
if self.eat(token::DOT) {
- alt copy self.token {
+ match copy self.token {
token::IDENT(i, _) => {
hi = self.span.hi;
self.bump();
again;
}
if self.expr_is_complete(e) { break; }
- alt copy self.token {
+ match copy self.token {
// expr(...)
token::LPAREN if self.permits_call() => {
let es = self.parse_unspanned_seq(
maybe_whole!{deref self, nt_tt};
fn parse_tt_tok(p: parser, delim_ok: bool) -> token_tree {
- alt p.token {
+ match p.token {
token::RPAREN | token::RBRACE | token::RBRACKET
if !delim_ok => {
p.fatal(~"incorrect close delimiter: `"
return res;
}
- return alt self.token {
+ return match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
tt_delim(vec::append(
// the interpolation of matchers
maybe_whole!{self, nt_matchers};
let name_idx = @mut 0u;
- return alt self.token {
+ return match self.token {
token::LBRACE | token::LPAREN | token::LBRACKET => {
self.parse_matcher_subseq(name_idx, copy self.token,
token::flip_delimiter(self.token))
let mut hi;
let mut ex;
- alt copy self.token {
+ match copy self.token {
token::NOT => {
self.bump();
let e = self.to_expr(self.parse_prefix_expr());
ex = expr_unary(not, e);
}
token::BINOP(b) => {
- alt b {
+ match b {
token::MINUS => {
self.bump();
let e = self.to_expr(self.parse_prefix_expr());
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
// HACK: turn &[...] into a &-evec
- ex = alt e.node {
+ ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => {
expr_vstore(e, vstore_slice(self.region_from_name(none)))
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
// HACK: turn @[...] into a @-evec
- ex = alt e.node {
+ ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, vstore_box),
_ => expr_unary(box(m), e)
let e = self.to_expr(self.parse_prefix_expr());
hi = e.span.hi;
// HACK: turn ~[...] into a ~-evec
- ex = alt e.node {
+ ex = match e.node {
expr_vec(*) | expr_lit(@{node: lit_str(_), span: _})
if m == m_imm => expr_vstore(e, vstore_uniq),
_ => expr_unary(uniq(m), e)
return lhs;
}
let cur_opt = token_to_binop(peeked);
- alt cur_opt {
+ match cur_opt {
some(cur_op) => {
let cur_prec = operator_prec(cur_op);
if cur_prec > min_prec {
fn parse_assign_expr() -> @expr {
let lo = self.span.lo;
let lhs = self.parse_binops();
- alt copy self.token {
+ match copy self.token {
token::EQ => {
self.bump();
let rhs = self.parse_expr();
self.bump();
let rhs = self.parse_expr();
let mut aop;
- alt op {
+ match op {
token::PLUS => aop = add,
token::MINUS => aop = subtract,
token::STAR => aop = mul,
fn parse_lambda_block_expr() -> @expr {
self.parse_lambda_expr_(
|| {
- alt self.token {
+ match self.token {
token::BINOP(token::OR) | token::OROR => {
self.parse_fn_block_decl()
}
// Turn on the restriction to stop at | or || so we can parse
// them as the lambda arguments
let e = self.parse_expr_res(RESTRICT_NO_BAR_OR_DOUBLEBAR_OP);
- alt e.node {
+ match e.node {
expr_call(f, args, false) => {
let block = self.parse_lambda_block_expr();
let last_arg = self.mk_expr(block.span.lo, block.span.hi,
}
fn parse_initializer() -> option<initializer> {
- alt self.token {
+ match self.token {
token::EQ => {
self.bump();
return some({op: init_assign, expr: self.parse_expr()});
let lo = self.span.lo;
let mut hi = self.span.hi;
let mut pat;
- alt self.token {
+ match self.token {
token::UNDERSCORE => { self.bump(); pat = pat_wild; }
token::AT => {
self.bump();
let sub = self.parse_pat(refutable);
hi = sub.span.hi;
// HACK: parse @"..." as a literal of a vstore @str
- pat = alt sub.node {
+ pat = match sub.node {
pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _
}) => {
let sub = self.parse_pat(refutable);
hi = sub.span.hi;
// HACK: parse ~"..." as a literal of a vstore ~str
- pat = alt sub.node {
+ pat = match sub.node {
pat_lit(e@@{
node: expr_lit(@{node: lit_str(_), span: _}), _
}) => {
}
if is_plain_ident(self.token) &&
- alt self.look_ahead(1) {
+ match self.look_ahead(1) {
token::LPAREN | token::LBRACKET | token::LT => {
false
}
hi = enum_path.span.hi;
let mut args: ~[@pat] = ~[];
let mut star_pat = false;
- alt self.token {
- token::LPAREN => alt self.look_ahead(1u) {
+ match self.token {
+ token::LPAREN => match self.look_ahead(1u) {
token::BINOP(token::STAR) => {
// This is a "top constructor only" pat
self.bump(); self.bump();
return @spanned(lo, decl.span.hi, stmt_decl(decl, self.get_id()));
} else {
let mut item_attrs;
- alt self.parse_outer_attrs_or_ext(first_item_attrs) {
+ match self.parse_outer_attrs_or_ext(first_item_attrs) {
none => item_attrs = ~[],
some(left(attrs)) => item_attrs = attrs,
some(right(ext)) => {
let item_attrs = vec::append(first_item_attrs, item_attrs);
- alt self.parse_item(item_attrs) {
+ match self.parse_item(item_attrs) {
some(i) => {
let mut hi = i.span.hi;
let decl = @spanned(lo, hi, decl_item(i));
}
while self.token != token::RBRACE {
- alt self.token {
+ match self.token {
token::SEMI => {
self.bump(); // empty
}
_ => {
let stmt = self.parse_stmt(initial_attrs);
initial_attrs = ~[];
- alt stmt.node {
+ match stmt.node {
stmt_expr(e, stmt_id) => { // Expression without semicolon:
- alt self.token {
+ match self.token {
token::SEMI => {
self.bump();
push(stmts,
}
fn is_self_ident() -> bool {
- alt self.token {
+ match self.token {
token::IDENT(sid, false) if ~"self" == *self.get_str(sid) => true,
_ => false
}
// backwards compatible.
let lo = self.span.lo;
let self_ty;
- alt copy self.token {
+ match copy self.token {
token::BINOP(token::AND) => {
// We need to make sure it isn't a mode.
self.bump();
// Parse an explicit region, if possible.
let region_name;
- alt copy self.token {
+ match copy self.token {
token::BINOP(token::SLASH) => {
self.bump();
- alt copy self.token {
+ match copy self.token {
token::IDENT(sid, false) => {
self.bump();
region_name = some(self.get_str(sid));
// If we parsed a self type, expect a comma before the argument list.
let args_or_capture_items;
if self_ty != sty_by_ref {
- alt copy self.token {
+ match copy self.token {
token::COMMA => {
self.bump();
let sep = seq_sep_trailing_disallowed(token::COMMA);
}
fn parse_method_name() -> ident {
- alt copy self.token {
+ match copy self.token {
token::BINOP(op) => { self.bump(); @token::binop_to_str(op) }
token::NOT => { self.bump(); @~"!" }
token::LBRACKET => {
} else {
traits = ~[];
};
- ident = alt ident_old {
+ ident = match ident_old {
some(name) => name,
none => { self.expect_keyword(~"of"); fail; }
};
codemap::span)> = none;
let mut the_dtor : option<(blk, ~[attribute], codemap::span)> = none;
while self.token != token::RBRACE {
- alt self.parse_class_item(class_path) {
+ match self.parse_class_item(class_path) {
ctor_decl(a_fn_decl, attrs, blk, s) => {
the_ctor = some((a_fn_decl, attrs, blk, s));
}
body: d_body},
span: d_s}};
self.bump();
- alt the_ctor {
+ match the_ctor {
some((ct_d, ct_attrs, ct_b, ct_s)) => {
(class_name,
item_class(ty_params, traits, ms, some({
}
fn token_is_pound_or_doc_comment(++tok: token::token) -> bool {
- alt tok {
+ match tok {
token::POUND | token::DOC_COMMENT(_) => true,
_ => false
}
first = false;
}
debug!{"parse_mod_items: parse_item(attrs=%?)", attrs};
- alt self.parse_item(attrs) {
+ match self.parse_item(attrs) {
some(i) => vec::push(items, i),
_ => {
self.fatal(~"expected item but found `" +
}
fn parse_fn_ty_proto() -> proto {
- alt self.token {
+ match self.token {
token::AT => {
self.bump();
proto_box
}
fn fn_expr_lookahead(tok: token::token) -> bool {
- alt tok {
+ match tok {
token::LPAREN | token::AT | token::TILDE | token::BINOP(_) => true,
_ => false
}
let pth = self.parse_path_without_tps();
self.expect(token::NOT);
let id = self.parse_ident();
- let tts = alt self.token {
+ let tts = match self.token {
token::LPAREN | token::LBRACE | token::LBRACKET => {
let ket = token::flip_delimiter(self.token);
self.parse_unspanned_seq(copy self.token, ket,
(id, item_mac(m), none)
} else { return none; };
some(self.mk_item(lo, self.last_span.hi, ident, item_, visibility,
- alt extra_attrs {
+ match extra_attrs {
some(as) => vec::append(attrs, as),
none => attrs
}))
let first_ident = self.parse_ident();
let mut path = ~[first_ident];
debug!{"parsed view_path: %s", *first_ident};
- alt self.token {
+ match self.token {
token::EQ => {
// x = foo::bar
self.bump();
while self.token == token::MOD_SEP {
self.bump();
- alt copy self.token {
+ match copy self.token {
token::IDENT(i, _) => {
self.bump();
}
fn parse_str() -> @~str {
- alt copy self.token {
+ match copy self.token {
token::LIT_STR(s) => { self.bump(); self.get_str(s) }
_ => self.fatal(~"expected string literal")
}
self.expect_keyword(~"module");
}
let id = self.parse_ident();
- alt self.token {
+ match self.token {
// mod x = "foo.rs";
token::SEMI => {
let mut hi = self.span.hi;
* operator and its precedence
*/
fn token_to_binop(tok: token) -> option<ast::binop> {
- alt tok {
+ match tok {
BINOP(STAR) => some(mul),
BINOP(SLASH) => some(div),
BINOP(PERCENT) => some(rem),
}
fn binop_to_str(o: binop) -> ~str {
- alt o {
+ match o {
PLUS => ~"+",
MINUS => ~"-",
STAR => ~"*",
}
fn to_str(in: interner<@~str>, t: token) -> ~str {
- alt t {
+ match t {
EQ => ~"=",
LT => ~"<",
LE => ~"<=",
EOF => ~"<eof>",
INTERPOLATED(nt) => {
~"an interpolated " +
- alt nt {
+ match nt {
nt_item(*) => ~"item",
nt_block(*) => ~"block",
nt_stmt(*) => ~"statement",
}
pure fn can_begin_expr(t: token) -> bool {
- alt t {
+ match t {
LPAREN => true,
LBRACE => true,
LBRACKET => true,
/// what's the opposite delimiter?
fn flip_delimiter(&t: token::token) -> token::token {
- alt t {
+ match t {
token::LPAREN => token::RPAREN,
token::LBRACE => token::RBRACE,
token::LBRACKET => token::RBRACKET,
fn is_lit(t: token) -> bool {
- alt t {
+ match t {
LIT_INT(_, _) => true,
LIT_UINT(_, _) => true,
LIT_INT_UNSUFFIXED(_) => true,
}
pure fn is_ident(t: token) -> bool {
- alt t { IDENT(_, _) => true, _ => false }
+ match t { IDENT(_, _) => true, _ => false }
}
pure fn is_ident_or_path(t: token) -> bool {
- alt t {
+ match t {
IDENT(_, _) | INTERPOLATED(nt_path(*)) => true,
_ => false
}
}
pure fn is_plain_ident(t: token) -> bool {
- alt t { IDENT(_, false) => true, _ => false }
+ match t { IDENT(_, false) => true, _ => false }
}
pure fn is_bar(t: token) -> bool {
- alt t { BINOP(OR) | OROR => true, _ => false }
+ match t { BINOP(OR) | OROR => true, _ => false }
}
/**
fn restricted_keyword_table() -> hashmap<~str, ()> {
let words = str_hash();
let keys = ~[
- ~"alt", ~"again", ~"assert",
+ ~"again", ~"assert",
~"break",
~"check", ~"class", ~"const", ~"copy",
~"do", ~"drop",
enum token { STRING(@~str, int), BREAK(break_t), BEGIN(begin_t), END, EOF, }
fn tok_str(++t: token) -> ~str {
- alt t {
+ match t {
STRING(s, len) => return fmt!{"STR(%s,%d)", *s, len},
BREAK(_) => return ~"BREAK",
BEGIN(_) => return ~"BEGIN",
fn replace_last_token(t: token) { self.token[self.right] = t; }
fn pretty_print(t: token) {
debug!{"pp ~[%u,%u]", self.left, self.right};
- alt t {
+ match t {
EOF => {
if !self.scan_stack_empty {
self.check_stack(0);
self.left, L};
if L >= 0 {
self.print(x, L);
- alt x {
+ match x {
BREAK(b) => self.left_total += b.blank_space,
STRING(_, len) => { assert (len == L); self.left_total += len; }
_ => ()
fn check_stack(k: int) {
if !self.scan_stack_empty {
let x = self.scan_top();
- alt copy self.token[x] {
+ match copy self.token[x] {
BEGIN(b) => {
if k > 0 {
self.size[self.scan_pop()] = self.size[x] +
debug!{"print %s %d (remaining line space=%d)", tok_str(x), L,
self.space};
log(debug, buf_str(self.token, self.size, self.left, self.right, 6u));
- alt x {
+ match x {
BEGIN(b) => {
if L > self.space {
let col = self.margin - self.space + b.offset;
}
BREAK(b) => {
let top = self.get_top();
- alt top.pbreak {
+ match top.pbreak {
fits => {
debug!{"print BREAK in fitting block"};
self.space -= b.blank_space;
fn bclose(s: ps, span: codemap::span) { bclose_(s, span, indent_unit); }
fn is_begin(s: ps) -> bool {
- alt s.s.last_token() { pp::BEGIN(_) => true, _ => false }
+ match s.s.last_token() { pp::BEGIN(_) => true, _ => false }
}
fn is_end(s: ps) -> bool {
- alt s.s.last_token() { pp::END => true, _ => false }
+ match s.s.last_token() { pp::END => true, _ => false }
}
fn is_bol(s: ps) -> bool {
}
fn print_region(s: ps, region: @ast::region) {
- alt region.node {
+ match region.node {
ast::re_anon => word_space(s, ~"&"),
ast::re_named(name) => {
word(s.s, ~"&");
fn print_type_ex(s: ps, &&ty: @ast::ty, print_colons: bool) {
maybe_print_comment(s, ty.span.lo);
ibox(s, 0u);
- alt ty.node {
+ match ty.node {
ast::ty_nil => word(s.s, ~"()"),
ast::ty_bot => word(s.s, ~"!"),
ast::ty_box(mt) => { word(s.s, ~"@"); print_mt(s, mt); }
ast::ty_uniq(mt) => { word(s.s, ~"~"); print_mt(s, mt); }
ast::ty_vec(mt) => {
word(s.s, ~"[");
- alt mt.mutbl {
+ match mt.mutbl {
ast::m_mutbl => word_space(s, ~"mut"),
ast::m_const => word_space(s, ~"const"),
ast::m_imm => ()
}
ast::ty_ptr(mt) => { word(s.s, ~"*"); print_mt(s, mt); }
ast::ty_rptr(region, mt) => {
- alt region.node {
+ match region.node {
ast::re_anon => word(s.s, ~"&"),
_ => { print_region(s, region); word(s.s, ~"/"); }
}
hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
- alt item.node {
+ match item.node {
ast::foreign_item_fn(decl, typarams) => {
print_fn(s, decl, item.ident, typarams);
end(s); // end head-ibox
print_outer_attributes(s, item.attrs);
let ann_node = node_item(s, item);
s.ann.pre(ann_node);
- alt item.node {
+ match item.node {
ast::item_const(ty, expr) => {
head(s, ~"const");
word_space(s, *item.ident + ~":");
hardbreak_if_not_bol(s);
maybe_print_comment(s, ci.span.lo);
let pr = ast_util::class_member_visibility(ci);
- alt pr {
+ match pr {
ast::private => {
head(s, ~"priv");
bopen(s);
}
_ => ()
}
- alt ci.node {
+ match ci.node {
ast::instance_var(nm, t, mt, _,_) => {
word_nbsp(s, ~"let");
- alt mt {
+ match mt {
ast::class_mutable => word_nbsp(s, ~"mut"),
_ => ()
}
print_method(s, m);
}
}
- alt pr {
+ match pr {
ast::private => bclose(s, ci.span),
_ => ()
}
/// and then pretty-print the resulting AST nodes (so, e.g., we print
/// expression arguments as expressions). It can be done! I think.
fn print_tt(s: ps, tt: ast::token_tree) {
- alt tt {
+ match tt {
ast::tt_delim(tts) => for tts.each() |tt_elt| { print_tt(s, tt_elt); }
ast::tt_tok(_, tk) => {
- alt tk {
+ match tk {
parse::token::IDENT(*) => { // don't let idents run together
if s.s.token_tree_last_was_ident { word(s.s, ~" ") }
s.s.token_tree_last_was_ident = true;
word(s.s, ~"$(");
for tts.each() |tt_elt| { print_tt(s, tt_elt); }
word(s.s, ~")");
- alt sep {
+ match sep {
some(tk) => word(s.s, parse::token::to_str(*s.intr, tk)),
none => ()
}
commasep(s, consistent, v.node.args, print_variant_arg);
pclose(s);
}
- alt v.node.disr_expr {
+ match v.node.disr_expr {
some(d) => {
space(s.s);
word_space(s, ~"=");
}
fn print_trait_method(s: ps, m: ast::trait_method) {
- alt m {
+ match m {
required(ty_m) => print_ty_method(s, ty_m),
provided(m) => print_method(s, m)
}
fn print_outer_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0;
for attrs.each |attr| {
- alt attr.node.style {
+ match attr.node.style {
ast::attr_outer => { print_attribute(s, attr); count += 1; }
_ => {/* fallthrough */ }
}
fn print_inner_attributes(s: ps, attrs: ~[ast::attribute]) {
let mut count = 0;
for attrs.each |attr| {
- alt attr.node.style {
+ match attr.node.style {
ast::attr_inner => {
print_attribute(s, attr);
if !attr.node.is_sugared_doc {
fn print_stmt(s: ps, st: ast::stmt) {
maybe_print_comment(s, st.span.lo);
- alt st.node {
+ match st.node {
ast::stmt_decl(decl, _) => {
print_decl(s, decl);
}
fn print_possibly_embedded_block_(s: ps, blk: ast::blk, embedded: embed_type,
indented: uint, attrs: ~[ast::attribute]) {
- alt blk.node.rules {
+ match blk.node.rules {
ast::unchecked_blk => word(s.s, ~"unchecked"),
ast::unsafe_blk => word(s.s, ~"unsafe"),
ast::default_blk => ()
maybe_print_comment(s, blk.span.lo);
let ann_node = node_block(s, blk);
s.ann.pre(ann_node);
- alt embedded {
+ match embedded {
block_block_fn => end(s),
block_normal => bopen(s)
}
for blk.node.stmts.each |st| {
print_stmt(s, *st);
}
- alt blk.node.expr {
+ match blk.node.expr {
some(expr) => {
space_if_not_bol(s);
print_expr(s, expr);
// return and fail, without arguments cannot appear is the discriminant of if,
// alt, do, & while unambiguously without being parenthesized
fn print_maybe_parens_discrim(s: ps, e: @ast::expr) {
- let disambig = alt e.node {
+ let disambig = match e.node {
ast::expr_ret(none) | ast::expr_fail(none) => true,
_ => false
};
space(s.s);
print_block(s, blk);
fn do_else(s: ps, els: option<@ast::expr>) {
- alt els {
+ match els {
some(_else) => {
- alt _else.node {
+ match _else.node {
// "another else-if"
ast::expr_if(i, t, e) => {
cbox(s, indent_unit - 1u);
}
fn print_mac(s: ps, m: ast::mac) {
- alt m.node {
+ match m.node {
ast::mac_invoc(path, arg, body) => {
word(s.s, ~"#");
print_path(s, path, false);
- alt arg {
+ match arg {
some(@{node: ast::expr_vec(_, _), _}) => (),
_ => word(s.s, ~" ")
}
}
fn print_vstore(s: ps, t: ast::vstore) {
- alt t {
+ match t {
ast::vstore_fixed(some(i)) => word(s.s, fmt!{"%u", i}),
ast::vstore_fixed(none) => word(s.s, ~"_"),
ast::vstore_uniq => word(s.s, ~"~"),
ast::vstore_box => word(s.s, ~"@"),
- ast::vstore_slice(r) => alt r.node {
+ ast::vstore_slice(r) => match r.node {
ast::re_anon => word(s.s, ~"&"),
ast::re_named(name) => {
word(s.s, ~"&");
ibox(s, indent_unit);
let ann_node = node_expr(s, expr);
s.ann.pre(ann_node);
- alt expr.node {
- ast::expr_vstore(e, v) => alt v {
+ match expr.node {
+ ast::expr_vstore(e, v) => match v {
ast::vstore_fixed(_) => {
print_expr(s, e);
word(s.s, ~"/");
ast::expr_rec(fields, wth) => {
word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span);
- alt wth {
+ match wth {
some(expr) => {
if vec::len(fields) > 0u { space(s.s); }
ibox(s, indent_unit);
print_path(s, path, true);
word(s.s, ~"{");
commasep_cmnt(s, consistent, fields, print_field, get_span);
- alt wth {
+ match wth {
some(expr) => {
if vec::len(fields) > 0u { space(s.s); }
ibox(s, indent_unit);
let mut base_args = args;
let blk = if has_block {
let blk_arg = vec::pop(base_args);
- alt blk_arg.node {
+ match blk_arg.node {
ast::expr_loop_body(_) => word_nbsp(s, ~"for"),
ast::expr_do_body(_) => word_nbsp(s, ~"do"),
_ => ()
ast::expr_alt(expr, arms, mode) => {
cbox(s, alt_indent_unit);
ibox(s, 4u);
- word_nbsp(s, ~"alt");
+ word_nbsp(s, ~"match");
if mode == ast::alt_check { word_nbsp(s, ~"check"); }
print_maybe_parens_discrim(s, expr);
space(s.s);
print_pat(s, p);
}
space(s.s);
- alt arm.guard {
+ match arm.guard {
some(e) => {
word_space(s, ~"if");
print_expr(s, e);
assert arm.body.node.view_items.is_empty();
assert arm.body.node.stmts.is_empty();
assert arm.body.node.rules == ast::default_blk;
- alt arm.body.node.expr {
+ match arm.body.node.expr {
some(expr) => {
end(s); // close the ibox for the pattern
print_expr(s, expr);
ast::expr_path(path) => print_path(s, path, true),
ast::expr_fail(maybe_fail_val) => {
word(s.s, ~"fail");
- alt maybe_fail_val {
+ match maybe_fail_val {
some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
_ => ()
}
ast::expr_again => word(s.s, ~"again"),
ast::expr_ret(result) => {
word(s.s, ~"return");
- alt result {
+ match result {
some(expr) => { word(s.s, ~" "); print_expr(s, expr); }
_ => ()
}
}
ast::expr_log(lvl, lexp, expr) => {
- alt check lvl {
+ match check lvl {
1 => { word_nbsp(s, ~"log"); print_expr(s, expr); }
0 => { word_nbsp(s, ~"log_err"); print_expr(s, expr); }
2 => {
}
fn print_expr_parens_if_not_bot(s: ps, ex: @ast::expr) {
- let parens = alt ex.node {
+ let parens = match ex.node {
ast::expr_fail(_) | ast::expr_ret(_) |
ast::expr_binary(_, _, _) | ast::expr_unary(_, _) |
ast::expr_move(_, _) | ast::expr_copy(_) |
fn print_local_decl(s: ps, loc: @ast::local) {
print_pat(s, loc.node.pat);
- alt loc.node.ty.node {
+ match loc.node.ty.node {
ast::ty_infer => (),
_ => { word_space(s, ~":"); print_type(s, loc.node.ty); }
}
fn print_decl(s: ps, decl: @ast::decl) {
maybe_print_comment(s, decl.span.lo);
- alt decl.node {
+ match decl.node {
ast::decl_local(locs) => {
space_if_not_bol(s);
ibox(s, indent_unit);
ibox(s, indent_unit);
print_local_decl(s, loc);
end(s);
- alt loc.node.init {
+ match loc.node.init {
some(init) => {
nbsp(s);
- alt init.op {
+ match init.op {
ast::init_assign => word_space(s, ~"="),
ast::init_move => word_space(s, ~"<-")
}
if path.rp.is_some() || !path.types.is_empty() {
if colons_before_params { word(s.s, ~"::"); }
- alt path.rp {
+ match path.rp {
none => { /* ok */ }
some(r) => {
word(s.s, ~"/");
s.ann.pre(ann_node);
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
- alt pat.node {
+ match pat.node {
ast::pat_wild => word(s.s, ~"_"),
ast::pat_ident(binding_mode, path, sub) => {
- alt binding_mode {
+ match binding_mode {
ast::bind_by_ref => word_space(s, ~"ref"),
ast::bind_by_value => ()
}
print_path(s, path, true);
- alt sub {
+ match sub {
some(p) => { word(s.s, ~"@"); print_pat(s, p); }
none => ()
}
}
ast::pat_enum(path, args_) => {
print_path(s, path, true);
- alt args_ {
+ match args_ {
none => word(s.s, ~"(*)"),
some(args) => {
if vec::len(args) > 0u {
fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident,
typarams: ~[ast::ty_param]) {
- alt decl.purity {
+ match decl.purity {
ast::impure_fn => head(s, ~"fn"),
_ => head(s, purity_to_str(decl.purity) + ~" fn")
}
}
fn mode_to_str(m: ast::mode) -> ~str {
- alt m {
+ match m {
ast::expl(ast::by_mutbl_ref) => ~"&",
ast::expl(ast::by_move) => ~"-",
ast::expl(ast::by_ref) => ~"&&",
word(s.s, ~":");
for vec::each(*bounds) |bound| {
nbsp(s);
- alt bound {
+ match bound {
ast::bound_copy => word(s.s, ~"copy"),
ast::bound_send => word(s.s, ~"send"),
ast::bound_const => word(s.s, ~"const"),
fn print_meta_item(s: ps, &&item: @ast::meta_item) {
ibox(s, indent_unit);
- alt item.node {
+ match item.node {
ast::meta_word(name) => word(s.s, *name),
ast::meta_name_value(name, value) => {
word_space(s, *name);
}
fn print_view_path(s: ps, &&vp: @ast::view_path) {
- alt vp.node {
+ match vp.node {
ast::view_path_simple(ident, path, _) => {
if path.idents[vec::len(path.idents)-1u] != ident {
word_space(s, *ident);
hardbreak_if_not_bol(s);
maybe_print_comment(s, item.span.lo);
print_outer_attributes(s, item.attrs);
- alt item.node {
+ match item.node {
ast::view_item_use(id, mta, _) => {
head(s, ~"use");
word(s.s, *id);
}
fn print_mutability(s: ps, mutbl: ast::mutability) {
- alt mutbl {
+ match mutbl {
ast::m_mutbl => word_nbsp(s, ~"mut"),
ast::m_const => word_nbsp(s, ~"const"),
ast::m_imm => {/* nothing */ }
fn print_arg(s: ps, input: ast::arg) {
ibox(s, indent_unit);
print_arg_mode(s, input.mode);
- alt input.ty.node {
+ match input.ty.node {
ast::ty_infer => word(s.s, *input.ident),
_ => {
if str::len(*input.ident) > 0u {
tps: option<~[ast::ty_param]>) {
ibox(s, indent_unit);
word(s.s, opt_proto_to_str(opt_proto));
- alt id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () }
- alt tps { some(tps) => print_type_params(s, tps), _ => () }
+ match id { some(id) => { word(s.s, ~" "); word(s.s, *id); } _ => () }
+ match tps { some(tps) => print_type_params(s, tps), _ => () }
zerobreak(s.s);
popen(s);
commasep(s, inconsistent, decl.inputs, print_arg);
fn maybe_print_trailing_comment(s: ps, span: codemap::span,
next_pos: option<uint>) {
let mut cm;
- alt s.cm { some(ccm) => cm = ccm, _ => return }
- alt next_comment(s) {
+ match s.cm { some(ccm) => cm = ccm, _ => return }
+ match next_comment(s) {
some(cmnt) => {
if cmnt.style != comments::trailing { return; }
let span_line = codemap::lookup_char_pos(cm, span.hi);
let comment_line = codemap::lookup_char_pos(cm, cmnt.pos);
let mut next = cmnt.pos + 1u;
- alt next_pos { none => (), some(p) => next = p }
+ match next_pos { none => (), some(p) => next = p }
if span.hi < cmnt.pos && cmnt.pos < next &&
span_line.line == comment_line.line {
print_comment(s, cmnt);
// make sure there is a line break at the end.
if option::is_none(next_comment(s)) { hardbreak(s.s); }
loop {
- alt next_comment(s) {
+ match next_comment(s) {
some(cmnt) => { print_comment(s, cmnt); s.cur_cmnt += 1u; }
_ => break
}
fn print_literal(s: ps, &&lit: @ast::lit) {
maybe_print_comment(s, lit.span.lo);
- alt next_lit(s, lit.span.lo) {
+ match next_lit(s, lit.span.lo) {
some(ltrl) => {
word(s.s, ltrl.lit);
return;
}
_ => ()
}
- alt lit.node {
+ match lit.node {
ast::lit_str(st) => print_string(s, *st),
ast::lit_int(ch, ast::ty_char) => {
word(s.s, ~"'" + char::escape_default(ch as char) + ~"'");
fn lit_to_str(l: @ast::lit) -> ~str { return to_str(l, print_literal); }
fn next_lit(s: ps, pos: uint) -> option<comments::lit> {
- alt s.literals {
+ match s.literals {
some(lits) => {
while s.cur_lit < vec::len(lits) {
let ltrl = lits[s.cur_lit];
fn maybe_print_comment(s: ps, pos: uint) {
loop {
- alt next_comment(s) {
+ match next_comment(s) {
some(cmnt) => {
if cmnt.pos < pos {
print_comment(s, cmnt);
}
fn print_comment(s: ps, cmnt: comments::cmnt) {
- alt cmnt.style {
+ match cmnt.style {
comments::mixed => {
assert (vec::len(cmnt.lines) == 1u);
zerobreak(s.s);
comments::blank_line => {
// We need to do at least one, possibly two hardbreaks.
let is_semi =
- alt s.s.last_token() {
+ match s.s.last_token() {
pp::STRING(s, _) => *s == ~";",
_ => false
};
}
fn next_comment(s: ps) -> option<comments::cmnt> {
- alt s.comments {
+ match s.comments {
some(cmnts) => {
if s.cur_cmnt < vec::len(cmnts) {
return some(cmnts[s.cur_cmnt]);
}
fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str {
- alt opt_p {
+ match opt_p {
none => ~"fn",
some(p) => proto_to_str(p)
}
}
pure fn purity_to_str(p: ast::purity) -> ~str {
- alt p {
+ match p {
ast::impure_fn => ~"impure",
ast::unsafe_fn => ~"unsafe",
ast::pure_fn => ~"pure",
}
fn print_purity(s: ps, p: ast::purity) {
- alt p {
+ match p {
ast::impure_fn => (),
_ => word_nbsp(s, purity_to_str(p))
}
}
fn proto_to_str(p: ast::proto) -> ~str {
- return alt p {
+ return match p {
ast::proto_bare => ~"extern fn",
ast::proto_block => ~"fn&",
ast::proto_uniq => ~"fn~",
impl <T: const copy> of interner<T> for hash_interner<T> {
fn intern(val: T) -> uint {
- alt self.map.find(val) {
+ match self.map.find(val) {
some(idx) => return idx,
none => {
let new_idx = self.vect.len();
}
fn name_of_fn(fk: fn_kind) -> ident {
- alt fk {
+ match fk {
fk_item_fn(name, _) | fk_method(name, _, _)
| fk_ctor(name, _, _, _, _) => /* FIXME (#2543) */ copy name,
fk_anon(*) | fk_fn_block(*) => @~"anon",
}
fn tps_of_fn(fk: fn_kind) -> ~[ty_param] {
- alt fk {
+ match fk {
fk_item_fn(_, tps) | fk_method(_, tps, _)
| fk_ctor(_, _, tps, _, _) | fk_dtor(tps, _, _, _) => {
/* FIXME (#2543) */ copy tps
}
fn visit_crate_directive<E>(cd: @crate_directive, e: E, v: vt<E>) {
- alt cd.node {
+ match cd.node {
cdir_src_mod(_, _) => (),
cdir_dir_mod(_, cdirs, _) => for cdirs.each |cdir| {
visit_crate_directive(cdir, e, v);
fn visit_local<E>(loc: @local, e: E, v: vt<E>) {
v.visit_pat(loc.node.pat, e, v);
v.visit_ty(loc.node.ty, e, v);
- alt loc.node.init {
+ match loc.node.init {
none => (),
some(i) => v.visit_expr(i.expr, e, v)
}
}
fn visit_item<E>(i: @item, e: E, v: vt<E>) {
- alt i.node {
+ match i.node {
item_const(t, ex) => { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); }
item_fn(decl, tp, body) => {
v.visit_fn(fk_item_fn(/* FIXME (#2543) */ copy i.ident,
}
fn visit_class_item<E>(cm: @class_member, e:E, v:vt<E>) {
- alt cm.node {
+ match cm.node {
instance_var(_, t, _, _, _) => v.visit_ty(t, e, v),
class_method(m) => visit_method_helper(m, e, v)
}
fn skip_ty<E>(_t: @ty, _e: E, _v: vt<E>) {}
fn visit_ty<E>(t: @ty, e: E, v: vt<E>) {
- alt t.node {
+ match t.node {
ty_box(mt) | ty_uniq(mt) |
ty_vec(mt) | ty_ptr(mt) | ty_rptr(_, mt) => {
v.visit_ty(mt.ty, e, v);
}
fn visit_pat<E>(p: @pat, e: E, v: vt<E>) {
- alt p.node {
+ match p.node {
pat_enum(path, children) => {
visit_path(path, e, v);
do option::iter(children) |children| {
}
fn visit_foreign_item<E>(ni: @foreign_item, e: E, v: vt<E>) {
- alt ni.node {
+ match ni.node {
foreign_item_fn(fd, tps) => {
v.visit_ty_params(tps, e, v);
visit_fn_decl(fd, e, v);
fn visit_ty_params<E>(tps: ~[ty_param], e: E, v: vt<E>) {
for tps.each |tp| {
for vec::each(*tp.bounds) |bound| {
- alt bound {
+ match bound {
bound_trait(t) => v.visit_ty(t, e, v),
bound_copy | bound_send | bound_const | bound_owned => ()
}
}
fn visit_trait_method<E>(m: trait_method, e: E, v: vt<E>) {
- alt m {
+ match m {
required(ty_m) => v.visit_ty_method(ty_m, e, v),
provided(m) => visit_method_helper(m, e, v)
}
}
fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
- alt s.node {
+ match s.node {
stmt_decl(d, _) => v.visit_decl(d, e, v),
stmt_expr(ex, _) => v.visit_expr(ex, e, v),
stmt_semi(ex, _) => v.visit_expr(ex, e, v)
}
fn visit_decl<E>(d: @decl, e: E, v: vt<E>) {
- alt d.node {
+ match d.node {
decl_local(locs) => for locs.each |loc| {
v.visit_local(loc, e, v)
}
}
fn visit_expr_opt<E>(eo: option<@expr>, e: E, v: vt<E>) {
- alt eo { none => (), some(ex) => v.visit_expr(ex, e, v) }
+ match eo { none => (), some(ex) => v.visit_expr(ex, e, v) }
}
fn visit_exprs<E>(exprs: ~[@expr], e: E, v: vt<E>) {
}
fn visit_mac<E>(m: mac, e: E, v: vt<E>) {
- alt m.node {
+ match m.node {
ast::mac_invoc(pth, arg, body) => {
option::map(arg, |arg| v.visit_expr(arg, e, v)); }
ast::mac_invoc_tt(pth, tt) => { /* no user-serviceable parts inside */ }
}
fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
- alt ex.node {
+ match ex.node {
expr_vstore(x, _) => v.visit_expr(x, e, v),
expr_vec(es, _) => visit_exprs(es, e, v),
expr_repeat(element, count, _) => {
// and the extension to use.
fn mk_intermediate_name(output_path: ~str, extension: ~str) ->
~str unsafe {
- let stem = alt str::find_char(output_path, '.') {
+ let stem = match str::find_char(output_path, '.') {
some(dot_pos) => str::slice(output_path, 0u, dot_pos),
none => output_path
};
// specified.
if opts.save_temps {
- alt opts.output_type {
+ match opts.output_type {
output_type_bitcode => {
if opts.optimize != 0u {
let filename = mk_intermediate_name(output, ~"no-opt.bc");
let LLVMOptDefault = 2 as c_int; // -O2, -Os
let LLVMOptAggressive = 3 as c_int; // -O3
- let mut CodeGenOptLevel = alt check opts.optimize {
+ let mut CodeGenOptLevel = match check opts.optimize {
0u => LLVMOptNone,
1u => LLVMOptLess,
2u => LLVMOptDefault,
attr::require_unique_names(sess.diagnostic(), linkage_metas);
for linkage_metas.each |meta| {
if *attr::get_meta_item_name(meta) == ~"name" {
- alt attr::get_meta_item_value_str(meta) {
+ match attr::get_meta_item_value_str(meta) {
some(v) => { name = some(v); }
none => vec::push(cmh_items, meta)
}
} else if *attr::get_meta_item_name(meta) == ~"vers" {
- alt attr::get_meta_item_value_str(meta) {
+ match attr::get_meta_item_value_str(meta) {
some(v) => { vers = some(v); }
none => vec::push(cmh_items, meta)
}
symbol_hasher.reset();
for cmh_items.each |m_| {
let m = m_;
- alt m.node {
+ match m.node {
ast::meta_name_value(key, value) => {
symbol_hasher.write_str(len_and_str(*key));
symbol_hasher.write_str(len_and_str_lit(value));
fn crate_meta_name(sess: session, _crate: ast::crate,
output: ~str, metas: provided_metas) -> @~str {
- return alt metas.name {
+ return match metas.name {
some(v) => v,
none => {
let name =
fn crate_meta_vers(sess: session, _crate: ast::crate,
metas: provided_metas) -> @~str {
- return alt metas.vers {
+ return match metas.vers {
some(v) => v,
none => {
let vers = ~"0.0";
}
fn get_symbol_hash(ccx: @crate_ctxt, t: ty::t) -> ~str {
- alt ccx.type_hashcodes.find(t) {
+ match ccx.type_hashcodes.find(t) {
some(h) => return h,
none => {
let hash = symbol_hash(ccx.tcx, ccx.symbol_hasher, t, ccx.link_meta);
fn sanitize(s: ~str) -> ~str {
let mut result = ~"";
do str::chars_iter(s) |c| {
- alt c {
+ match c {
'@' => result += ~"_sbox_",
'~' => result += ~"_ubox_",
'*' => result += ~"_ptr_",
let mut n = ~"_ZN"; // Begin name-sequence.
for ss.each |s| {
- alt s { path_name(s) | path_mod(s) => {
+ match s { path_name(s) | path_mod(s) => {
let sani = sanitize(*s);
n += fmt!{"%u%s", str::len(sani), sani};
} }
vec::pop(parts);
return str::connect(parts, ~".");
}
- return alt config.os {
+ return match config.os {
session::os_macos => rmext(rmlib(filename)),
session::os_linux => rmext(rmlib(filename)),
session::os_freebsd => rmext(rmlib(filename)),
export get_rpath_flags;
pure fn not_win32(os: session::os) -> bool {
- alt os {
+ match os {
session::os_win32 => false,
_ => true
}
assert not_win32(os);
// Mac doesn't appear to support $ORIGIN
- let prefix = alt os {
+ let prefix = match os {
session::os_linux => ~"$ORIGIN" + path::path_sep(),
session::os_freebsd => ~"$ORIGIN" + path::path_sep(),
session::os_macos => ~"@executable_path" + path::path_sep(),
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
- data_layout: alt target_os {
+ data_layout: match target_os {
session::os_macos => {
~"e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16" +
~"-i32:32:32-i64:32:64" +
}
},
- target_triple: alt target_os {
+ target_triple: match target_os {
session::os_macos => ~"i686-apple-darwin",
session::os_win32 => ~"i686-pc-mingw32",
session::os_linux => ~"i686-unknown-linux-gnu",
meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
- data_layout: alt target_os {
+ data_layout: match target_os {
session::os_macos => {
~"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-"+
~"f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-"+
}
},
- target_triple: alt target_os {
+ target_triple: match target_os {
session::os_macos => ~"x86_64-apple-darwin",
session::os_win32 => ~"x86_64-pc-mingw32",
session::os_linux => ~"x86_64-unknown-linux-gnu",
fn anon_src() -> ~str { ~"<anon>" }
fn source_name(input: input) -> ~str {
- alt input {
+ match input {
file_input(ifile) => ifile,
str_input(_) => anon_src()
}
fn default_configuration(sess: session, argv0: ~str, input: input) ->
ast::crate_cfg {
- let libc = alt sess.targ_cfg.os {
+ let libc = match sess.targ_cfg.os {
session::os_win32 => ~"msvcrt.dll",
session::os_macos => ~"libc.dylib",
session::os_linux => ~"libc.so.6",
let mk = attr::mk_name_value_item_str;
- let (arch,wordsz) = alt sess.targ_cfg.arch {
+ let (arch,wordsz) = match sess.targ_cfg.arch {
session::arch_x86 => (~"x86",~"32"),
session::arch_x86_64 => (~"x86_64",~"64"),
session::arch_arm => (~"arm",~"32")
fn parse_input(sess: session, cfg: ast::crate_cfg, input: input)
-> @ast::crate {
- alt input {
+ match input {
file_input(file) => {
parse::parse_crate_from_file(file, cfg, sess.parse_sess)
}
fn pretty_print_input(sess: session, cfg: ast::crate_cfg, input: input,
ppm: pp_mode) {
fn ann_paren_for_expr(node: pprust::ann_node) {
- alt node {
+ match node {
pprust::node_expr(s, expr) => pprust::popen(s),
_ => ()
}
}
fn ann_typed_post(tcx: ty::ctxt, node: pprust::ann_node) {
- alt node {
+ match node {
pprust::node_expr(s, expr) => {
pp::space(s.s);
pp::word(s.s, ~"as");
}
}
fn ann_identified_post(node: pprust::ann_node) {
- alt node {
+ match node {
pprust::node_item(s, item) => {
pp::space(s.s);
pprust::synth_comment(s, int::to_str(item.id, 10u));
// to collect comments and literals, and we need to support reading
// from stdin, we're going to just suck the source into a string
// so both the parser and pretty-printer can use it.
- let upto = alt ppm {
+ let upto = match ppm {
ppm_expanded | ppm_expanded_identified => cu_expand,
ppm_typed => cu_typeck,
_ => cu_parse
};
let {crate, tcx} = compile_upto(sess, cfg, input, upto, none);
- let ann = alt ppm {
+ let ann = match ppm {
ppm_typed => {
{pre: ann_paren_for_expr,
post: |a| ann_typed_post(option::get(tcx), a) }
fn build_target_config(sopts: @session::options,
demitter: diagnostic::emitter) -> @session::config {
- let os = alt get_os(sopts.target_triple) {
+ let os = match get_os(sopts.target_triple) {
some(os) => os,
none => early_error(demitter, ~"unknown operating system")
};
- let arch = alt get_arch(sopts.target_triple) {
+ let arch = match get_arch(sopts.target_triple) {
some(arch) => arch,
none => early_error(demitter,
~"unknown architecture: " + sopts.target_triple)
};
- let (int_type, uint_type, float_type) = alt arch {
+ let (int_type, uint_type, float_type) = match arch {
session::arch_x86 => (ast::ty_i32, ast::ty_u32, ast::ty_f64),
session::arch_x86_64 => (ast::ty_i64, ast::ty_u64, ast::ty_f64),
session::arch_arm => (ast::ty_i32, ast::ty_u32, ast::ty_f64)
};
- let target_strs = alt arch {
+ let target_strs = match arch {
session::arch_x86 => x86::get_target_strs(os),
session::arch_x86_64 => x86_64::get_target_strs(os),
session::arch_arm => x86::get_target_strs(os)
getopts::opt_strs(matches, level_name));
for flags.each |lint_name| {
let lint_name = str::replace(lint_name, ~"-", ~"_");
- alt lint_dict.find(lint_name) {
+ match lint_dict.find(lint_name) {
none => {
early_error(demitter, fmt!{"unknown %s flag: %s",
level_name, lint_name});
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
let target_opt = getopts::opt_maybe_str(matches, ~"target");
let save_temps = getopts::opt_present(matches, ~"save-temps");
- alt output_type {
+ match output_type {
// unless we're emitting huamn-readable assembly, omit comments.
link::output_type_llvm_assembly | link::output_type_assembly => (),
_ => debugging_opts |= session::no_asm_comments
}
2u
} else if opt_present(matches, ~"opt-level") {
- alt getopts::opt_str(matches, ~"opt-level") {
+ match getopts::opt_str(matches, ~"opt-level") {
~"0" => 0u,
~"1" => 1u,
~"2" => 2u,
}
} else { 0u };
let target =
- alt target_opt {
+ match target_opt {
none => host_triple(),
some(s) => s
};
}
fn parse_pretty(sess: session, &&name: ~str) -> pp_mode {
- alt name {
+ match name {
~"normal" => ppm_normal,
~"expanded" => ppm_expanded,
~"typed" => ppm_typed,
let obj_suffix =
- alt sopts.output_type {
+ match sopts.output_type {
link::output_type_none => ~"none",
link::output_type_bitcode => ~"bc",
link::output_type_assembly => ~"s",
link::output_type_object | link::output_type_exe => ~"o"
};
- alt ofile {
+ match ofile {
none => {
// "-" as input file will cause the parser to read from stdin so we
// have to make up a name
// We want to toss everything after the final '.'
- let dirname = alt odir {
+ let dirname = match odir {
some(d) => d,
- none => alt input {
+ none => match input {
str_input(_) => os::getcwd(),
file_input(ifile) => path::dirname(ifile)
}
};
- let base_filename = alt input {
+ let base_filename = match input {
file_input(ifile) => {
let (path, _) = path::splitext(ifile);
path::basename(path)
#[test]
fn test_switch_implies_cfg_test() {
let matches =
- alt getopts::getopts(~[~"--test"], opts()) {
+ match getopts::getopts(~[~"--test"], opts()) {
ok(m) => m,
err(f) => fail ~"test_switch_implies_cfg_test: " +
getopts::fail_str(f)
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let matches =
- alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
+ match getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
ok(m) => m,
err(f) => {
fail ~"test_switch_implies_cfg_test_unless_cfg_test: " +
let k = str::replace(k, ~"_", ~"-");
io::println(fmt!{" %s %7.7s %s",
padded(max_key, k),
- alt v.default {
+ match v.default {
lint::allow => ~"allow",
lint::warn => ~"warn",
lint::deny => ~"deny",
if vec::len(args) == 0u { usage(binary); return; }
let matches =
- alt getopts::getopts(args, opts()) {
+ match getopts::getopts(args, opts()) {
ok(m) => m,
err(f) => {
early_error(demitter, getopts::fail_str(f))
version(binary);
return;
}
- let input = alt vec::len(matches.free) {
+ let input = match vec::len(matches.free) {
0u => early_error(demitter, ~"no input filename given"),
1u => {
let ifile = matches.free[0];
option::map(getopts::opt_default(matches, ~"pretty",
~"normal"),
|a| parse_pretty(sess, a) );
- alt pretty {
+ match pretty {
some::<pp_mode>(ppm) => {
pretty_print_input(sess, cfg, input, ppm);
return;
}
let ls = opt_present(matches, ~"ls");
if ls {
- alt input {
+ match input {
file_input(ifile) => {
list_metadata(sess, ifile, io::stdout());
}
let p = comm::port();
let ch = comm::chan(p);
- alt do task::try {
+ match do task::try {
// The 'diagnostics emitter'. Every error, warning, etc. should
// go through this function.
}
fn span_lint_level(level: lint::level,
sp: span, msg: ~str) {
- alt level {
+ match level {
lint::allow => { },
lint::warn => self.span_warn(sp, msg),
lint::deny | lint::forbid => {
fn building_library(req_crate_type: crate_type, crate: @ast::crate,
testing: bool) -> bool {
- alt req_crate_type {
+ match req_crate_type {
bin_crate => false,
lib_crate => true,
unknown_crate => {
if testing {
false
} else {
- alt syntax::attr::first_attr_value_str_by_name(
+ match syntax::attr::first_attr_value_str_by_name(
crate.node.attrs,
~"crate_type") {
option::some(@~"lib") => true,
fn sess_os_to_meta_os(os: os) -> metadata::loader::os {
import metadata::loader;
- alt os {
+ match os {
os_win32 => loader::os_win32,
os_linux => loader::os_linux,
os_macos => loader::os_macos,
fn filter_stmt(cx: ctxt, &&stmt: @ast::stmt) ->
option<@ast::stmt> {
- alt stmt.node {
+ match stmt.node {
ast::stmt_decl(decl, _) => {
- alt decl.node {
+ match decl.node {
ast::decl_item(item) => {
if item_in_cfg(cx, item) {
option::some(stmt)
~[],
sess.parse_sess);
let item =
- alt item {
+ match item {
some(i) => i,
none => {
sess.fatal(~"no item found in intrinsic module");
// FIXME (#2403): This is sloppy. Instead we should have some mechanism to
// indicate to the translation pass which function we want to be main.
fn nomain(&&item: @ast::item) -> option<@ast::item> {
- alt item.node {
+ match item.node {
ast::item_fn(_, _, _) => {
if *item.ident == ~"main" {
option::none
debug!{"current path: %s", ast_util::path_name_i(cx.path)};
if is_test_fn(i) {
- alt i.node {
+ match i.node {
ast::item_fn(decl, _, _) if decl.purity == ast::unsafe_fn => {
cx.sess.span_fatal(
i.span,
vec::len(attr::find_attrs_by_name(i.attrs, ~"test")) > 0u;
fn has_test_signature(i: @ast::item) -> bool {
- alt i.node {
+ match i.node {
ast::item_fn(decl, tps, _) => {
let input_cnt = vec::len(decl.inputs);
let no_output = decl.output.node == ast::ty_nil;
// the paths with std::
let is_std = {
let items = attr::find_linkage_metas(cx.crate.node.attrs);
- alt attr::last_meta_item_value_str_by_name(items, ~"name") {
+ match attr::last_meta_item_value_str_by_name(items, ~"name") {
some(@~"std") => true,
_ => false
}
fn type_to_str_inner(names: type_names, outer0: ~[TypeRef], ty: TypeRef) ->
~str {
- alt type_has_name(names, ty) {
+ match type_has_name(names, ty) {
option::some(n) => return n,
_ => {}
}
return s;
}
- alt kind {
+ match kind {
Void => return ~"Void",
Half => return ~"Half",
Float => return ~"Float",
}
fn float_width(llt: TypeRef) -> uint {
- return alt llvm::LLVMGetTypeKind(llt) as int {
+ return match llvm::LLVMGetTypeKind(llt) as int {
1 => 32u,
2 => 64u,
3 => 80u,
mut next_crate_num: ast::crate_num};
fn visit_view_item(e: env, i: @ast::view_item) {
- alt i.node {
+ match i.node {
ast::view_item_use(ident, meta_items, id) => {
debug!{"resolving use stmt. ident: %?, meta: %?", ident, meta_items};
let cnum = resolve_crate(e, ident, meta_items, ~"", i.span);
}
fn visit_item(e: env, i: @ast::item) {
- alt i.node {
+ match i.node {
ast::item_foreign_mod(m) => {
- alt attr::foreign_abi(i.attrs) {
+ match attr::foreign_abi(i.attrs) {
either::right(abi) => {
if abi != ast::foreign_abi_cdecl &&
abi != ast::foreign_abi_stdcall { return; }
let cstore = e.cstore;
let foreign_name =
- alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
+ match attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
some(nn) => {
if *nn == ~"" {
e.diag.span_fatal(
~"' already added: can't specify link_args.");
}
for link_args.each |a| {
- alt attr::get_meta_item_value_str(attr::attr_meta(a)) {
+ match attr::get_meta_item_value_str(attr::attr_meta(a)) {
some(linkarg) => {
cstore::add_used_link_args(cstore, *linkarg);
}
hash: ~str, span: span) -> ast::crate_num {
let metas = metas_with_ident(ident, metas);
- alt existing_match(e, metas, hash) {
+ match existing_match(e, metas, hash) {
none => {
let load_ctxt: loader::ctxt = {
diag: e.diag,
let cnum_map = resolve_crate_deps(e, cdata);
let cname =
- alt attr::last_meta_item_value_str_by_name(metas, ~"name") {
+ match attr::last_meta_item_value_str_by_name(metas, ~"name") {
option::some(v) => v,
option::none => ident
};
let cmetas = metas_with(dep.vers, @~"vers", ~[]);
debug!{"resolving dep crate %s ver: %s hash: %s",
*dep.name, *dep.vers, *dep.hash};
- alt existing_match(e, metas_with_ident(cname, cmetas), *dep.hash) {
+ match existing_match(e, metas_with_ident(cname, cmetas), *dep.hash) {
some(local_cnum) => {
debug!{"already have it"};
// We've already seen this crate
fn lookup_method_purity(cstore: cstore::cstore, did: ast::def_id)
-> ast::purity {
let cdata = cstore::get_crate_data(cstore, did.crate).data;
- alt check decoder::lookup_def(did.crate, cdata, did) {
+ match check decoder::lookup_def(did.crate, cdata, did) {
ast::def_fn(_, p) => p
}
}
// Internal method to retrieve the data from the cstore
pure fn p(cstore: cstore) -> cstore_private {
- alt cstore { private(p) => p }
+ match cstore { private(p) => p }
}
fn mk_cstore() -> cstore {
// to the item data.
fn lookup_item(item_id: int, data: @~[u8]) -> ebml::doc {
let items = ebml::get_doc(ebml::doc(data), tag_items);
- alt maybe_find_item(item_id, items) {
+ match maybe_find_item(item_id, items) {
none => fail(fmt!{"lookup_item: id not found: %d", item_id}),
some(d) => d
}
ebml::maybe_get_doc(d, tag_class_mut),
ast::class_immutable,
|d| {
- alt ebml::doc_as_u8(d) as char {
+ match ebml::doc_as_u8(d) as char {
'm' => ast::class_mutable,
_ => ast::class_immutable
}
}
fn item_ty_region_param(item: ebml::doc) -> bool {
- alt ebml::maybe_get_doc(item, tag_region_param) {
+ match ebml::maybe_get_doc(item, tag_region_param) {
some(_) => true,
none => false
}
fn item_to_def_like(item: ebml::doc, did: ast::def_id, cnum: ast::crate_num)
-> def_like {
let fam_ch = item_family(item);
- alt fam_ch {
+ match fam_ch {
'c' => dl_def(ast::def_const(did)),
'C' => dl_def(ast::def_class(did, true)),
'S' => dl_def(ast::def_class(did, false)),
name: ast::ident) -> ast::def_id {
let items = ebml::get_doc(ebml::doc(cdata.data), tag_items);
let mut found = none;
- let cls_items = alt maybe_find_item(id, items) {
+ let cls_items = match maybe_find_item(id, items) {
some(it) => it,
none => fail (fmt!{"get_class_method: class id not found \
when looking up method %s", *name})
found = some(m_did);
}
}
- alt found {
+ match found {
some(found) => found,
none => fail (fmt!{"get_class_method: no method named %s", *name})
}
fn class_dtor(cdata: cmd, id: ast::node_id) -> option<ast::def_id> {
let items = ebml::get_doc(ebml::doc(cdata.data), tag_items);
let mut found = none;
- let cls_items = alt maybe_find_item(id, items) {
+ let cls_items = match maybe_find_item(id, items) {
some(it) => it,
none => fail (fmt!{"class_dtor: class id not found \
when looking up dtor for %d", id})
}
fn def_like_to_def(def_like: def_like) -> ast::def {
- alt def_like {
+ match def_like {
dl_def(def) => return def,
dl_impl(*) => fail ~"found impl in def_like_to_def",
dl_field => fail ~"found field in def_like_to_def"
let def_id = class_member_id(path_doc, cdata);
// Get the item.
- alt maybe_find_item(def_id.node, items) {
+ match maybe_find_item(def_id.node, items) {
none => {
debug!{"(each_path) ignoring implicit item: %s",
*path};
debug!{"Looking up item: %d", id};
let item_doc = lookup_item(id, cdata.data);
let path = vec::init(item_path(item_doc));
- alt decode_inlined_item(cdata, tcx, path, item_doc) {
+ match decode_inlined_item(cdata, tcx, path, item_doc) {
some(ii) => csearch::found(ii),
none => {
- alt item_parent_item(item_doc) {
+ match item_parent_item(item_doc) {
some(did) => {
let did = translate_def_id(cdata, did);
let parent_item = lookup_item(did.node, cdata.data);
- alt decode_inlined_item(cdata, tcx, path,
+ match decode_inlined_item(cdata, tcx, path,
parent_item) {
some(ii) => csearch::found_parent(did, ii),
none => csearch::not_found
tcx, cdata);
let name = item_name(item);
let mut arg_tys: ~[ty::t] = ~[];
- alt ty::get(ctor_ty).struct {
+ match ty::get(ctor_ty).struct {
ty::ty_fn(f) => {
for f.inputs.each |a| { vec::push(arg_tys, a.ty); }
}
_ => { /* Nullary enum variant. */ }
}
- alt variant_disr_val(item) {
+ match variant_disr_val(item) {
some(val) => { disr_val = val; }
_ => { /* empty */ }
}
fn get_self_ty(item: ebml::doc) -> ast::self_ty_ {
fn get_mutability(ch: u8) -> ast::mutability {
- alt ch as char {
+ match ch as char {
'i' => { ast::m_imm }
'm' => { ast::m_mutbl }
'c' => { ast::m_const }
let string = ebml::doc_as_str(self_type_doc);
let self_ty_kind = string[0];
- alt self_ty_kind as char {
+ match self_ty_kind as char {
'r' => { return ast::sty_by_ref; }
'v' => { return ast::sty_value; }
'@' => { return ast::sty_box(get_mutability(string[1])); }
let impl_data = impl_cdata.data;
let item = lookup_item(local_did.node, impl_data);
let nm = item_name(item);
- if alt name { some(n) => { n == nm } none => { true } } {
+ if match name { some(n) => { n == nm } none => { true } } {
let base_tps = item_ty_param_count(item);
vec::push(result, @{
did: local_did, ident: nm,
let bounds = item_ty_param_bounds(mth, tcx, cdata);
let name = item_name(mth);
let ty = doc_type(mth, tcx, cdata);
- let fty = alt ty::get(ty).struct {
+ let fty = match ty::get(ty).struct {
ty::ty_fn(f) => f,
_ => {
tcx.diag.handler().bug(
let self_ty = get_self_ty(mth);
vec::push(result, {ident: name, tps: bounds, fty: fty,
self_ty: self_ty,
- purity: alt check item_family(mth) {
+ purity: match check item_family(mth) {
'u' => ast::unsafe_fn,
'f' => ast::impure_fn,
'p' => ast::pure_fn
}
pure fn family_to_visibility(family: char) -> ast::visibility {
- alt family {
+ match family {
'g' => ast::public,
'j' => ast::private,
'N' => ast::inherited,
}
fn family_has_type_params(fam_ch: char) -> bool {
- alt check fam_ch {
+ match check fam_ch {
'c' | 'T' | 'm' | 'n' | 'g' | 'h' | 'j' => false,
'f' | 'u' | 'p' | 'F' | 'U' | 'P' | 'y' | 't' | 'v' | 'i' | 'I' | 'C'
| 'a' | 'S'
}
fn family_names_type(fam_ch: char) -> bool {
- alt fam_ch { 'y' | 't' | 'I' => true, _ => false }
+ match fam_ch { 'y' | 't' | 'I' => true, _ => false }
}
fn read_path(d: ebml::doc) -> {path: ~str, pos: uint} {
fn describe_def(items: ebml::doc, id: ast::def_id) -> ~str {
if id.crate != ast::local_crate { return ~"external"; }
- let it = alt maybe_find_item(id.node, items) {
+ let it = match maybe_find_item(id.node, items) {
some(it) => it,
none => fail (fmt!{"describe_def: item not found %?", id})
};
}
fn item_family_to_str(fam: char) -> ~str {
- alt check fam {
+ match check fam {
'c' => return ~"const",
'f' => return ~"fn",
'u' => return ~"unsafe fn",
fn get_attributes(md: ebml::doc) -> ~[ast::attribute] {
let mut attrs: ~[ast::attribute] = ~[];
- alt ebml::maybe_get_doc(md, tag_attributes) {
+ match ebml::maybe_get_doc(md, tag_attributes) {
option::some(attrs_d) => {
for ebml::tagged_docs(attrs_d, tag_attribute) |attr_doc| {
let meta_items = get_meta_items(attr_doc);
fn get_crate_vers(data: @~[u8]) -> @~str {
let attrs = decoder::get_crate_attributes(data);
- return alt attr::last_meta_item_value_str_by_name(
+ return match attr::last_meta_item_value_str_by_name(
attr::find_linkage_metas(attrs), ~"vers") {
some(ver) => ver,
none => @~"0.0"
return {crate: cdata.cnum, node: did.node};
}
- alt cdata.cnum_map.find(did.crate) {
+ match cdata.cnum_map.find(did.crate) {
option::some(n) => return {crate: n, node: did.node},
option::none => fail ~"didn't find a crate in the cnum_map"
}
fn encode_mutability(ebml_w: ebml::writer, mt: class_mutability) {
do ebml_w.wr_tag(tag_class_mut) {
- let val = alt mt {
+ let val = match mt {
class_immutable => 'i',
class_mutable => 'm'
};
fn encode_class_item_paths(ebml_w: ebml::writer,
items: ~[@class_member], path: ~[ident], &index: ~[entry<~str>]) {
for items.each |it| {
- alt ast_util::class_member_visibility(it) {
+ match ast_util::class_member_visibility(it) {
private => again,
public | inherited => {
- let (id, ident) = alt it.node {
+ let (id, ident) = match it.node {
instance_var(v, _, _, vid, _) => (vid, v),
class_method(it) => (it.id, it.ident)
};
if !ast_util::is_item_impl(it) {
add_to_index(ebml_w, path, index, it.ident);
}
- alt it.node {
+ match it.node {
item_const(_, _) => {
encode_named_def_id(ebml_w, it.ident, local_def(it.id));
}
// class and for its ctor
add_to_index(ebml_w, path, index, it.ident);
- alt m_ctor {
+ match m_ctor {
none => {
// Nothing to do.
}
fn encode_symbol(ecx: @encode_ctxt, ebml_w: ebml::writer, id: node_id) {
ebml_w.start_tag(tag_items_data_item_symbol);
- let sym = alt ecx.item_symbols.find(id) {
+ let sym = match ecx.item_symbols.find(id) {
some(x) => x,
none => {
ecx.diag.handler().bug(
path: ast_map::path,
name: ast_map::path_elt) {
fn encode_path_elt(ebml_w: ebml::writer, elt: ast_map::path_elt) {
- let (tag, name) = alt elt {
+ let (tag, name) = match elt {
ast_map::path_mod(name) => (tag_path_elt_mod, name),
ast_map::path_name(name) => (tag_path_elt_name, name)
};
ast_util::is_exported(ident, md)};
ebml_w.start_tag(tag_mod_impl);
- alt ecx.tcx.items.find(did.node) {
+ match ecx.tcx.items.find(did.node) {
some(ast_map::node_item(it@@{node: cl@item_class(*),_},_)) => {
/* If did stands for a trait
ref, we need to map it to its parent class */
}
fn encode_visibility(ebml_w: ebml::writer, visibility: visibility) {
- encode_family(ebml_w, alt visibility {
+ encode_family(ebml_w, match visibility {
public => 'g',
private => 'j',
inherited => 'N'
}
fn encode_region(ebml_w: ebml::writer, region: region) {
- alt region.node {
+ match region.node {
re_anon => {
ebml_w.wr_tagged_str(tag_item_trait_method_self_ty, ~"");
}
// Encode the base self type.
let ch;
- alt self_type {
+ match self_type {
sty_by_ref => { ch = 'r' as u8; }
sty_value => { ch = 'v' as u8; }
sty_region(_, _) => { ch = '&' as u8; }
ebml_w.writer.write(&[ ch ]);
// Encode mutability.
- alt self_type {
+ match self_type {
sty_by_ref | sty_value => { /* No-op. */ }
sty_region(_, m_imm) | sty_box(m_imm) | sty_uniq(m_imm) => {
ebml_w.writer.write(&[ 'i' as u8 ]);
}
// Encode the region.
- alt self_type {
+ match self_type {
sty_region(region, _) => {
encode_region(ebml_w, *region);
}
for items.each |ci| {
/* We encode both private and public fields -- need to include
private fields to get the offsets right */
- alt ci.node {
+ match ci.node {
instance_var(nm, _, mt, id, vis) => {
vec::push(*index, {val: id, pos: ebml_w.writer.tell()});
vec::push(*global_index, {val: id, pos: ebml_w.writer.tell()});
ebml_w.end_tag();
}
class_method(m) => {
- alt m.vis {
+ match m.vis {
public | inherited => {
vec::push(*index, {val: m.id, pos: ebml_w.writer.tell()});
vec::push(*global_index,
util::ppaux::ty_to_str(ecx.tcx, its_ty), id};
encode_type(ecx, ebml_w, its_ty);
encode_path(ebml_w, path, ast_map::path_name(ident));
- alt item {
+ match item {
some(it) => {
ecx.encode_inlined_item(ecx, ebml_w, path, it);
}
}
fn purity_fn_family(p: purity) -> char {
- alt p {
+ match p {
unsafe_fn => 'u',
pure_fn => 'p',
impure_fn => 'f',
fn should_inline(attrs: ~[attribute]) -> bool {
- alt attr::find_inline_attr(attrs) {
+ match attr::find_inline_attr(attrs) {
attr::ia_none | attr::ia_never => false,
attr::ia_hint | attr::ia_always => true
}
let tcx = ecx.tcx;
let must_write =
- alt item.node {
+ match item.node {
item_enum(_, _) | item_impl(*)
| item_trait(*) | item_class(*) => true,
_ => false
}
let add_to_index = |copy ebml_w| add_to_index_(item, ebml_w, index);
- alt item.node {
+ match item.node {
item_const(_, _) => {
add_to_index();
ebml_w.start_tag(tag_items_data_item);
ebml_w.start_tag(tag_items_data_item);
encode_def_id(ebml_w, local_def(item.id));
- alt ctor {
+ match ctor {
none => encode_family(ebml_w, 'S'),
some(_) => encode_family(ebml_w, 'C')
}
ebml_w.end_tag();
}
for ms.each |m| {
- alt m.vis {
+ match m.vis {
private => { /* do nothing */ }
public | inherited => {
/* Write the info that's needed when viewing this class
encode_attributes(ebml_w, item.attrs);
let mut i = 0u;
for vec::each(*ty::trait_methods(tcx, local_def(item.id))) |mty| {
- alt ms[i] {
+ match ms[i] {
required(ty_m) => {
ebml_w.start_tag(tag_item_trait_method);
encode_name(ebml_w, mty.ident);
vec::push(*index, {val: nitem.id, pos: ebml_w.writer.tell()});
ebml_w.start_tag(tag_items_data_item);
- alt nitem.node {
+ match nitem.node {
foreign_item_fn(fn_decl, tps) => {
encode_def_id(ebml_w, local_def(nitem.id));
encode_family(ebml_w, purity_fn_family(fn_decl.purity));
visit_expr: |_e, _cx, _v| { },
visit_item: |i, cx, v, copy ebml_w| {
visit::visit_item(i, cx, v);
- alt check ecx.tcx.items.get(i.id) {
+ match check ecx.tcx.items.get(i.id) {
ast_map::node_item(_, pt) => {
encode_info_for_item(ecx, ebml_w, i, index, *pt);
/* encode ctor, then encode items */
- alt i.node {
+ match i.node {
item_class(tps, _, _, some(ctor), m_dtor) => {
debug!{"encoding info for ctor %s %d", *i.ident,
ctor.node.id};
},
visit_foreign_item: |ni, cx, v, copy ebml_w| {
visit::visit_foreign_item(ni, cx, v);
- alt check ecx.tcx.items.get(ni.id) {
+ match check ecx.tcx.items.get(ni.id) {
ast_map::node_foreign_item(_, abi, pt) => {
encode_info_for_foreign_item(ecx, ebml_w, ni,
index, *pt, abi);
}
fn encode_meta_item(ebml_w: ebml::writer, mi: meta_item) {
- alt mi.node {
+ match mi.node {
meta_word(name) => {
ebml_w.start_tag(tag_meta_item_word);
ebml_w.start_tag(tag_meta_item_name);
ebml_w.end_tag();
}
meta_name_value(name, value) => {
- alt value.node {
+ match value.node {
lit_str(value) => {
ebml_w.start_tag(tag_meta_item_name_value);
ebml_w.start_tag(tag_meta_item_name);
if *attr::get_attr_name(attr) != ~"link" {
attr
} else {
- alt attr.node.value.node {
+ match attr.node.value.node {
meta_list(n, l) => {
found_link_attr = true;;
synthesize_link_attr(ecx, l)
vec::push(paths,
make_target_lib_path(self.sysroot, self.target_triple));
- alt get_cargo_lib_path_nearest() {
+ match get_cargo_lib_path_nearest() {
result::ok(p) => vec::push(paths, p),
result::err(p) => ()
}
- alt get_cargo_lib_path() {
+ match get_cargo_lib_path() {
result::ok(p) => vec::push(paths, p),
result::err(p) => ()
}
}
fn get_default_sysroot() -> path {
- alt os::self_exe_path() {
+ match os::self_exe_path() {
option::some(p) => path::normalize(path::connect(p, ~"..")),
option::none => fail ~"can't determine value for sysroot"
}
}
fn get_sysroot(maybe_sysroot: option<path>) -> path {
- alt maybe_sysroot {
+ match maybe_sysroot {
option::some(sr) => sr,
option::none => get_default_sysroot()
}
}
fn get_cargo_root() -> result<path, ~str> {
- alt os::getenv(~"CARGO_ROOT") {
+ match os::getenv(~"CARGO_ROOT") {
some(_p) => result::ok(_p),
- none => alt os::homedir() {
+ none => match os::homedir() {
some(_q) => result::ok(path::connect(_q, ~".cargo")),
none => result::err(~"no CARGO_ROOT or home directory")
}
};
fn load_library_crate(cx: ctxt) -> {ident: ~str, data: @~[u8]} {
- alt find_library_crate(cx) {
+ match find_library_crate(cx) {
some(t) => return t,
none => {
cx.diag.span_fatal(
fn libname(cx: ctxt) -> {prefix: ~str, suffix: ~str} {
if cx.static { return {prefix: ~"lib", suffix: ~".rlib"}; }
- alt cx.os {
+ match cx.os {
os_win32 => return {prefix: ~"", suffix: ~".dll"},
os_macos => return {prefix: ~"lib", suffix: ~".dylib"},
os_linux => return {prefix: ~"lib", suffix: ~".so"},
option::none::<()>
} else {
debug!{"%s is a candidate", path};
- alt get_metadata_section(cx.os, path) {
+ match get_metadata_section(cx.os, path) {
option::some(cvec) => {
if !crate_matches(cvec, cx.metas, cx.hash) {
debug!{"skipping %s, metadata doesn't match", path};
fn crate_name_from_metas(metas: ~[@ast::meta_item]) -> @~str {
let name_items = attr::find_meta_items_by_name(metas, ~"name");
- alt vec::last_opt(name_items) {
+ match vec::last_opt(name_items) {
some(i) => {
- alt attr::get_meta_item_value_str(i) {
+ match attr::get_meta_item_value_str(i) {
some(n) => n,
// FIXME (#2406): Probably want a warning here since the user
// is using the wrong type of meta item.
llvm::LLVMRustCreateMemoryBufferWithContentsOfFile(buf)
});
if mb as int == 0 { return option::none::<@~[u8]>; }
- let of = alt mk_object_file(mb) {
+ let of = match mk_object_file(mb) {
option::some(of) => of,
_ => return option::none::<@~[u8]>
};
}
fn meta_section_name(os: os) -> ~str {
- alt os {
+ match os {
os_macos => ~"__DATA,__note.rustc",
os_win32 => ~".note.rustc",
os_linux => ~".note.rustc",
// A diagnostic function for dumping crate metadata to an output stream
fn list_file_metadata(os: os, path: ~str, out: io::writer) {
- alt get_metadata_section(os, path) {
+ match get_metadata_section(os, path) {
option::some(bytes) => decoder::list_crate_metadata(bytes, out),
option::none => {
out.write_str(~"could not find metadata in " + path + ~".\n");
}
fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
- alt peek(st) {
+ match peek(st) {
'!' => { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
_ => (ast::return_val, parse_ty(st, conv))
}
fn is_last(c: char) -> bool { return c == '(' || c == ':'; }
vec::push(idents, parse_ident_(st, is_last));
loop {
- alt peek(st) {
+ match peek(st) {
':' => { next(st); next(st); }
c => {
if c == '(' {
}
fn parse_proto(c: char) -> ast::proto {
- alt c {
+ match c {
'~' => ast::proto_uniq,
'@' => ast::proto_box,
'&' => ast::proto_block,
return ty::vstore_fixed(n);
}
- alt check next(st) {
+ match check next(st) {
'~' => ty::vstore_uniq,
'@' => ty::vstore_box,
'&' => ty::vstore_slice(parse_region(st))
}
fn parse_bound_region(st: @pstate) -> ty::bound_region {
- alt check next(st) {
+ match check next(st) {
's' => ty::br_self,
'a' => ty::br_anon,
'[' => ty::br_named(@parse_str(st, ']')),
}
fn parse_region(st: @pstate) -> ty::region {
- alt check next(st) {
+ match check next(st) {
'b' => {
ty::re_bound(parse_bound_region(st))
}
}
fn parse_opt<T>(st: @pstate, f: fn() -> T) -> option<T> {
- alt check next(st) {
+ match check next(st) {
'n' => none,
's' => some(f())
}
}
fn parse_ty(st: @pstate, conv: conv_did) -> ty::t {
- alt check next(st) {
+ match check next(st) {
'n' => return ty::mk_nil(st.tcx),
'z' => return ty::mk_bot(st.tcx),
'b' => return ty::mk_bool(st.tcx),
'u' => return ty::mk_uint(st.tcx),
'l' => return ty::mk_float(st.tcx),
'M' => {
- alt check next(st) {
+ match check next(st) {
'b' => return ty::mk_mach_uint(st.tcx, ast::ty_u8),
'w' => return ty::mk_mach_uint(st.tcx, ast::ty_u16),
'l' => return ty::mk_mach_uint(st.tcx, ast::ty_u32),
}
'Y' => return ty::mk_type(st.tcx),
'C' => {
- let ck = alt check next(st) {
+ let ck = match check next(st) {
'&' => ty::ck_block,
'@' => ty::ck_box,
'~' => ty::ck_uniq
assert (next(st) == ':');
let len = parse_hex(st);
assert (next(st) == '#');
- alt st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
+ match st.tcx.rcache.find({cnum: st.crate, pos: pos, len: len}) {
some(tt) => return tt,
none => {
let ps = @{pos: pos with *st};
fn parse_mt(st: @pstate, conv: conv_did) -> ty::mt {
let mut m;
- alt peek(st) {
+ match peek(st) {
'm' => { next(st); m = ast::m_mutbl; }
'?' => { next(st); m = ast::m_const; }
_ => { m = ast::m_imm; }
}
fn parse_purity(c: char) -> purity {
- alt check c {
+ match check c {
'u' => unsafe_fn,
'p' => pure_fn,
'i' => impure_fn,
assert (next(st) == '[');
let mut inputs: ~[ty::arg] = ~[];
while peek(st) != ']' {
- let mode = alt check peek(st) {
+ let mode = match check peek(st) {
'&' => ast::by_mutbl_ref,
'-' => ast::by_move,
'+' => ast::by_copy,
let crate_part = vec::slice(buf, 0u, colon_idx);
let def_part = vec::slice(buf, colon_idx + 1u, len);
- let crate_num = alt uint::parse_buf(crate_part, 10u) {
+ let crate_num = match uint::parse_buf(crate_part, 10u) {
some(cn) => cn as int,
none => fail (fmt!{"internal error: parse_def_id: crate number \
expected, but found %?", crate_part})
};
- let def_num = alt uint::parse_buf(def_part, 10u) {
+ let def_num = match uint::parse_buf(def_part, 10u) {
some(dn) => dn as int,
none => fail (fmt!{"internal error: parse_def_id: id expected, but \
found %?", def_part})
fn parse_bounds(st: @pstate, conv: conv_did) -> @~[ty::param_bound] {
let mut bounds = ~[];
loop {
- vec::push(bounds, alt check next(st) {
+ vec::push(bounds, match check next(st) {
'S' => ty::bound_send,
'C' => ty::bound_copy,
'K' => ty::bound_const,
enum abbrev_ctxt { ac_no_abbrevs, ac_use_abbrevs(hashmap<ty::t, ty_abbrev>), }
fn cx_uses_abbrevs(cx: @ctxt) -> bool {
- alt cx.abbrevs {
+ match cx.abbrevs {
ac_no_abbrevs => return false,
ac_use_abbrevs(_) => return true
}
}
fn enc_ty(w: io::writer, cx: @ctxt, t: ty::t) {
- alt cx.abbrevs {
+ match cx.abbrevs {
ac_no_abbrevs => {
- let result_str = alt cx.tcx.short_names_cache.find(t) {
+ let result_str = match cx.tcx.short_names_cache.find(t) {
some(s) => *s,
none => {
let buf = io::mem_buffer();
w.write_str(result_str);
}
ac_use_abbrevs(abbrevs) => {
- alt abbrevs.find(t) {
+ match abbrevs.find(t) {
some(a) => { w.write_str(*a.s); return; }
none => {
let pos = w.tell();
- alt ty::type_def_id(t) {
+ match ty::type_def_id(t) {
some(def_id) => {
// Do not emit node ids that map to unexported names. Those
// are not helpful.
}
}
fn enc_mt(w: io::writer, cx: @ctxt, mt: ty::mt) {
- alt mt.mutbl {
+ match mt.mutbl {
m_imm => (),
m_mutbl => w.write_char('m'),
m_const => w.write_char('?')
}
fn enc_opt<T>(w: io::writer, t: option<T>, enc_f: fn(T)) {
- alt t {
+ match t {
none => w.write_char('n'),
some(v) => {
w.write_char('s');
}
fn enc_region(w: io::writer, cx: @ctxt, r: ty::region) {
- alt r {
+ match r {
ty::re_bound(br) => {
w.write_char('b');
enc_bound_region(w, br);
}
fn enc_bound_region(w: io::writer, br: ty::bound_region) {
- alt br {
+ match br {
ty::br_self => w.write_char('s'),
ty::br_anon => w.write_char('a'),
ty::br_named(s) => {
fn enc_vstore(w: io::writer, cx: @ctxt, v: ty::vstore) {
w.write_char('/');
- alt v {
+ match v {
ty::vstore_fixed(u) => {
w.write_uint(u);
w.write_char('|');
}
fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
- alt st {
+ match st {
ty::ty_nil => w.write_char('n'),
ty::ty_bot => w.write_char('z'),
ty::ty_bool => w.write_char('b'),
ty::ty_int(t) => {
- alt t {
+ match t {
ty_i => w.write_char('i'),
ty_char => w.write_char('c'),
ty_i8 => w.write_str(&"MB"),
}
}
ty::ty_uint(t) => {
- alt t {
+ match t {
ty_u => w.write_char('u'),
ty_u8 => w.write_str(&"Mb"),
ty_u16 => w.write_str(&"Mw"),
}
}
ty::ty_float(t) => {
- alt t {
+ match t {
ty_f => w.write_char('l'),
ty_f32 => w.write_str(&"Mf"),
ty_f64 => w.write_str(&"MF"),
}
}
fn enc_proto(w: io::writer, proto: proto) {
- alt proto {
+ match proto {
proto_uniq => w.write_str(&"f~"),
proto_box => w.write_str(&"f@"),
proto_block => w.write_str(~"f&"),
}
fn enc_mode(w: io::writer, cx: @ctxt, m: mode) {
- alt ty::resolved_mode(cx.tcx, m) {
+ match ty::resolved_mode(cx.tcx, m) {
by_mutbl_ref => w.write_char('&'),
by_move => w.write_char('-'),
by_copy => w.write_char('+'),
}
fn enc_purity(w: io::writer, p: purity) {
- alt p {
+ match p {
pure_fn => w.write_char('p'),
impure_fn => w.write_char('i'),
unsafe_fn => w.write_char('u'),
enc_ty(w, cx, arg.ty);
}
w.write_char(']');
- alt ft.ret_style {
+ match ft.ret_style {
noreturn => w.write_char('!'),
_ => enc_ty(w, cx, ft.output)
}
fn enc_bounds(w: io::writer, cx: @ctxt, bs: @~[ty::param_bound]) {
for vec::each(*bs) |bound| {
- alt bound {
+ match bound {
ty::bound_send => w.write_char('S'),
ty::bound_copy => w.write_char('C'),
ty::bound_const => w.write_char('K'),
path: ast_map::path,
par_doc: ebml::doc) -> option<ast::inlined_item> {
let dcx = @{cdata: cdata, tcx: tcx, maps: maps};
- alt par_doc.opt_child(c::tag_ast) {
+ match par_doc.opt_child(c::tag_ast) {
none => none,
some(ast_doc) => {
debug!{"> Decoding inlined fn: %s::?", ast_map::path_to_str(path)};
decode_side_tables(xcx, ast_doc);
debug!{"< Decoded inlined fn: %s::%s",
ast_map::path_to_str(path), *ii.ident()};
- alt ii {
+ match ii {
ast::ii_item(i) => {
debug!{">>> DECODED ITEM >>>\n%s\n<<< DECODED ITEM <<<",
syntax::print::pprust::item_to_str(i)};
fn simplify_ast(ii: ast::inlined_item) -> ast::inlined_item {
fn drop_nested_items(blk: ast::blk_, fld: fold::ast_fold) -> ast::blk_ {
let stmts_sans_items = do vec::filter(blk.stmts) |stmt| {
- alt stmt.node {
+ match stmt.node {
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) |
ast::stmt_decl(@{node: ast::decl_local(_), span: _}, _) => true,
ast::stmt_decl(@{node: ast::decl_item(_), span: _}, _) => false
with *fold::default_ast_fold()
});
- alt ii {
+ match ii {
ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get()) //hack: we're not dropping items
}
with *fold::default_ast_fold()
});
- alt ii {
+ match ii {
ast::ii_item(i) => {
ast::ii_item(fld.fold_item(i).get())
}
impl of tr for ast::def {
fn tr(xcx: extended_decode_ctxt) -> ast::def {
- alt self {
+ match self {
ast::def_fn(did, p) => ast::def_fn(did.tr(xcx), p),
ast::def_self(nid) => ast::def_self(xcx.tr_id(nid)),
ast::def_mod(did) => ast::def_mod(did.tr(xcx)),
impl of tr for method_origin {
fn tr(xcx: extended_decode_ctxt) -> method_origin {
- alt self {
+ match self {
typeck::method_static(did) => {
typeck::method_static(did.tr(xcx))
}
ebml_w: ebml::writer,
vtable_origin: typeck::vtable_origin) {
do ebml_w.emit_enum(~"vtable_origin") {
- alt vtable_origin {
+ match vtable_origin {
typeck::vtable_static(def_id, tys, vtable_res) => {
do ebml_w.emit_enum_variant(~"vtable_static", 0u, 3u) {
do ebml_w.emit_enum_variant_arg(0u) {
-> typeck::vtable_origin {
do self.read_enum(~"vtable_origin") {
do self.read_enum_variant |i| {
- alt check i {
+ match check i {
0u => {
typeck::vtable_static(
do self.read_enum_variant_arg(0u) {
return {eq_fn: eq_int, mut data: ~[]};
}
});
- alt (item_out, item_exp) {
+ match (item_out, item_exp) {
(ast::ii_item(item_out), ast::ii_item(item_exp)) => {
assert pprust::item_to_str(item_out) == pprust::item_to_str(item_exp);
}
fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
if !cx.allow_block {
- alt ty::get(ty::expr_ty(cx.tcx, ex)).struct {
+ match ty::get(ty::expr_ty(cx.tcx, ex)).struct {
ty::ty_fn({proto: p, _}) if is_blockish(p) => {
cx.tcx.sess.span_err(ex.span,
~"expressions with stack closure type \
}
}
let outer = cx.allow_block;
- alt ex.node {
+ match ex.node {
expr_call(f, args, _) => {
cx.allow_block = true;
v.visit_expr(f, cx, v);
but its type can change:
let mut x = some(5);
- alt x {
+ match x {
some(ref y) => { ... }
none => { ... }
}
like the following:
let mut x = ~some(5);
- alt x {
+ match x {
~some(ref y) => { ... }
~none => { ... }
}
cat_stack_upvar(cmt), // upvar in stack closure
cat_deref(cmt, uint, ptr_kind), // deref of a ptr
cat_comp(cmt, comp_kind), // adjust to locate an internal component
- cat_discr(cmt, ast::node_id), // alt discriminant (see preserve())
+ cat_discr(cmt, ast::node_id), // match discriminant (see preserve())
}
// different kinds of pointers:
impl error_methods for borrowck_ctxt {
fn report_if_err(bres: bckres<()>) {
- alt bres {
+ match bres {
ok(()) => (),
err(e) => self.report(e)
}
}
fn add_to_mutbl_map(cmt: cmt) {
- alt cmt.cat {
+ match cmt.cat {
cat_local(id) | cat_arg(id) => {
self.mutbl_map.insert(id, ());
}
impl to_str_methods for borrowck_ctxt {
fn cat_to_repr(cat: categorization) -> ~str {
- alt cat {
+ match cat {
cat_special(sk_method) => ~"method",
cat_special(sk_static_item) => ~"static_item",
cat_special(sk_self) => ~"self",
}
fn mut_to_str(mutbl: ast::mutability) -> ~str {
- alt mutbl {
+ match mutbl {
m_mutbl => ~"mutable",
m_const => ~"const",
m_imm => ~"immutable"
}
fn ptr_sigil(ptr: ptr_kind) -> ~str {
- alt ptr {
+ match ptr {
uniq_ptr => ~"~",
gc_ptr => ~"@",
region_ptr(_) => ~"&",
}
fn comp_to_repr(comp: comp_kind) -> ~str {
- alt comp {
+ match comp {
comp_field(fld, _) => *fld,
comp_index(*) => ~"[]",
comp_tuple => ~"()",
}
fn lp_to_str(lp: @loan_path) -> ~str {
- alt *lp {
+ match *lp {
lp_local(node_id) => {
fmt!{"local(%d)", node_id}
}
fn cmt_to_str(cmt: cmt) -> ~str {
let mut_str = self.mut_to_str(cmt.mutbl);
- alt cmt.cat {
+ match cmt.cat {
cat_special(sk_method) => ~"method",
cat_special(sk_static_item) => ~"static item",
cat_special(sk_self) => ~"self reference",
cat_comp(_, comp_tuple) => ~"tuple content",
cat_comp(_, comp_variant(_)) => ~"enum content",
cat_comp(_, comp_index(t, _)) => {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_evec(*) => mut_str + ~" vec content",
ty::ty_estr(*) => mut_str + ~" str content",
_ => mut_str + ~" indexed content"
}
fn bckerr_code_to_str(code: bckerr_code) -> ~str {
- alt code {
+ match code {
err_mutbl(req, act) => {
fmt!{"creating %s alias to aliasable, %s memory",
self.mut_to_str(req), self.mut_to_str(act)}
// mutability can be "overridden" if the component is embedded in a
// mutable structure.
fn inherent_mutability(ck: comp_kind) -> mutability {
- alt ck {
+ match ck {
comp_tuple | comp_variant(_) => m_imm,
comp_field(_, m) | comp_index(_, m) => m
}
// derefable (we model an index as the combination of a deref and then a
// pointer adjustment).
fn opt_deref_kind(t: ty::t) -> option<deref_kind> {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_uniq(*) |
ty::ty_evec(_, ty::vstore_uniq) |
ty::ty_estr(ty::vstore_uniq) => {
}
fn deref_kind(tcx: ty::ctxt, t: ty::t) -> deref_kind {
- alt opt_deref_kind(t) {
+ match opt_deref_kind(t) {
some(k) => k,
none => {
tcx.sess.bug(
fn cat_borrow_of_expr(expr: @ast::expr) -> cmt {
// a borrowed expression must be either an @, ~, or a @vec, ~vec
let expr_ty = ty::expr_ty(self.tcx, expr);
- alt ty::get(expr_ty).struct {
+ match ty::get(expr_ty).struct {
ty::ty_evec(*) | ty::ty_estr(*) => {
self.cat_index(expr, expr)
}
let tcx = self.tcx;
let expr_ty = tcx.ty(expr);
- alt expr.node {
+ match expr.node {
ast::expr_unary(ast::deref, e_base) => {
if self.method_map.contains_key(expr.id) {
return self.cat_rvalue(expr, expr_ty);
}
let base_cmt = self.cat_expr(e_base);
- alt self.cat_deref(expr, base_cmt, 0u, true) {
+ match self.cat_deref(expr, base_cmt, 0u, true) {
some(cmt) => return cmt,
none => {
tcx.sess.span_bug(
span: span,
expr_ty: ty::t,
def: ast::def) -> cmt {
- alt def {
+ match def {
ast::def_fn(*) | ast::def_mod(_) |
ast::def_foreign_mod(_) | ast::def_const(_) |
ast::def_use(_) | ast::def_variant(*) |
// m: mutability of the argument
// lp: loan path, must be none for aliasable things
- let {m,lp} = alt ty::resolved_mode(self.tcx, mode) {
+ let {m,lp} = match ty::resolved_mode(self.tcx, mode) {
ast::by_mutbl_ref => {
{m: m_mutbl, lp: none}
}
ast::def_upvar(upvid, inner, fn_node_id) => {
let ty = ty::node_id_to_type(self.tcx, fn_node_id);
let proto = ty::ty_fn_proto(ty);
- alt proto {
+ match proto {
ast::proto_block => {
let upcmt = self.cat_def(id, span, expr_ty, *inner);
@{id:id, span:span,
/// or if the container is mutable.
fn inherited_mutability(base_m: ast::mutability,
comp_m: ast::mutability) -> ast::mutability {
- alt comp_m {
+ match comp_m {
m_imm => {base_m} // imm: as mutable as the container
m_mutbl | m_const => {comp_m}
}
fn cat_field<N:ast_node>(node: N, base_cmt: cmt,
f_name: ast::ident) -> cmt {
- let f_mutbl = alt field_mutbl(self.tcx, base_cmt.ty, f_name) {
+ let f_mutbl = match field_mutbl(self.tcx, base_cmt.ty, f_name) {
some(f_mutbl) => f_mutbl,
none => {
self.tcx.sess.span_bug(
fn cat_deref<N:ast_node>(node: N, base_cmt: cmt, derefs: uint,
expl: bool) -> option<cmt> {
do ty::deref(self.tcx, base_cmt.ty, expl).map |mt| {
- alt deref_kind(self.tcx, base_cmt.ty) {
+ match deref_kind(self.tcx, base_cmt.ty) {
deref_ptr(ptr) => {
let lp = do base_cmt.lp.chain |l| {
// Given that the ptr itself is loanable, we can
// the only way to reach the data they point at.
// Other ptr types admit aliases and are therefore
// not loanable.
- alt ptr {
+ match ptr {
uniq_ptr => {some(@lp_deref(l, ptr))}
gc_ptr | region_ptr(_) | unsafe_ptr => {none}
}
// for unique ptrs, we inherit mutability from the
// owning reference.
- let m = alt ptr {
+ let m = match ptr {
uniq_ptr => {
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
}
fn cat_index(expr: @ast::expr, base: @ast::expr) -> cmt {
let base_cmt = self.cat_autoderef(base);
- let mt = alt ty::index(self.tcx, base_cmt.ty) {
+ let mt = match ty::index(self.tcx, base_cmt.ty) {
some(mt) => mt,
none => {
self.tcx.sess.span_bug(
}
};
- return alt deref_kind(self.tcx, base_cmt.ty) {
+ return match deref_kind(self.tcx, base_cmt.ty) {
deref_ptr(ptr) => {
// (a) the contents are loanable if the base is loanable
// and this is a *unique* vector
- let deref_lp = alt ptr {
+ let deref_lp = match ptr {
uniq_ptr => {base_cmt.lp.map(|lp| @lp_deref(lp, uniq_ptr))}
_ => {none}
};
// (b) for unique ptrs, we inherit mutability from the
// owning reference.
- let m = alt ptr {
+ let m = match ptr {
uniq_ptr => {
self.inherited_mutability(base_cmt.mutbl, mt.mutbl)
}
let mut ctr = 0u;
loop {
ctr += 1u;
- alt self.cat_deref(base, cmt, ctr, false) {
+ match self.cat_deref(base, cmt, ctr, false) {
none => return cmt,
some(cmt1) => cmt = cmt1
}
base_ty: ty::t,
f_name: ast::ident) -> option<ast::mutability> {
// Need to refactor so that records/class fields can be treated uniformly.
- alt ty::get(base_ty).struct {
+ match ty::get(base_ty).struct {
ty::ty_rec(fields) => {
for fields.each |f| {
if f.ident == f_name {
ty::ty_class(did, substs) => {
for ty::lookup_class_fields(tcx, did).each |fld| {
if fld.ident == f_name {
- let m = alt fld.mutability {
+ let m = match fld.mutability {
ast::class_mutable => ast::m_mutbl,
ast::class_immutable => ast::m_imm
};
fn checked_by_liveness() -> bool {
// the liveness pass guarantees that immutable local variables
// are only assigned once; but it doesn't consider &mut
- alt self {
+ match self {
at_straight_up => true,
at_swap => true,
at_mutbl_ref => false
}
}
fn ing_form(desc: ~str) -> ~str {
- alt self {
+ match self {
at_straight_up => ~"assigning to " + desc,
at_swap => ~"swapping to and from " + desc,
at_mutbl_ref => ~"taking mut reference to " + desc
fn tcx() -> ty::ctxt { self.bccx.tcx }
fn purity(scope_id: ast::node_id) -> option<purity_cause> {
- let default_purity = alt self.declared_purity {
+ let default_purity = match self.declared_purity {
// an unsafe declaration overrides all
ast::unsafe_fn => return none,
let region_map = self.tcx().region_map;
let pure_map = self.req_maps.pure_map;
loop {
- alt pure_map.find(scope_id) {
+ match pure_map.find(scope_id) {
none => (),
some(e) => return some(pc_cmt(e))
}
- alt region_map.find(scope_id) {
+ match region_map.find(scope_id) {
none => return default_purity,
some(next_scope_id) => scope_id = next_scope_id
}
}
}
- alt region_map.find(scope_id) {
+ match region_map.find(scope_id) {
none => return,
some(next_scope_id) => scope_id = next_scope_id,
}
// (c) B is a pure fn;
// (d) B is not a fn.
- alt opt_expr {
+ match opt_expr {
some(expr) => {
- alt expr.node {
+ match expr.node {
ast::expr_path(_) if pc == pc_pure_fn => {
let def = self.tcx().def_map.get(expr.id);
let did = ast_util::def_id_of_def(def);
}
let callee_ty = ty::node_id_to_type(tcx, callee_id);
- alt ty::get(callee_ty).struct {
+ match ty::get(callee_ty).struct {
ty::ty_fn(fn_ty) => {
- alt fn_ty.purity {
+ match fn_ty.purity {
ast::pure_fn => return, // case (c) above
ast::impure_fn | ast::unsafe_fn | ast::extern_fn => {
self.report_purity_error(
fn is_stack_closure(id: ast::node_id) -> bool {
let fn_ty = ty::node_id_to_type(self.tcx(), id);
let proto = ty::ty_fn_proto(fn_ty);
- alt proto {
+ match proto {
ast::proto_block => true,
ast::proto_bare | ast::proto_uniq | ast::proto_box => false
}
}
fn is_allowed_pure_arg(expr: @ast::expr) -> bool {
- return alt expr.node {
+ return match expr.node {
ast::expr_path(_) => {
let def = self.tcx().def_map.get(expr.id);
let did = ast_util::def_id_of_def(def);
}
fn check_for_conflicting_loans(scope_id: ast::node_id) {
- let new_loanss = alt self.req_maps.req_loan_map.find(scope_id) {
+ let new_loanss = match self.req_maps.req_loan_map.find(scope_id) {
none => return,
some(loanss) => loanss
};
for (*new_loanss).each |new_loans| {
for (*new_loans).each |new_loan| {
if old_loan.lp != new_loan.lp { again; }
- alt (old_loan.mutbl, new_loan.mutbl) {
+ match (old_loan.mutbl, new_loan.mutbl) {
(m_const, _) | (_, m_const) |
(m_mutbl, m_mutbl) | (m_imm, m_imm) => {
/*ok*/
}
fn is_local_variable(cmt: cmt) -> bool {
- alt cmt.cat {
+ match cmt.cat {
cat_local(_) => true,
_ => false
}
}
fn is_self_field(cmt: cmt) -> bool {
- alt cmt.cat {
+ match cmt.cat {
cat_comp(cmt_base, comp_field(*)) => {
- alt cmt_base.cat {
+ match cmt_base.cat {
cat_special(sk_self) => true,
_ => false
}
// liveness guarantees that immutable local variables
// are only assigned once
} else {
- alt cmt.mutbl {
+ match cmt.mutbl {
m_mutbl => { /*ok*/ }
m_const | m_imm => {
self.bccx.span_err(
// if this is a pure function, only loan-able state can be
// assigned, because it is uniquely tied to this function and
// is not visible from the outside
- alt self.purity(ex.id) {
+ match self.purity(ex.id) {
none => (),
some(pc) => {
if cmt.lp.is_none() {
lp: @loan_path) {
for self.walk_loans_of(ex.id, lp) |loan| {
- alt loan.mutbl {
+ match loan.mutbl {
m_mutbl | m_const => { /*ok*/ }
m_imm => {
self.bccx.span_err(
// let mut x = {f: some(3)};
// let y = &x; // x loaned out as immutable
// x.f = none; // changes type of y.f, which appears to be imm
- alt *lp {
+ match *lp {
lp_comp(lp_base, ck) if inherent_mutability(ck) != m_mutbl => {
self.check_for_loan_conflicting_with_assignment(
at, ex, cmt, lp_base);
}
fn report_purity_error(pc: purity_cause, sp: span, msg: ~str) {
- alt pc {
+ match pc {
pc_pure_fn => {
self.tcx().sess.span_err(
sp,
debug!{"check_move_out_from_cmt(cmt=%s)",
self.bccx.cmt_to_repr(cmt)};
- alt cmt.cat {
+ match cmt.cat {
// Rvalues, locals, and arguments can be moved:
cat_rvalue | cat_local(_) | cat_arg(_) => {}
self.bccx.add_to_mutbl_map(cmt);
// check for a conflicting loan:
- let lp = alt cmt.lp {
+ let lp = match cmt.lp {
none => return,
some(lp) => lp
};
// safe to consider the use a last_use.
fn check_last_use(expr: @ast::expr) {
let cmt = self.bccx.cat_expr(expr);
- let lp = alt cmt.lp {
+ let lp = match cmt.lp {
none => return,
some(lp) => lp
};
callee_id: ast::node_id,
callee_span: span,
args: ~[@ast::expr]) {
- alt self.purity(expr.id) {
+ match self.purity(expr.id) {
none => {}
some(pc) => {
self.check_pure_callee_or_arg(
ty::ty_fn_args(
ty::node_id_to_type(self.tcx(), callee_id));
do vec::iter2(args, arg_tys) |arg, arg_ty| {
- alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
+ match ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_move => {
self.check_move_out(arg);
}
// of otherwise immutable fields and typestate wouldn't be
// able to "see" into those functions anyway, so it
// wouldn't be very helpful.
- alt fk {
+ match fk {
visit::fk_ctor(*) => {
self.in_ctor = true;
self.declared_purity = decl.purity;
fn check_loans_in_local(local: @ast::local,
&&self: check_loan_ctxt,
vt: visit::vt<check_loan_ctxt>) {
- alt local.node.init {
+ match local.node.init {
some({op: ast::init_move, expr: expr}) => {
self.check_move_out(expr);
}
vt: visit::vt<check_loan_ctxt>) {
self.check_for_conflicting_loans(expr.id);
- alt expr.node {
+ match expr.node {
ast::expr_path(*) if self.bccx.last_use_map.contains_key(expr.id) => {
self.check_last_use(expr);
}
}
}
ast::expr_addr_of(mutbl, base) => {
- alt mutbl {
+ match mutbl {
m_const => { /*all memory is const*/ }
m_mutbl => {
// If we are taking an &mut ptr, make sure the memory
do save_and_restore(self.declared_purity) {
self.check_for_conflicting_loans(blk.node.id);
- alt blk.node.rules {
+ match blk.node.rules {
ast::default_blk => {
}
ast::unchecked_blk => {
let old_root_ub = self.root_ub;
self.root_ub = body.node.id;
- alt fk {
+ match fk {
visit::fk_anon(*) | visit::fk_fn_block(*) => {}
visit::fk_item_fn(*) | visit::fk_method(*) |
visit::fk_ctor(*) | visit::fk_dtor(*) => {
}
// Special checks for various kinds of expressions:
- alt ex.node {
+ match ex.node {
ast::expr_addr_of(mutbl, base) => {
let base_cmt = self.bccx.cat_expr(base);
// make sure that the thing we are pointing out stays valid
// for the lifetime `scope_r` of the resulting ptr:
let scope_r =
- alt check ty::get(tcx.ty(ex)).struct {
+ match check ty::get(tcx.ty(ex)).struct {
ty::ty_rptr(r, _) => r
};
self.guarantee_valid(base_cmt, mutbl, scope_r);
let arg_tys = ty::ty_fn_args(ty::expr_ty(self.tcx(), f));
let scope_r = ty::re_scope(ex.id);
do vec::iter2(args, arg_tys) |arg, arg_ty| {
- alt ty::resolved_mode(self.tcx(), arg_ty.mode) {
+ match ty::resolved_mode(self.tcx(), arg_ty.mode) {
ast::by_mutbl_ref => {
let arg_cmt = self.bccx.cat_expr(arg);
self.guarantee_valid(arg_cmt, m_mutbl, scope_r);
// immutable (whereas something like {f:int} would be
// fine).
//
- alt opt_deref_kind(arg_ty.ty) {
+ match opt_deref_kind(arg_ty.ty) {
some(deref_ptr(region_ptr(_))) |
some(deref_ptr(unsafe_ptr)) => {
/* region pointers are (by induction) guaranteed */
region_to_str(self.tcx(), scope_r)};
let _i = indenter();
- alt cmt.lp {
+ match cmt.lp {
// If this expression is a loanable path, we MUST take out a
// loan. This is somewhat non-obvious. You might think,
// for example, that if we have an immutable local variable
// it within that scope, the loan will be detected and an
// error will be reported.
some(_) => {
- alt self.bccx.loan(cmt, scope_r, req_mutbl) {
+ match self.bccx.loan(cmt, scope_r, req_mutbl) {
err(e) => { self.bccx.report(e); }
ok(loans) if loans.len() == 0 => {}
ok(loans) => {
- alt scope_r {
+ match scope_r {
ty::re_scope(scope_id) => {
self.add_loans(scope_id, loans);
}
};
- alt result {
+ match result {
ok(pc_ok) => {
// we were able guarantee the validity of the ptr,
// perhaps by rooting or because it is immutably
ok(pc_if_pure(e)) => {
// we are only able to guarantee the validity if
// the scope is pure
- alt scope_r {
+ match scope_r {
ty::re_scope(pure_id) => {
// if the scope is some block/expr in the fn,
// then just require that this scope be pure
// mutable memory.
fn check_mutbl(req_mutbl: ast::mutability,
cmt: cmt) -> bckres<preserve_condition> {
- alt (req_mutbl, cmt.mutbl) {
+ match (req_mutbl, cmt.mutbl) {
(m_const, _) |
(m_imm, m_imm) |
(m_mutbl, m_mutbl) => {
}
fn add_loans(scope_id: ast::node_id, loans: @dvec<loan>) {
- alt self.req_maps.req_loan_map.find(scope_id) {
+ match self.req_maps.req_loan_map.find(scope_id) {
some(l) => {
(*l).push(loans);
}
// To see what I mean about ids etc, consider:
//
// let x = @@3;
- // alt x {
+ // match x {
// @@y { ... }
// }
//
let _i = indenter();
let tcx = self.tcx();
- alt pat.node {
+ match pat.node {
ast::pat_wild => {
// _
}
}
ast::pat_enum(_, some(subpats)) => {
// variant(x, y, z)
- let enum_did = alt self.bccx.tcx.def_map
+ let enum_did = match self.bccx.tcx.def_map
.find(pat.id) {
some(ast::def_variant(enum_did, _)) => enum_did,
e => tcx.sess.span_bug(pat.span,
ast::pat_box(subpat) | ast::pat_uniq(subpat) => {
// @p1, ~p1
- alt self.bccx.cat_deref(subpat, cmt, 0u, true) {
+ match self.bccx.cat_deref(subpat, cmt, 0u, true) {
some(subcmt) => {
self.gather_pat(subcmt, subpat, arm_id, alt_id);
}
let lc = loan_ctxt_(@{bccx: self,
scope_region: scope_region,
loans: @dvec()});
- alt lc.loan(cmt, mutbl) {
+ match lc.loan(cmt, mutbl) {
ok(()) => {ok(lc.loans)}
err(e) => {err(e)}
}
~"loan() called with non-lendable value");
}
- alt cmt.cat {
+ match cmt.cat {
cat_binding(_) | cat_rvalue | cat_special(_) => {
// should never be loanable
self.bccx.tcx.sess.span_bug(
fn loan_stable_comp(cmt: cmt,
cmt_base: cmt,
req_mutbl: ast::mutability) -> bckres<()> {
- let base_mutbl = alt req_mutbl {
+ let base_mutbl = match req_mutbl {
m_imm => m_imm,
m_const | m_mutbl => m_const
};
// combines two preservation conditions such that if either of
// them requires purity, the result requires purity
fn combine(pc: preserve_condition) -> preserve_condition {
- alt self {
+ match self {
pc_ok => {pc}
pc_if_pure(e) => {self}
}
self.root_managed_data};
let _i = indenter();
- alt cmt.cat {
+ match cmt.cat {
cat_special(sk_self) | cat_special(sk_heap_upvar) => {
self.compare_scope(cmt, ty::re_scope(self.item_ub))
}
if base.mutbl == m_imm {
let non_rooting_ctxt =
preserve_ctxt({root_managed_data: false with **self});
- alt (&non_rooting_ctxt).preserve(base) {
+ match (&non_rooting_ctxt).preserve(base) {
ok(pc_ok) => {
ok(pc_ok)
}
// As an example, consider this scenario:
//
// let mut x = @some(3);
- // alt *x { some(y) {...} none {...} }
+ // match *x { some(y) {...} none {...} }
//
// Technically, the value `x` need only be rooted
// in the `some` arm. However, we evaluate `x` in trans
// As a second example, consider *this* scenario:
//
// let x = @mut @some(3);
- // alt x { @@some(y) {...} @@none {...} }
+ // match x { @@some(y) {...} @@none {...} }
//
// Here again, `x` need only be rooted in the `some` arm.
// In this case, the value which needs to be rooted is
// also yielded suboptimal results for patterns like:
//
// let x = @mut @...;
- // alt x { @@some_variant(y) | @@some_other_variant(y) {...} }
+ // match x { @@some_variant(y) | @@some_other_variant(y) =>
//
// The reason is that we would root the value once for
// each pattern and not once per arm. This is also easily
// current scope must be the arm, which is always a child of alt:
assert {
- alt check self.scope_region {
+ match check self.scope_region {
ty::re_scope(arm_id) => {
self.tcx().region_map.get(arm_id) == alt_id
}
code: bckerr_code) -> bckres<preserve_condition> {
// Variant contents and unique pointers: must be immutably
// rooted to a preserved address.
- alt self.preserve(cmt_base) {
+ match self.preserve(cmt_base) {
// the base is preserved, but if we are not mutable then
// purity is required
ok(pc_ok) => {
- alt cmt_base.mutbl {
+ match cmt_base.mutbl {
m_mutbl | m_const => {
ok(pc_if_pure({cmt:cmt, code:code}))
}
}
let root_region = ty::re_scope(self.root_ub);
- alt self.scope_region {
+ match self.scope_region {
// we can only root values if the desired region is some concrete
// scope within the fn body
ty::re_scope(scope_id) => {
// now go through anything that is referenced but was not explicitly
// named and add that
- let implicit_mode = alt fn_proto {
+ let implicit_mode = match fn_proto {
ast::proto_block => cap_ref,
ast::proto_bare | ast::proto_box | ast::proto_uniq => cap_copy
};
do vec::iter(*freevars) |fvar| {
let fvar_def_id = ast_util::def_id_of_def(fvar.def).node;
- alt cap_map.find(fvar_def_id) {
+ match cap_map.find(fvar_def_id) {
option::some(_) => { /* was explicitly named, do nothing */ }
option::none => {
cap_map.insert(fvar_def_id, {def:fvar.def,
fn check_expr(tcx: ty::ctxt, ex: @expr, &&s: (), v: visit::vt<()>) {
visit::visit_expr(ex, s, v);
- alt ex.node {
+ match ex.node {
expr_alt(scrut, arms, mode) => {
check_arms(tcx, arms);
/* Check for exhaustiveness */
// Vacuously exhaustive
return;
}
- alt ty::get(pat_ty).struct {
+ match ty::get(pat_ty).struct {
ty_enum(did, _) => {
if (*enum_variants(tcx, did)).is_empty() && arms.is_empty() {
for arms.each |arm| {
for arm.pats.each |pat| {
let v = ~[pat];
- alt is_useful(tcx, seen, v) {
+ match is_useful(tcx, seen, v) {
not_useful => {
tcx.sess.span_err(pat.span, ~"unreachable pattern");
}
}
fn raw_pat(p: @pat) -> @pat {
- alt p.node {
+ match p.node {
pat_ident(_, _, some(s)) => { raw_pat(s) }
_ => { p }
}
fn check_exhaustive(tcx: ty::ctxt, sp: span, pats: ~[@pat]) {
assert(pats.is_not_empty());
- let ext = alt is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) {
+ let ext = match is_useful(tcx, vec::map(pats, |p| ~[p]), ~[wild()]) {
not_useful => return, // This is good, wildcard pattern isn't reachable
useful_ => none,
useful(ty, ctor) => {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_bool => {
- alt check ctor {
+ match check ctor {
val(const_int(1i64)) => some(@~"true"),
val(const_int(0i64)) => some(@~"false")
}
}
ty::ty_enum(id, _) => {
- let vid = alt check ctor { variant(id) => id };
- alt check vec::find(*ty::enum_variants(tcx, id),
+ let vid = match check ctor { variant(id) => id };
+ match check vec::find(*ty::enum_variants(tcx, id),
|v| v.id == vid) {
some(v) => some(v.name)
}
}
}
};
- let msg = ~"non-exhaustive patterns" + alt ext {
+ let msg = ~"non-exhaustive patterns" + match ext {
some(s) => ~": " + *s + ~" not covered",
none => ~""
};
fn is_useful(tcx: ty::ctxt, m: matrix, v: ~[@pat]) -> useful {
if m.len() == 0u { return useful_; }
if m[0].len() == 0u { return not_useful; }
- let real_pat = alt vec::find(m, |r| r[0].id != 0) {
+ let real_pat = match vec::find(m, |r| r[0].id != 0) {
some(r) => r[0], none => v[0]
};
let left_ty = if real_pat.id == 0 { ty::mk_nil(tcx) }
else { ty::node_id_to_type(tcx, real_pat.id) };
- alt pat_ctor_id(tcx, v[0]) {
+ match pat_ctor_id(tcx, v[0]) {
none => {
- alt missing_ctor(tcx, m, left_ty) {
+ match missing_ctor(tcx, m, left_ty) {
none => {
- alt ty::get(left_ty).struct {
+ match ty::get(left_ty).struct {
ty::ty_bool => {
- alt is_useful_specialized(tcx, m, v, val(const_int(1i64)),
+ match is_useful_specialized(tcx, m, v, val(const_int(1i64)),
0u, left_ty){
not_useful => {
is_useful_specialized(tcx, m, v, val(const_int(0i64)),
}
ty::ty_enum(eid, _) => {
for (*ty::enum_variants(tcx, eid)).each |va| {
- alt is_useful_specialized(tcx, m, v, variant(va.id),
+ match is_useful_specialized(tcx, m, v, variant(va.id),
va.args.len(), left_ty) {
not_useful => (),
u => return u
}
}
some(ctor) => {
- alt is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ),
+ match is_useful(tcx, vec::filter_map(m, |r| default(tcx, r) ),
vec::tail(v)) {
useful_ => useful(left_ty, ctor),
u => u
fn is_useful_specialized(tcx: ty::ctxt, m: matrix, v: ~[@pat], ctor: ctor,
arity: uint, lty: ty::t) -> useful {
let ms = vec::filter_map(m, |r| specialize(tcx, r, ctor, arity, lty) );
- alt is_useful(tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty))){
+ let could_be_useful = is_useful(
+ tcx, ms, option::get(specialize(tcx, v, ctor, arity, lty)));
+ match could_be_useful {
useful_ => useful(lty, ctor),
u => u
}
fn pat_ctor_id(tcx: ty::ctxt, p: @pat) -> option<ctor> {
let pat = raw_pat(p);
- alt pat.node {
+ match pat.node {
pat_wild => { none }
pat_ident(_, _, _) | pat_enum(_, _) => {
- alt tcx.def_map.find(pat.id) {
+ match tcx.def_map.find(pat.id) {
some(def_variant(_, id)) => some(variant(id)),
_ => none
}
fn is_wild(tcx: ty::ctxt, p: @pat) -> bool {
let pat = raw_pat(p);
- alt pat.node {
+ match pat.node {
pat_wild => { true }
pat_ident(_, _, _) => {
- alt tcx.def_map.find(pat.id) {
+ match tcx.def_map.find(pat.id) {
some(def_variant(_, _)) => { false }
_ => { true }
}
}
fn missing_ctor(tcx: ty::ctxt, m: matrix, left_ty: ty::t) -> option<ctor> {
- alt ty::get(left_ty).struct {
+ match ty::get(left_ty).struct {
ty::ty_box(_) | ty::ty_uniq(_) | ty::ty_tup(_) | ty::ty_rec(_) => {
for m.each |r| {
if !is_wild(tcx, r[0]) { return none; }
ty::ty_bool => {
let mut true_found = false, false_found = false;
for m.each |r| {
- alt check pat_ctor_id(tcx, r[0]) {
+ match check pat_ctor_id(tcx, r[0]) {
none => (),
some(val(const_int(1i64))) => true_found = true,
some(val(const_int(0i64))) => false_found = true
}
fn ctor_arity(tcx: ty::ctxt, ctor: ctor, ty: ty::t) -> uint {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_tup(fs) => fs.len(),
ty::ty_rec(fs) => fs.len(),
ty::ty_box(_) | ty::ty_uniq(_) => 1u,
ty::ty_enum(eid, _) => {
- let id = alt check ctor { variant(id) => id };
- alt check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) {
+ let id = match check ctor { variant(id) => id };
+ match check vec::find(*ty::enum_variants(tcx, eid), |v| v.id == id ) {
some(v) => v.args.len()
}
}
fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
left_ty: ty::t) -> option<~[@pat]> {
let r0 = raw_pat(r[0]);
- alt r0.node {
+ match r0.node {
pat_wild => some(vec::append(vec::from_elem(arity, wild()),
vec::tail(r))),
pat_ident(_, _, _) => {
- alt tcx.def_map.find(r0.id) {
+ match tcx.def_map.find(r0.id) {
some(def_variant(_, id)) => {
if variant(id) == ctor_id { some(vec::tail(r)) }
else { none }
}
}
pat_enum(_, args) => {
- alt check tcx.def_map.get(r0.id) {
+ match check tcx.def_map.get(r0.id) {
def_variant(_, id) if variant(id) == ctor_id => {
- let args = alt args {
+ let args = match args {
some(args) => args,
none => vec::from_elem(arity, wild())
};
}
}
pat_rec(flds, _) => {
- let ty_flds = alt check ty::get(left_ty).struct {
+ let ty_flds = match check ty::get(left_ty).struct {
ty::ty_rec(flds) => flds
};
let args = vec::map(ty_flds, |ty_f| {
- alt vec::find(flds, |f| f.ident == ty_f.ident ) {
+ match vec::find(flds, |f| f.ident == ty_f.ident ) {
some(f) => f.pat, _ => wild()
}
});
pat_box(a) | pat_uniq(a) => some(vec::append(~[a], vec::tail(r))),
pat_lit(expr) => {
let e_v = eval_const_expr(tcx, expr);
- let match_ = alt check ctor_id {
+ let match_ = match check ctor_id {
val(v) => compare_const_vals(e_v, v) == 0,
range(c_lo, c_hi) => {
compare_const_vals(c_lo, e_v) >= 0 &&
if match_ { some(vec::tail(r)) } else { none }
}
pat_range(lo, hi) => {
- let (c_lo, c_hi) = alt check ctor_id {
+ let (c_lo, c_hi) = match check ctor_id {
val(v) => (v, v),
range(lo, hi) => (lo, hi),
single => return some(vec::tail(r)),
}
fn is_refutable(tcx: ty::ctxt, pat: @pat) -> bool {
- alt tcx.def_map.find(pat.id) {
+ match tcx.def_map.find(pat.id) {
some(def_variant(enum_id, var_id)) => {
if vec::len(*ty::enum_variants(tcx, enum_id)) != 1u { return true; }
}
_ => ()
}
- alt pat.node {
+ match pat.node {
pat_box(sub) | pat_uniq(sub) | pat_ident(_, _, some(sub)) => {
is_refutable(tcx, sub)
}
fn check_item(sess: session, ast_map: ast_map::map,
def_map: resolve3::DefMap,
it: @item, &&_is_const: bool, v: visit::vt<bool>) {
- alt it.node {
+ match it.node {
item_const(_, ex) => {
v.visit_expr(ex, true, v);
check_item_recursion(sess, ast_map, def_map, it);
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
fn is_str(e: @expr) -> bool {
- alt e.node {
+ match e.node {
expr_vstore(@{node: expr_lit(@{node: lit_str(_), _}), _},
vstore_uniq) => true,
_ => false
}
}
- alt p.node {
+ match p.node {
// Let through plain ~-string literals here
pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); }
pat_range(a, b) => {
method_map: typeck::method_map, tcx: ty::ctxt,
e: @expr, &&is_const: bool, v: visit::vt<bool>) {
if is_const {
- alt e.node {
+ match e.node {
expr_unary(box(_), _) | expr_unary(uniq(_), _) |
expr_unary(deref, _) => {
sess.span_err(e.span,
}
}
expr_path(_) => {
- alt def_map.find(e.id) {
+ match def_map.find(e.id) {
some(def_const(def_id)) => {
if !ast_util::is_local(def_id) {
sess.span_err(
}
}
}
- alt e.node {
+ match e.node {
expr_lit(@{node: lit_int(v, t), _}) => {
if t != ty_char {
if (v as u64) > ast_util::int_ty_max(
}
fn visit_expr(e: @expr, &&env: env, v: visit::vt<env>) {
- alt e.node {
+ match e.node {
expr_path(path) => {
- alt env.def_map.find(e.id) {
+ match env.def_map.find(e.id) {
some(def_const(def_id)) => {
- alt check env.ast_map.get(def_id.node) {
+ match check env.ast_map.get(def_id.node) {
ast_map::node_item(it, _) => {
v.visit_item(it, env, v);
}
visit::visit_item(i, {in_loop: false, can_ret: true}, v);
},
visit_expr: |e: @expr, cx: ctx, v: visit::vt<ctx>| {
- alt e.node {
+ match e.node {
expr_while(e, b) => {
v.visit_expr(e, cx, v);
v.visit_block(b, {in_loop: true with cx}, v);
}
fn join(a: constness, b: constness) -> constness {
- alt (a,b) {
+ match (a,b) {
(integral_const, integral_const) => integral_const,
(integral_const, general_const)
| (general_const, integral_const)
def_map: resolve3::DefMap,
tcx: ty::ctxt) -> constness {
let did = ast_util::local_def(e.id);
- alt tcx.ccache.find(did) {
+ match tcx.ccache.find(did) {
some(x) => x,
none => {
let cn =
- alt e.node {
+ match e.node {
ast::expr_lit(lit) => {
- alt lit.node {
+ match lit.node {
ast::lit_str(*) |
ast::lit_float(*) => general_const,
_ => integral_const
}
ast::expr_vstore(e, vstore) => {
- alt vstore {
+ match vstore {
ast::vstore_fixed(_) |
ast::vstore_slice(_) => classify(e, def_map, tcx),
ast::vstore_uniq |
// FIXME: #1272, we can probably do something CCI-ish
// surrounding nonlocal constants. But we don't yet.
ast::expr_path(_) => {
- alt def_map.find(e.id) {
+ match def_map.find(e.id) {
some(ast::def_const(def_id)) => {
if ast_util::is_local(def_id) {
let ty = ty::expr_ty(tcx, e);
fn eval_const_expr(tcx: middle::ty::ctxt, e: @expr) -> const_val {
import middle::ty;
fn fromb(b: bool) -> const_val { const_int(b as i64) }
- alt check e.node {
+ match check e.node {
expr_unary(neg, inner) => {
- alt check eval_const_expr(tcx, inner) {
+ match check eval_const_expr(tcx, inner) {
const_float(f) => const_float(-f),
const_int(i) => const_int(-i),
const_uint(i) => const_uint(-i)
}
}
expr_unary(not, inner) => {
- alt check eval_const_expr(tcx, inner) {
+ match check eval_const_expr(tcx, inner) {
const_int(i) => const_int(!i),
const_uint(i) => const_uint(!i)
}
}
expr_binary(op, a, b) => {
- alt check (eval_const_expr(tcx, a), eval_const_expr(tcx, b)) {
+ match check (eval_const_expr(tcx, a), eval_const_expr(tcx, b)) {
(const_float(a), const_float(b)) => {
- alt check op {
+ match check op {
add => const_float(a + b),
subtract => const_float(a - b),
mul => const_float(a * b),
}
}
(const_int(a), const_int(b)) => {
- alt check op {
+ match check op {
add => const_int(a + b),
subtract => const_int(a - b),
mul => const_int(a * b),
}
}
(const_uint(a), const_uint(b)) => {
- alt check op {
+ match check op {
add => const_uint(a + b),
subtract => const_uint(a - b),
mul => const_uint(a * b),
}
// shifts can have any integral type as their rhs
(const_int(a), const_uint(b)) => {
- alt check op {
+ match check op {
shl => const_int(a << b),
shr => const_int(a >> b)
}
}
(const_uint(a), const_int(b)) => {
- alt check op {
+ match check op {
shl => const_uint(a << b),
shr => const_uint(a >> b)
}
expr_cast(base, _) => {
let ety = ty::expr_ty(tcx, e);
let base = eval_const_expr(tcx, base);
- alt check ty::get(ety).struct {
+ match check ty::get(ety).struct {
ty::ty_float(_) => {
- alt check base {
+ match check base {
const_uint(u) => const_float(u as f64),
const_int(i) => const_float(i as f64),
const_float(_) => base
}
}
ty::ty_uint(_) => {
- alt check base {
+ match check base {
const_uint(_) => base,
const_int(i) => const_uint(i as u64),
const_float(f) => const_uint(f as u64)
}
}
ty::ty_int(_) | ty::ty_bool => {
- alt check base {
+ match check base {
const_uint(u) => const_int(u as i64),
const_int(_) => base,
const_float(f) => const_int(f as i64)
}
fn lit_to_const(lit: @lit) -> const_val {
- alt lit.node {
+ match lit.node {
lit_str(s) => const_str(*s),
lit_int(n, _) => const_int(n),
lit_uint(n, _) => const_uint(n),
}
fn compare_const_vals(a: const_val, b: const_val) -> int {
- alt (a, b) {
+ match (a, b) {
(const_int(a), const_int(b)) => {
if a == b {
0
fn ignore_item(_i: @ast::item, &&_depth: int, _v: visit::vt<int>) { }
let walk_expr = fn@(expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
- alt expr.node {
+ match expr.node {
ast::expr_fn(proto, decl, _, _) => {
if proto != ast::proto_bare {
visit::visit_expr(expr, depth + 1, v);
}
ast::expr_path(path) => {
let mut i = 0;
- alt def_map.find(expr.id) {
+ match def_map.find(expr.id) {
none => fail (~"Not found: " + path_to_str(path)),
some(df) => {
let mut def = df;
while i < depth {
- alt copy def {
+ match copy def {
ast::def_upvar(_, inner, _) => { def = *inner; }
_ => break
}
}
fn get_freevars(tcx: ty::ctxt, fid: ast::node_id) -> freevar_info {
- alt tcx.freevars.find(fid) {
+ match tcx.freevars.find(fid) {
none => fail ~"get_freevars: " + int::str(fid) + ~" has no freevars",
some(d) => return d
}
}
let fty = ty::node_id_to_type(cx.tcx, id);
- alt ty::ty_fn_proto(fty) {
+ match ty::ty_fn_proto(fty) {
proto_uniq => b(check_for_uniq),
proto_box => b(check_for_box),
proto_bare => b(check_for_bare),
// errors and produce a list of the def id's for all capture
// variables. This list is used below to avoid checking and reporting
// on a given variable twice.
- let cap_clause = alt fk {
+ let cap_clause = match fk {
visit::fk_anon(_, cc) | visit::fk_fn_block(cc) => cc,
visit::fk_item_fn(*) | visit::fk_method(*) |
visit::fk_ctor(*) | visit::fk_dtor(*) => @~[]
// if this is the last use of the variable, then it will be
// a move and not a copy
let is_move = {
- alt check cx.last_use_map.find(fn_id) {
+ match check cx.last_use_map.find(fn_id) {
some(vars) => (*vars).contains(id),
none => false
}
}
fn check_block(b: blk, cx: ctx, v: visit::vt<ctx>) {
- alt b.node.expr {
+ match b.node.expr {
some(ex) => maybe_copy(cx, ex),
_ => ()
}
fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
debug!{"kind::check_expr(%s)", expr_to_str(e)};
- alt e.node {
+ match e.node {
expr_assign(_, ex) |
expr_unary(box(_), ex) | expr_unary(uniq(_), ex) |
expr_ret(some(ex)) => {
}
expr_rec(fields, def) => {
for fields.each |field| { maybe_copy(cx, field.node.expr); }
- alt def {
+ match def {
some(ex) => {
// All noncopyable fields must be overridden
let t = ty::expr_ty(cx.tcx, ex);
- let ty_fields = alt ty::get(t).struct {
+ let ty_fields = match ty::get(t).struct {
ty::ty_rec(f) => f,
_ => cx.tcx.sess.span_bug(ex.span, ~"bad expr type in record")
};
expr_call(f, args, _) => {
let mut i = 0u;
for ty::ty_fn_args(ty::expr_ty(cx.tcx, f)).each |arg_t| {
- alt ty::arg_mode(cx.tcx, arg_t) {
+ match ty::arg_mode(cx.tcx, arg_t) {
by_copy => maybe_copy(cx, args[i]),
by_ref | by_val | by_mutbl_ref | by_move => ()
}
}
expr_path(_) | expr_field(_, _, _) => {
do option::iter(cx.tcx.node_type_substs.find(e.id)) |ts| {
- let bounds = alt check e.node {
+ let bounds = match check e.node {
expr_path(_) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(e.id));
ty::lookup_item_type(cx.tcx, did).bounds
}
expr_field(base, _, _) => {
- alt cx.method_map.get(e.id).origin {
+ match cx.method_map.get(e.id).origin {
typeck::method_static(did) => {
// n.b.: When we encode class/impl methods, the bounds
// that we encode include both the class/impl bounds
}
fn check_stmt(stmt: @stmt, cx: ctx, v: visit::vt<ctx>) {
- alt stmt.node {
+ match stmt.node {
stmt_decl(@{node: decl_local(locals), _}, _) => {
for locals.each |local| {
- alt local.node.init {
+ match local.node.init {
some({op: init_assign, expr}) => maybe_copy(cx, expr),
_ => {}
}
}
fn check_ty(aty: @ty, cx: ctx, v: visit::vt<ctx>) {
- alt aty.node {
+ match aty.node {
ty_path(_, id) => {
do option::iter(cx.tcx.node_type_substs.find(id)) |ts| {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(id));
}
fn is_nullary_variant(cx: ctx, ex: @expr) -> bool {
- alt ex.node {
+ match ex.node {
expr_path(_) => {
- alt cx.tcx.def_map.get(ex.id) {
+ match cx.tcx.def_map.get(ex.id) {
def_variant(edid, vdid) => {
vec::len(ty::enum_variant_with_id(cx.tcx, edid, vdid).args) == 0u
}
fn check_imm_free_var(cx: ctx, def: def, sp: span) {
let msg = ~"mutable variables cannot be implicitly captured; \
use a capture clause";
- alt def {
+ match def {
def_local(_, is_mutbl) => {
if is_mutbl {
cx.tcx.sess.span_err(sp, msg);
}
}
def_arg(_, mode) => {
- alt ty::resolved_mode(cx.tcx, mode) {
+ match ty::resolved_mode(cx.tcx, mode) {
by_ref | by_val | by_move | by_copy => { /* ok */ }
by_mutbl_ref => {
cx.tcx.sess.span_err(sp, msg);
// note: also used from middle::typeck::regionck!
fn check_owned(tcx: ty::ctxt, ty: ty::t, sp: span) -> bool {
if !ty::kind_is_owned(ty::type_kind(tcx, ty)) {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_param(*) => {
tcx.sess.span_err(sp, ~"value may contain borrowed \
pointers; use `owned` bound");
// Determine what type we are casting to; if it is not an trait, then no
// worries.
let target_ty = ty::expr_ty(cx.tcx, target);
- let target_substs = alt ty::get(target_ty).struct {
+ let target_substs = match ty::get(target_ty).struct {
ty::ty_trait(_, substs) => {substs}
_ => { return; /* not a cast to a trait */ }
};
// Check, based on the region associated with the trait, whether it can
// possibly escape the enclosing fn item (note that all type parameters
// must have been declared on the enclosing fn item):
- alt target_substs.self_r {
+ match target_substs.self_r {
some(ty::re_scope(*)) => { return; /* case (1) */ }
none | some(ty::re_static) | some(ty::re_free(*)) => {}
some(ty::re_bound(*)) | some(ty::re_var(*)) => {
let target_params = ty::param_tys_in_type(target_ty);
let source_ty = ty::expr_ty(cx.tcx, source);
do ty::walk_ty(source_ty) |ty| {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_param(source_param) => {
if target_params.contains(source_param) {
/* case (2) */
fn match_and_collect_meta_item(item_def_id: def_id,
meta_item: meta_item) {
- alt meta_item.node {
+ match meta_item.node {
meta_name_value(key, literal) => {
- alt literal.node {
+ match literal.node {
lit_str(value) => {
self.match_and_collect_item(item_def_id,
*key,
return; // Didn't match.
}
- alt self.item_refs.find(value) {
+ match self.item_refs.find(value) {
none => {
// Didn't match.
}
some(item_ref) => {
// Check for duplicates.
- alt copy *item_ref {
+ match copy *item_ref {
some(original_def_id)
if original_def_id != item_def_id => {
do iter_crate_data(crate_store) |crate_number, _crate_metadata| {
for each_path(crate_store, crate_number) |path_entry| {
let def_id;
- alt path_entry.def_like {
+ match path_entry.def_like {
dl_def(def_ty(did)) => {
def_id = did;
}
fn check_completeness() {
for self.item_refs.each |key, item_ref| {
- alt copy *item_ref {
+ match copy *item_ref {
none => {
self.session.err(fmt!{"no item found for `%s`", key});
}
// This is pretty unfortunate. We really want some sort of "deriving Enum"
// type of thing.
fn int_to_lint(i: int) -> lint {
- alt check i {
+ match check i {
0 => ctypes,
1 => unused_imports,
2 => while_true,
}
fn level_to_str(lv: level) -> ~str {
- alt lv {
+ match lv {
allow => ~"allow",
warn => ~"warn",
deny => ~"deny",
}
fn get_lint_level(modes: lint_modes, lint: lint) -> level {
- alt modes.find(lint as uint) {
+ match modes.find(lint as uint) {
some(c) => c,
none => allow
}
lint_mode: lint,
_expr_id: ast::node_id,
item_id: ast::node_id) -> level {
- alt settings.settings_map.find(item_id) {
+ match settings.settings_map.find(item_id) {
some(modes) => get_lint_level(modes, lint_mode),
none => get_lint_level(settings.default_settings, lint_mode)
}
attr::attr_metas(attr::find_attrs_by_name(attrs,
level_name));
for metas.each |meta| {
- alt meta.node {
+ match meta.node {
ast::meta_list(_, metas) => {
for metas.each |meta| {
- alt meta.node {
+ match meta.node {
ast::meta_word(lintname) => {
vec::push(triples, (meta, level, lintname));
}
for triples.each |pair| {
let (meta, level, lintname) = pair;
- alt self.dict.find(*lintname) {
+ match self.dict.find(*lintname) {
none => {
self.span_lint(
new_ctxt.get_level(unrecognized_lint),
fn check_item_while_true(cx: ty::ctxt, it: @ast::item) {
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_expr: fn@(e: @ast::expr) {
- alt e.node {
+ match e.node {
ast::expr_while(cond, _) => {
- alt cond.node {
+ match cond.node {
ast::expr_lit(@{node: ast::lit_bool(true),_}) => {
cx.sess.span_lint(
while_true, e.id, it.id,
decl: ast::fn_decl) {
let tys = vec::map(decl.inputs, |a| a.ty );
for vec::each(vec::append_one(tys, decl.output)) |ty| {
- alt ty.node {
+ match ty.node {
ast::ty_path(_, id) => {
- alt cx.def_map.get(id) {
+ match cx.def_map.get(id) {
ast::def_prim_ty(ast::ty_int(ast::ty_i)) => {
cx.sess.span_lint(
ctypes, id, fn_id,
}
}
- alt it.node {
+ match it.node {
ast::item_foreign_mod(nmod) if attr::foreign_abi(it.attrs) !=
either::right(ast::foreign_abi_rust_intrinsic) => {
for nmod.items.each |ni| {
- alt ni.node {
+ match ni.node {
ast::foreign_item_fn(decl, tps) => {
check_foreign_fn(cx, it.id, decl);
}
fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_stmt: fn@(s: @ast::stmt) {
- alt s.node {
+ match s.node {
ast::stmt_semi(@{id: id,
callee_id: _,
node: ast::expr_path(@path),
}
}
- alt it.node {
+ match it.node {
ast::item_ty(*) | ast::item_class(*) |
ast::item_trait(*) | ast::item_impl(*) => {
check_case(cx, it.ident, it.id, it.id, it.span)
// don't complain about blocks, since they tend to get their modes
// specified from the outside
- alt fk {
+ match fk {
visit::fk_fn_block(*) => { return; }
_ => {}
}
let fn_ty = ty::node_id_to_type(tcx, id);
- alt check ty::get(fn_ty).struct {
+ match check ty::get(fn_ty).struct {
ty::ty_fn(fn_ty) => {
let mut counter = 0;
do vec::iter2(fn_ty.inputs, decl.inputs) |arg_ty, arg_ast| {
counter,
ty_to_str(tcx, arg_ty.ty),
mode_to_str(arg_ast.mode)};
- alt arg_ast.mode {
+ match arg_ast.mode {
ast::expl(ast::by_copy) => {
/* always allow by-copy */
}
}
fn relevant_def(def: def) -> option<relevant_def> {
- alt def {
+ match def {
def_self(_) => some(rdef_self),
def_arg(nid, _) | def_local(nid, _) => some(rdef_var(nid)),
_ => none
vec::push(self.var_kinds, vk);
self.num_vars += 1u;
- alt vk {
+ match vk {
vk_local(node_id, _) | vk_arg(node_id, _, _) => {
self.variable_map.insert(node_id, v);
}
}
fn variable(node_id: node_id, span: span) -> variable {
- alt self.variable_map.find(node_id) {
+ match self.variable_map.find(node_id) {
some(var) => var,
none => {
self.tcx.sess.span_bug(
}
fn variable_name(var: variable) -> ident {
- alt self.var_kinds[*var] {
+ match self.var_kinds[*var] {
vk_local(_, name) | vk_arg(_, name, _) => name,
vk_field(name) => @(~"self." + *name),
vk_self => @~"self",
}
fn captures(expr: @expr) -> @~[capture_info] {
- alt self.capture_map.find(expr.id) {
+ match self.capture_map.find(expr.id) {
some(caps) => caps,
none => {
self.tcx.sess.span_bug(expr.span, ~"no registered caps");
fn add_last_use(expr_id: node_id, var: variable) {
let vk = self.var_kinds[*var];
debug!{"Node %d is a last use of variable %?", expr_id, vk};
- alt vk {
+ match vk {
vk_arg(id, name, by_move) |
vk_arg(id, name, by_copy) |
vk_local(id, name) => {
- let v = alt self.last_use_map.find(expr_id) {
+ let v = match self.last_use_map.find(expr_id) {
some(v) => v,
none => {
let v = @dvec();
// and so forth:
visit::visit_fn(fk, decl, body, sp, id, fn_maps, v);
- alt fk {
+ match fk {
visit::fk_ctor(_, _, _, _, class_did) => {
add_class_fields(fn_maps, class_did);
}
}
fn visit_expr(expr: @expr, &&self: @ir_maps, vt: vt<@ir_maps>) {
- alt expr.node {
+ match expr.node {
// live nodes required for uses or definitions of variables:
expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
proto, cap_clause);
let mut call_caps = ~[];
for cvs.each |cv| {
- alt relevant_def(cv.def) {
+ match relevant_def(cv.def) {
some(rv) => {
let cv_ln = (*self).add_live_node(lnk_freevar(cv.span));
- let is_move = alt cv.mode {
+ let is_move = match cv.mode {
cap_move | cap_drop => true, // var must be dead afterwards
cap_copy | cap_ref => false // var can still be used
};
// _______________________________________________________________________
fn live_node(node_id: node_id, span: span) -> live_node {
- alt self.ir.live_node_map.find(node_id) {
+ match self.ir.live_node_map.find(node_id) {
some(ln) => ln,
none => {
// This must be a mismatch between the ir_map construction
}
fn variable_from_rdef(rv: relevant_def, span: span) -> variable {
- alt rv {
+ match rv {
rdef_self => self.s.self_var,
rdef_var(nid) => self.variable(nid, span)
}
}
fn variable_from_path(expr: @expr) -> option<variable> {
- alt expr.node {
+ match expr.node {
expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
relevant_def(def).map(
fn variable_from_def_map(node_id: node_id,
span: span) -> option<variable> {
- alt self.tcx.def_map.find(node_id) {
+ match self.tcx.def_map.find(node_id) {
some(def) => {
relevant_def(def).map(
|rdef| self.variable_from_rdef(rdef, span)
fn propagate_through_fn_block(decl: fn_decl, blk: blk) -> live_node {
// inputs passed by & mode should be considered live on exit:
for decl.inputs.each |arg| {
- alt ty::resolved_mode(self.tcx, arg.mode) {
+ match ty::resolved_mode(self.tcx, arg.mode) {
by_mutbl_ref | by_ref | by_val => {
// These are "non-owned" modes, so register a read at
// the end. This will prevent us from moving out of
}
fn propagate_through_stmt(stmt: @stmt, succ: live_node) -> live_node {
- alt stmt.node {
+ match stmt.node {
stmt_decl(decl, _) => {
return self.propagate_through_decl(decl, succ);
}
}
fn propagate_through_decl(decl: @decl, succ: live_node) -> live_node {
- alt decl.node {
+ match decl.node {
decl_local(locals) => {
do locals.foldr(succ) |local, succ| {
self.propagate_through_local(local, succ)
}
fn propagate_through_expr(expr: @expr, succ: live_node) -> live_node {
- alt expr.node {
+ match expr.node {
// Interesting cases with control flow or which gen/kill
expr_path(_) => {
// then we treat it as a read of that variable.
// Otherwise, we ignore it and just propagate down to
// process `e`.
- alt self.as_self_field(e, nm) {
+ match self.as_self_field(e, nm) {
some((ln, var)) => {
self.init_from_succ(ln, succ);
self.acc(ln, var, ACC_READ | ACC_USE);
// these errors are detected in the later pass borrowck. We
// just ignore such cases and treat them as reads.
- alt expr.node {
+ match expr.node {
expr_path(_) => succ,
- expr_field(e, nm, _) => alt self.as_self_field(e, nm) {
+ expr_field(e, nm, _) => match self.as_self_field(e, nm) {
some(_) => succ,
none => self.propagate_through_expr(e, succ)
}
fn write_lvalue(expr: @expr,
succ: live_node,
acc: uint) -> live_node {
- alt expr.node {
+ match expr.node {
expr_path(_) => self.access_path(expr, succ, acc),
- expr_field(e, nm, _) => alt self.as_self_field(e, nm) {
+ expr_field(e, nm, _) => match self.as_self_field(e, nm) {
some((ln, var)) => {
self.init_from_succ(ln, succ);
self.acc(ln, var, acc);
fn access_path(expr: @expr, succ: live_node, acc: uint) -> live_node {
let def = self.tcx.def_map.get(expr.id);
- alt relevant_def(def) {
+ match relevant_def(def) {
some(rdef_self) => {
// Accessing `self` is like accessing every field of
// the current object. This allows something like
// If we checking a constructor, then we treat self.f as a
// variable. we use the live_node id that will be assigned to
// the reference to self but the variable id for `f`.
- alt expr.node {
+ match expr.node {
expr_path(_) => {
let def = self.tcx.def_map.get(expr.id);
- alt def {
+ match def {
def_self(_) => {
// Note: the field_map is empty unless we are in a ctor
return self.ir.field_map.find(fld).map(|var| {
// Checking for error conditions
fn check_local(local: @local, &&self: @liveness, vt: vt<@liveness>) {
- alt local.node.init {
+ match local.node.init {
some({op: op, expr: expr}) => {
// Initializer:
- alt op {
+ match op {
init_move => self.check_move_from_expr(expr, vt),
init_assign => ()
}
debug!{"check_local() with no initializer"};
do (*self).pat_bindings(local.node.pat) |ln, var, sp| {
if !self.warn_about_unused(sp, ln, var) {
- alt (*self).live_on_exit(ln, var) {
+ match (*self).live_on_exit(ln, var) {
none => { /* not live: good */ }
some(lnk) => {
self.report_illegal_read(
}
fn check_expr(expr: @expr, &&self: @liveness, vt: vt<@liveness>) {
- alt expr.node {
+ match expr.node {
expr_path(_) => {
for (*self).variable_from_def_map(expr.id, expr.span).each |var| {
let ln = (*self).live_node(expr.id, expr.span);
let targs = ty::ty_fn_args(ty::expr_ty(self.tcx, f));
vt.visit_expr(f, self, vt);
do vec::iter2(args, targs) |arg_expr, arg_ty| {
- alt ty::resolved_mode(self.tcx, arg_ty.mode) {
+ match ty::resolved_mode(self.tcx, arg_ty.mode) {
by_val | by_copy | by_ref | by_mutbl_ref => {
vt.visit_expr(arg_expr, self, vt);
}
impl check_methods for @liveness {
fn check_fields(sp: span, entry_ln: live_node) {
for self.ir.field_map.each |nm, var| {
- alt (*self).live_on_entry(entry_ln, var) {
+ match (*self).live_on_entry(entry_ln, var) {
none => { /* ok */ }
some(lnk_exit) => {
self.tcx.sess.span_err(
self.tcx.sess.span_err(
sp, ~"some control paths may return");
} else {
- alt fk {
+ match fk {
visit::fk_ctor(*) => {
// ctors are written as though they are unit.
}
debug!{"check_move_from_var(%s, %s)",
ln.to_str(), var.to_str()};
- alt (*self).live_on_exit(ln, var) {
+ match (*self).live_on_exit(ln, var) {
none => {}
some(lnk) => self.report_illegal_move(span, lnk, var)
}
}
fn consider_last_use(expr: @expr, ln: live_node, var: variable) {
- alt (*self).live_on_exit(ln, var) {
+ match (*self).live_on_exit(ln, var) {
some(_) => {}
none => (*self.ir).add_last_use(expr.id, var)
}
return vt.visit_expr(expr, self, vt);
}
- alt expr.node {
+ match expr.node {
expr_path(_) => {
- alt (*self).variable_from_path(expr) {
+ match (*self).variable_from_path(expr) {
some(var) => {
let ln = (*self).live_node(expr.id, expr.span);
self.check_move_from_var(expr.span, ln, var);
}
fn check_lvalue(expr: @expr, vt: vt<@liveness>) {
- alt expr.node {
+ match expr.node {
expr_path(_) => {
- alt self.tcx.def_map.get(expr.id) {
+ match self.tcx.def_map.get(expr.id) {
def_local(nid, false) => {
// Assignment to an immutable variable or argument:
// only legal if there is no later assignment.
self.warn_about_dead_assign(expr.span, ln, var);
}
def => {
- alt relevant_def(def) {
+ match relevant_def(def) {
some(rdef_var(nid)) => {
let ln = (*self).live_node(expr.id, expr.span);
let var = (*self).variable(nid, expr.span);
fn check_for_reassignment(ln: live_node, var: variable,
orig_span: span) {
- alt (*self).assigned_on_exit(ln, var) {
+ match (*self).assigned_on_exit(ln, var) {
some(lnk_expr(span)) => {
self.tcx.sess.span_err(
span,
// we give a slightly different error message in those cases.
if lnk == lnk_exit {
let vk = self.ir.var_kinds[*var];
- alt vk {
+ match vk {
vk_arg(_, name, _) => {
self.tcx.sess.span_err(
move_span,
lnk: live_node_kind,
var: variable,
rk: read_kind) {
- let msg = alt rk {
+ let msg = match rk {
possibly_uninitialized_variable => {
~"possibly uninitialized variable"
}
moved_variable => ~"moved variable"
};
let name = (*self.ir).variable_name(var);
- alt lnk {
+ match lnk {
lnk_freevar(span) => {
self.tcx.sess.span_err(
span,
fn warn_about_unused_args(sp: span, decl: fn_decl, entry_ln: live_node) {
for decl.inputs.each |arg| {
let var = (*self).variable(arg.id, arg.ty.span);
- alt ty::resolved_mode(self.tcx, arg.mode) {
+ match ty::resolved_mode(self.tcx, arg.mode) {
by_mutbl_ref => {
// for mutable reference arguments, something like
// x = 1;
// is not worth warning about, as it has visible
// side effects outside the fn.
- alt (*self).assigned_on_entry(entry_ln, var) {
+ match (*self).assigned_on_entry(entry_ln, var) {
some(_) => { /*ok*/ }
none => {
// but if it is not written, it ought to be used
}
fn pat_is_variant(dm: resolve3::DefMap, pat: @pat) -> bool {
- alt pat.node {
+ match pat.node {
pat_enum(_, _) => true,
- pat_ident(_, _, none) => alt dm.find(pat.id) {
+ pat_ident(_, _, none) => match dm.find(pat.id) {
some(def_variant(_, _)) => true,
_ => false
}
fn pat_bindings(dm: resolve3::DefMap, pat: @pat,
it: fn(node_id, span, @path)) {
do walk_pat(pat) |p| {
- alt p.node {
+ match p.node {
pat_ident(_, pth, _) if !pat_is_variant(dm, p) => {
it(p.id, p.span, pth);
}
subscope: ast::node_id) -> bool {
let mut subscope = subscope;
while superscope != subscope {
- alt region_map.find(subscope) {
+ match region_map.find(subscope) {
none => return false,
some(scope) => subscope = scope
}
super_region: ty::region,
sub_region: ty::region) -> bool {
super_region == sub_region ||
- alt (super_region, sub_region) {
+ match (super_region, sub_region) {
(ty::re_static, _) => {true}
(ty::re_scope(super_scope), ty::re_scope(sub_scope)) |
let mut result = ~[scope];
let mut scope = scope;
loop {
- alt region_map.find(scope) {
+ match region_map.find(scope) {
none => return result,
some(superscope) => {
vec::push(result, superscope);
/// Extracts that current parent from cx, failing if there is none.
fn parent_id(cx: ctxt, span: span) -> ast::node_id {
- alt cx.parent {
+ match cx.parent {
none => {
cx.sess.span_bug(span, ~"crate should not be parent here");
}
/// Records the current parent (if any) as the parent of `child_id`.
fn record_parent(cx: ctxt, child_id: ast::node_id) {
- alt cx.parent {
+ match cx.parent {
none => { /* no-op */ }
some(parent_id) => {
debug!{"parent of node %d is node %d", child_id, parent_id};
}
fn resolve_pat(pat: @ast::pat, cx: ctxt, visitor: visit::vt<ctxt>) {
- alt pat.node {
+ match pat.node {
ast::pat_ident(_, path, _) => {
let defn_opt = cx.def_map.find(pat.id);
- alt defn_opt {
+ match defn_opt {
some(ast::def_variant(_,_)) => {
/* Nothing to do; this names a variant. */
}
record_parent(cx, expr.id);
let mut new_cx = cx;
- alt expr.node {
+ match expr.node {
ast::expr_call(*) => {
debug!{"node %d: %s", expr.id, pprust::expr_to_str(expr)};
new_cx.parent = some(expr.id);
sp: span, id: ast::node_id, cx: ctxt,
visitor: visit::vt<ctxt>) {
- let fn_cx = alt fk {
+ let fn_cx = match fk {
visit::fk_item_fn(*) | visit::fk_method(*) |
visit::fk_ctor(*) | visit::fk_dtor(*) => {
// Top-level functions are a root scope.
from, to,
ast_map::node_id_to_str(self.ast_map, from),
ast_map::node_id_to_str(self.ast_map, to)};
- let vec = alt self.dep_map.find(from) {
+ let vec = match self.dep_map.find(from) {
some(vec) => {vec}
none => {
let vec = @dvec();
// (anon_implies_rp) to true when we enter an item and setting
// that flag to false when we enter a method.
fn region_is_relevant(r: @ast::region) -> bool {
- alt r.node {
+ match r.node {
ast::re_anon => self.anon_implies_rp,
ast::re_named(@~"self") => true,
ast::re_named(_) => false
// if this type directly references a region, either via a
// region pointer like &r.ty or a region-parameterized path
// like path/r, add to the worklist/set
- alt ty.node {
+ match ty.node {
ast::ty_rptr(r, _) |
ast::ty_path(@{rp: some(r), _}, _) => {
debug!{"referenced type with regions %s", pprust::ty_to_str(ty)};
// to the dep_map. If the type is not defined in this crate,
// then check whether it is region-parameterized and consider
// that as a direct dependency.
- alt ty.node {
+ match ty.node {
ast::ty_path(_, id) => {
- alt cx.def_map.get(id) {
+ match cx.def_map.get(id) {
ast::def_ty(did) | ast::def_class(did, _) => {
if did.crate == ast::local_crate {
cx.add_dep(did.node, cx.item_id);
_ => {}
}
- alt ty.node {
+ match ty.node {
ast::ty_fn(*) => {
do cx.with(cx.item_id, false) {
visit::visit_ty(ty, cx, visitor);
while cx.worklist.len() != 0 {
let id = cx.worklist.pop();
debug!{"popped %d from worklist", id};
- alt cx.dep_map.find(id) {
+ match cx.dep_map.find(id) {
none => {}
some(vec) => {
for vec.each |to_id| {
}
fn intern(string: @~str) -> Atom {
- alt self.atoms.find(string) {
+ match self.atoms.find(string) {
none => { /* fall through */ }
some(atom) => return atom
}
}
fn target_for_namespace(namespace: Namespace) -> option<Target> {
- alt namespace {
+ match namespace {
ModuleNS => return copy self.module_target,
TypeNS => return copy self.type_target,
ValueNS => return copy self.value_target,
// requiring a T:copy.
pure fn is_none<T>(x: option<T>) -> bool {
- alt x {
+ match x {
none => return true,
some(_) => return false
}
/// Returns the module node if applicable.
fn get_module_if_available() -> option<@Module> {
- alt self.module_def {
+ match self.module_def {
NoModuleDef => return none,
ModuleDef(module_) => return some(module_)
}
* definition.
*/
fn get_module() -> @Module {
- alt self.module_def {
+ match self.module_def {
NoModuleDef => {
fail
~"get_module called on a node with no module definition!";
}
fn defined_in_namespace(namespace: Namespace) -> bool {
- alt namespace {
+ match namespace {
ModuleNS => return self.module_def != NoModuleDef,
TypeNS => return self.type_def != none,
ValueNS => return self.value_def != none,
}
fn def_for_namespace(namespace: Namespace) -> option<def> {
- alt namespace {
+ match namespace {
TypeNS => return self.type_def,
ValueNS => return self.value_def,
- ModuleNS => alt self.module_def {
+ ModuleNS => match self.module_def {
NoModuleDef => return none,
- ModuleDef(module_) => alt module_.def_id {
+ ModuleDef(module_) => match module_.def_id {
none => return none,
some(def_id) => return some(def_mod(def_id))
}
/// Returns the current module tracked by the reduced graph parent.
fn get_module_from_parent(reduced_graph_parent: ReducedGraphParent)
-> @Module {
- alt reduced_graph_parent {
+ match reduced_graph_parent {
ModuleReducedGraphParent(module_) => {
return module_;
}
// module and add the child to that.
let mut module_;
- alt reduced_graph_parent {
+ match reduced_graph_parent {
ModuleReducedGraphParent(parent_module) => {
module_ = parent_module;
}
// Add or reuse the child.
let new_parent = ModuleReducedGraphParent(module_);
- alt module_.children.find(name) {
+ match module_.children.find(name) {
none => {
let child = @NameBindings();
module_.children.insert(name, child);
// Check each statement.
for block.node.stmts.each |statement| {
- alt statement.node {
+ match statement.node {
stmt_decl(declaration, _) => {
- alt declaration.node {
+ match declaration.node {
decl_item(_) => {
return true;
}
}
fn get_parent_link(parent: ReducedGraphParent, name: Atom) -> ParentLink {
- alt parent {
+ match parent {
ModuleReducedGraphParent(module_) => {
return ModuleParentLink(module_, name);
}
let atom = (*self.atom_table).intern(item.ident);
let (name_bindings, new_parent) = self.add_child(atom, parent);
- alt item.node {
+ match item.node {
item_mod(module_) => {
let parent_link = self.get_parent_link(new_parent, atom);
let def_id = { crate: 0, node: item.id };
item_class(_, _, class_members, optional_ctor, _) => {
(*name_bindings).define_type(def_ty(local_def(item.id)));
- alt optional_ctor {
+ match optional_ctor {
none => {
// Nothing to do.
}
let mut method_infos = ~[];
for class_members.each |class_member| {
- alt class_member.node {
+ match class_member.node {
class_method(method) => {
// XXX: Combine with impl method code below.
method_infos += ~[
let method_names = @atom_hashmap();
for methods.each |method| {
let atom;
- alt method {
+ match method {
required(required_method) => {
atom = (*self.atom_table).intern
(required_method.ident);
fn build_reduced_graph_for_view_item(view_item: @view_item,
parent: ReducedGraphParent,
&&_visitor: vt<ReducedGraphParent>) {
- alt view_item.node {
+ match view_item.node {
view_item_import(view_paths) => {
for view_paths.each |view_path| {
// Extract and intern the module part of the path. For
// for simple paths we have to munge the path a little.
let module_path = @dvec();
- alt view_path.node {
+ match view_path.node {
view_path_simple(_, full_path, _) => {
let path_len = full_path.idents.len();
assert path_len != 0u;
// Build up the import directives.
let module_ = self.get_module_from_parent(parent);
- alt view_path.node {
+ match view_path.node {
view_path_simple(binding, full_path, _) => {
let target_atom =
(*self.atom_table).intern(binding);
view_item_export(view_paths) => {
let module_ = self.get_module_from_parent(parent);
for view_paths.each |view_path| {
- alt view_path.node {
+ match view_path.node {
view_path_simple(ident, full_path, ident_id) => {
let last_ident = full_path.idents.last();
if last_ident != ident {
}
view_item_use(name, _, node_id) => {
- alt find_use_stmt_cnum(self.session.cstore, node_id) {
+ match find_use_stmt_cnum(self.session.cstore, node_id) {
some(crate_id) => {
let atom = (*self.atom_table).intern(name);
let (child_name_bindings, new_parent) =
let name = (*self.atom_table).intern(foreign_item.ident);
let (name_bindings, new_parent) = self.add_child(name, parent);
- alt foreign_item.node {
+ match foreign_item.node {
foreign_item_fn(fn_decl, type_parameters) => {
let def = def_fn(local_def(foreign_item.id), fn_decl.purity);
(*name_bindings).define_value(def);
ModuleReducedGraphParent(current_module));
// Define or reuse the module node.
- alt child_name_bindings.module_def {
+ match child_name_bindings.module_def {
NoModuleDef => {
debug!{"(building reduced graph for external crate) \
autovivifying %s", ident};
self.add_child(atom,
ModuleReducedGraphParent(current_module));
- alt path_entry.def_like {
+ match path_entry.def_like {
dl_def(def) => {
- alt def {
+ match def {
def_mod(def_id) | def_foreign_mod(def_id) => {
- alt copy child_name_bindings.module_def {
+ match copy child_name_bindings.module_def {
NoModuleDef => {
debug!{"(building reduced graph for \
external crate) building module \
self.get_parent_link(new_parent,
atom);
- alt modules.find(def_id) {
+ match modules.find(def_id) {
none => {
(*child_name_bindings).
define_module(parent_link,
resolution.
outstanding_references = 0;
- alt existing_module.parent_link {
+ match existing_module
+ .parent_link {
+
NoParentLink |
BlockParentLink(*) => {
fail ~"can't happen";
// If this is a trait, add all the method names
// to the trait info.
- alt get_method_names_if_trait(self.session.cstore,
- def_id) {
+ match get_method_names_if_trait(
+ self.session.cstore, def_id) {
+
none => {
// Nothing to do.
}
self.build_reduced_graph_for_impls_in_external_module(module_);
for module_.children.each |_name, child_node| {
- alt (*child_node).get_module_if_available() {
+ match (*child_node).get_module_if_available() {
none => {
// Nothing to do.
}
self.module_to_str(module_),
copy module_.def_id};
- alt module_.def_id {
+ match module_.def_id {
none => {
debug!{"(building reduced graph for impls in external \
module) no def ID for `%s`, skipping",
// Bump the reference count on the name. Or, if this is a glob, set
// the appropriate flag.
- alt *subclass {
+ match *subclass {
SingleImport(target, _) => {
- alt module_.import_resolutions.find(target) {
+ match module_.import_resolutions.find(target) {
some(resolution) => {
resolution.outstanding_references += 1u;
}
self.resolve_imports_for_module(module_);
for module_.children.each |_name, child_node| {
- alt (*child_node).get_module_if_available() {
+ match (*child_node).get_module_if_available() {
none => {
// Nothing to do.
}
while module_.resolved_import_count < import_count {
let import_index = module_.resolved_import_count;
let import_directive = module_.imports.get_elt(import_index);
- alt self.resolve_import_for_module(module_, import_directive) {
+ match self.resolve_import_for_module(module_, import_directive) {
Failed => {
// We presumably emitted an error. Continue.
self.session.span_err(import_directive.span,
import_directive);
} else {
// First, resolve the module path for the directive, if necessary.
- alt self.resolve_module_path_for_import(module_,
+ match self.resolve_module_path_for_import(module_,
module_path,
NoXray,
import_directive.span) {
// We found the module that the target is contained
// within. Attempt to resolve the import within it.
- alt *import_directive.subclass {
+ match *import_directive.subclass {
SingleImport(target, source) => {
resolution_result =
self.resolve_single_import(module_,
}
// Decrement the count of unresolved imports.
- alt resolution_result {
+ match resolution_result {
Success(()) => {
assert self.unresolved_imports >= 1u;
self.unresolved_imports -= 1u;
// resolve_imports_for_module.)
if resolution_result != Indeterminate {
- alt *import_directive.subclass {
+ match *import_directive.subclass {
GlobImport => {
assert module_.glob_count >= 1u;
module_.glob_count -= 1u;
let mut impl_result = UnknownImplResult;
// Search for direct children of the containing module.
- alt containing_module.children.find(source) {
+ match containing_module.children.find(source) {
none => {
// Continue.
}
// Unless we managed to find a result in all four namespaces
// (exceedingly unlikely), search imports as well.
- alt (module_result, value_result, type_result, impl_result) {
+ match (module_result, value_result, type_result, impl_result) {
(BoundResult(*), BoundResult(*), BoundResult(*),
BoundImplResult(*)) => {
// Continue.
// Now search the exported imports within the containing
// module.
- alt containing_module.import_resolutions.find(source) {
+ match containing_module.import_resolutions.find(source) {
none => {
// The containing module definitely doesn't have an
// exported import with the name in question. We can
namespace: Namespace)
-> NamespaceResult {
- alt (*import_resolution).
+ match (*import_resolution).
target_for_namespace(namespace) {
none => {
return UnboundResult;
assert module_.import_resolutions.contains_key(target);
let import_resolution = module_.import_resolutions.get(target);
- alt module_result {
+ match module_result {
BoundResult(target_module, name_bindings) => {
debug!{"(resolving single import) found module binding"};
import_resolution.module_target =
fail ~"module result should be known at this point";
}
}
- alt value_result {
+ match value_result {
BoundResult(target_module, name_bindings) => {
import_resolution.value_target =
some(Target(target_module, name_bindings));
fail ~"value result should be known at this point";
}
}
- alt type_result {
+ match type_result {
BoundResult(target_module, name_bindings) => {
import_resolution.type_target =
some(Target(target_module, name_bindings));
fail ~"type result should be known at this point";
}
}
- alt impl_result {
+ match impl_result {
BoundImplResult(targets) => {
for (*targets).each |target| {
(*import_resolution.impl_target).push(target);
}
let i = import_resolution;
- alt (i.module_target, i.value_target, i.type_target, i.impl_target) {
+ match (i.module_target, i.value_target,
+ i.type_target, i.impl_target) {
/*
If this name wasn't found in any of the four namespaces, it's
definitely unresolved
self.module_to_str(module_)};
// Here we merge two import resolutions.
- alt module_.import_resolutions.find(atom) {
+ match module_.import_resolutions.find(atom) {
none => {
// Simple: just copy the old import resolution.
let new_import_resolution =
// Merge the two import resolutions at a finer-grained
// level.
- alt copy target_import_resolution.module_target {
+ match copy target_import_resolution.module_target {
none => {
// Continue.
}
some(copy module_target);
}
}
- alt copy target_import_resolution.value_target {
+ match copy target_import_resolution.value_target {
none => {
// Continue.
}
some(copy value_target);
}
}
- alt copy target_import_resolution.type_target {
+ match copy target_import_resolution.type_target {
none => {
// Continue.
}
}
let mut dest_import_resolution;
- alt module_.import_resolutions.find(atom) {
+ match module_.import_resolutions.find(atom) {
none => {
// Create a new import resolution from this child.
dest_import_resolution = @ImportResolution(span);
while index < module_path_len {
let name = (*module_path).get_elt(index);
- alt self.resolve_name_in_module(search_module, name, ModuleNS,
+ match self.resolve_name_in_module(search_module, name, ModuleNS,
xray) {
Failed => {
return Indeterminate;
}
Success(target) => {
- alt target.bindings.module_def {
+ match target.bindings.module_def {
NoModuleDef => {
// Not a module.
self.session.span_err(span,
let first_element = (*module_path).get_elt(0u);
let mut search_module;
- alt self.resolve_module_in_lexical_scope(module_, first_element) {
+ match self.resolve_module_in_lexical_scope(module_, first_element) {
Failed => {
self.session.span_err(span, ~"unresolved name");
return Failed;
// The current module node is handled specially. First, check for
// its immediate children.
- alt module_.children.find(name) {
+ match module_.children.find(name) {
some(name_bindings)
if (*name_bindings).defined_in_namespace(namespace) => {
// adjacent import statements are processed as though they mutated the
// current scope.
- alt module_.import_resolutions.find(name) {
+ match module_.import_resolutions.find(name) {
none => {
// Not found; continue.
}
some(import_resolution) => {
- alt (*import_resolution).target_for_namespace(namespace) {
+ match (*import_resolution).target_for_namespace(namespace) {
none => {
// Not found; continue.
debug!{"(resolving item in lexical scope) found \
let mut search_module = module_;
loop {
// Go to the next parent.
- alt search_module.parent_link {
+ match search_module.parent_link {
NoParentLink => {
// No more parents. This module was unresolved.
debug!{"(resolving item in lexical scope) unresolved \
}
// Resolve the name in the parent module.
- alt self.resolve_name_in_module(search_module, name, namespace,
+ match self.resolve_name_in_module(search_module, name, namespace,
Xray) {
Failed => {
// Continue up the search chain.
fn resolve_module_in_lexical_scope(module_: @Module, name: Atom)
-> ResolveResult<@Module> {
- alt self.resolve_item_in_lexical_scope(module_, name, ModuleNS) {
+ match self.resolve_item_in_lexical_scope(module_, name, ModuleNS) {
Success(target) => {
- alt target.bindings.module_def {
+ match target.bindings.module_def {
NoModuleDef => {
error!{"!!! (resolving module in lexical scope) module
wasn't actually a module!"};
}
// First, check the direct children of the module.
- alt module_.children.find(name) {
+ match module_.children.find(name) {
some(name_bindings)
if (*name_bindings).defined_in_namespace(namespace) => {
}
// Otherwise, we check the list of resolved imports.
- alt module_.import_resolutions.find(name) {
+ match module_.import_resolutions.find(name) {
some(import_resolution) => {
if import_resolution.outstanding_references != 0u {
debug!{"(resolving name in module) import unresolved; \
return Indeterminate;
}
- alt (*import_resolution).target_for_namespace(namespace) {
+ match (*import_resolution).target_for_namespace(namespace) {
none => {
debug!{"(resolving name in module) name found, but \
not in namespace %?",
let mut target_name;
let mut source_name;
- alt *import_directive.subclass {
+ match *import_directive.subclass {
SingleImport(target, source) => {
target_name = target;
source_name = source;
let mut module_result;
debug!{"(resolving one-level naming result) searching for module"};
- alt self.resolve_item_in_lexical_scope(module_,
+ match self.resolve_item_in_lexical_scope(module_,
source_name,
ModuleNS) {
let mut value_result;
debug!{"(resolving one-level naming result) searching for value"};
- alt self.resolve_item_in_lexical_scope(module_,
+ match self.resolve_item_in_lexical_scope(module_,
source_name,
ValueNS) {
let mut type_result;
debug!{"(resolving one-level naming result) searching for type"};
- alt self.resolve_item_in_lexical_scope(module_,
+ match self.resolve_item_in_lexical_scope(module_,
source_name,
TypeNS) {
let mut impl_result;
debug!{"(resolving one-level naming result) searching for impl"};
- alt self.resolve_item_in_lexical_scope(module_,
+ match self.resolve_item_in_lexical_scope(module_,
source_name,
ImplNS) {
}
// Otherwise, proceed and write in the bindings.
- alt module_.import_resolutions.find(target_name) {
+ match module_.import_resolutions.find(target_name) {
none => {
fail ~"(resolving one-level renaming import) reduced graph \
construction or glob importing should have created the \
import_resolution.value_target = value_result;
import_resolution.type_target = type_result;
- alt impl_result {
+ match impl_result {
none => {
// Nothing to do.
}
// Descend into children and anonymous children.
for module_.children.each |_name, child_node| {
- alt (*child_node).get_module_if_available() {
+ match (*child_node).get_module_if_available() {
none => {
// Continue.
}
// If this isn't a local crate, then bail out. We don't need to record
// exports for local crates.
- alt module_.def_id {
+ match module_.def_id {
some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
self.record_exports_for_module(module_);
for module_.children.each |_atom, child_name_bindings| {
- alt (*child_name_bindings).get_module_if_available() {
+ match (*child_name_bindings).get_module_if_available() {
none => {
// Nothing to do.
}
again;
}
- alt self.resolve_definition_of_name_in_module(module_,
+ match self.resolve_definition_of_name_in_module(module_,
name,
namespace,
Xray) {
// If this isn't a local crate, then bail out. We don't need to
// resolve implementations for external crates.
- alt module_.def_id {
+ match module_.def_id {
some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
self.build_impl_scope_for_module(module_);
for module_.children.each |_atom, child_name_bindings| {
- alt (*child_name_bindings).get_module_if_available() {
+ match (*child_name_bindings).get_module_if_available() {
none => {
// Nothing to do.
}
// Determine the parent's implementation scope.
let mut parent_impl_scopes;
- alt module_.parent_link {
+ match module_.parent_link {
NoParentLink => {
parent_impl_scopes = @nil;
}
let orig_module = self.current_module;
// Move down in the graph.
- alt name {
+ match name {
none => {
// Nothing to do.
}
some(name) => {
- alt orig_module.children.find(name) {
+ match orig_module.children.find(name) {
none => {
debug!{"!!! (with scope) didn't find `%s` in `%s`",
*(*self.atom_table).atom_to_str(name),
self.module_to_str(orig_module)};
}
some(name_bindings) => {
- alt (*name_bindings).get_module_if_available() {
+ match (*name_bindings).get_module_if_available() {
none => {
debug!{"!!! (with scope) didn't find module \
for `%s` in `%s`",
let mut def;
let mut is_ty_param;
- alt def_like {
+ match def_like {
dl_def(d @ def_local(*)) | dl_def(d @ def_upvar(*)) |
dl_def(d @ def_arg(*)) | dl_def(d @ def_binding(*)) => {
def = d;
let mut rib_index = rib_index + 1u;
while rib_index < (*ribs).len() {
let rib = (*ribs).get_elt(rib_index);
- alt rib.kind {
+ match rib.kind {
NormalRibKind => {
// Nothing to do. Continue.
}
MethodRibKind(item_id, method_id) => {
// If the def is a ty param, and came from the parent
// item, it's ok
- alt def {
+ match def {
def_ty_param(did, _) if self.def_map.find(copy(did.node))
== some(def_typaram_binder(item_id)) => {
// ok
while i != 0u {
i -= 1u;
let rib = (*ribs).get_elt(i);
- alt rib.bindings.find(name) {
+ match rib.bindings.find(name) {
some(def_like) => {
return self.upvarify(ribs, i, def_like, span,
allow_capturing_self);
self.xray_context = Xray;
}
- alt item.node {
+ match item.node {
item_enum(_, type_parameters) |
item_ty(_, type_parameters) => {
do self.with_type_parameter_rib
//
// XXX: Do we need a node ID here?
- alt method {
+ match method {
required(ty_m) => {
do self.with_type_parameter_rib
(HasTypeParameters(&ty_m.tps,
let atom = (*self.atom_table).intern(item.ident);
do self.with_scope(some(atom)) {
for foreign_module.items.each |foreign_item| {
- alt foreign_item.node {
+ match foreign_item.node {
foreign_item_fn(_, type_parameters) => {
do self.with_type_parameter_rib
(HasTypeParameters(&type_parameters,
}
fn with_type_parameter_rib(type_parameters: TypeParameters, f: fn()) {
- alt type_parameters {
+ match type_parameters {
HasTypeParameters(type_parameters, node_id, initial_index,
rib_kind) => {
f();
- alt type_parameters {
+ match type_parameters {
HasTypeParameters(type_parameters, _, _, _) => {
(*self.type_ribs).pop();
}
visitor: ResolveVisitor) {
// Check each element of the capture clause.
- alt capture_clause {
+ match capture_clause {
NoCaptureClause => {
// Nothing to do.
}
HasCaptureClause(capture_clause) => {
// Resolve each captured item.
for (*capture_clause).each |capture_item| {
- alt self.resolve_identifier(capture_item.name,
+ match self.resolve_identifier(capture_item.name,
ValueNS,
true,
capture_item.span) {
// If this function has type parameters, add them now.
do self.with_type_parameter_rib(type_parameters) {
// Resolve the type parameters.
- alt type_parameters {
+ match type_parameters {
NoTypeParameters => {
// Continue.
}
}
// Add self to the rib, if necessary.
- alt self_binding {
+ match self_binding {
NoSelfBinding => {
// Nothing to do.
}
}
// Add each argument to the rib.
- alt optional_declaration {
+ match optional_declaration {
none => {
// Nothing to do.
}
for type_parameters.each |type_parameter| {
for (*type_parameter.bounds).each |bound| {
- alt bound {
+ match bound {
bound_copy | bound_send | bound_const | bound_owned => {
// Nothing to do.
}
// Resolve implemented traits.
for traits.each |trt| {
- alt self.resolve_path(trt.path, TypeNS, true, visitor) {
+ match self.resolve_path(trt.path, TypeNS, true, visitor) {
none => {
self.session.span_err(trt.path.span,
~"attempt to implement a \
// Resolve methods.
for class_members.each |class_member| {
- alt class_member.node {
+ match class_member.node {
class_method(method) => {
self.resolve_method(MethodRibKind(id,
Provided(method.id)),
}
// Resolve the constructor, if applicable.
- alt optional_constructor {
+ match optional_constructor {
none => {
// Nothing to do.
}
}
// Resolve the destructor, if applicable.
- alt optional_destructor {
+ match optional_destructor {
none => {
// Nothing to do.
}
if trait_references.len() >= 1 {
let mut new_trait_refs = @dvec();
for trait_references.each |trait_reference| {
- alt self.resolve_path(trait_reference.path, TypeNS, true,
- visitor) {
+ match self.resolve_path(
+ trait_reference.path, TypeNS, true, visitor) {
none => {
self.session.span_err(span,
~"attempt to implement an \
self.resolve_type(local.node.ty, visitor);
// Resolve the initializer, if necessary.
- alt local.node.init {
+ match local.node.init {
none => {
// Nothing to do.
}
// Move down in the graph, if there's an anonymous module rooted here.
let orig_module = self.current_module;
- alt self.current_module.anonymous_children.find(block.node.id) {
+ match self.current_module.anonymous_children.find(block.node.id) {
none => { /* Nothing to do. */ }
some(anonymous_module) => {
debug!{"(resolving block) found anonymous module, moving \
}
fn resolve_type(ty: @ty, visitor: ResolveVisitor) {
- alt ty.node {
+ match ty.node {
// Like path expressions, the interpretation of path types depends
// on whether the path has multiple elements in it or not.
// scopes looking for it.
let mut result_def;
- alt self.resolve_path(path, TypeNS, true, visitor) {
+ match self.resolve_path(path, TypeNS, true, visitor) {
some(def) => {
debug!{"(resolving type) resolved `%s` to type",
*path.idents.last()};
}
}
- alt result_def {
+ match result_def {
some(_) => {
// Continue.
}
let name =
(*self.atom_table).intern(path.idents.last());
- alt self.primitive_type_table
+ match self.primitive_type_table
.primitive_types
.find(name) {
}
}
- alt copy result_def {
+ match copy result_def {
some(def) => {
// Write the result into the def map.
debug!{"(resolving type) writing resolution for `%s` \
let pat_id = pattern.id;
do walk_pat(pattern) |pattern| {
- alt pattern.node {
+ match pattern.node {
pat_ident(binding_mode, path, _)
if !path.global && path.idents.len() == 1u => {
let atom = (*self.atom_table).intern(path.idents[0]);
- alt self.resolve_enum_variant_or_const(atom) {
+ match self.resolve_enum_variant_or_const(atom) {
FoundEnumVariant(def) if mode == RefutableMode => {
debug!{"(resolving pattern) resolving `%s` to \
enum variant",
let is_mutable = mutability == Mutable;
- let def = alt mode {
+ let def = match mode {
RefutableMode => {
// For pattern arms, we must use
// `def_binding` definitions.
// because that breaks the assumptions later
// passes make about or-patterns.)
- alt bindings_list {
+ match bindings_list {
some(bindings_list)
if !bindings_list.contains_key(atom) => {
let last_rib = (*self.value_ribs).last();
pat_ident(_, path, _) | pat_enum(path, _) => {
// These two must be enum variants.
- alt self.resolve_path(path, ValueNS, false, visitor) {
+ match self.resolve_path(path, ValueNS, false, visitor) {
some(def @ def_variant(*)) => {
self.record_def(pattern.id, def);
}
fn resolve_enum_variant_or_const(name: Atom)
-> EnumVariantOrConstResolution {
- alt self.resolve_item_in_lexical_scope(self.current_module,
+ match self.resolve_item_in_lexical_scope(self.current_module,
name,
ValueNS) {
Success(target) => {
- alt target.bindings.value_def {
+ match target.bindings.value_def {
none => {
fail ~"resolved name in the value namespace to a set \
of name bindings with no def?!";
-> option<def> {
if check_ribs {
- alt self.resolve_identifier_in_local_ribs(identifier,
+ match self.resolve_identifier_in_local_ribs(identifier,
namespace,
span) {
some(def) => {
}
// First, search children.
- alt containing_module.children.find(name) {
+ match containing_module.children.find(name) {
some(child_name_bindings) => {
- alt (*child_name_bindings).def_for_namespace(namespace) {
+ match (*child_name_bindings).def_for_namespace(namespace) {
some(def) => {
// Found it. Stop the search here.
return ChildNameDefinition(def);
}
// Next, search import resolutions.
- alt containing_module.import_resolutions.find(name) {
+ match containing_module.import_resolutions.find(name) {
some(import_resolution) => {
- alt (*import_resolution).target_for_namespace(namespace) {
+ match (*import_resolution).target_for_namespace(namespace) {
some(target) => {
- alt (*target.bindings).def_for_namespace(namespace) {
+ match (*target.bindings)
+ .def_for_namespace(namespace) {
some(def) => {
// Found it.
import_resolution.used = true;
let module_path_atoms = self.intern_module_part_of_path(path);
let mut containing_module;
- alt self.resolve_module_path_for_import(self.current_module,
+ match self.resolve_module_path_for_import(self.current_module,
module_path_atoms,
xray,
path.span) {
}
let name = (*self.atom_table).intern(path.idents.last());
- alt self.resolve_definition_of_name_in_module(containing_module,
+ match self.resolve_definition_of_name_in_module(containing_module,
name,
namespace,
xray) {
let root_module = (*self.graph_root).get_module();
let mut containing_module;
- alt self.resolve_module_path_from_root(root_module,
+ match self.resolve_module_path_from_root(root_module,
module_path_atoms,
0u,
xray,
}
let name = (*self.atom_table).intern(path.idents.last());
- alt self.resolve_definition_of_name_in_module(containing_module,
+ match self.resolve_definition_of_name_in_module(containing_module,
name,
namespace,
xray) {
// Check the local set of ribs.
let mut search_result;
- alt namespace {
+ match namespace {
ValueNS => {
search_result = self.search_ribs(self.value_ribs, name, span,
DontAllowCapturingSelf);
}
}
- alt copy search_result {
+ match copy search_result {
some(dl_def(def)) => {
debug!{"(resolving path in local ribs) resolved `%s` to \
local: %?",
let name = (*self.atom_table).intern(ident);
// Check the items.
- alt self.resolve_item_in_lexical_scope(self.current_module,
+ match self.resolve_item_in_lexical_scope(self.current_module,
name,
namespace) {
Success(target) => {
- alt (*target.bindings).def_for_namespace(namespace) {
+ match (*target.bindings).def_for_namespace(namespace) {
none => {
fail ~"resolved name in a namespace to a set of name \
bindings with no def for that namespace?!";
self.record_candidate_traits_for_expr_if_necessary(expr);
// Next, resolve the node.
- alt expr.node {
+ match expr.node {
// The interpretation of paths depends on whether the path has
// multiple elements in it or not.
// This is a local path in the value namespace. Walk through
// scopes looking for it.
- alt self.resolve_path(path, ValueNS, true, visitor) {
+ match self.resolve_path(path, ValueNS, true, visitor) {
some(def) => {
// Write the result into the def map.
debug!{"(resolving expr) resolved `%s`",
// type Bar<A> = Foo<A>;
// let bar = Bar { ... } // no type parameters
- alt self.resolve_path(path, TypeNS, false, visitor) {
+ match self.resolve_path(path, TypeNS, false, visitor) {
some(definition @ def_ty(class_id))
if self.structs.contains_key(class_id) => {
}
fn record_impls_for_expr_if_necessary(expr: @expr) {
- alt expr.node {
+ match expr.node {
expr_field(*) | expr_path(*) | expr_cast(*) | expr_binary(*) |
expr_unary(*) | expr_assign_op(*) | expr_index(*) => {
self.impl_map.insert(expr.id,
}
fn record_candidate_traits_for_expr_if_necessary(expr: @expr) {
- alt expr.node {
+ match expr.node {
expr_field(_, ident, _) => {
let atom = (*self.atom_table).intern(ident);
let traits = self.search_for_traits_containing_method(atom);
let mut search_module = self.current_module;
loop {
// Look for the current trait.
- alt copy self.current_trait_refs {
+ match copy self.current_trait_refs {
some(trait_def_ids) => {
for trait_def_ids.each |trait_def_id| {
self.add_trait_info_if_containing_method
// Look for trait children.
for search_module.children.each |_name, child_name_bindings| {
- alt child_name_bindings.def_for_namespace(TypeNS) {
+ match child_name_bindings.def_for_namespace(TypeNS) {
some(def_ty(trait_def_id)) => {
self.add_trait_info_if_containing_method(found_traits,
trait_def_id,
for search_module.import_resolutions.each
|_atom, import_resolution| {
- alt import_resolution.target_for_namespace(TypeNS) {
+ match import_resolution.target_for_namespace(TypeNS) {
none => {
// Continue.
}
some(target) => {
- alt target.bindings.def_for_namespace(TypeNS) {
+ match target.bindings.def_for_namespace(TypeNS) {
some(def_ty(trait_def_id)) => {
self.add_trait_info_if_containing_method
(found_traits, trait_def_id, name);
}
// Move to the next parent.
- alt search_module.parent_link {
+ match search_module.parent_link {
NoParentLink => {
// Done.
break;
trait_def_id: def_id,
name: Atom) {
- alt self.trait_info.find(trait_def_id) {
+ match self.trait_info.find(trait_def_id) {
some(trait_info) if trait_info.contains_key(name) => {
debug!{"(adding trait info if containing method) found trait \
%d:%d for method '%s'",
// If this isn't a local crate, then bail out. We don't need to check
// for unused imports in external crates.
- alt module_.def_id {
+ match module_.def_id {
some(def_id) if def_id.crate == local_crate => {
// OK. Continue.
}
self.check_for_unused_imports_in_module(module_);
for module_.children.each |_atom, child_name_bindings| {
- alt (*child_name_bindings).get_module_if_available() {
+ match (*child_name_bindings).get_module_if_available() {
none => {
// Nothing to do.
}
fn check_for_unused_imports_in_module(module_: @Module) {
for module_.import_resolutions.each |_impl_name, import_resolution| {
if !import_resolution.used {
- alt self.unused_import_lint_level {
+ match self.unused_import_lint_level {
warn => {
self.session.span_warn(import_resolution.span,
~"unused import");
let atoms = dvec();
let mut current_module = module_;
loop {
- alt current_module.parent_link {
+ match current_module.parent_link {
NoParentLink => {
break;
}
debug!{"Import resolutions:"};
for module_.import_resolutions.each |name, import_resolution| {
let mut module_repr;
- alt (*import_resolution).target_for_namespace(ModuleNS) {
+ match (*import_resolution).target_for_namespace(ModuleNS) {
none => { module_repr = ~""; }
some(target) => {
module_repr = ~" module:?";
}
let mut value_repr;
- alt (*import_resolution).target_for_namespace(ValueNS) {
+ match (*import_resolution).target_for_namespace(ValueNS) {
none => { value_repr = ~""; }
some(target) => {
value_repr = ~" value:?";
}
let mut type_repr;
- alt (*import_resolution).target_for_namespace(TypeNS) {
+ match (*import_resolution).target_for_namespace(TypeNS) {
none => { type_repr = ~""; }
some(target) => {
type_repr = ~" type:?";
}
let mut impl_repr;
- alt (*import_resolution).target_for_namespace(ImplNS) {
+ match (*import_resolution).target_for_namespace(ImplNS) {
none => { impl_repr = ~""; }
some(target) => {
impl_repr = ~" impl:?";
let mut i = 0u;
let mut impl_scopes = impl_scopes;
loop {
- alt *impl_scopes {
+ match *impl_scopes {
cons(impl_scope, rest_impl_scopes) => {
debug!{"Impl scope %u:", i};
range(@ast::expr, @ast::expr)
}
fn opt_eq(tcx: ty::ctxt, a: opt, b: opt) -> bool {
- alt (a, b) {
+ match (a, b) {
(lit(a), lit(b)) => const_eval::compare_lit_exprs(tcx, a, b) == 0,
(range(a1, a2), range(b1, b2)) => {
const_eval::compare_lit_exprs(tcx, a1, b1) == 0 &&
let _icx = bcx.insn_ctxt(~"alt::trans_opt");
let ccx = bcx.ccx();
let mut bcx = bcx;
- alt o {
+ match o {
lit(l) => {
- alt l.node {
+ match l.node {
ast::expr_vstore(@{node: ast::expr_lit(
@{node: ast::lit_str(s), _}), _},
ast::vstore_uniq) => {
fn has_nested_bindings(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_ident(_, _, some(_)) => return true,
_ => ()
}
let mut result = ~[];
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_ident(mode, name, some(inner)) => {
let pats = vec::append(
vec::slice(br.pats, 0u, col),
e: enter_pat) -> match_ {
let mut result = ~[];
for vec::each(m) |br| {
- alt e(br.pats[col]) {
+ match e(br.pats[col]) {
some(sub) => {
let pats = vec::append(
vec::append(sub, vec::view(br.pats, 0u, col)),
vec::view(br.pats, col + 1u, br.pats.len()));
let self = br.pats[col];
- let bound = alt self.node {
+ let bound = match self.node {
ast::pat_ident(mode, name, none)
if !pat_is_variant(dm, self) => {
vec::append(br.bound,
-> match_ {
do enter_match(bcx, dm, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) => some(~[]),
ast::pat_ident(_, _, none) if !pat_is_variant(dm, p) => some(~[]),
_ => none
let tcx = bcx.tcx();
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, tcx.def_map, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_enum(_, subpats) => {
if opt_eq(tcx, variant_opt(tcx, p.id), opt) {
some(option::get_default(subpats,
fields: ~[ast::ident], val: ValueRef) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_rec(fpats, _) => {
let mut pats = ~[];
for vec::each(fields) |fname| {
n_elts: uint) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_tup(elts) => some(elts),
_ => some(vec::from_elem(n_elts, dummy))
}
-> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_box(sub) => some(~[sub]),
_ => some(~[dummy])
}
-> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(bcx, dm, m, col, val) |p| {
- alt p.node {
+ match p.node {
ast::pat_uniq(sub) => some(~[sub]),
_ => some(~[dummy])
}
if pat_is_variant(ccx.tcx.def_map, cur) {
add_to_set(ccx.tcx, found, variant_opt(ccx.tcx, br.pats[col].id));
} else {
- alt cur.node {
+ match cur.node {
ast::pat_lit(l) => add_to_set(ccx.tcx, found, lit(l)),
ast::pat_range(l1, l2) => {
add_to_set(ccx.tcx, found, range(l1, l2));
{vals: ~[ValueRef], bcx: block} {
let _icx = bcx.insn_ctxt(~"alt::extract_variant_args");
let ccx = bcx.fcx.ccx;
- let enum_ty_substs = alt check ty::get(node_id_type(bcx, pat_id)).struct {
+ let enum_ty_substs = match check ty::get(node_id_type(bcx, pat_id))
+ .struct {
+
ty::ty_enum(id, substs) => { assert id == vdefs.enm; substs.tps }
};
let mut blobptr = val;
fn collect_record_fields(m: match_, col: uint) -> ~[ast::ident] {
let mut fields: ~[ast::ident] = ~[];
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_rec(fs, _) => {
for vec::each(fs) |f| {
if !vec::any(fields, |x| str::eq(f.ident, x)) {
for vec::each(m) |br| {
let pat_id = br.pats[col].id;
- alt bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) {
+ match bcx.ccx().maps.root_map.find({id:pat_id, derefs:0u}) {
none => (),
some(scope_id) => {
// Note: the scope_id will always be the id of the alt. See the
fn any_box_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_box(_) => return true,
_ => ()
}
fn any_uniq_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_uniq(_) => return true,
_ => ()
}
fn any_tup_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
- alt br.pats[col].node {
+ match br.pats[col].node {
ast::pat_tup(_) => return true,
_ => ()
}
fn pick_col(m: match_) -> uint {
fn score(p: @ast::pat) -> uint {
- alt p.node {
+ match p.node {
ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) => 1u,
ast::pat_ident(_, _, some(p)) => score(p),
_ => 0u
if m.len() == 0u { Br(bcx, option::get(chk)()); return; }
if m[0].pats.len() == 0u {
let data = m[0].data;
- alt data.guard {
+ match data.guard {
some(e) => {
// Temporarily set bindings. They'll be rewritten to PHI nodes
// for the actual arm block.
if any_tup_pat(m, col) {
let tup_ty = node_id_type(bcx, pat_id);
- let n_tup_elts = alt ty::get(tup_ty).struct {
+ let n_tup_elts = match ty::get(tup_ty).struct {
ty::ty_tup(elts) => elts.len(),
_ => ccx.sess.bug(~"non-tuple type in tuple pattern")
};
let mut kind = no_branch;
let mut test_val = val;
if opts.len() > 0u {
- alt opts[0] {
+ match opts[0] {
var(_, vdef) => {
if (*ty::enum_variants(tcx, vdef.enm)).len() == 1u {
kind = single;
}
}
for vec::each(opts) |o| {
- alt o {
+ match o {
range(_, _) => { kind = compare; break }
_ => ()
}
}
- let else_cx = alt kind {
+ let else_cx = match kind {
no_branch | single => bcx,
_ => sub_block(bcx, ~"match_else")
};
let mut opt_cx = else_cx;
if !exhaustive || i < len {
opt_cx = sub_block(bcx, ~"match_case");
- alt kind {
+ match kind {
single => Br(bcx, opt_cx.llbb),
switch => {
- alt check trans_opt(bcx, opt) {
+ match check trans_opt(bcx, opt) {
single_result(r) => {
llvm::LLVMAddCase(sw, r.val, opt_cx.llbb);
bcx = r.bcx;
let t = node_id_type(bcx, pat_id);
let {bcx: after_cx, val: matches} = {
do with_scope_result(bcx, none, ~"compare_scope") |bcx| {
- alt trans_opt(bcx, opt) {
+ match trans_opt(bcx, opt) {
single_result({bcx, val}) => {
trans_compare(bcx, ast::eq, test_val, t, val, t)
}
} else if kind == compare { Br(bcx, else_cx.llbb); }
let mut size = 0u;
let mut unpacked = ~[];
- alt opt {
+ match opt {
var(_, vdef) => {
let args = extract_variant_args(opt_cx, pat_id, vdef, val);
size = args.vals.len();
let mut vals = ~[];
for vec::each(map) |ex| {
if ex.to as uint == our_block {
- alt assoc(name, ex.bound) {
+ match assoc(name, ex.bound) {
some(binding) => {
vec::push(llbbs, ex.from);
vec::push(vals, binding.val);
fn mk_fail(bcx: block, sp: span, msg: ~str,
done: @mut option<BasicBlockRef>) -> BasicBlockRef {
- alt *done { some(bb) => return bb, _ => () }
+ match *done { some(bb) => return bb, _ => () }
let fail_cx = sub_block(bcx, ~"case_fallthrough");
trans_fail(fail_cx, some(sp), msg);
*done = some(fail_cx.llbb);
return fail_cx.llbb;
}
let t = node_id_type(bcx, expr.id);
- let mk_fail = alt mode {
+ let mk_fail = match mode {
ast::alt_check => {
let fail_cx = @mut none;
// Cached fail-on-fallthrough block
let mut bcx = bcx;
// Necessary since bind_irrefutable_pat is called outside trans_alt
- alt pat.node {
+ match pat.node {
ast::pat_ident(_, _,inner) => {
if pat_is_variant(bcx.tcx().def_map, pat) { return bcx; }
if make_copy {
bcx.fcx.lllocals.insert(pat.id, local_mem(alloc));
add_clean(bcx, alloc, ty);
} else { bcx.fcx.lllocals.insert(pat.id, local_mem(val)); }
- alt inner {
+ match inner {
some(pat) => { bcx = bind_irrefutable_pat(bcx, pat, val, true); }
_ => ()
}
}
fn dest_str(ccx: @crate_ctxt, d: dest) -> ~str {
- alt d {
+ match d {
by_val(v) => fmt!{"by_val(%s)", val_str(ccx.tn, *v)},
save_in(v) => fmt!{"save_in(%s)", val_str(ccx.tn, v)},
ignore => ~"ignore"
}
fn dup_for_join(dest: dest) -> dest {
- alt dest {
+ match dest {
by_val(_) => by_val(empty_dest_cell()),
_ => dest
}
if !cx.unreachable {
Br(cx, out.llbb);
reachable = true;
- alt in_ds[i] {
+ match in_ds[i] {
by_val(cell) => {
if option::is_none(phi) {
phi = some(EmptyPhi(out, val_ty(*cell)));
if !reachable {
Unreachable(out);
} else {
- alt out_dest {
+ match out_dest {
by_val(cell) => *cell = option::get(phi),
_ => ()
}
// Used to put an immediate value in a dest.
fn store_in_dest(bcx: block, val: ValueRef, dest: dest) -> block {
- alt dest {
+ match dest {
ignore => (),
by_val(cell) => *cell = val,
save_in(addr) => Store(bcx, val, addr)
}
fn get_dest_addr(dest: dest) -> ValueRef {
- alt dest {
+ match dest {
save_in(a) => a,
_ => fail ~"get_dest_addr: not a save_in"
}
let _icx = bcx.insn_ctxt(~"malloc_raw");
let ccx = bcx.ccx();
- let (mk_fn, rtcall) = alt heap {
+ let (mk_fn, rtcall) = match heap {
heap_shared => (ty::mk_imm_box, ~"malloc"),
heap_exchange => (ty::mk_imm_uniq, ~"exchange_malloc")
};
}
fn get_tydesc(ccx: @crate_ctxt, t: ty::t) -> @tydesc_info {
- alt ccx.tydescs.find(t) {
+ match ccx.tydescs.find(t) {
some(inf) => inf,
_ => {
ccx.stats.n_static_tydescs += 1u;
fn set_inline_hint_if_appr(attrs: ~[ast::attribute],
llfn: ValueRef) {
- alt attr::find_inline_attr(attrs) {
+ match attr::find_inline_attr(attrs) {
attr::ia_hint => set_inline_hint(llfn),
attr::ia_always => set_always_inline(llfn),
attr::ia_never => set_no_inline(llfn),
let glue_fn_ty = T_ptr(T_glue_fn(ccx));
let ti = val;
let take_glue =
- alt copy ti.take_glue {
+ match copy ti.take_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let drop_glue =
- alt copy ti.drop_glue {
+ match copy ti.drop_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let free_glue =
- alt copy ti.free_glue {
+ match copy ti.free_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
some(v) => { ccx.stats.n_real_glues += 1u; v }
};
let visit_glue =
- alt copy ti.visit_glue {
+ match copy ti.visit_glue {
none => { ccx.stats.n_null_glues += 1u; C_null(glue_fn_ty) }
some(v) => { ccx.stats.n_real_glues += 1u; v }
};
fn make_take_glue(bcx: block, v: ValueRef, t: ty::t) {
let _icx = bcx.insn_ctxt(~"make_take_glue");
// NB: v is a *pointer* to type t here, not a direct value.
- let bcx = alt ty::get(t).struct {
+ let bcx = match ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_evec(_, ty::vstore_box) | ty::ty_estr(ty::vstore_box) => {
incr_refcnt_of_boxed(bcx, Load(bcx, v)); bcx
// everything to a pointer to the type that the glue acts on).
let _icx = bcx.insn_ctxt(~"make_free_glue");
let ccx = bcx.ccx();
- let bcx = alt ty::get(t).struct {
+ let bcx = match ty::get(t).struct {
ty::ty_box(body_mt) => {
let v = PointerCast(bcx, v, type_of(ccx, t));
let body = GEPi(bcx, v, ~[0u, abi::box_field_body]);
// NB: v0 is an *alias* of type t here, not a direct value.
let _icx = bcx.insn_ctxt(~"make_drop_glue");
let ccx = bcx.ccx();
- let bcx = alt ty::get(t).struct {
+ let bcx = match ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_estr(ty::vstore_box) | ty::ty_evec(_, ty::vstore_box) => {
decr_refcnt_maybe_free(bcx, Load(bcx, v0), t)
}
ty::ty_class(did, substs) => {
let tcx = bcx.tcx();
- alt ty::ty_dtor(tcx, did) {
+ match ty::ty_dtor(tcx, did) {
some(dtor) => {
trans_class_drop(bcx, v0, dtor, did, substs)
}
t: ty::t, op: ast::binop) -> result {
let f = |a| compare_scalar_values(cx, lhs, rhs, a, op);
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_nil => return rslt(cx, f(nil_type)),
ty::ty_bool | ty::ty_ptr(_) => return rslt(cx, f(unsigned_int)),
ty::ty_int(_) => return rslt(cx, f(signed_int)),
comparison operator");
}
let die = fn@() -> ! { die_(cx) };
- alt nt {
+ match nt {
nil_type => {
// We don't need to do actual comparisons for nil.
// () == () holds but () < () does not.
- alt op {
+ match op {
ast::eq | ast::le | ast::ge => return C_bool(true),
ast::ne | ast::lt | ast::gt => return C_bool(false),
// refinements would be nice
}
}
floating_point => {
- let cmp = alt op {
+ let cmp = match op {
ast::eq => lib::llvm::RealOEQ,
ast::ne => lib::llvm::RealUNE,
ast::lt => lib::llvm::RealOLT,
return FCmp(cx, cmp, lhs, rhs);
}
signed_int => {
- let cmp = alt op {
+ let cmp = match op {
ast::eq => lib::llvm::IntEQ,
ast::ne => lib::llvm::IntNE,
ast::lt => lib::llvm::IntSLT,
return ICmp(cx, cmp, lhs, rhs);
}
unsigned_int => {
- let cmp = alt op {
+ let cmp = match op {
ast::eq => lib::llvm::IntEQ,
ast::ne => lib::llvm::IntNE,
ast::lt => lib::llvm::IntULT,
let fn_ty = variant.ctor_ty;
let ccx = cx.ccx();
let mut cx = cx;
- alt ty::get(fn_ty).struct {
+ match ty::get(fn_ty).struct {
ty::ty_fn({inputs: args, _}) => {
let mut j = 0u;
let v_id = variant.id;
Typestate constraint that shows the unimpl case doesn't happen?
*/
let mut cx = cx;
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_rec(fields) => {
for vec::eachi(fields) |i, fld| {
let llfld_a = GEPi(cx, av, ~[0u, i]);
ti: @tydesc_info) {
let _icx = ccx.insn_ctxt(~"lazily_emit_tydesc_glue");
if field == abi::tydesc_field_take_glue {
- alt ti.take_glue {
+ match ti.take_glue {
some(_) => (),
none => {
debug!{"+++ lazily_emit_tydesc_glue TAKE %s",
}
}
} else if field == abi::tydesc_field_drop_glue {
- alt ti.drop_glue {
+ match ti.drop_glue {
some(_) => (),
none => {
debug!{"+++ lazily_emit_tydesc_glue DROP %s",
}
}
} else if field == abi::tydesc_field_free_glue {
- alt ti.free_glue {
+ match ti.free_glue {
some(_) => (),
none => {
debug!{"+++ lazily_emit_tydesc_glue FREE %s",
}
}
} else if field == abi::tydesc_field_visit_glue {
- alt ti.visit_glue {
+ match ti.visit_glue {
some(_) => (),
none => {
debug!{"+++ lazily_emit_tydesc_glue VISIT %s",
if cx.unreachable { return; }
let mut static_glue_fn = none;
- alt static_ti {
+ match static_ti {
none => {/* no-op */ }
some(sti) => {
lazily_emit_tydesc_glue(cx.ccx(), field, sti);
let llrawptr = PointerCast(cx, v, T_ptr(T_i8()));
let llfn = {
- alt static_glue_fn {
+ match static_glue_fn {
none => {
// Select out the glue function to call from the tydesc
let llfnptr = GEPi(cx, tydesc, ~[0u, field]);
fn drop_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> block {
let _icx = bcx.insn_ctxt(~"drop_ty_immediate");
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_uniq(_) |
ty::ty_evec(_, ty::vstore_uniq) |
ty::ty_estr(ty::vstore_uniq) => {
fn take_ty_immediate(bcx: block, v: ValueRef, t: ty::t) -> result {
let _icx = bcx.insn_ctxt(~"take_ty_immediate");
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_box(_) | ty::ty_opaque_box |
ty::ty_evec(_, ty::vstore_box) |
ty::ty_estr(ty::vstore_box) => {
// constant element of a tydesc works).
let _icx = cx.insn_ctxt(~"call_memmove");
let ccx = cx.ccx();
- let key = alt ccx.sess.targ_cfg.arch {
+ let key = match ccx.sess.targ_cfg.arch {
session::arch_x86 | session::arch_arm => ~"llvm.memmove.p0i8.p0i8.i32",
session::arch_x86_64 => ~"llvm.memmove.p0i8.p0i8.i64"
};
// These are the types that are passed by pointer.
fn type_is_structural_or_param(t: ty::t) -> bool {
if ty::type_is_structural(t) { return true; }
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_param(*) => return true,
_ => return false
}
un_expr: @ast::expr, dest: dest) -> block {
let _icx = bcx.insn_ctxt(~"trans_unary");
// Check for user-defined method call
- alt bcx.ccx().maps.method_map.find(un_expr.id) {
+ match bcx.ccx().maps.method_map.find(un_expr.id) {
some(mentry) => {
let fty = node_id_type(bcx, un_expr.callee_id);
return trans_call_inner(
if dest == ignore { return trans_expr(bcx, e, ignore); }
let e_ty = expr_ty(bcx, e);
- alt op {
+ match op {
ast::not => {
let {bcx, val} = trans_temp_expr(bcx, e);
store_in_dest(bcx, Not(bcx, val), dest)
// Determine the operation we need.
let llop = {
- alt op {
+ match op {
ast::eq | ast::ne => C_u8(abi::cmp_glue_op_eq),
ast::lt | ast::ge => C_u8(abi::cmp_glue_op_lt),
ast::le | ast::gt => C_u8(abi::cmp_glue_op_le),
let cmpval = call_cmp_glue(cx, lhs, rhs, rhs_t, llop);
// Invert the result if necessary.
- alt op {
+ match op {
ast::eq | ast::lt | ast::le => rslt(cx, cmpval),
ast::ne | ast::ge | ast::gt => rslt(cx, Not(cx, cmpval)),
_ => cx.tcx().sess.bug(~"trans_compare got non-comparison-op")
} else {
~"modulo zero"
};
- let is_zero = alt ty::get(rhs_t).struct {
+ let is_zero = match ty::get(rhs_t).struct {
ty::ty_int(t) => {
let zero = C_integral(T_int_ty(cx.ccx(), t), 0u64, False);
ICmp(cx, lib::llvm::IntEQ, rhs, zero)
let rhs = cast_shift_expr_rhs(cx, op, lhs, rhs);
let mut cx = cx;
- let val = alt op {
+ let val = match op {
ast::add => {
if is_float { FAdd(cx, lhs, rhs) }
else { Add(cx, lhs, rhs) }
assert (lhs_res.kind == lv_owned);
// A user-defined operator method
- alt bcx.ccx().maps.method_map.find(ex.id) {
+ match bcx.ccx().maps.method_map.find(ex.id) {
some(origin) => {
let bcx = lhs_res.bcx;
debug!{"user-defined method callee_id: %s",
// root the autoderef'd value, if necessary:
derefs += 1u;
- alt ccx.maps.root_map.find({id:e_id, derefs:derefs}) {
+ match ccx.maps.root_map.find({id:e_id, derefs:derefs}) {
none => (),
some(scope_id) => {
root_value(cx, v1, t1, scope_id);
}
}
- alt ty::get(t1).struct {
+ match ty::get(t1).struct {
ty::ty_box(mt) => {
let body = GEPi(cx, v1, ~[0u, abi::box_field_body]);
t1 = mt.ty;
if past_lhs.unreachable { return past_lhs; }
let join = sub_block(bcx, ~"join"), before_rhs = sub_block(bcx, ~"rhs");
- alt op {
+ match op {
lazy_and => CondBr(past_lhs, lhs, before_rhs.llbb, join.llbb),
lazy_or => CondBr(past_lhs, lhs, join.llbb, before_rhs.llbb)
}
rhs: @ast::expr, dest: dest, ex: @ast::expr) -> block {
let _icx = bcx.insn_ctxt(~"trans_binary");
// User-defined operators
- alt bcx.ccx().maps.method_map.find(ex.id) {
+ match bcx.ccx().maps.method_map.find(ex.id) {
some(origin) => {
let fty = node_id_type(bcx, ex.callee_id);
return trans_call_inner(
}
// First couple cases are lazy:
- alt op {
+ match op {
ast::and => {
return trans_lazy_binop(bcx, lazy_and, lhs, rhs, dest);
}
// because trans_expr will create another scope block
// context for the block, but we've already got the
// 'else' context
- let else_bcx = alt els {
+ let else_bcx = match els {
some(elexpr) => {
- alt elexpr.node {
+ match elexpr.node {
ast::expr_if(_, _, _) => {
let elseif_blk = ast_util::block_from_expr(elexpr);
trans_block(else_cx, elseif_blk, else_dest)
fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did);
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_fn(_) => {
let llty = type_of_fn_from_ty(ccx, t);
return get_extern_fn(ccx.externs, ccx.llmod, name,
fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> option<ty::t> {
// FIXME[mono] could do this recursively. is that worthwhile? (#2529)
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_box(mt) => {
some(ty::mk_opaque_box(tcx))
}
fn make_mono_id(ccx: @crate_ctxt, item: ast::def_id, substs: ~[ty::t],
vtables: option<typeck::vtable_res>,
param_uses: option<~[type_use::type_uses]>) -> mono_id {
- let precise_param_ids = alt vtables {
+ let precise_param_ids = match vtables {
some(vts) => {
let bounds = ty::lookup_item_type(ccx.tcx, item).bounds;
let mut i = 0u;
vec::map2(*bounds, substs, |bounds, subst| {
let mut v = ~[];
for vec::each(*bounds) |bound| {
- alt bound {
+ match bound {
ty::bound_trait(_) => {
vec::push(v, impl::vtable_id(ccx, vts[i]));
i += 1u;
vec::map(substs, |subst| mono_precise(subst, none))
}
};
- let param_ids = alt param_uses {
+ let param_ids = match param_uses {
some(uses) => {
vec::map2(precise_param_ids, uses, |id, uses| {
- alt check id {
+ match check id {
mono_precise(_, some(_)) => id,
mono_precise(subst, none) => {
if uses == 0u { mono_any }
let _icx = ccx.insn_ctxt(~"monomorphic_fn");
let mut must_cast = false;
let substs = vec::map(real_substs, |t| {
- alt normalize_for_monomorphization(ccx.tcx, t) {
+ match normalize_for_monomorphization(ccx.tcx, t) {
some(t) => { must_cast = true; t }
none => t
}
let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
let hash_id = make_mono_id(ccx, fn_id, substs, vtables, some(param_uses));
if vec::any(hash_id.params,
- |p| alt p { mono_precise(_, _) => false, _ => true }) {
+ |p| match p { mono_precise(_, _) => false, _ => true }) {
must_cast = true;
}
real_substs.map(|s| ty_to_str(ccx.tcx, s)),
substs.map(|s| ty_to_str(ccx.tcx, s)), hash_id];
- alt ccx.monomorphized.find(hash_id) {
+ match ccx.monomorphized.find(hash_id) {
some(val) => {
debug!{"leaving monomorphic fn %s",
ty::item_path_str(ccx.tcx, fn_id)};
(may have attempted to monomorphize an item defined in a different \
crate?)", fn_id});
// Get the path so that we can create a symbol
- let (pt, name, span) = alt map_node {
+ let (pt, name, span) = match map_node {
ast_map::node_item(i, pt) => (pt, i.ident, i.span),
ast_map::node_variant(v, enm, pt) => (pt, v.node.name, enm.span),
ast_map::node_method(m, _, pt) => (pt, m.ident, m.span),
};
let psubsts = some({tys: substs, vtables: vtables, bounds: tpt.bounds});
- let lldecl = alt map_node {
+ let lldecl = match map_node {
ast_map::node_item(i@@{node: ast::item_fn(decl, _, body), _}, _) => {
let d = mk_lldecl();
set_inline_hint_if_appr(i.attrs, d);
d
}
ast_map::node_dtor(_, dtor, _, pt) => {
- let parent_id = alt ty::ty_to_def_id(ty::node_id_to_type(ccx.tcx,
+ let parent_id = match ty::ty_to_def_id(ty::node_id_to_type(ccx.tcx,
dtor.node.self_id)) {
some(did) => did,
none => ccx.sess.span_bug(dtor.span, ~"Bad self ty in \
fn maybe_instantiate_inline(ccx: @crate_ctxt, fn_id: ast::def_id)
-> ast::def_id {
let _icx = ccx.insn_ctxt(~"maybe_instantiate_inline");
- alt ccx.external.find(fn_id) {
+ match ccx.external.find(fn_id) {
some(some(node_id)) => {
// Already inline
debug!{"maybe_instantiate_inline(%s): already inline as node id %d",
}
some(none) => fn_id, // Not inlinable
none => { // Not seen yet
- alt csearch::maybe_get_item_ast(
+ match csearch::maybe_get_item_ast(
ccx.tcx, fn_id,
|a,b,c,d| {
astencode::decode_inlined_item(a, b, ccx.maps, c, d)
csearch::found_parent(parent_id, ast::ii_item(item)) => {
ccx.external.insert(parent_id, some(item.id));
let mut my_id = 0;
- alt check item.node {
+ match check item.node {
ast::item_enum(_, _) => {
let vs_here = ty::enum_variants(ccx.tcx, local_def(item.id));
let vs_there = ty::enum_variants(ccx.tcx, parent_id);
ccx, node_id_type(bcx, id))));
}
- alt ty::get(tpt.ty).struct {
+ match ty::get(tpt.ty).struct {
ty::ty_fn(fn_ty) => {
- alt fn_ty.purity {
+ match fn_ty.purity {
ast::extern_fn => {
// Extern functions are just opaque pointers
let val = PointerCast(bcx, val, T_ptr(T_i8()));
fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
let _icx = ccx.insn_ctxt(~"lookup_discriminant");
- alt ccx.discrims.find(vid) {
+ match ccx.discrims.find(vid) {
none => {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let _icx = cx.insn_ctxt(~"trans_local_var");
fn take_local(table: hashmap<ast::node_id, local_val>,
id: ast::node_id) -> local_var_result {
- alt table.find(id) {
+ match table.find(id) {
some(local_mem(v)) => {val: v, kind: lv_owned},
some(local_imm(v)) => {val: v, kind: lv_owned_imm},
r => fail(~"take_local: internal error")
}
}
- alt def {
+ match def {
ast::def_upvar(nid, _, _) => {
assert (cx.fcx.llupvars.contains_key(nid));
return { val: cx.fcx.llupvars.get(nid), kind: lv_owned };
return take_local(cx.fcx.lllocals, nid);
}
ast::def_self(sid) => {
- let slf = alt copy cx.fcx.llself {
+ let slf = match copy cx.fcx.llself {
some(s) => cast_self(cx, s),
none => cx.sess().bug(~"trans_local_var: reference to self \
out of context")
fn trans_path(cx: block, id: ast::node_id)
-> lval_maybe_callee {
let _icx = cx.insn_ctxt(~"trans_path");
- alt cx.tcx().def_map.find(id) {
+ match cx.tcx().def_map.find(id) {
none => cx.sess().bug(~"trans_path: unbound node ID"),
some(df) => {
return trans_var(cx, df, id);
fn trans_var(cx: block, def: ast::def, id: ast::node_id)-> lval_maybe_callee {
let _icx = cx.insn_ctxt(~"trans_var");
let ccx = cx.ccx();
- alt def {
+ match def {
ast::def_fn(did, _) => {
return lval_static_fn(cx, did, id);
}
fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
field: ast::ident, sp: span) -> lval_result {
let mut llderef = false;
- let fields = alt ty::get(ty).struct {
+ let fields = match ty::get(ty).struct {
ty::ty_rec(fs) => fs,
ty::ty_class(did, substs) => {
if option::is_some(ty::ty_dtor(bcx.tcx(), did)) {
fn trans_callee(bcx: block, e: @ast::expr) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"trans_callee");
- alt e.node {
+ match e.node {
ast::expr_path(path) => return trans_path(bcx, e.id),
ast::expr_field(base, _, _) => {
// Lval means this is a record field, so not a method
if !expr_is_lval(bcx, e) {
- alt bcx.ccx().maps.method_map.find(e.id) {
+ match bcx.ccx().maps.method_map.find(e.id) {
some(origin) => { // An impl method
return impl::trans_method_callee(bcx, e.id, base, origin);
}
// represented as an alloca or heap, hence needs a 'load' to be used as an
// immediate).
fn trans_lval(cx: block, e: @ast::expr) -> lval_result {
- return alt cx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
+ return match cx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
// No need to root this lvalue.
none => unrooted(cx, e),
fn unrooted(cx: block, e: @ast::expr) -> lval_result {
let _icx = cx.insn_ctxt(~"trans_lval");
- alt e.node {
+ match e.node {
ast::expr_path(_) => {
let v = trans_path(cx, e.id);
return lval_maybe_callee_to_lval(v, e.span);
let ccx = cx.ccx();
let sub = trans_temp_expr(cx, base);
let t = expr_ty(cx, base);
- let val = alt check ty::get(t).struct {
+ let val = match check ty::get(t).struct {
ty::ty_box(_) => {
let non_gc_val = non_gc_box_cast(sub.bcx, sub.val);
GEPi(sub.bcx, non_gc_val, ~[0u, abi::box_field_body])
}
fn lval_maybe_callee_to_lval(c: lval_maybe_callee, sp: span) -> lval_result {
- alt c.env {
+ match c.env {
self_env(*) => {
c.bcx.sess().span_bug(sp, ~"implicitly binding method call");
}
enum cast_kind { cast_pointer, cast_integral, cast_float,
cast_enum, cast_other, }
fn cast_type_kind(t: ty::t) -> cast_kind {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_float(*) => cast_float,
ty::ty_ptr(*) => cast_pointer,
ty::ty_rptr(*) => cast_pointer,
let _icx = cx.insn_ctxt(~"trans_cast");
let ccx = cx.ccx();
let t_out = node_id_type(cx, id);
- alt ty::get(t_out).struct {
+ match ty::get(t_out).struct {
ty::ty_trait(_, _) => return impl::trans_cast(cx, e, id, dest),
_ => ()
}
let s_in = k_in == cast_integral && ty::type_is_signed(t_in);
let newval =
- alt {in: k_in, out: k_out} {
+ match {in: k_in, out: k_out} {
{in: cast_integral, out: cast_integral} => {
int_cast(e_res.bcx, ll_t_out, ll_t_in, e_res.val, s_in)
}
let av_enum = PointerCast(cx, e_res.val, llenumty);
let lldiscrim_a_ptr = GEPi(cx, av_enum, ~[0u, 0u]);
let lldiscrim_a = Load(cx, lldiscrim_a_ptr);
- alt k_out {
+ match k_out {
cast_integral => int_cast(e_res.bcx, ll_t_out,
val_ty(lldiscrim_a),
lldiscrim_a, true),
fn trans_loop_body(bcx: block, e: @ast::expr, ret_flag: option<ValueRef>,
dest: dest) -> block {
- alt check e.node {
+ match check e.node {
ast::expr_loop_body(b@@{
node: ast::expr_fn_block(decl, body, cap),
_
}) => {
- alt check ty::get(expr_ty(bcx, e)).struct {
+ match check ty::get(expr_ty(bcx, e)).struct {
ty::ty_fn({proto, _}) => {
closure::trans_expr_fn(bcx, proto, decl, body, b.id,
cap, some(ret_flag),
let is_bot = ty::type_is_bot(e_ty);
// translate the arg expr as an lvalue
- let lv = alt ret_flag {
+ let lv = match ret_flag {
// If there is a ret_flag, this *must* be a loop body
- some(ptr) => alt check e.node {
+ some(ptr) => match check e.node {
ast::expr_loop_body(blk) => {
let scratch = alloc_ty(cx, expr_ty(cx, blk));
let bcx = trans_loop_body(cx, e, ret_flag, save_in(scratch));
// to have type lldestty (the callee's expected type).
val = llvm::LLVMGetUndef(lldestty);
} else {
- alt arg_mode {
+ match arg_mode {
ast::by_ref | ast::by_mutbl_ref => {
// Ensure that the value is spilled into memory:
if lv.kind != lv_owned && ty::type_is_immediate(e_ty) {
return {lv:lv, ty:e_ty};
}
- alt ty::get(e_ty).struct {
+ match ty::get(e_ty).struct {
ty::ty_uniq(mt) | ty::ty_box(mt) => {
let box_ptr = load_value_from_lval_result(lv, e_ty);
let body_ptr = GEPi(bcx, box_ptr, ~[0u, abi::box_field_body]);
ty::ty_estr(_) | ty::ty_evec(_, _) => {
let ccx = bcx.ccx();
- let val = alt lv.kind {
+ let val = match lv.kind {
lv_temporary => lv.val,
lv_owned => load_if_immediate(bcx, lv.val, e_ty),
lv_owned_imm => lv.val
let retty = ty::ty_fn_ret(fn_ty);
// Arg 0: Output pointer.
- let llretslot = alt dest {
+ let llretslot = match dest {
ignore => {
if ty::type_is_nil(retty) {
llvm::LLVMGetUndef(T_ptr(T_nil()))
// First we figure out the caller's view of the types of the arguments.
// This will be needed if this is a generic call, because the callee has
// to cast her view of the arguments to the caller's view.
- alt args {
+ match args {
arg_exprs(es) => {
let llarg_tys = type_of_explicit_args(ccx, arg_tys);
let last = es.len() - 1u;
visit_item: |_i, _cx, _v| { },
visit_expr: |e: @ast::expr, cx: {mut found: bool}, v| {
if !cx.found {
- alt e.node {
+ match e.node {
ast::expr_ret(_) => cx.found = true,
_ => visit::visit_expr(e, cx, v),
}
dest: dest) -> block {
do with_scope(in_cx, call_info, ~"call") |cx| {
- let ret_in_loop = alt args {
+ let ret_in_loop = match args {
arg_exprs(args) => {
- args.len() > 0u && alt vec::last(args).node {
+ args.len() > 0u && match vec::last(args).node {
ast::expr_loop_body(@{
node: ast::expr_fn_block(_, body, _),
_
} else { none };
let mut faddr = f_res.val;
- let llenv = alt f_res.env {
+ let llenv = match f_res.env {
null_env => {
llvm::LLVMGetUndef(T_opaque_box_ptr(ccx))
}
type _|_. Since that means it diverges, the code
for the call itself is unreachable. */
bcx = invoke(bcx, faddr, llargs);
- alt dest {
+ match dest {
ignore => {
if llvm::LLVMIsUndef(llretslot) != lib::llvm::True {
bcx = drop_ty(bcx, llretslot, ret_ty);
// Walk the scopes to look for cleanups
let mut cur = bcx;
loop {
- alt cur.kind {
+ match cur.kind {
block_scope(inf) => {
for vec::each(inf.cleanups) |cleanup| {
- alt cleanup {
+ match cleanup {
clean(_, cleanup_type) | clean_temp(_, _, cleanup_type) => {
if cleanup_type == normal_exit_and_unwind {
return true;
}
_ => ()
}
- cur = alt cur.parent {
+ cur = match cur.parent {
some(next) => next,
none => return false
}
fn have_cached_lpad(bcx: block) -> bool {
let mut res = false;
do in_lpad_scope_cx(bcx) |inf| {
- alt inf.landing_pad {
+ match inf.landing_pad {
some(_) => res = true,
none => res = false
}
fn in_lpad_scope_cx(bcx: block, f: fn(scope_info)) {
let mut bcx = bcx;
loop {
- alt bcx.kind {
+ match bcx.kind {
block_scope(inf) => {
if inf.cleanups.len() > 0u || is_none(bcx.parent) {
f(inf); return;
let mut cached = none, pad_bcx = bcx; // Guaranteed to be set below
do in_lpad_scope_cx(bcx) |inf| {
// If there is a valid landing pad still around, use it
- alt copy inf.landing_pad {
+ match copy inf.landing_pad {
some(target) => cached = some(target),
none => {
pad_bcx = lpad_block(bcx, ~"unwind");
}
}
// Can't return from block above
- alt cached { some(b) => return b, none => () }
+ match cached { some(b) => return b, none => () }
// The landing pad return type (the type being propagated). Not sure what
// this represents but it's determined by the personality function and
// this is what the EH proposal example uses.
// We store the retval in a function-central alloca, so that calls to
// Resume can find it.
- alt copy bcx.fcx.personality {
+ match copy bcx.fcx.personality {
some(addr) => Store(pad_bcx, llretval, addr),
none => {
let addr = alloca(pad_bcx, val_ty(llretval));
fn trans_tup(bcx: block, elts: ~[@ast::expr], dest: dest) -> block {
let _icx = bcx.insn_ctxt(~"trans_tup");
let mut bcx = bcx;
- let addr = alt dest {
+ let addr = match dest {
ignore => {
for vec::each(elts) |ex| { bcx = trans_expr(bcx, ex, ignore); }
return bcx;
let _icx = bcx.insn_ctxt(~"trans_rec");
let t = node_id_type(bcx, id);
let mut bcx = bcx;
- let addr = alt check dest {
+ let addr = match check dest {
ignore => {
for vec::each(fields) |fld| {
bcx = trans_expr(bcx, fld.node.expr, ignore);
save_in(pos) => pos
};
- let ty_fields = alt check ty::get(t).struct { ty::ty_rec(f) => f };
+ let ty_fields = match check ty::get(t).struct { ty::ty_rec(f) => f };
let mut temp_cleanups = ~[];
for fields.each |fld| {
add_clean_temp_mem(bcx, dst, ty_fields[ix].mt.ty);
vec::push(temp_cleanups, dst);
}
- alt base {
+ match base {
some(bexp) => {
let {bcx: cx, val: base_val} = trans_temp_expr(bcx, bexp);
bcx = cx;
// Get the address to store the structure into. If there is no address,
// just translate each field and be done with it.
let dest_address;
- alt dest {
+ match dest {
ignore => {
for fields.each |field| {
block_context = trans_expr(block_context,
// Get the class ID and its fields.
let class_fields, class_id, substitutions;
- alt ty::get(struct_type).struct {
+ match ty::get(struct_type).struct {
ty::ty_class(existing_class_id, existing_substitutions) => {
class_id = existing_class_id;
substitutions = existing_substitutions;
}
let index, field_id;
- alt found {
+ match found {
some((found_index, found_field_id)) => {
index = found_index;
field_id = found_field_id;
}
fn load_value_from_lval_result(lv: lval_result, ty: ty::t) -> ValueRef {
- alt lv.kind {
+ match lv.kind {
lv_temporary => lv.val,
lv_owned => load_if_immediate(lv.bcx, lv.val, ty),
lv_owned_imm => lv.val
fn find_bcx_for_scope(bcx: block, scope_id: ast::node_id) -> block {
let mut bcx_sid = bcx;
loop {
- bcx_sid = alt bcx_sid.node_info {
+ bcx_sid = match bcx_sid.node_info {
some({id, _}) if id == scope_id => {
return bcx_sid
}
_ => {
- alt bcx_sid.parent {
+ match bcx_sid.parent {
none => bcx.tcx().sess.bug(
fmt!{"no enclosing scope with id %d", scope_id}),
some(bcx_par) => bcx_par
return lval_to_dps(bcx, e, dest);
}
- return alt bcx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
+ return match bcx.ccx().maps.root_map.find({id:e.id, derefs:0u}) {
none => unrooted(bcx, e, dest),
some(scope_id) => {
debug!{"expression %d found in root map with scope %d",
fn unrooted(bcx: block, e: @ast::expr, dest: dest) -> block {
let tcx = bcx.tcx();
- alt e.node {
+ match e.node {
ast::expr_if(cond, thn, els) => {
return trans_if(bcx, cond, thn, els, dest);
}
cap_clause, none, dest);
}
ast::expr_fn_block(decl, body, cap_clause) => {
- alt check ty::get(expr_ty(bcx, e)).struct {
+ match check ty::get(expr_ty(bcx, e)).struct {
ty::ty_fn({proto, _}) => {
debug!{"translating fn_block %s with type %s",
expr_to_str(e),
last_use: bool, dest: dest) -> block {
let mut {bcx, val, kind} = lv;
let ccx = bcx.ccx();
- alt dest {
+ match dest {
by_val(cell) => {
if kind == lv_temporary {
revoke_clean(bcx, val);
let modpath = vec::append(
~[path_mod(ccx.link_meta.name)],
vec::filter(bcx.fcx.path, |e|
- alt e { path_mod(_) => true, _ => false }
+ match e { path_mod(_) => true, _ => false }
));
let modname = path_str(modpath);
fail_expr: option<@ast::expr>) -> block {
let _icx = bcx.insn_ctxt(~"trans_fail_expr");
let mut bcx = bcx;
- alt fail_expr {
+ match fail_expr {
some(expr) => {
let ccx = bcx.ccx(), tcx = ccx.tcx;
let expr_res = trans_temp_expr(bcx, expr);
let _icx = bcx.insn_ctxt(~"trans_trace");
add_comment(bcx, trace_str);
let V_trace_str = C_cstr(bcx.ccx(), trace_str);
- let {V_filename, V_line} = alt sp_opt {
+ let {V_filename, V_line} = match sp_opt {
some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
V_fail_str: ValueRef) -> block {
let _icx = bcx.insn_ctxt(~"trans_fail_value");
let ccx = bcx.ccx();
- let {V_filename, V_line} = alt sp_opt {
+ let {V_filename, V_line} = match sp_opt {
some(sp) => {
let sess = bcx.sess();
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
let mut unwind = bcx;
let mut target;
loop {
- alt unwind.kind {
+ match unwind.kind {
block_scope({loop_break: some(brk), _}) => {
target = if to_end {
brk
}
_ => ()
}
- unwind = alt unwind.parent {
+ unwind = match unwind.parent {
some(cx) => cx,
// This is a return from a loop body block
none => {
fn trans_ret(bcx: block, e: option<@ast::expr>) -> block {
let _icx = bcx.insn_ctxt(~"trans_ret");
let mut bcx = bcx;
- let retptr = alt copy bcx.fcx.loop_ret {
+ let retptr = match copy bcx.fcx.loop_ret {
some({flagptr, retptr}) => {
// This is a loop body return. Must set continue flag (our retptr)
// to false, return flag to true, and then store the value in the
// parent's retptr.
Store(bcx, C_bool(true), flagptr);
Store(bcx, C_bool(false), bcx.fcx.llretptr);
- alt e {
+ match e {
some(x) => PointerCast(bcx, retptr,
T_ptr(type_of(bcx.ccx(), expr_ty(bcx, x)))),
none => retptr
}
none => bcx.fcx.llretptr
};
- alt e {
+ match e {
some(x) => {
bcx = trans_expr_save_in(bcx, x, retptr);
}
fn init_local(bcx: block, local: @ast::local) -> block {
let _icx = bcx.insn_ctxt(~"init_local");
let ty = node_id_type(bcx, local.node.id);
- let llptr = alt bcx.fcx.lllocals.find(local.node.id) {
+ let llptr = match bcx.fcx.lllocals.find(local.node.id) {
some(local_mem(v)) => v,
_ => { bcx.tcx().sess.span_bug(local.span,
~"init_local: Someone forgot to document why it's\
};
let mut bcx = bcx;
- alt local.node.init {
+ match local.node.init {
some(init) => {
if init.op == ast::init_assign || !expr_is_lval(bcx, init.expr) {
bcx = trans_expr_save_in(bcx, init.expr, llptr);
let mut bcx = cx;
debuginfo::update_source_pos(cx, s.span);
- alt s.node {
+ match s.node {
ast::stmt_expr(e, _) | ast::stmt_semi(e, _) => {
bcx = trans_expr(cx, e, ignore);
}
ast::stmt_decl(d, _) => {
- alt d.node {
+ match d.node {
ast::decl_local(locals) => {
for vec::each(locals) |local| {
bcx = init_local(bcx, local);
let _icx = bcx.insn_ctxt(~"trans_block_cleanups");
if bcx.unreachable { return bcx; }
let mut bcx = bcx;
- alt check cleanup_cx.kind {
+ match check cleanup_cx.kind {
block_scope({cleanups, _}) => {
let cleanups = copy cleanups;
do vec::riter(cleanups) |cu| {
- alt cu {
+ match cu {
clean(cfn, cleanup_type) | clean_temp(_, cfn, cleanup_type) => {
// Some types don't need to be cleaned up during
// landing pads because they can be freed en mass later
fmt!{"cleanup_and_leave(%s)", cur.to_str()});
}
- alt cur.kind {
+ match cur.kind {
block_scope(inf) if inf.cleanups.len() > 0u => {
for vec::find(inf.cleanup_paths,
|cp| cp.target == leave).each |cp| {
}
_ => ()
}
- alt upto {
+ match upto {
some(bb) => { if cur.llbb == bb { break; } }
_ => ()
}
- cur = alt cur.parent {
+ cur = match cur.parent {
some(next) => next,
none => { assert is_none(upto); break; }
};
}
- alt leave {
+ match leave {
some(target) => Br(bcx, target),
none => { Resume(bcx, Load(bcx, option::get(bcx.fcx.personality))); }
}
fn block_locals(b: ast::blk, it: fn(@ast::local)) {
for vec::each(b.node.stmts) |s| {
- alt s.node {
+ match s.node {
ast::stmt_decl(d, _) => {
- alt d.node {
+ match d.node {
ast::decl_local(locals) => {
for vec::each(locals) |local| { it(local); }
}
fn alloc_local(cx: block, local: @ast::local) -> block {
let _icx = cx.insn_ctxt(~"alloc_local");
let t = node_id_type(cx, local.node.id);
- let simple_name = alt local.node.pat.node {
+ let simple_name = match local.node.pat.node {
ast::pat_ident(_, pth, none) => some(path_to_ident(pth)),
_ => none
};
debuginfo::update_source_pos(bcx, b.span);
bcx = trans_stmt(bcx, *s);
}
- alt b.node.expr {
+ match b.node.expr {
some(e) => {
let bt = ty::type_is_bot(expr_ty(bcx, e));
debuginfo::update_source_pos(bcx, e.span);
let _icx = cx.insn_ctxt(~"create_llargs_for_fn_args");
// Skip the implicit arguments 0, and 1.
let mut arg_n = first_real_arg;
- alt ty_self {
+ match ty_self {
impl_self(tt) => {
cx.llself = some({v: cx.llenv, t: tt});
}
};
for vec::each(arg_tys) |arg| {
let id = args[arg_n].id;
- let argval = alt fcx.llargs.get(id) {
+ let argval = match fcx.llargs.get(id) {
local_mem(v) => v,
_ => epic_fail()
};
- alt ty::resolved_mode(tcx, arg.mode) {
+ match ty::resolved_mode(tcx, arg.mode) {
ast::by_mutbl_ref => (),
ast::by_move | ast::by_copy => add_clean(bcx, argval, arg.ty),
ast::by_val => {
let fcx = new_fn_ctxt_w_id(ccx, ~[], llfndecl, variant.node.id,
param_substs, none);
create_llargs_for_fn_args(fcx, no_self, fn_args);
- let ty_param_substs = alt param_substs {
+ let ty_param_substs = match param_substs {
some(substs) => substs.tys,
none => ~[]
};
// If this argument to this function is a enum, it'll have come in to
// this function as an opaque blob due to the way that type_of()
// works. So we have to cast to the destination's view of the type.
- let llarg = alt check fcx.llargs.find(va.id) {
+ let llarg = match check fcx.llargs.find(va.id) {
some(local_mem(x)) => x
};
let arg_ty = arg_tys[i].ty;
fn trans_item(ccx: @crate_ctxt, item: ast::item) {
let _icx = ccx.insn_ctxt(~"trans_item");
- let path = alt check ccx.tcx.items.get(item.id) {
+ let path = match check ccx.tcx.items.get(item.id) {
ast_map::node_item(_, p) => p
};
- alt item.node {
+ match item.node {
ast::item_fn(decl, tps, body) => {
if decl.purity == ast::extern_fn {
let llfndecl = get_item_val(ccx, item.id);
decl, body, llfndecl, no_self, none, item.id);
} else {
for vec::each(body.node.stmts) |stmt| {
- alt stmt.node {
+ match stmt.node {
ast::stmt_decl(@{node: ast::decl_item(i), _}, _) => {
trans_item(ccx, *i);
}
}
ast::item_const(_, expr) => consts::trans_const(ccx, expr, item.id),
ast::item_foreign_mod(foreign_mod) => {
- let abi = alt attr::foreign_abi(item.attrs) {
+ let abi = match attr::foreign_abi(item.attrs) {
either::right(abi_) => abi_,
either::left(msg) => ccx.sess.span_fatal(item.span, msg)
};
let main_takes_argv =
// invariant!
- alt ty::get(main_node_type).struct {
+ match ty::get(main_node_type).struct {
ty::ty_fn({inputs, _}) => inputs.len() != 0u,
_ => ccx.sess.span_fatal(sp, ~"main has a non-function type")
};
fn item_path(ccx: @crate_ctxt, i: @ast::item) -> path {
vec::append(
- *alt check ccx.tcx.items.get(i.id) {
+ *match check ccx.tcx.items.get(i.id) {
ast_map::node_item(_, p) => p
},
~[path_name(i.ident)])
fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id,
substs: option<param_substs>) -> ~str {
let t = ty::node_id_to_type(ccx.tcx, id);
- alt ccx.item_symbols.find(id) {
+ match ccx.item_symbols.find(id) {
some(s) => s,
none if is_none(substs) => {
let s = mangle_exported_name(
none => {
// Monomorphizing, so just make a symbol, don't add
// this to item_symbols
- alt substs {
+ match substs {
some(ss) => {
let mono_ty = ty::subst_tps(ccx.tcx, ss.tys, t);
mangle_exported_name(
fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
let tcx = ccx.tcx;
- alt ccx.item_vals.find(id) {
+ match ccx.item_vals.find(id) {
some(v) => v,
none => {
let mut exprt = false;
- let val = alt check ccx.tcx.items.get(id) {
+ let val = match check ccx.tcx.items.get(id) {
ast_map::node_item(i, pth) => {
let my_path = vec::append(*pth, ~[path_name(i.ident)]);
- alt check i.node {
+ match check i.node {
ast::item_const(_, _) => {
let typ = ty::node_id_to_type(ccx.tcx, i.id);
let s = mangle_exported_name(ccx, my_path, typ);
let pth = vec::append(*pth,
~[path_name(enm.ident),
path_name(v.node.name)]);
- let llfn = alt check enm.node {
+ let llfn = match check enm.node {
ast::item_enum(_, _) => {
register_fn(ccx, v.span, pth, id)
}
// The constant translation pass.
fn trans_constant(ccx: @crate_ctxt, it: @ast::item) {
let _icx = ccx.insn_ctxt(~"trans_constant");
- alt it.node {
+ match it.node {
ast::item_enum(variants, _) => {
let vi = ty::enum_variants(ccx.tcx, {crate: ast::local_crate,
node: it.id});
fn trap(bcx: block) {
let v: ~[ValueRef] = ~[];
- alt bcx.ccx().intrinsics.find(~"llvm.trap") {
+ match bcx.ccx().intrinsics.find(~"llvm.trap") {
some(x) => { Call(bcx, x, v); },
_ => bcx.sess().bug(~"unbound llvm.trap in trap")
}
fn gather_local_rtcalls(ccx: @crate_ctxt, crate: @ast::crate) {
visit::visit_crate(*crate, (), visit::mk_simple_visitor(@{
- visit_item: |item| alt item.node {
+ visit_item: |item| match item.node {
ast::item_fn(decl, _, _) => {
let attr_metas = attr::attr_metas(
attr::find_attrs_by_name(item.attrs, ~"rt"));
do vec::iter(attr_metas) |attr_meta| {
- alt attr::get_meta_item_list(attr_meta) {
+ match attr::get_meta_item_list(attr_meta) {
some(list) => {
let name = *attr::get_meta_item_name(vec::head(list));
push_rtcall(ccx, name, {crate: ast::local_crate,
do cstore::iter_crate_data(ccx.sess.cstore) |_cnum, cmeta| {
do decoder::each_path(cmeta) |path| {
let pathname = path.path_string;
- alt path.def_like {
+ match path.def_like {
decoder::dl_def(d) => {
- alt d {
+ match d {
ast::def_fn(did, _) => {
// FIXME (#2861): This should really iterate attributes
// like gather_local_rtcalls, but we'll need to
for cx.exp_map.each |exp_id, defs| {
for defs.each |def| {
if !def.reexp { again; }
- let path = alt check cx.tcx.items.get(exp_id) {
+ let path = match check cx.tcx.items.get(exp_id) {
ast_map::node_export(_, path) => {
ast_map::path_to_str(*path)
}
s += ~"/";
s += category;
- let n = alt h.find(s) {
+ let n = match h.find(s) {
some(n) => n,
_ => 0u
};
}
fn ev_to_str(ccx: @crate_ctxt, ev: environment_value) -> ~str {
- alt ev {
+ match ev {
env_copy(v, t, lk) => fmt!{"copy(%s,%s)", val_str(ccx.tn, v),
ty_to_str(ccx.tcx, t)},
env_move(v, t, lk) => fmt!{"move(%s,%s)", val_str(ccx.tn, v),
// Compute the closed over data
for vec::each(bound_values) |bv| {
- vec::push(bound_tys, alt bv {
+ vec::push(bound_tys, match bv {
env_copy(_, t, _) => t,
env_move(_, t, _) => t,
env_ref(_, t, _) => t
}
// Allocate and initialize the box:
- let {bcx, val} = alt ck {
+ let {bcx, val} = match ck {
ty::ck_box => malloc_raw(bcx, cdata_ty, heap_shared),
ty::ck_uniq => malloc_raw(bcx, cdata_ty, heap_exchange),
ty::ck_block => {
let bound_data = GEPi(bcx, llbox,
~[0u, abi::box_field_body, i]);
- alt bv {
+ match bv {
env_copy(val, ty, lv_owned) => {
let val1 = load_if_immediate(bcx, val, ty);
bcx = base::copy_val(bcx, INIT, bound_data, val1, ty);
debug!{"Node id is %s",
syntax::ast_map::node_id_to_str(bcx.ccx().tcx.items, nid)};
let mut ty = node_id_type(bcx, nid);
- alt cap_var.mode {
+ match cap_var.mode {
capture::cap_ref => {
assert ck == ty::ck_block;
ty = ty::mk_mut_ptr(tcx, ty);
vec::push(env_vals, env_ref(lv.val, ty, lv.kind));
}
capture::cap_copy => {
- let mv = alt check ccx.maps.last_use_map.find(id) {
+ let mv = match check ccx.maps.last_use_map.find(id) {
none => false,
some(vars) => (*vars).contains(nid)
};
}
}
do option::iter(include_ret_handle) |flagptr| {
- let our_ret = alt bcx.fcx.loop_ret {
+ let our_ret = match bcx.fcx.loop_ret {
some({retptr, _}) => retptr,
none => bcx.fcx.llretptr
};
// Populate the upvars from the environment.
let mut i = 0u;
do vec::iter(cap_vars) |cap_var| {
- alt cap_var.mode {
+ match cap_var.mode {
capture::cap_drop => { /* ignore */ }
_ => {
let mut upvarptr =
GEPi(bcx, llcdata, ~[0u, i]);
- alt ck {
+ match ck {
ty::ck_block => { upvarptr = Load(bcx, upvarptr); }
ty::ck_uniq | ty::ck_box => ()
}
let trans_closure_env = fn@(ck: ty::closure_kind) -> result {
let cap_vars = capture::compute_capture_vars(
ccx.tcx, id, proto, cap_clause);
- let ret_handle = alt is_loop_body { some(x) => x, none => none };
+ let ret_handle = match is_loop_body { some(x) => x, none => none };
let {llbox, cdata_ty, bcx} = build_closure(bcx, cap_vars, ck, id,
ret_handle);
trans_closure(ccx, sub_path, decl, body, llfn, no_self,
{bcx: bcx, val: llbox}
};
- let {bcx: bcx, val: closure} = alt proto {
+ let {bcx: bcx, val: closure} = match proto {
ast::proto_block => trans_closure_env(ty::ck_block),
ast::proto_box => trans_closure_env(ty::ck_box),
ast::proto_uniq => trans_closure_env(ty::ck_uniq),
}
};
- return alt ty::get(t).struct {
+ return match ty::get(t).struct {
ty::ty_fn({proto: ast::proto_bare, _}) |
ty::ty_fn({proto: ast::proto_block, _}) => bcx,
ty::ty_fn({proto: ast::proto_uniq, _}) => fn_env(ty::ck_uniq),
-> block {
// Easy cases:
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_take_glue");
- alt ck {
+ match ck {
ty::ck_block => return bcx,
ty::ck_box => {
incr_refcnt_of_boxed(bcx, Load(bcx, cboxptr));
cboxptr: ValueRef) // ptr to the opaque closure
-> block {
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_drop_glue");
- alt ck {
+ match ck {
ty::ck_block => bcx,
ty::ck_box => {
decr_refcnt_maybe_free(bcx, Load(bcx, cboxptr),
cbox: ValueRef) // ptr to the opaque closure
-> block {
let _icx = bcx.insn_ctxt(~"closure::make_opaque_cbox_free_glue");
- alt ck {
+ match ck {
ty::ck_block => return bcx,
ty::ck_box | ty::ck_uniq => { /* hard cases: */ }
}
abi::tydesc_field_drop_glue, none);
// Free the ty descr (if necc) and the box itself
- alt ck {
+ match ck {
ty::ck_block => fail ~"Impossible",
ty::ck_box => trans_free(bcx, cbox),
ty::ck_uniq => trans_unique_free(bcx, cbox)
}
}
fn add_clean_free(cx: block, ptr: ValueRef, heap: heap) {
- let free_fn = alt heap {
+ let free_fn = match heap {
heap_shared => |a| base::trans_free(a, ptr),
heap_exchange => |a| base::trans_unique_free(a, ptr)
};
fn revoke_clean(cx: block, val: ValueRef) {
do in_scope_cx(cx) |info| {
do option::iter(vec::position(info.cleanups, |cu| {
- alt cu {
+ match cu {
clean_temp(v, _, _) if v == val => true,
_ => false
}
fn in_scope_cx(cx: block, f: fn(scope_info)) {
let mut cur = cx;
loop {
- alt cur.kind {
+ match cur.kind {
block_scope(inf) => { f(inf); return; }
_ => ()
}
}
fn block_parent(cx: block) -> block {
- alt cx.parent {
+ match cx.parent {
some(b) => b,
none => cx.sess().bug(fmt!{"block_parent called on root block %?",
cx})
ty_to_str(self.tcx(), t)
}
fn to_str() -> ~str {
- alt self.node_info {
+ match self.node_info {
some(node_info) => {
fmt!{"[block %d]", node_info.id}
}
fn T_bool() -> TypeRef { return T_i1(); }
fn T_int(targ_cfg: @session::config) -> TypeRef {
- return alt targ_cfg.arch {
+ return match targ_cfg.arch {
session::arch_x86 => T_i32(),
session::arch_x86_64 => T_i64(),
session::arch_arm => T_i32()
}
fn T_int_ty(cx: @crate_ctxt, t: ast::int_ty) -> TypeRef {
- alt t {
+ match t {
ast::ty_i => cx.int_type,
ast::ty_char => T_char(),
ast::ty_i8 => T_i8(),
}
fn T_uint_ty(cx: @crate_ctxt, t: ast::uint_ty) -> TypeRef {
- alt t {
+ match t {
ast::ty_u => cx.int_type,
ast::ty_u8 => T_i8(),
ast::ty_u16 => T_i16(),
}
fn T_float_ty(cx: @crate_ctxt, t: ast::float_ty) -> TypeRef {
- alt t {
+ match t {
ast::ty_f => cx.float_type,
ast::ty_f32 => T_f32(),
ast::ty_f64 => T_f64()
}
fn T_float(targ_cfg: @session::config) -> TypeRef {
- return alt targ_cfg.arch {
+ return match targ_cfg.arch {
session::arch_x86 => T_f64(),
session::arch_x86_64 => T_f64(),
session::arch_arm => T_f64()
fn T_glue_fn(cx: @crate_ctxt) -> TypeRef {
let s = ~"glue_fn";
- alt name_has_type(cx.tn, s) {
+ match name_has_type(cx.tn, s) {
some(t) => return t,
_ => ()
}
// This type must never be used directly; it must always be cast away.
fn T_typaram(tn: type_names) -> TypeRef {
let s = ~"typaram";
- alt name_has_type(tn, s) {
+ match name_has_type(tn, s) {
some(t) => return t,
_ => ()
}
fn T_opaque_enum(cx: @crate_ctxt) -> TypeRef {
let s = ~"opaque_enum";
- alt name_has_type(cx.tn, s) {
+ match name_has_type(cx.tn, s) {
some(t) => return t,
_ => ()
}
// This is a 'c-like' raw string, which differs from
// our boxed-and-length-annotated strings.
fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef {
- alt cx.const_cstr_cache.find(s) {
+ match cx.const_cstr_cache.find(s) {
some(llval) => return llval,
none => ()
}
pure fn hash_mono_id(mi: &mono_id) -> uint {
let mut h = syntax::ast_util::hash_def(&mi.def);
for vec::each(mi.params) |param| {
- h = h * alt param {
+ h = h * match param {
mono_precise(ty, vts) => {
let mut h = ty::type_id(ty);
do option::iter(vts) |vts| {
fn path_str(p: path) -> ~str {
let mut r = ~"", first = true;
for vec::each(p) |e| {
- alt e { ast_map::path_name(s) | ast_map::path_mod(s) => {
+ match e { ast_map::path_name(s) | ast_map::path_mod(s) => {
if first { first = false; }
else { r += ~"::"; }
r += *s;
fn node_id_type(bcx: block, id: ast::node_id) -> ty::t {
let tcx = bcx.tcx();
let t = ty::node_id_to_type(tcx, id);
- alt bcx.fcx.param_substs {
+ match bcx.fcx.param_substs {
some(substs) => ty::subst_tps(tcx, substs.tys, t),
_ => { assert !ty::type_has_params(t); t }
}
fn node_id_type_params(bcx: block, id: ast::node_id) -> ~[ty::t] {
let tcx = bcx.tcx();
let params = ty::node_id_to_type_params(tcx, id);
- alt bcx.fcx.param_substs {
+ match bcx.fcx.param_substs {
some(substs) => {
vec::map(params, |t| ty::subst_tps(tcx, substs.tys, t))
}
fn field_idx_strict(cx: ty::ctxt, sp: span, ident: ast::ident,
fields: ~[ty::field])
-> uint {
- alt ty::field_idx(ident, fields) {
+ match ty::field_idx(ident, fields) {
none => cx.sess.span_bug(
sp, fmt!{"base expr doesn't appear to \
have a field named %s", *ident}),
fn const_lit(cx: @crate_ctxt, e: @ast::expr, lit: ast::lit)
-> ValueRef {
let _icx = cx.insn_ctxt(~"trans_lit");
- alt lit.node {
+ match lit.node {
ast::lit_int(i, t) => C_integral(T_int_ty(cx, t), i as u64, True),
ast::lit_uint(u, t) => C_integral(T_uint_ty(cx, t), u, False),
ast::lit_int_unsuffixed(i) => {
let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id);
- alt ty::get(lit_int_ty).struct {
+ match ty::get(lit_int_ty).struct {
ty::ty_int(t) => {
C_integral(T_int_ty(cx, t), i as u64, True)
}
fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
let _icx = cx.insn_ctxt(~"const_expr");
- alt e.node {
+ match e.node {
ast::expr_lit(lit) => consts::const_lit(cx, e, *lit),
ast::expr_binary(b, e1, e2) => {
let te1 = const_expr(cx, e1);
let ty = ty::expr_ty(cx.tcx, e1);
let is_float = ty::type_is_fp(ty);
let signed = ty::type_is_signed(ty);
- return alt b {
+ return match b {
ast::add => {
if is_float { llvm::LLVMConstFAdd(te1, te2) }
else { llvm::LLVMConstAdd(te1, te2) }
let te = const_expr(cx, e);
let ty = ty::expr_ty(cx.tcx, e);
let is_float = ty::type_is_fp(ty);
- return alt u {
+ return match u {
ast::box(_) |
ast::uniq(_) |
ast::deref => cx.sess.span_bug(e.span,
let ety = ty::expr_ty(cx.tcx, e), llty = type_of::type_of(cx, ety);
let basety = ty::expr_ty(cx.tcx, base);
let v = const_expr(cx, base);
- alt check (base::cast_type_kind(basety), base::cast_type_kind(ety)) {
+ match check (base::cast_type_kind(basety),
+ base::cast_type_kind(ety)) {
+
(base::cast_integral, base::cast_integral) => {
let s = if ty::type_is_signed(basety) { True } else { False };
llvm::LLVMConstIntCast(v, llty, s)
const_expr(cx, e)
}
ast::expr_vstore(sub, ast::vstore_slice(_)) => {
- alt sub.node {
+ match sub.node {
ast::expr_lit(lit) => {
- alt lit.node {
+ match lit.node {
ast::lit_str(*) => { const_expr(cx, sub) }
_ => { cx.sess.span_bug(e.span,
~"bad const-slice lit") }
}
}
ast::expr_path(path) => {
- alt cx.tcx.def_map.find(e.id) {
+ match cx.tcx.def_map.find(e.id) {
some(ast::def_const(def_id)) => {
// Don't know how to handle external consts
assert ast_util::is_local(def_id);
- alt cx.tcx.items.get(def_id.node) {
+ match cx.tcx.items.get(def_id.node) {
ast_map::node_item(@{
node: ast::item_const(_, subexpr), _
}, _) => {
}
fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
- alt val {
+ match val {
file_metadata(md) => cast_safely(md),
compile_unit_metadata(md) => cast_safely(md),
subprogram_metadata(md) => cast_safely(md),
let cache = get_cache(cx);
let crate_name = option::get(cx.dbg_cx).crate_file;
let tg = CompileUnitTag;
- alt cached_metadata::<@metadata<compile_unit_md>>(cache, tg,
+ match cached_metadata::<@metadata<compile_unit_md>>(cache, tg,
|md| md.data.name == crate_name) {
option::some(md) => return md,
option::none => ()
fn create_file(cx: @crate_ctxt, full_path: ~str) -> @metadata<file_md> {
let cache = get_cache(cx);;
let tg = FileDescriptorTag;
- alt cached_metadata::<@metadata<file_md>>(
+ match cached_metadata::<@metadata<file_md>>(
cache, tg, |md| md.data.path == full_path) {
option::some(md) => return md,
option::none => ()
let cache = get_cache(cx.ccx());
let mut cx = cx;
while option::is_none(cx.node_info) {
- alt cx.parent {
+ match cx.parent {
some(b) => cx = b,
none => fail
}
option::none {}
}*/
- let parent = alt cx.parent {
+ let parent = match cx.parent {
none => create_function(cx.fcx).node,
some(bcx) => create_block(bcx).node
};
let file_node = create_file(cx.ccx(), fname);
- let unique_id = alt cache.find(LexicalBlockTag) {
+ let unique_id = match cache.find(LexicalBlockTag) {
option::some(v) => vec::len(v) as int,
option::none => 0
};
-> @metadata<tydesc_md> {
let cache = get_cache(cx);
let tg = BasicTypeDescriptorTag;
- alt cached_metadata::<@metadata<tydesc_md>>(
+ match cached_metadata::<@metadata<tydesc_md>>(
cache, tg, |md| ty::type_id(t) == md.data.hash) {
option::some(md) => return md,
option::none => ()
}
- let (name, encoding) = alt check ty {
+ let (name, encoding) = match check ty {
ast::ty_bool => (~"bool", DW_ATE_boolean),
- ast::ty_int(m) => alt m {
+ ast::ty_int(m) => match m {
ast::ty_char => (~"char", DW_ATE_unsigned),
ast::ty_i => (~"int", DW_ATE_signed),
ast::ty_i8 => (~"i8", DW_ATE_signed_char),
ast::ty_i32 => (~"i32", DW_ATE_signed),
ast::ty_i64 => (~"i64", DW_ATE_signed)
}
- ast::ty_uint(m) => alt m {
+ ast::ty_uint(m) => match m {
ast::ty_u => (~"uint", DW_ATE_unsigned),
ast::ty_u8 => (~"u8", DW_ATE_unsigned_char),
ast::ty_u16 => (~"u16", DW_ATE_unsigned),
ast::ty_u32 => (~"u32", DW_ATE_unsigned),
ast::ty_u64 => (~"u64", DW_ATE_unsigned)
}
- ast::ty_float(m) => alt m {
+ ast::ty_float(m) => match m {
ast::ty_f => (~"float", DW_ATE_float),
ast::ty_f32 => (~"f32", DW_ATE_float),
ast::ty_f64 => (~"f64", DW_ATE_float)
-> @metadata<tydesc_md> {
let tg = PointerTypeTag;
/*let cache = cx.llmetadata;
- alt cached_metadata::<@metadata<tydesc_md>>(
+ match cached_metadata::<@metadata<tydesc_md>>(
cache, tg, {|md| ty::hash_ty(t) == ty::hash_ty(md.data.hash)}) {
option::some(md) { return md; }
option::none {}
-> @metadata<tydesc_md> {
//let tg = StructureTypeTag;
/*let cache = cx.llmetadata;
- alt cached_metadata::<@metadata<tydesc_md>>(
+ match cached_metadata::<@metadata<tydesc_md>>(
cache, tg, {|md| ty::hash_ty(outer) == ty::hash_ty(md.data.hash)}) {
option::some(md) { return md; }
option::none {}
fn create_ty(_cx: @crate_ctxt, _t: ty::t, _ty: @ast::ty)
-> @metadata<tydesc_md> {
/*let cache = get_cache(cx);
- alt cached_metadata::<@metadata<tydesc_md>>(
+ match cached_metadata::<@metadata<tydesc_md>>(
cache, tg, {|md| t == md.data.hash}) {
option::some(md) { return md; }
option::none {}
fail;
/*
fn t_to_ty(cx: crate_ctxt, t: ty::t, span: span) -> @ast::ty {
- let ty = alt ty::get(t).struct {
+ let ty = match ty::get(t).struct {
ty::ty_nil { ast::ty_nil }
ty::ty_bot { ast::ty_bot }
ty::ty_bool { ast::ty_bool }
return @{node: ty, span: span};
}
- alt ty.node {
+ match ty.node {
ast::ty_box(mt) {
- let inner_t = alt ty::get(t).struct {
+ let inner_t = match ty::get(t).struct {
ty::ty_box(boxed) { boxed.ty }
_ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
};
}
ast::ty_uniq(mt) {
- let inner_t = alt ty::get(t).struct {
+ let inner_t = match ty::get(t).struct {
ty::ty_uniq(boxed) { boxed.ty }
// Hoping we'll have a way to eliminate this check soon.
_ { cx.sess.span_bug(ty.span, "t_to_ty was incoherent"); }
}
ast::ty_path(_, id) {
- alt cx.tcx.def_map.get(id) {
+ match cx.tcx.def_map.get(id) {
ast::def_prim_ty(pty) {
return create_basic_type(cx, t, pty, ty.span);
}
let cx = bcx.ccx();
let cache = get_cache(cx);
let tg = AutoVariableTag;
- alt cached_metadata::<@metadata<local_var_md>>(
+ match cached_metadata::<@metadata<local_var_md>>(
cache, tg, |md| md.data.id == local.node.id) {
option::some(md) => return md,
option::none => ()
}
- let name = alt local.node.pat.node {
+ let name = match local.node.pat.node {
ast::pat_ident(_, pth, _) => ast_util::path_to_ident(pth),
// FIXME this should be handled (#2533)
_ => fail ~"no single variable name for local"
let ty = node_id_type(bcx, local.node.id);
let tymd = create_ty(cx, ty, local.node.ty);
let filemd = create_file(cx, loc.file.name);
- let context = alt bcx.parent {
+ let context = match bcx.parent {
none => create_function(bcx.fcx).node,
some(_) => create_block(bcx).node
};
let mdval = @{node: mdnode, data: {id: local.node.id}};
update_cache(cache, AutoVariableTag, local_var_metadata(mdval));
- let llptr = alt bcx.fcx.lllocals.find(local.node.id) {
+ let llptr = match bcx.fcx.lllocals.find(local.node.id) {
option::some(local_mem(v)) => v,
option::some(_) => {
bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
something weird");
}
option::none => {
- alt bcx.fcx.lllocals.get(local.node.pat.id) {
+ match bcx.fcx.lllocals.get(local.node.pat.id) {
local_imm(v) => v,
_ => bcx.tcx().sess.span_bug(local.span, ~"local is bound to \
something weird")
let fcx = bcx.fcx, cx = fcx.ccx;
let cache = get_cache(cx);
let tg = ArgVariableTag;
- alt cached_metadata::<@metadata<argument_md>>(
+ match cached_metadata::<@metadata<argument_md>>(
cache, ArgVariableTag, |md| md.data.id == arg.id) {
option::some(md) => return md,
option::none => ()
let mdval = @{node: mdnode, data: {id: arg.id}};
update_cache(cache, tg, argument_metadata(mdval));
- let llptr = alt fcx.llargs.get(arg.id) {
+ let llptr = match fcx.llargs.get(arg.id) {
local_mem(v) | local_imm(v) => v,
};
let declargs = ~[llmdnode(~[llptr]), mdnode];
let sp = option::get(fcx.span);
log(debug, codemap::span_to_str(sp, cx.sess.codemap));
- let (ident, ret_ty, id) = alt cx.tcx.items.get(fcx.id) {
+ let (ident, ret_ty, id) = match cx.tcx.items.get(fcx.id) {
ast_map::node_item(item, _) => {
- alt item.node {
+ match item.node {
ast::item_fn(decl, _, _) => {
(item.ident, decl.output, item.id)
}
(nm, ctor.node.dec.output, ctor.node.id)
}
ast_map::node_expr(expr) => {
- alt expr.node {
+ match expr.node {
ast::expr_fn(_, decl, _, _) => {
(@dbg_cx.names(~"fn"), decl.output, expr.id)
}
log(debug, id);
let cache = get_cache(cx);
- alt cached_metadata::<@metadata<subprogram_md>>(
+ match cached_metadata::<@metadata<subprogram_md>>(
cache, SubprogramTag, |md| md.data.id == id) {
option::some(md) => return md,
option::none => ()
sp.lo);
let file_node = create_file(cx, loc.file.name).node;
let ty_node = if cx.sess.opts.extra_debuginfo {
- alt ret_ty.node {
+ match ret_ty.node {
ast::ty_nil => llnull(),
_ => create_ty(cx, ty::node_id_to_type(cx.tcx, id), ret_ty).node
}
}
fn is_sse(++c: x86_64_reg_class) -> bool {
- return alt c {
+ return match c {
sse_fs_class | sse_fv_class |
sse_ds_class | sse_dv_class => true,
_ => false
}
fn ty_align(ty: TypeRef) -> uint {
- return alt llvm::LLVMGetTypeKind(ty) as int {
+ return match llvm::LLVMGetTypeKind(ty) as int {
8 /* integer */ => {
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u
}
}
fn ty_size(ty: TypeRef) -> uint {
- return alt llvm::LLVMGetTypeKind(ty) as int {
+ return match llvm::LLVMGetTypeKind(ty) as int {
8 /* integer */ => {
((llvm::LLVMGetIntTypeWidth(ty) as uint) + 7u) / 8u
}
return;
}
- alt llvm::LLVMGetTypeKind(ty) as int {
+ match llvm::LLVMGetTypeKind(ty) as int {
8 /* integer */ |
12 /* pointer */ => {
unify(cls, ix + off / 8u, integer_class);
let mut i = 0u;
let e = vec::len(cls);
while i < e {
- alt cls[i] {
+ match cls[i] {
integer_class => {
vec::push(tys, T_i64());
}
rty: TypeRef,
ret_def: bool) -> x86_64_tys {
fn is_reg_ty(ty: TypeRef) -> bool {
- return alt llvm::LLVMGetTypeKind(ty) as int {
+ return match llvm::LLVMGetTypeKind(ty) as int {
8 /* integer */ |
12 /* pointer */ |
2 /* float */ |
let llfn = decl(fnty);
do vec::iteri(tys.attrs) |i, a| {
- alt a {
+ match a {
option::some(attr) => {
let llarg = get_param(llfn, i);
llvm::LLVMAddAttribute(llarg, attr as c_uint);
}
fn link_name(i: @ast::foreign_item) -> ~str {
- alt attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
+ match attr::first_attr_value_str_by_name(i.attrs, ~"link_name") {
none => return *i.ident,
option::some(ln) => return *ln
}
fn c_arg_and_ret_lltys(ccx: @crate_ctxt,
id: ast::node_id) -> (~[TypeRef], TypeRef, ty::t) {
- alt ty::get(ty::node_id_to_type(ccx.tcx, id)).struct {
+ match ty::get(ty::node_id_to_type(ccx.tcx, id)).struct {
ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) => {
let llargtys = type_of_explicit_args(ccx, arg_tys);
let llretty = type_of::type_of(ccx, ret_ty);
let mut i = 0u;
let n = vec::len(tys.arg_tys);
- alt tys.x86_64_tys {
+ match tys.x86_64_tys {
some(x86_64) => {
let mut atys = x86_64.arg_tys;
let mut attrs = x86_64.attrs;
fn build_ret(bcx: block, tys: @c_stack_tys,
llargbundle: ValueRef, llretval: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::shim::build_ret");
- alt tys.x86_64_tys {
+ match tys.x86_64_tys {
some(x86_64) => {
do vec::iteri(x86_64.attrs) |i, a| {
- alt a {
+ match a {
some(attr) => {
llvm::LLVMAddInstrAttribute(
llretval, (i + 1u) as c_uint,
fn base_fn(ccx: @crate_ctxt, lname: ~str, tys: @c_stack_tys,
cc: lib::llvm::CallConv) -> ValueRef {
// Declare the "prototype" for the base function F:
- alt tys.x86_64_tys {
+ match tys.x86_64_tys {
some(x86_64) => {
do decl_x86_64_fn(x86_64) |fnty| {
decl_fn(ccx.llmod, lname, cc, fnty)
build_args, build_ret);
}
- let mut cc = alt abi {
+ let mut cc = match abi {
ast::foreign_abi_rust_intrinsic |
ast::foreign_abi_cdecl => lib::llvm::CCallConv,
ast::foreign_abi_stdcall => lib::llvm::X86StdcallCallConv
};
for vec::each(foreign_mod.items) |foreign_item| {
- alt foreign_item.node {
+ match foreign_item.node {
ast::foreign_item_fn(fn_decl, typarams) => {
let id = foreign_item.id;
if abi != ast::foreign_abi_rust_intrinsic {
// monomorphic_fn, but ones without are emitted here
if typarams.is_empty() {
let llwrapfn = get_item_val(ccx, id);
- let path = alt ccx.tcx.items.find(id) {
+ let path = match ccx.tcx.items.find(id) {
some(ast_map::node_foreign_item(_, _, pt)) => pt,
_ => {
ccx.sess.span_bug(foreign_item.span,
let fcx = new_fn_ctxt_w_id(ccx, path, decl, item.id,
some(substs), some(item.span));
let mut bcx = top_scope_block(fcx, none), lltop = bcx.llbb;
- alt check *item.ident {
+ match check *item.ident {
~"atomic_xchng" => {
let old = AtomicRMW(bcx, Xchg,
get_param(decl, first_real_arg),
let tp_sz = shape::llsize_of_real(ccx, lltp_ty),
out_sz = shape::llsize_of_real(ccx, llout_ty);
if tp_sz != out_sz {
- let sp = alt check ccx.tcx.items.get(option::get(ref_id)) {
+ let sp = match check ccx.tcx.items.get(option::get(ref_id)) {
ast_map::node_expr(e) => e.span
};
ccx.sess.span_fatal(
fn build_args(bcx: block, tys: @c_stack_tys,
llwrapfn: ValueRef, llargbundle: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_args");
- alt tys.x86_64_tys {
+ match tys.x86_64_tys {
option::some(x86_64) => {
let mut atys = x86_64.arg_tys;
let mut attrs = x86_64.attrs;
fn build_ret(bcx: block, tys: @c_stack_tys,
llargbundle: ValueRef) {
let _icx = bcx.insn_ctxt(~"foreign::foreign::wrap::build_ret");
- alt tys.x86_64_tys {
+ match tys.x86_64_tys {
option::some(x86_64) => {
if x86_64.sret || !tys.ret_def {
RetVoid(bcx);
fn abi_of_foreign_fn(ccx: @crate_ctxt, i: @ast::foreign_item)
-> ast::foreign_abi {
- alt attr::first_attr_value_str_by_name(i.attrs, ~"abi") {
- none => alt check ccx.tcx.items.get(i.id) {
+ match attr::first_attr_value_str_by_name(i.attrs, ~"abi") {
+ none => match check ccx.tcx.items.get(i.id) {
ast_map::node_foreign_item(_, abi, _) => abi
}
- some(_) => alt attr::foreign_abi(i.attrs) {
+ some(_) => match attr::foreign_abi(i.attrs) {
either::right(abi) => abi,
either::left(msg) => ccx.sess.span_fatal(i.span, msg)
}
self: @ast::expr, mentry: typeck::method_map_entry)
-> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"impl::trans_method_callee");
- alt mentry.origin {
+ match mentry.origin {
typeck::method_static(did) => {
let {bcx, val} = trans_self_arg(bcx, self, mentry.derefs);
{env: self_env(val, node_id_type(bcx, self.id), none)
}
typeck::method_param({trait_id:iid, method_num:off,
param_num:p, bound_num:b}) => {
- alt check bcx.fcx.param_substs {
+ match check bcx.fcx.param_substs {
some(substs) => {
trans_monomorphized_callee(bcx, callee_id, self, mentry.derefs,
iid, off, p, b, substs)
fn method_with_name(ccx: @crate_ctxt, impl_id: ast::def_id,
name: ast::ident) -> ast::def_id {
if impl_id.crate == ast::local_crate {
- alt check ccx.tcx.items.get(impl_id.node) {
+ match check ccx.tcx.items.get(impl_id.node) {
ast_map::node_item(@{node: ast::item_impl(_, _, _, ms), _}, _) => {
method_from_methods(ms, name)
}
fn method_ty_param_count(ccx: @crate_ctxt, m_id: ast::def_id,
i_id: ast::def_id) -> uint {
if m_id.crate == ast::local_crate {
- alt check ccx.tcx.items.get(m_id.node) {
+ match check ccx.tcx.items.get(m_id.node) {
ast_map::node_method(m, _, _) => vec::len(m.tps),
}
} else {
n_param: uint, n_bound: uint,
substs: param_substs) -> lval_maybe_callee {
let _icx = bcx.insn_ctxt(~"impl::trans_monomorphized_callee");
- alt find_vtable_in_fn_ctxt(substs, n_param, n_bound) {
+ match find_vtable_in_fn_ctxt(substs, n_param, n_bound) {
typeck::vtable_static(impl_did, impl_substs, sub_origins) => {
let ccx = bcx.ccx();
let mname = ty::trait_methods(ccx.tcx, trait_id)[n_method].ident;
for vec::each(*ps.bounds) |bounds| {
if i >= n_param { break; }
for vec::each(*bounds) |bound| {
- alt bound { ty::bound_trait(_) => vtable_off += 1u, _ => () }
+ match bound { ty::bound_trait(_) => vtable_off += 1u, _ => () }
}
i += 1u;
}
// eliminate any vtable_params.
fn resolve_vtable_in_fn_ctxt(fcx: fn_ctxt, vt: typeck::vtable_origin)
-> typeck::vtable_origin {
- alt vt {
+ match vt {
typeck::vtable_static(iid, tys, sub) => {
- let tys = alt fcx.param_substs {
+ let tys = match fcx.param_substs {
some(substs) => {
vec::map(tys, |t| ty::subst_tps(fcx.ccx.tcx, substs.tys, t))
}
typeck::vtable_static(iid, tys, resolve_vtables_in_fn_ctxt(fcx, sub))
}
typeck::vtable_param(n_param, n_bound) => {
- alt check fcx.param_substs {
+ match check fcx.param_substs {
some(substs) => {
find_vtable_in_fn_ctxt(substs, n_param, n_bound)
}
}
fn vtable_id(ccx: @crate_ctxt, origin: typeck::vtable_origin) -> mono_id {
- alt check origin {
+ match check origin {
typeck::vtable_static(impl_id, substs, sub_vtables) => {
make_mono_id(ccx, impl_id, substs,
if (*sub_vtables).len() == 0u { none }
fn get_vtable(ccx: @crate_ctxt, origin: typeck::vtable_origin)
-> ValueRef {
let hash_id = vtable_id(ccx, origin);
- alt ccx.vtables.find(hash_id) {
+ match ccx.vtables.find(hash_id) {
some(val) => val,
- none => alt check origin {
+ none => match check origin {
typeck::vtable_static(id, substs, sub_vtables) => {
make_impl_vtable(ccx, id, substs, sub_vtables)
}
fn traverse_exports(cx: ctx, vis: ~[@view_item]) -> bool {
let mut found_export = false;
for vec::each(vis) |vi| {
- alt vi.node {
+ match vi.node {
view_item_export(vps) => {
found_export = true;
for vec::each(vps) |vp| {
- alt vp.node {
+ match vp.node {
view_path_simple(_, _, id) | view_path_glob(_, id) |
view_path_list(_, _, id) => {
traverse_export(cx, id);
fn traverse_def_id(cx: ctx, did: def_id) {
if did.crate != local_crate { return; }
- let n = alt cx.tcx.items.find(did.node) {
+ let n = match cx.tcx.items.find(did.node) {
none => return, // This can happen for self, for example
some(n) => n
};
- alt n {
+ match n {
ast_map::node_item(item, _) => traverse_public_item(cx, item),
ast_map::node_method(_, impl_id, _) => traverse_def_id(cx, impl_id),
ast_map::node_foreign_item(item, _, _) => {
fn traverse_public_item(cx: ctx, item: @item) {
if cx.rmap.contains_key(item.id) { return; }
cx.rmap.insert(item.id, ());
- alt item.node {
+ match item.node {
item_mod(m) => traverse_public_mod(cx, m),
item_foreign_mod(nm) => {
if !traverse_exports(cx, nm.view_items) {
}
}
for vec::each(items) |item| {
- alt item.node {
+ match item.node {
class_method(m) => {
cx.rmap.insert(m.id, ());
if tps.len() > 0u ||
if cx.rmap.contains_key(ty.id) { return; }
cx.rmap.insert(ty.id, ());
- alt ty.node {
+ match ty.node {
ty_path(p, p_id) => {
- alt cx.tcx.def_map.find(p_id) {
+ match cx.tcx.def_map.find(p_id) {
// Kind of a hack to check this here, but I'm not sure what else
// to do
some(def_prim_ty(_)) => { /* do nothing */ }
fn traverse_inline_body(cx: ctx, body: blk) {
fn traverse_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
- alt e.node {
+ match e.node {
expr_path(_) => {
- alt cx.tcx.def_map.find(e.id) {
+ match cx.tcx.def_map.find(e.id) {
some(d) => {
traverse_def_id(cx, def_id_of_def(d));
}
}
}
expr_field(_, _, _) => {
- alt cx.method_map.find(e.id) {
+ match cx.method_map.find(e.id) {
some({origin: typeck::method_static(did), _}) => {
traverse_def_id(cx, did);
}
visit_expr: |_e, _cx, _v| { },
visit_item: |i, cx, v| {
visit::visit_item(i, cx, v);
- alt i.node {
+ match i.node {
item_class(_, _, _, _, some(_)) => {
traverse_public_item(cx, i);
}
fn vstore_name_and_extra(t: ty::t,
vstore: ty::vstore,
f: fn(~str,~[ValueRef])) {
- alt vstore {
+ match vstore {
ty::vstore_fixed(n) => {
let extra = vec::append(~[self.c_uint(n)],
self.c_size_and_align(t));
debug!{"reflect::visit_ty %s",
ty_to_str(bcx.ccx().tcx, t)};
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_bot => self.leaf(~"bot"),
ty::ty_nil => self.leaf(~"nil"),
ty::ty_bool => self.leaf(~"bool"),
// FIXME (#2594): fetch constants out of intrinsic:: for the
// numbers.
ty::ty_fn(fty) => {
- let pureval = alt fty.purity {
+ let pureval = match fty.purity {
ast::pure_fn => 0u,
ast::unsafe_fn => 1u,
ast::impure_fn => 2u,
ast::extern_fn => 3u
};
- let protoval = alt fty.proto {
+ let protoval = match fty.proto {
ast::proto_bare => 0u,
ast::proto_uniq => 2u,
ast::proto_box => 3u,
ast::proto_block => 4u
};
- let retval = alt fty.ret_style {
+ let retval = match fty.ret_style {
ast::noreturn => 0u,
ast::return_val => 1u
};
self.c_uint(retval)];
self.visit(~"enter_fn", extra);
for fty.inputs.eachi |i, arg| {
- let modeval = alt arg.mode {
+ let modeval = match arg.mode {
ast::infer(_) => 0u,
- ast::expl(e) => alt e {
+ ast::expl(e) => match e {
ast::by_ref => 1u,
ast::by_val => 2u,
ast::by_mutbl_ref => 3u,
ty::ty_type => self.leaf(~"type"),
ty::ty_opaque_box => self.leaf(~"opaque_box"),
ty::ty_opaque_closure_ptr(ck) => {
- let ckval = alt ck {
+ let ckval = match ck {
ty::ck_block => 0u,
ty::ck_box => 1u,
ty::ck_uniq => 2u
// Returns the code corresponding to the pointer size on this architecture.
fn s_int(tcx: ty_ctxt) -> u8 {
- return alt tcx.sess.targ_cfg.arch {
+ return match tcx.sess.targ_cfg.arch {
session::arch_x86 => shape_i32,
session::arch_x86_64 => shape_i64,
session::arch_arm => shape_i32
}
fn s_uint(tcx: ty_ctxt) -> u8 {
- return alt tcx.sess.targ_cfg.arch {
+ return match tcx.sess.targ_cfg.arch {
session::arch_x86 => shape_u32,
session::arch_x86_64 => shape_u64,
session::arch_arm => shape_u32
}
fn s_float(tcx: ty_ctxt) -> u8 {
- return alt tcx.sess.targ_cfg.arch {
+ return match tcx.sess.targ_cfg.arch {
session::arch_x86 => shape_f64,
session::arch_x86_64 => shape_f64,
session::arch_arm => shape_f64
}
fn shape_of(ccx: @crate_ctxt, t: ty::t) -> ~[u8] {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_nil | ty::ty_bool | ty::ty_uint(ast::ty_u8) |
ty::ty_bot => ~[shape_u8],
ty::ty_int(ast::ty_i) => ~[s_int(ccx.tcx)],
shape_of(ccx, tvec::expand_boxed_vec_ty(ccx.tcx, t))
}
ty::ty_enum(did, substs) => {
- alt enum_kind(ccx, did) {
+ match enum_kind(ccx, did) {
tk_unit => ~[s_variant_enum_t(ccx.tcx)],
tk_enum => ~[s_variant_enum_t(ccx.tcx)],
tk_newtype | tk_complex => {
let mut s = ~[shape_enum], id;
let nom_id = mk_nominal_id(ccx.tcx, did, none, substs.tps);
- alt ccx.shape_cx.tag_id_to_index.find(nom_id) {
+ match ccx.shape_cx.tag_id_to_index.find(nom_id) {
none => {
id = ccx.shape_cx.next_tag_id;
ccx.shape_cx.tag_id_to_index.insert(nom_id, id);
// Computes the size of the data part of an enum.
fn static_size_of_enum(cx: @crate_ctxt, t: ty::t) -> uint {
if cx.enum_sizes.contains_key(t) { return cx.enum_sizes.get(t); }
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_enum(tid, substs) => {
// Compute max(variant sizes).
let mut max_size = 0u;
ty::mk_ptr(tcx, {ty: ty::mk_nil(tcx), mutbl: ast::m_imm})
}
fn simplifier(tcx: ty::ctxt, typ: ty::t) -> ty::t {
- alt ty::get(typ).struct {
+ match ty::get(typ).struct {
ty::ty_box(_) | ty::ty_opaque_box | ty::ty_uniq(_) |
ty::ty_evec(_, ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_box) |
ty::ty_estr(ty::vstore_uniq) | ty::ty_estr(ty::vstore_box) |
fn expand_boxed_vec_ty(tcx: ty::ctxt, t: ty::t) -> ty::t {
let unit_ty = ty::sequence_element_type(tcx, t);
let unboxed_vec_ty = ty::mk_mut_unboxed_vec(tcx, unit_ty);
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_estr(ty::vstore_uniq) | ty::ty_evec(_, ty::vstore_uniq) => {
ty::mk_imm_uniq(tcx, unboxed_vec_ty)
}
let unit_sz = llsize_of(ccx, llunitty);
let mut {bcx, val, dataptr} =
- alt vst {
+ match vst {
ast::vstore_fixed(_) => {
// Destination should be pre-allocated for us.
- let v = alt dest {
+ let v = match dest {
base::save_in(v) => {
PointerCast(bcx, v, T_ptr(llunitty))
}
for vec::each(temp_cleanups) |cln| { revoke_clean(bcx, cln); }
- alt vst {
+ match vst {
ast::vstore_fixed(_) => {
// We wrote into the destination in the fixed case.
return bcx;
fn trans_vstore(bcx: block, e: @ast::expr,
v: ast::vstore, dest: dest) -> block {
- alt e.node {
+ match e.node {
ast::expr_lit(@{node: ast::lit_str(s), span: _}) => {
return trans_estr(bcx, s, some(v), dest);
}
let llunitty = type_of::type_of(ccx, unit_ty);
let unit_sz = llsize_of(ccx, llunitty);
- let vstore = alt ty::get(vec_ty).struct {
+ let vstore = match ty::get(vec_ty).struct {
ty::ty_estr(vst) | ty::ty_evec(_, vst) => vst,
_ => ty::vstore_uniq
};
- alt vstore {
+ match vstore {
ty::vstore_fixed(n) => {
let base = GEPi(cx, v, ~[0u, 0u]);
let n = if ty::type_is_str(e_ty) { n + 1u } else { n };
if dest == base::ignore { return bcx; }
let ccx = bcx.ccx();
- let c = alt vstore {
+ let c = match vstore {
some(ast::vstore_fixed(_)) => {
// "hello"/_ => "hello"/5 => ~[i8 x 6] in llvm
debug!{"trans_estr: fixed: %s", *s};
do vec::map(inputs) |arg| {
let arg_ty = arg.ty;
let llty = type_of(cx, arg_ty);
- alt ty::resolved_mode(cx.tcx, arg.mode) {
+ match ty::resolved_mode(cx.tcx, arg.mode) {
ast::by_val => llty,
_ => T_ptr(llty)
}
if t != t_norm {
type_of_non_gc_box(cx, t_norm)
} else {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_box(mt) => {
T_ptr(T_box(cx, type_of(cx, mt.ty)))
}
llty = type_of(cx, t_norm);
cx.lltypes.insert(t, llty);
} else {
- llty = alt ty::get(t).struct {
+ llty = match ty::get(t).struct {
ty::ty_nil | ty::ty_bot => T_nil(),
ty::ty_bool => T_bool(),
ty::ty_int(t) => T_int_ty(cx, t),
cx.lltypes.insert(t, llty);
// If this was a class, fill in the type now.
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_class(did, ts) => {
// Only instance vars are record fields at runtime.
let fields = ty::lookup_class_fields(cx.tcx, did);
}
fn llvm_type_name(cx: @crate_ctxt, t: ty::t) -> ~str {
- let (name, did, tps) = alt check ty::get(t).struct {
+ let (name, did, tps) = match check ty::get(t).struct {
ty::ty_enum(did, substs) => (~"enum", did, substs.tps),
ty::ty_class(did, substs) => (~"class", did, substs.tps)
};
fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
-> ~[type_uses] {
- alt ccx.type_use_cache.find(fn_id) {
+ match ccx.type_use_cache.find(fn_id) {
some(uses) => return uses,
none => ()
}
ccx.type_use_cache.insert(fn_id, vec::from_elem(n_tps, 3u));
let cx = {ccx: ccx, uses: vec::to_mut(vec::from_elem(n_tps, 0u))};
- alt ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct {
+ match ty::get(ty::lookup_item_type(cx.ccx.tcx, fn_id).ty).struct {
ty::ty_fn({inputs, _}) => {
for vec::each(inputs) |arg| {
if arg.mode == expl(by_val) { type_needs(cx, use_repr, arg.ty); }
ccx.type_use_cache.insert(fn_id, uses);
return uses;
}
- let map_node = alt ccx.tcx.items.find(fn_id_loc.node) {
+ let map_node = match ccx.tcx.items.find(fn_id_loc.node) {
some(x) => x,
none => ccx.sess.bug(fmt!{"type_uses_for: unbound item ID %?",
fn_id_loc})
};
- alt check map_node {
+ match check map_node {
ast_map::node_item(@{node: item_fn(_, _, body), _}, _) |
ast_map::node_method(@{body, _}, _, _) => {
handle_body(cx, body);
ast_map::node_foreign_item(i@@{node: foreign_item_fn(_, _), _},
abi, _) => {
if abi == foreign_abi_rust_intrinsic {
- let flags = alt check *i.ident {
+ let flags = match check *i.ident {
~"size_of" | ~"pref_align_of" | ~"min_align_of" |
~"init" | ~"reinterpret_cast" |
~"move_val" | ~"move_val_init" => {
enums_seen: @list<def_id>) {
do ty::maybe_walk_ty(ty) |ty| {
if ty::type_has_params(ty) {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
/*
This previously included ty_box -- that was wrong
because if we cast an @T to an trait (for example) and return
}
fn mark_for_expr(cx: ctx, e: @expr) {
- alt e.node {
+ match e.node {
expr_vstore(_, _) |
expr_vec(_, _) |
expr_rec(_, _) | expr_struct(*) | expr_tup(_) |
}
expr_cast(base, _) => {
let result_t = ty::node_id_to_type(cx.ccx.tcx, e.id);
- alt ty::get(result_t).struct {
+ match ty::get(result_t).struct {
ty::ty_trait(*) => {
// When we're casting to an trait, we need the
// tydesc for the expr that's being cast.
}
}
expr_binary(op, lhs, _) => {
- alt op {
+ match op {
eq | lt | le | ne | ge | gt => {
node_type_needs(cx, use_tydesc, lhs.id)
}
}
}
expr_fn(*) | expr_fn_block(*) => {
- alt ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
+ match ty::ty_fn_proto(ty::expr_ty(cx.ccx.tcx, e)) {
proto_bare | proto_uniq => {}
proto_box | proto_block => {
for vec::each(*freevars::get_freevars(cx.ccx.tcx, e.id)) |fv| {
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
do option::iter(cx.ccx.maps.method_map.find(e.id)) |mth| {
- alt mth.origin {
+ match mth.origin {
typeck::method_static(did) => {
do option::iter(cx.ccx.tcx.node_type_substs.find(e.id)) |ts| {
do vec::iter2(type_uses_for(cx.ccx, did, ts.len()), ts)
}
expr_call(f, _, _) => {
vec::iter(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)), |a| {
- alt a.mode {
+ match a.mode {
expl(by_move) | expl(by_copy) | expl(by_val) => {
type_needs(cx, use_repr, a.ty);
}
}
fn content_ty(t: ty::t) -> ty::t {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_uniq({ty: ct, _}) => ct,
_ => core::unreachable()
}
}
fn trit_str(t: trit) -> ~str {
- alt t { dont_care { ~"?" } ttrue { ~"1" } tfalse { ~"0" } }
+ match t { dont_care { ~"?" } ttrue { ~"1" } tfalse { ~"0" } }
}
// FIXME (#2538): Would be nice to have unit tests for some of these
}
fn collect_ids_stmt(s: @stmt, rs: @mut ~[node_id]) {
- alt s.node {
+ match s.node {
stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
debug!{"node_id %s", int::str(id)};
debug!{"%s", stmt_to_str(*s)};
let mut comma = false;
for args.each |a| {
if comma { rslt += ~", "; } else { comma = true; }
- alt a.node {
+ match a.node {
carg_base { rslt += ~"*"; }
carg_ident(i) { rslt += *i.ident; }
carg_lit(l) { rslt += lit_to_str(l); }
let mut s = ~"";
let mut comma = false;
for constraints(fcx).each |p| {
- alt v.get(p.bit_num) {
+ match v.get(p.bit_num) {
dont_care { }
tt {
s +=
/********* utils ********/
fn node_id_to_ts_ann(ccx: crate_ctxt, id: node_id) -> ts_ann {
- alt get_ts_ann(ccx, id) {
+ match get_ts_ann(ccx, id) {
none {
error!{"node_id_to_ts_ann: no ts_ann for node_id %d", id};
fail;
fn stmt_to_ann(ccx: crate_ctxt, s: stmt) -> ts_ann {
debug!{"stmt_to_ann"};
- alt s.node {
+ match s.node {
stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
return node_id_to_ts_ann(ccx, id);
}
If it has a function type with a ! annotation,
the answer is noreturn. */
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> ret_style {
- alt ty::get(ty::node_id_to_type(ccx.tcx, e.id)).struct {
+ match ty::get(ty::node_id_to_type(ccx.tcx, e.id)).struct {
ty::ty_fn(f) { return f.ret_style; }
_ { return return_val; }
}
}
fn constraints_expr(cx: ty::ctxt, e: @expr) -> ~[@ty::constr] {
- alt ty::get(ty::node_id_to_type(cx, e.id)).struct {
+ match ty::get(ty::node_id_to_type(cx, e.id)).struct {
ty::ty_fn(f) { return f.constraints; }
_ { return ~[]; }
}
}
fn node_id_to_def_strict(cx: ty::ctxt, id: node_id) -> def {
- alt cx.def_map.find(id) {
+ match cx.def_map.find(id) {
none {
error!{"node_id_to_def: node_id %d has no def", id};
fail;
}
fn def_id_for_constr(tcx: ty::ctxt, t: node_id) -> def_id {
- alt tcx.def_map.find(t) {
+ match tcx.def_map.find(t) {
none {
tcx.sess.bug(~"node_id_for_constr: bad node_id " + int::str(t));
}
}
fn expr_to_constr_arg(tcx: ty::ctxt, e: @expr) -> @constr_arg_use {
- alt e.node {
+ match e.node {
expr_path(p) {
- alt tcx.def_map.find(e.id) {
+ match tcx.def_map.find(e.id) {
some(def_local(nid, _)) | some(def_arg(nid, _)) |
some(def_binding(nid, _)) | some(def_upvar(nid, _, _)) {
return @respan(p.span,
}
fn expr_to_constr(tcx: ty::ctxt, e: @expr) -> sp_constr {
- alt e.node {
+ match e.node {
expr_call(operator, args, _) {
- alt operator.node {
+ match operator.node {
expr_path(p) {
return respan(e.span,
{path: p,
fn substitute_arg(cx: ty::ctxt, actuals: ~[@expr], a: @constr_arg) ->
@constr_arg_use {
let num_actuals = vec::len(actuals);
- alt a.node {
+ match a.node {
carg_ident(i) {
if i < num_actuals {
return expr_to_constr_arg(cx, actuals[i]);
let mut i = 0u;
for desc.node.args.each |c| {
let n = pattern[i];
- alt c.node {
+ match c.node {
carg_ident(p) {
- alt n {
+ match n {
carg_ident(q) { if p.node != q.node { return false; } }
_ { return false; }
}
}
carg_base { if n != carg_base { return false; } }
carg_lit(l) {
- alt n {
+ match n {
carg_lit(m) { if !const_eval::lit_eq(l, m) { return false; } }
_ { return false; }
}
if args_mention(d.node.args, find_in_subst_bool, subst) {
let old_bit_num = d.node.bit_num;
let newv = replace(subst, d);
- alt find_instance_(newv, v) {
+ match find_instance_(newv, v) {
some(d1) {vec::push(res, {from: old_bit_num, to: d1})}
_ {}
}
for stuff.each |i| {
rslt +=
~" " +
- alt i {
+ match i {
carg_ident(p) { *p.ident }
carg_base { ~"*" }
carg_lit(_) { ~"~[lit]" }
fn replace(subst: subst, d: pred_args) -> ~[constr_arg_general_<inst>] {
let mut rslt: ~[constr_arg_general_<inst>] = ~[];
for d.node.args.each |c| {
- alt c.node {
+ match c.node {
carg_ident(p) {
- alt find_in_subst(p.node, subst) {
+ match find_in_subst(p.node, subst) {
some(newv) { vec::push(rslt, carg_ident(newv)); }
_ { vec::push(rslt, c.node); }
}
fn local_node_id_to_def_id_strict(fcx: fn_ctxt, sp: span, i: node_id) ->
def_id {
- alt local_node_id_to_def(fcx, i) {
+ match local_node_id_to_def(fcx, i) {
some(def_local(nid, _)) | some(def_arg(nid, _)) |
some(def_upvar(nid, _, _)) {
return local_def(nid);
}
fn local_node_id_to_def_id(fcx: fn_ctxt, i: node_id) -> option<def_id> {
- alt local_node_id_to_def(fcx, i) {
+ match local_node_id_to_def(fcx, i) {
some(def_local(nid, _)) | some(def_arg(nid, _)) |
some(def_binding(nid, _)) | some(def_upvar(nid, _, _)) {
some(local_def(nid))
fn local_node_id_to_local_def_id(fcx: fn_ctxt, i: node_id) ->
option<node_id> {
- alt local_node_id_to_def_id(fcx, i) {
+ match local_node_id_to_def_id(fcx, i) {
some(did) { some(did.node) }
_ { none }
}
target_post: poststate, dest: inst, src: inst,
ty: oper_type) {
let mut subst;
- alt ty {
+ match ty {
oper_swap { subst = ~[{from: dest, to: src}, {from: src, to: dest}]; }
oper_assign_op {
return; // Don't do any propagation
s: ~[T]) -> bool {
for args.each |a| {
- alt a.node {
+ match a.node {
carg_ident(p1) { if q(s, p1.node) { return true; } } _ { }
}
}
}
fn op_to_oper_ty(io: init_op) -> oper_type {
- alt io { init_move { oper_move } _ { oper_assign } }
+ match io { init_move { oper_move } _ { oper_assign } }
}
// default function visitor
vec::push(
actuals,
@respan(a.span,
- alt a.node {
+ match a.node {
carg_base { carg_base }
carg_ident(i) {
if i < num_args {
fn callee_modes(fcx: fn_ctxt, callee: node_id) -> ~[mode] {
let ty = ty::type_autoderef(fcx.ccx.tcx,
ty::node_id_to_type(fcx.ccx.tcx, callee));
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_fn({inputs: args, _}) {
let mut modes = ~[];
for args.each |arg| { vec::push(modes, arg.mode); }
fn callee_arg_init_ops(fcx: fn_ctxt, callee: node_id) -> ~[init_op] {
do vec::map(callee_modes(fcx, callee)) |m| {
- alt ty::resolved_mode(fcx.ccx.tcx, m) {
+ match ty::resolved_mode(fcx.ccx.tcx, m) {
by_move { init_move }
by_copy | by_ref | by_val | by_mutbl_ref { init_assign }
}
type ctxt = {cs: @mut ~[sp_constr], tcx: ty::ctxt};
fn collect_pred(e: @expr, cx: ctxt, v: visit::vt<ctxt>) {
- alt e.node {
+ match e.node {
expr_check(_, ch) { vec::push(*cx.cs, expr_to_constr(cx.tcx, ch)); }
expr_if_check(ex, _, _) {
vec::push(*cx.cs, expr_to_constr(cx.tcx, ex));
constraint_to_str(tcx, c) + ~" |-> " + uint::str(next));
let {path: p, def_id: d_id, args: args} = c.node;
- alt tbl.find(d_id) {
+ match tbl.find(d_id) {
some(ct) {
(*ct.descs).push(respan(c.span, {args: args, bit_num: next}));
}
}
fn find_pre_post_item(ccx: crate_ctxt, i: item) {
- alt i.node {
+ match i.node {
item_const(_, e) {
// do nothing -- item_consts don't refer to local vars
}
maybe_alt: option<@expr>, id: node_id, chck: if_ty) {
find_pre_post_expr(fcx, antec);
find_pre_post_block(fcx, conseq);
- alt maybe_alt {
+ match maybe_alt {
none {
- alt chck {
+ match chck {
if_check {
let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
gen(fcx, antec.id, c.node);
/* Be sure to set the bit for the check condition here,
so that it's *not* set in the alternative. */
- alt chck {
+ match chck {
if_check {
let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
gen(fcx, antec.id, c.node);
fn gen_if_local(fcx: fn_ctxt, lhs: @expr, rhs: @expr, larger_id: node_id,
new_var: node_id) {
- alt node_id_to_def(fcx.ccx, new_var) {
+ match node_id_to_def(fcx.ccx, new_var) {
some(d) {
- alt d {
+ match d {
def_local(nid, _) {
find_pre_post_expr(fcx, rhs);
let p = expr_pp(fcx.ccx, rhs);
fn handle_update(fcx: fn_ctxt, parent: @expr, lhs: @expr, rhs: @expr,
ty: oper_type) {
find_pre_post_expr(fcx, rhs);
- alt lhs.node {
+ match lhs.node {
expr_path(p) {
let post = expr_postcond(fcx.ccx, parent);
let tmp = post.clone();
- alt ty {
+ match ty {
oper_move {
if is_path(rhs) { forget_in_postcond(fcx, parent.id, rhs.id); }
}
}
gen_if_local(fcx, lhs, rhs, parent.id, lhs.id);
- alt rhs.node {
+ match rhs.node {
expr_path(p1) {
let d = local_node_id_to_local_def_id(fcx, lhs.id);
let d1 = local_node_id_to_local_def_id(fcx, rhs.id);
- alt d {
+ match d {
some(id) {
- alt d1 {
+ match d1 {
some(id1) {
let instlhs =
{ident: path_to_ident(p), node: id};
fn forget_args_moved_in(fcx: fn_ctxt, parent: @expr, modes: ~[mode],
operands: ~[@expr]) {
do vec::iteri(modes) |i,mode| {
- alt ty::resolved_mode(fcx.ccx.tcx, mode) {
+ match ty::resolved_mode(fcx.ccx.tcx, mode) {
by_move { forget_in_postcond(fcx, parent.id, operands[i].id); }
by_ref | by_val | by_mutbl_ref | by_copy { }
}
fn do_rand_(fcx: fn_ctxt, e: @expr) { find_pre_post_expr(fcx, e); }
- alt e.node {
+ match e.node {
expr_call(operator, operands, _) {
/* copy */
operands);
/* if this is a failing call, its postcondition sets everything */
- alt controlflow_expr(fcx.ccx, operator) {
+ match controlflow_expr(fcx.ccx, operator) {
noreturn { set_postcond_false(fcx.ccx, e.id); }
_ { }
}
}
expr_rec(fields, maybe_base) {
let mut es = field_exprs(fields);
- alt maybe_base { none {/* no-op */ } some(b) { vec::push(es, b); } }
+ match maybe_base { none {/* no-op */ } some(b) { vec::push(es, b); } }
find_pre_post_exprs(fcx, es, e.id);
}
expr_tup(elts) { find_pre_post_exprs(fcx, elts, e.id); }
}
expr_lit(_) { clear_pp(expr_pp(fcx.ccx, e)); }
expr_ret(maybe_val) {
- alt maybe_val {
+ match maybe_val {
none {
clear_precond(fcx.ccx, e.id);
set_postcond_false(fcx.ccx, e.id);
expr_alt(ex, alts, _) {
find_pre_post_expr(fcx, ex);
fn do_an_alt(fcx: fn_ctxt, an_alt: arm) -> pre_and_post {
- alt an_alt.guard {
+ match an_alt.guard {
some(e) { find_pre_post_expr(fcx, e); }
_ {}
}
}
expr_fail(maybe_val) {
let mut prestate;
- alt maybe_val {
+ match maybe_val {
none { prestate = empty_prestate(num_local_vars); }
some(fail_val) {
find_pre_post_expr(fcx, fail_val);
fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) {
debug!{"stmt = %s", stmt_to_str(s)};
- alt s.node {
+ match s.node {
stmt_decl(adecl, id) {
- alt adecl.node {
+ match adecl.node {
decl_local(alocals) {
let prev_pp = empty_pre_post(num_constraints(fcx.enclosing));
for alocals.each |alocal| {
- alt alocal.node.init {
+ match alocal.node.init {
some(an_init) {
/* LHS always becomes initialized,
whether or not this is a move */
copy_pre_post(fcx.ccx, id, an_init.expr);
let mut p = none;
- alt an_init.expr.node {
+ match an_init.expr.node {
expr_path(_p) { p = some(_p); }
_ { }
}
do pat_bindings(fcx.ccx.tcx.def_map, alocal.node.pat)
|p_id, _s, n| {
let ident = path_to_ident(n);
- alt p {
+ match p {
some(p) {
copy_in_postcond(fcx, id,
{ident: ident, node: p_id},
let mut pps: ~[pre_and_post] = ~[];
for b.node.stmts.each |s| { vec::push(pps, stmt_pp(fcx.ccx, *s)); }
- alt b.node.expr {
+ match b.node.expr {
none {/* no-op */ }
some(e) { vec::push(pps, expr_pp(fcx.ccx, e)); }
}
find_pre_post_block(fcx, body);
// Treat the tail expression as a return statement
- alt body.node.expr {
+ match body.node.expr {
some(tailexpr) { set_postcond_false(fcx.ccx, tailexpr.id); }
none {/* fallthrough */ }
}
import std::map::hashmap;
fn forbid_upvar(fcx: fn_ctxt, rhs_id: node_id, sp: span, t: oper_type) {
- alt t {
+ match t {
oper_move {
- alt local_node_id_to_def(fcx, rhs_id) {
+ match local_node_id_to_def(fcx, rhs_id) {
some(def_upvar(_, _, _)) {
fcx.ccx.tcx.sess.span_err(sp,
~"tried to deinitialize a variable \
forbid_upvar(fcx, rhs_id, rhs_path.span, op_to_oper_ty(init_op));
let rhs_d_id = local_node_id_to_def_id(fcx, rhs_id);
- alt rhs_d_id {
+ match rhs_d_id {
some(rhsid) {
// RHS is a local var
let instrhs =
{ident: path_to_ident(rhs_path), node: rhsid.node};
- alt destlhs {
+ match destlhs {
local_dest(instlhs) {
copy_in_poststate(fcx, post, instlhs, instrhs,
op_to_oper_ty(init_op));
let mut changed = false;
let mut post = pres.clone();
for bindings.each |b| {
- alt b.rhs {
+ match b.rhs {
some(an_init) {
// an expression, with or without a destination
changed |=
find_pre_post_state_expr(fcx, post, an_init.expr) || changed;
post = expr_poststate(fcx.ccx, an_init.expr).clone();
for b.lhs.each |d| {
- alt an_init.expr.node {
+ match an_init.expr.node {
expr_path(p) {
handle_move_or_copy(fcx, post, p, an_init.expr.id, d,
an_init.op);
changed = set_prestate_ann(fcx.ccx, parent, pres) || changed;
let post = expr_poststate(fcx.ccx, e).clone();
- alt c {
+ match c {
none { }
some(c1) { set_in_poststate_(bit_num(fcx, c1), post); }
}
let post = expr_poststate(fcx.ccx, rhs).clone();
- alt lhs.node {
+ match lhs.node {
expr_path(p) {
// for termination, need to make sure intermediate changes don't set
// changed flag
// for substitution purposes
let tmp = post.clone();
- alt ty {
+ match ty {
oper_move {
if is_path(rhs) { forget_in_poststate(fcx, post, rhs.id); }
forget_in_poststate(fcx, post, lhs.id);
_ { forget_in_poststate(fcx, post, lhs.id); }
}
- alt rhs.node {
+ match rhs.node {
expr_path(p1) {
let d = local_node_id_to_local_def_id(fcx, lhs.id);
let d1 = local_node_id_to_local_def_id(fcx, rhs.id);
- alt d {
+ match d {
some(id) {
- alt d1 {
+ match d1 {
some(id1) {
let instlhs =
{ident: path_to_ident(p), node: id};
let rs = seq_states(fcx, pres, arg_bindings(ops, es));
let mut changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres);
/* if this is a failing call, it sets everything as initialized */
- alt cf {
+ match cf {
noreturn {
let post = false_postcond(num_constraints(fcx.enclosing));
changed |= set_poststate_ann(fcx.ccx, id, post);
set_prestate_ann(fcx.ccx, id, pres) |
find_pre_post_state_expr(fcx, pres, antec);
- alt maybe_alt {
+ match maybe_alt {
none {
- alt chk {
+ match chk {
if_check {
let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
let conseq_prestate = expr_poststate(fcx.ccx, antec).clone();
altern);
let mut conseq_prestate = expr_poststate(fcx.ccx, antec);
- alt chk {
+ match chk {
if_check {
let c: sp_constr = expr_to_constr(fcx.ccx.tcx, antec);
conseq_prestate = conseq_prestate.clone();
fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
let num_constrs = num_constraints(fcx.enclosing);
- alt e.node {
+ match e.node {
expr_new(p, _, v) {
return find_pre_post_state_two(fcx, pres, p, v, e.id, oper_pure);
}
init_assign),
exs, return_val);
- let base_pres = alt vec::last_opt(exs) { none { pres }
+ let base_pres = match vec::last_opt(exs) { none { pres }
some(f) { expr_poststate(fcx.ccx, f) }};
option::iter(maybe_base, |base| {
changed |= find_pre_post_state_expr(fcx, base_pres, base) |
set_poststate_ann(fcx.ccx, e.id, post);
- alt maybe_ret_val {
+ match maybe_ret_val {
none {/* do nothing */ }
some(ret_val) {
changed |= find_pre_post_state_expr(fcx, pres, ret_val);
if vec::len(alts) > 0u {
a_post = false_postcond(num_constrs);
for alts.each |an_alt| {
- alt an_alt.guard {
+ match an_alt.guard {
some(e) {
changed |= find_pre_post_state_expr(fcx, e_post, e);
}
debug!{"*prestate = %s", stmt_ann.states.prestate.to_str()};
debug!{"*poststate = %s", stmt_ann.states.prestate.to_str()};
- alt s.node {
+ match s.node {
stmt_decl(adecl, id) {
- alt adecl.node {
+ match adecl.node {
decl_local(alocals) {
set_prestate(stmt_ann, pres);
let c_and_p = seq_states(fcx, pres,
pres = stmt_poststate(fcx.ccx, *s);
}
let mut post = pres;
- alt b.node.expr {
+ match b.node.expr {
none { }
some(e) {
changed |= find_pre_post_state_expr(fcx, pres, e);
}
pure fn set(i: uint, t: trit) -> bool {
let old = self.get(i);
- alt t {
+ match t {
dont_care {
self.uncertain.set(i, true);
self.val.set(i, false);
let mut rslt: ~[uint] = ~[];
for uint::range(0, self.nbits) |i| {
vec::push(rslt,
- alt self.get(i) {
+ match self.get(i) {
dont_care { 2 }
ttrue { 1 }
tfalse { 0 }
let mut rs: str = "";
for uint::range(0, self.nbits) |i| {
rs +=
- alt self.get(i) {
+ match self.get(i) {
dont_care { "?" }
ttrue { "1" }
tfalse { "0" }
0 - 1 is an error
0 - anything else - 0
*/
- alt a {
+ match a {
dont_care { dont_care }
ttrue {
- alt b {
+ match b {
ttrue { dont_care }
tfalse { ttrue }
/* internally contradictory, but
}
}
tfalse {
- alt b {
+ match b {
ttrue { tfalse }
/* see above comment */
_ {
}
fn trit_or(a: trit, b: trit) -> trit {
- alt a {
+ match a {
dont_care { b }
ttrue { ttrue }
tfalse {
- alt b {
+ match b {
ttrue { dont_care }
/* FIXME (#2538): ??????
Again, unit tests would help here
// to make it so that all constraints start out in a 0 state
// (we consider a constraint false until proven true), too.
fn trit_and(a: trit, b: trit) -> trit {
- alt a {
+ match a {
dont_care { b }
// also seems wrong for case b = ttrue
ttrue {
- alt b {
+ match b {
dont_care { ttrue }
// ??? Seems wrong
ttrue {
fn param_bounds_to_kind(bounds: param_bounds) -> kind {
let mut kind = kind_noncopyable();
for vec::each(*bounds) |bound| {
- alt bound {
+ match bound {
bound_copy => {
kind = raise_kind(kind, kind_implicitly_copyable());
}
// and returns the box as cast to an unsafe ptr (see comments for t above).
fn mk_t_with_id(cx: ctxt, st: sty, o_def_id: option<ast::def_id>) -> t {
let key = {struct: st, o_def_id: o_def_id};
- alt cx.interner.find(key) {
+ match cx.interner.find(key) {
some(t) => unsafe { return unsafe::reinterpret_cast(t); }
_ => ()
}
let mut flags = 0u;
fn rflags(r: region) -> uint {
(has_regions as uint) | {
- alt r {
+ match r {
ty::re_var(_) => needs_infer as uint,
_ => 0u
}
substs.self_r.iter(|r| f |= rflags(r));
return f;
}
- alt st {
+ match st {
ty_estr(vstore_slice(r)) => {
flags |= rflags(r);
}
// Converts s to its machine type equivalent
pure fn mach_sty(cfg: @session::config, t: t) -> sty {
- alt get(t).struct {
+ match get(t).struct {
ty_int(ast::ty_i) => ty_int(cfg.int_type),
ty_uint(ast::ty_u) => ty_uint(cfg.uint_type),
ty_float(ast::ty_f) => ty_float(cfg.float_type),
// Returns the narrowest lifetime enclosing the evaluation of the expression
// with id `id`.
fn encl_region(cx: ctxt, id: ast::node_id) -> ty::region {
- alt cx.region_map.find(id) {
+ match cx.region_map.find(id) {
some(encl_scope) => ty::re_scope(encl_scope),
none => ty::re_static
}
fn maybe_walk_ty(ty: t, f: fn(t) -> bool) {
if !f(ty) { return; }
- alt get(ty).struct {
+ match get(ty).struct {
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_estr(_) | ty_type | ty_opaque_box | ty_self |
ty_opaque_closure_ptr(_) | ty_var(_) | ty_var_integral(_) |
tps: substs.tps.map(|t| fldop(t))}
}
- alt sty {
+ match sty {
ty_box(tm) => {
ty_box({ty: fldop(tm.ty), mutbl: tm.mutbl})
}
}
let tb = ty::get(ty);
- alt tb.struct {
+ match tb.struct {
ty::ty_rptr(r, mt) => {
let m_r = fldr(r);
let m_t = fldt(mt.ty);
fldop: fn(region, bool) -> region) -> t {
let tb = get(t0);
if !tbox_has_flag(tb, has_regions) { return t0; }
- alt tb.struct {
+ match tb.struct {
ty_rptr(r, {ty: t1, mutbl: m}) => {
let m_r = fldop(r, under_r);
let m_t1 = do_fold(cx, t1, true, fldop);
if tps.len() == 0u { return typ; }
let tb = ty::get(typ);
if !tbox_has_flag(tb, has_params) { return typ; }
- alt tb.struct {
+ match tb.struct {
ty_param(p) => tps[p.idx],
sty => fold_sty_to_ty(cx, sty, |t| subst_tps(cx, tps, t))
}
typ: t) -> t {
let tb = get(typ);
if !tbox_has_flag(tb, needs_subst) { return typ; }
- alt tb.struct {
+ match tb.struct {
ty_param(p) => substs.tps[p.idx],
ty_self => substs.self_ty.get(),
_ => {
fold_regions_and_ty(
cx, typ,
- |r| alt r {
+ |r| match r {
re_bound(br_self) => substs.self_r.get(),
_ => r
},
fn type_is_bot(ty: t) -> bool { get(ty).struct == ty_bot }
fn type_is_var(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_var(_) => true,
_ => false
}
}
fn type_is_var_integral(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_var_integral(_) => true,
_ => false
}
fn type_is_bool(ty: t) -> bool { get(ty).struct == ty_bool }
fn type_is_structural(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_rec(_) | ty_class(*) | ty_tup(_) | ty_enum(*) | ty_fn(_) |
ty_trait(*) |
ty_evec(_, vstore_fixed(_)) | ty_estr(vstore_fixed(_)) |
}
fn type_is_sequence(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_estr(_) | ty_evec(_, _) => true,
_ => false
}
}
fn type_is_str(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_estr(_) => true,
_ => false
}
}
fn sequence_element_type(cx: ctxt, ty: t) -> t {
- alt get(ty).struct {
+ match get(ty).struct {
ty_estr(_) => return mk_mach_uint(cx, ast::ty_u8),
ty_evec(mt, _) | ty_unboxed_vec(mt) => return mt.ty,
_ => cx.sess.bug(
}
fn get_element_type(ty: t, i: uint) -> t {
- alt get(ty).struct {
+ match get(ty).struct {
ty_rec(flds) => return flds[i].mt.ty,
ty_tup(ts) => return ts[i],
_ => fail ~"get_element_type called on invalid type"
}
pure fn type_is_box(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_box(_) => return true,
_ => return false
}
}
pure fn type_is_boxed(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_box(_) | ty_opaque_box |
ty_evec(_, vstore_box) | ty_estr(vstore_box) => true,
_ => false
}
pure fn type_is_region_ptr(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_rptr(_, _) => true,
_ => false
}
}
pure fn type_is_slice(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_evec(_, vstore_slice(_)) | ty_estr(vstore_slice(_)) => true,
_ => return false
}
}
pure fn type_is_unique_box(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_uniq(_) => return true,
_ => return false
}
}
pure fn type_is_unsafe_ptr(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_ptr(_) => return true,
_ => return false
}
}
pure fn type_is_vec(ty: t) -> bool {
- return alt get(ty).struct {
+ return match get(ty).struct {
ty_evec(_, _) | ty_unboxed_vec(_) => true,
ty_estr(_) => true,
_ => false
}
pure fn type_is_unique(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_uniq(_) => return true,
ty_evec(_, vstore_uniq) => true,
ty_estr(vstore_uniq) => true,
contents are abstract to rustc.)
*/
pure fn type_is_scalar(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_var_integral(_) | ty_type | ty_ptr(_) => true,
_ => false
}
fn type_needs_drop(cx: ctxt, ty: t) -> bool {
- alt cx.needs_drop_cache.find(ty) {
+ match cx.needs_drop_cache.find(ty) {
some(result) => return result,
none => {/* fall through */ }
}
let mut accum = false;
- let result = alt get(ty).struct {
+ let result = match get(ty).struct {
// scalar types
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_type | ty_ptr(_) | ty_rptr(_, _) |
accum
}
ty_fn(fty) => {
- alt fty.proto {
+ match fty.proto {
proto_bare | proto_block => false,
_ => true
}
// that only contain scalars and shared boxes can avoid unwind
// cleanups.
fn type_needs_unwind_cleanup(cx: ctxt, ty: t) -> bool {
- alt cx.needs_unwind_cleanup_cache.find(ty) {
+ match cx.needs_unwind_cleanup_cache.find(ty) {
some(result) => return result,
none => ()
}
encountered_box: bool) -> bool {
// Prevent infinite recursion
- alt tycache.find(ty) {
+ match tycache.find(ty) {
some(_) => return false,
none => { tycache.insert(ty, ()); }
}
let mut needs_unwind_cleanup = false;
do maybe_walk_ty(ty) |ty| {
let old_encountered_box = encountered_box;
- let result = alt get(ty).struct {
+ let result = match get(ty).struct {
ty_box(_) | ty_opaque_box => {
encountered_box = true;
true
}
fn proto_kind(p: proto) -> kind {
- alt p {
+ match p {
ast::proto_block => kind_noncopyable(),
ast::proto_box => kind_safe_for_default_mode() | kind_owned(),
ast::proto_uniq => kind_send_copy() | kind_owned(),
// This is used to prevent objects containing mutable state from being
// implicitly copied and to compute whether things have const kind.
fn mutability_kind(m: mutability) -> kind {
- alt (m) {
+ match (m) {
m_mutbl => remove_const(remove_implicit(kind_top())),
m_const => remove_implicit(kind_top()),
m_imm => kind_top()
}
fn type_kind(cx: ctxt, ty: t) -> kind {
- alt cx.kind_cache.find(ty) {
+ match cx.kind_cache.find(ty) {
some(result) => return result,
none => {/* fall through */ }
}
// Insert a default in case we loop back on self recursively.
cx.kind_cache.insert(ty, kind_top());
- let mut result = alt get(ty).struct {
+ let mut result = match get(ty).struct {
// Scalar and unique types are sendable, constant, and owned
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_ptr(_) => {
/// gives a rough estimate of how much space it takes to represent
/// an instance of `ty`. Used for the mode transition.
fn type_size(cx: ctxt, ty: t) -> uint {
- alt get(ty).struct {
+ match get(ty).struct {
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
ty_ptr(_) | ty_box(_) | ty_uniq(_) | ty_estr(vstore_uniq) |
ty_trait(*) | ty_rptr(*) | ty_evec(_, vstore_uniq) |
ty_to_str(cx, r_ty),
ty_to_str(cx, ty)};
- let r = alt get(ty).struct {
+ let r = match get(ty).struct {
ty_nil |
ty_bot |
ty_bool |
let sty = get(ty).struct;
debug!{"type_structurally_contains: %s", ty_to_str(cx, ty)};
if test(sty) { return true; }
- alt sty {
+ match sty {
ty_enum(did, substs) => {
for vec::each(*enum_variants(cx, did)) |variant| {
for variant.args.each |aty| {
fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
return type_structurally_contains(cx, ty, |sty| {
- alt sty {
+ match sty {
ty_uniq(_) |
ty_evec(_, vstore_uniq) |
ty_estr(vstore_uniq) => true,
}
fn type_is_integral(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool => true,
_ => false
}
}
fn type_is_fp(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_float(_) => true,
_ => false
}
}
fn type_is_signed(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_int(_) => true,
_ => false
}
// that the cycle collector might care about.
fn type_is_pod(cx: ctxt, ty: t) -> bool {
let mut result = true;
- alt get(ty).struct {
+ match get(ty).struct {
// Scalar types
ty_nil | ty_bot | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
ty_type | ty_ptr(_) => result = true,
}
fn type_is_enum(ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_enum(_, _) => return true,
_ => return false
}
// Whether a type is enum like, that is a enum type with only nullary
// constructors
fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
- alt get(ty).struct {
+ match get(ty).struct {
ty_enum(did, substs) => {
let variants = enum_variants(cx, did);
let some_n_ary = vec::any(*variants, |v| vec::len(v.args) > 0u);
}
fn type_param(ty: t) -> option<uint> {
- alt get(ty).struct {
+ match get(ty).struct {
ty_param(p) => return some(p.idx),
_ => {/* fall through */ }
}
deref_sty(cx, get(t).struct, expl)
}
fn deref_sty(cx: ctxt, sty: sty, expl: bool) -> option<mt> {
- alt sty {
+ match sty {
ty_rptr(_, mt) | ty_box(mt) | ty_uniq(mt) => {
some(mt)
}
fn type_autoderef(cx: ctxt, t: t) -> t {
let mut t = t;
loop {
- alt deref(cx, t, false) {
+ match deref(cx, t, false) {
none => return t,
some(mt) => t = mt.ty
}
}
fn index_sty(cx: ctxt, sty: sty) -> option<mt> {
- alt sty {
+ match sty {
ty_evec(mt, _) => some(mt),
ty_estr(_) => some({ty: mk_u8(cx), mutbl: ast::m_imm}),
_ => none
}
pure fn hash_bound_region(br: &bound_region) -> uint {
- alt *br { // no idea if this is any good
+ match *br { // no idea if this is any good
ty::br_self => 0u,
ty::br_anon => 1u,
ty::br_named(str) => str::hash(str),
h
}
pure fn hash_region(r: ®ion) -> uint {
- alt *r { // no idea if this is any good
+ match *r { // no idea if this is any good
re_bound(br) => (hash_bound_region(&br)) << 2u | 0u,
re_free(id, br) => ((id as uint) << 4u) |
(hash_bound_region(&br)) << 2u | 1u,
let h = hash_subtys(h, substs.tps);
h + substs.self_r.map_default(0u, |r| hash_region(&r))
}
- alt st {
+ match st {
ty_nil => 0u,
ty_bool => 1u,
- ty_int(t) => alt t {
+ ty_int(t) => match t {
ast::ty_i => 2u,
ast::ty_char => 3u,
ast::ty_i8 => 4u,
ast::ty_i32 => 6u,
ast::ty_i64 => 7u
}
- ty_uint(t) => alt t {
+ ty_uint(t) => match t {
ast::ty_u => 8u,
ast::ty_u8 => 9u,
ast::ty_u16 => 10u,
ast::ty_u32 => 11u,
ast::ty_u64 => 12u
}
- ty_float(t) => alt t {
+ ty_float(t) => match t {
ast::ty_f => 13u,
ast::ty_f32 => 14u,
ast::ty_f64 => 15u
}
fn node_id_to_type(cx: ctxt, id: ast::node_id) -> t {
- alt smallintmap::find(*cx.node_types, id as uint) {
+ match smallintmap::find(*cx.node_types, id as uint) {
some(t) => t,
none => cx.sess.bug(fmt!{"node_id_to_type: unbound node ID %s",
ast_map::node_id_to_str(cx.items, id)})
}
fn node_id_to_type_params(cx: ctxt, id: ast::node_id) -> ~[t] {
- alt cx.node_type_substs.find(id) {
+ match cx.node_type_substs.find(id) {
none => return ~[],
some(ts) => return ts
}
// Type accessors for substructures of types
fn ty_fn_args(fty: t) -> ~[arg] {
- alt get(fty).struct {
+ match get(fty).struct {
ty_fn(f) => f.inputs,
_ => fail ~"ty_fn_args() called on non-fn type"
}
}
fn ty_fn_proto(fty: t) -> ast::proto {
- alt get(fty).struct {
+ match get(fty).struct {
ty_fn(f) => f.proto,
_ => fail ~"ty_fn_proto() called on non-fn type"
}
}
pure fn ty_fn_ret(fty: t) -> t {
- alt get(fty).struct {
+ match get(fty).struct {
ty_fn(f) => f.output,
_ => fail ~"ty_fn_ret() called on non-fn type"
}
}
fn ty_fn_ret_style(fty: t) -> ast::ret_style {
- alt get(fty).struct {
+ match get(fty).struct {
ty_fn(f) => f.ret_style,
_ => fail ~"ty_fn_ret_style() called on non-fn type"
}
}
fn is_fn_ty(fty: t) -> bool {
- alt get(fty).struct {
+ match get(fty).struct {
ty_fn(_) => return true,
_ => return false
}
}
fn ty_var_id(typ: t) -> tv_vid {
- alt get(typ).struct {
+ match get(typ).struct {
ty_var(vid) => return vid,
_ => { error!{"ty_var_id called on non-var ty"}; fail; }
}
}
fn ty_var_integral_id(typ: t) -> tvi_vid {
- alt get(typ).struct {
+ match get(typ).struct {
ty_var_integral(vid) => return vid,
_ => { error!{"ty_var_integral_id called on ty other than \
ty_var_integral"};
}
fn expr_is_lval(method_map: typeck::method_map, e: @ast::expr) -> bool {
- alt e.node {
+ match e.node {
ast::expr_path(_) | ast::expr_unary(ast::deref, _) => true,
ast::expr_field(_, _, _) | ast::expr_index(_, _) => {
!method_map.contains_key(e.id)
}
fn stmt_node_id(s: @ast::stmt) -> ast::node_id {
- alt s.node {
+ match s.node {
ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) => {
return id;
}
}
fn get_field(rec_ty: t, id: ast::ident) -> field {
- alt check vec::find(get_fields(rec_ty), |f| str::eq(f.ident, id)) {
+ match check vec::find(get_fields(rec_ty), |f| str::eq(f.ident, id)) {
some(f) => f
}
}
fn get_fields(rec_ty:t) -> ~[field] {
- alt check get(rec_ty).struct {
+ match check get(rec_ty).struct {
ty_rec(fields) => fields
}
}
fn param_tys_in_type(ty: t) -> ~[param_ty] {
let mut rslt = ~[];
do walk_ty(ty) |ty| {
- alt get(ty).struct {
+ match get(ty).struct {
ty_param(p) => {
vec::push(rslt, p);
}
fn vars_in_type(ty: t) -> ~[tv_vid] {
let mut rslt = ~[];
do walk_ty(ty) |ty| {
- alt get(ty).struct {
+ match get(ty).struct {
ty_var(v) => vec::push(rslt, v),
_ => ()
}
// the current head value for `m0`.
fn canon<T:copy>(tbl: hashmap<ast::node_id, ast::inferable<T>>,
m0: ast::inferable<T>) -> ast::inferable<T> {
- alt m0 {
- ast::infer(id) => alt tbl.find(id) {
+ match m0 {
+ ast::infer(id) => match tbl.find(id) {
none => m0,
some(m1) => {
let cm1 = canon(tbl, m1);
// Returns the head value for mode, failing if `m` was a infer(_) that
// was never inferred. This should be safe for use after typeck.
fn resolved_mode(cx: ctxt, m: ast::mode) -> ast::rmode {
- alt canon_mode(cx, m) {
+ match canon_mode(cx, m) {
ast::infer(_) => {
cx.sess.bug(fmt!{"mode %? was never resolved", m});
}
// Unifies `m1` and `m2`. Returns unified value or failure code.
fn unify_mode(cx: ctxt, m1: ast::mode, m2: ast::mode)
-> result<ast::mode, type_err> {
- alt (canon_mode(cx, m1), canon_mode(cx, m2)) {
+ match (canon_mode(cx, m1), canon_mode(cx, m2)) {
(m1, m2) if (m1 == m2) => {
result::ok(m1)
}
// If `m` was never unified, unifies it with `m_def`. Returns the final value
// for `m`.
fn set_default_mode(cx: ctxt, m: ast::mode, m_def: ast::rmode) {
- alt canon_mode(cx, m) {
+ match canon_mode(cx, m) {
ast::infer(id) => {
cx.inferred_modes.insert(id, ast::expl(m_def));
}
}
fn ty_sort_str(cx: ctxt, t: t) -> ~str {
- alt get(t).struct {
+ match get(t).struct {
ty_nil | ty_bot | ty_bool | ty_int(_) |
ty_uint(_) | ty_float(_) | ty_estr(_) |
ty_type | ty_opaque_box | ty_opaque_closure_ptr(_) => {
fn type_err_to_str(cx: ctxt, err: type_err) -> ~str {
fn terr_vstore_kind_to_str(k: terr_vstore_kind) -> ~str {
- alt k { terr_vec => ~"[]", terr_str => ~"str" }
+ match k { terr_vec => ~"[]", terr_str => ~"str" }
}
- alt err {
+ match err {
terr_mismatch => return ~"types differ",
terr_ret_style_mismatch(expect, actual) => {
fn to_str(s: ast::ret_style) -> ~str {
- alt s {
+ match s {
ast::noreturn => ~"non-returning",
ast::return_val => ~"return-by-value"
}
}
fn def_has_ty_params(def: ast::def) -> bool {
- alt def {
+ match def {
ast::def_fn(_, _) | ast::def_variant(_, _) | ast::def_class(_, _)
=> true,
_ => false
}
fn trait_methods(cx: ctxt, id: ast::def_id) -> @~[method] {
- alt cx.trait_method_cache.find(id) {
+ match cx.trait_method_cache.find(id) {
some(ms) => return ms,
_ => ()
}
fn impl_traits(cx: ctxt, id: ast::def_id) -> ~[t] {
if id.crate == ast::local_crate {
debug!{"(impl_traits) searching for trait impl %?", id};
- alt cx.items.find(id.node) {
+ match cx.items.find(id.node) {
some(ast_map::node_item(@{
node: ast::item_impl(_, trait_refs, _, _),
_},
}
some(ast_map::node_item(@{node: ast::item_class(*),
_},_)) => {
- alt cx.def_map.find(id.node) {
+ match cx.def_map.find(id.node) {
some(def_ty(trait_id)) => {
// XXX: Doesn't work cross-crate.
debug!{"(impl_traits) found trait id %?", trait_id};
}
fn ty_to_def_id(ty: t) -> option<ast::def_id> {
- alt get(ty).struct {
+ match get(ty).struct {
ty_trait(id, _) | ty_class(id, _) | ty_enum(id, _) => some(id),
_ => none
}
Otherwise return none. */
fn ty_dtor(cx: ctxt, class_id: def_id) -> option<def_id> {
if is_local(class_id) {
- alt cx.items.find(class_id.node) {
+ match cx.items.find(class_id.node) {
some(ast_map::node_item(@{node: ast::item_class(_, _, _, _,
some(dtor)), _}, _))
=> some(local_def(dtor.node.id)),
csearch::get_item_path(cx, id)
} else {
let node = cx.items.get(id.node);
- alt node {
+ match node {
ast_map::node_item(item, path) => {
- let item_elt = alt item.node {
+ let item_elt = match item.node {
item_mod(_) | item_foreign_mod(_) => {
ast_map::path_mod(item.ident)
}
}
fn type_is_empty(cx: ctxt, t: t) -> bool {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(),
_ => false
}
}
fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[variant_info] {
- alt cx.enum_var_cache.find(id) {
+ match cx.enum_var_cache.find(id) {
some(variants) => return variants,
_ => { /* fallthrough */ }
}
call eval_const_expr, it should never get called twice for the same
expr, since check_enum_variants also updates the enum_var_cache
*/
- alt cx.items.get(id.node) {
+ match cx.items.get(id.node) {
ast_map::node_item(@{node: ast::item_enum(variants, _), _}, _) => {
let mut disr_val = -1;
@vec::map(variants, |variant| {
ty_fn_args(ctor_ty).map(|a| a.ty)
} else { ~[] }
};
- alt variant.node.disr_expr {
+ match variant.node.disr_expr {
some (ex) => {
// FIXME: issue #1417
- disr_val = alt const_eval::eval_const_expr(cx, ex) {
+ disr_val = match const_eval::eval_const_expr(cx, ex) {
const_eval::const_int(val) =>val as int,
_ => cx.sess.bug(~"tag_variants: bad disr expr")
}
// If the given item is in an external crate, looks up its type and adds it to
// the type cache. Returns the type parameters and type.
fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_bounds_and_ty {
- alt cx.tcache.find(did) {
+ match cx.tcache.find(did) {
some(tpt) => return tpt,
none => {
// The item is in this crate. The caller should have added it to the
node_id_to_type(tcx, id.node)
}
else {
- alt tcx.tcache.find(id) {
+ match tcx.tcache.find(id) {
some(tpt) => tpt.ty,
none => {
let tpt = csearch::get_field_type(tcx, class_id, id);
// Fails if the id is not bound to a class.
fn lookup_class_fields(cx: ctxt, did: ast::def_id) -> ~[field_ty] {
if did.crate == ast::local_crate {
- alt cx.items.find(did.node) {
+ match cx.items.find(did.node) {
some(ast_map::node_item(i,_)) => {
- alt i.node {
+ match i.node {
ast::item_class(_, _, items, _, _) => {
class_field_tys(items)
}
fn lookup_class_field(cx: ctxt, parent: ast::def_id, field_id: ast::def_id)
-> field_ty {
- alt vec::find(lookup_class_fields(cx, parent),
+ match vec::find(lookup_class_fields(cx, parent),
|f| f.id.node == field_id.node) {
some(t) => t,
none => cx.sess.bug(~"class ID not found in parent's fields")
-> ~[{name: ident, id: node_id, vis: visibility}] {
assert is_local(did);
- alt cx.items.find(did.node) {
+ match cx.items.find(did.node) {
some(ast_map::node_item(@{
node: item_class(_,_,items,_,_), _
}, _)) => {
fn class_field_tys(items: ~[@class_member]) -> ~[field_ty] {
let mut rslt = ~[];
for items.each |it| {
- alt it.node {
+ match it.node {
instance_var(nm, _, cm, id, vis) => {
vec::push(rslt, {ident: nm, id: ast_util::local_def(id),
vis: vis, mutability: cm});
// mutability.
fn class_items_as_fields(cx:ctxt, did: ast::def_id,
substs: substs) -> ~[field] {
- class_item_fields(cx, did, substs, |mt| alt mt {
+ class_item_fields(cx, did, substs, |mt| match mt {
class_mutable => m_mutbl,
class_immutable => m_imm })
}
const opcat_logic: int = 7;
fn opcat(op: ast::binop) -> int {
- alt op {
+ match op {
ast::add => opcat_add,
ast::subtract => opcat_sub,
ast::mul => opcat_mult,
}
fn tycat(ty: t) -> int {
- alt get(ty).struct {
+ match get(ty).struct {
ty_bool => tycat_bool,
ty_int(_) | ty_uint(_) | ty_var_integral(_) => tycat_int,
ty_float(_) => tycat_float,
}
}
- alt cx.normalized_cache.find(t) {
+ match cx.normalized_cache.find(t) {
some(t) => return t,
none => ()
}
}
fn lookup_def_tcx(tcx: ty::ctxt, sp: span, id: ast::node_id) -> ast::def {
- alt tcx.def_map.find(id) {
+ match tcx.def_map.find(id) {
some(x) => x,
_ => {
tcx.sess.span_fatal(sp, ~"internal error looking up a definition")
msg: fn() -> ~str) -> bool {
let l_tcx, l_infcx;
- alt maybe_infcx {
+ match maybe_infcx {
none => {
l_tcx = tcx;
l_infcx = infer::new_infer_ctxt(tcx);
}
}
- alt infer::mk_eqty(l_infcx, t1, t2) {
+ match infer::mk_eqty(l_infcx, t1, t2) {
result::ok(()) => true,
result::err(terr) => {
l_tcx.sess.span_err(span, msg() + ~": " +
}
fn arg_is_argv_ty(_tcx: ty::ctxt, a: ty::arg) -> bool {
- alt ty::get(a.ty).struct {
+ match ty::get(a.ty).struct {
ty::ty_evec(mt, vstore_uniq) => {
if mt.mutbl != ast::m_imm { return false; }
- alt ty::get(mt.ty).struct {
+ match ty::get(mt.ty).struct {
ty::ty_estr(vstore_uniq) => return true,
_ => return false
}
let tcx = ccx.tcx;
let main_t = ty::node_id_to_type(tcx, main_id);
- alt ty::get(main_t).struct {
+ match ty::get(main_t).struct {
ty::ty_fn({purity: ast::impure_fn, proto: ast::proto_bare,
inputs, output, ret_style: ast::return_val}) => {
- alt tcx.items.find(main_id) {
+ match tcx.items.find(main_id) {
some(ast_map::node_item(it,_)) => {
- alt it.node {
+ match it.node {
ast::item_fn(_,ps,_) if vec::is_not_empty(ps) => {
tcx.sess.span_err(main_span,
~"main function is not allowed to have type parameters");
fn check_for_main_fn(ccx: @crate_ctxt) {
let tcx = ccx.tcx;
if !tcx.sess.building_library {
- alt copy tcx.sess.main_fn {
+ match copy tcx.sess.main_fn {
some((id, sp)) => check_main_fn_ty(ccx, id, sp),
none => tcx.sess.err(~"main function not found")
}
span: span,
res: result<ty::region, ~str>) -> ty::region {
- alt res {
+ match res {
result::ok(r) => r,
result::err(e) => {
tcx.sess.span_err(span, e);
fn ast_region_to_region<AC: ast_conv, RS: region_scope copy owned>(
self: AC, rscope: RS, span: span, a_r: @ast::region) -> ty::region {
- let res = alt a_r.node {
+ let res = match a_r.node {
ast::re_anon => rscope.anon_region(),
ast::re_named(id) => rscope.named_region(id)
};
// If the type is parameterized by the self region, then replace self
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
- let self_r = alt (decl_rp, path.rp) {
+ let self_r = match (decl_rp, path.rp) {
(false, none) => {
none
}
let tcx = self.tcx();
- alt a_seq_ty.ty.node {
+ match a_seq_ty.ty.node {
// to convert to an e{vec,str}, there can't be a mutability argument
_ if a_seq_ty.mutbl != ast::m_imm => (),
ast::ty_vec(mt) => {
return ty::mk_evec(tcx, ast_mt_to_mt(self, rscope, mt), vst);
}
ast::ty_path(path, id) => {
- alt tcx.def_map.find(id) {
+ match tcx.def_map.find(id) {
some(ast::def_prim_ty(ast::ty_str)) => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
return ty::mk_estr(tcx, vst);
let tcx = self.tcx();
- alt tcx.ast_ty_to_ty_cache.find(ast_ty) {
+ match tcx.ast_ty_to_ty_cache.find(ast_ty) {
some(ty::atttce_resolved(ty)) => return ty,
some(ty::atttce_unresolved) => {
tcx.sess.span_fatal(ast_ty.span, ~"illegal recursive type; \
}
tcx.ast_ty_to_ty_cache.insert(ast_ty, ty::atttce_unresolved);
- let typ = alt ast_ty.node {
+ let typ = match ast_ty.node {
ast::ty_nil => ty::mk_nil(tcx),
ast::ty_bot => ty::mk_bot(tcx),
ast::ty_box(mt) => {
ty::mk_fn(tcx, ty_of_fn_decl(self, rscope, proto, decl, none))
}
ast::ty_path(path, id) => {
- let a_def = alt tcx.def_map.find(id) {
+ let a_def = match tcx.def_map.find(id) {
none => tcx.sess.span_fatal(ast_ty.span, fmt!{"unbound path %s",
path_to_str(path)}),
some(d) => d
};
- alt a_def {
+ match a_def {
ast::def_ty(did) | ast::def_class(did, _) => {
ast_path_to_ty(self, rscope, did, path, id).ty
}
ast::def_prim_ty(nty) => {
- alt nty {
+ match nty {
ast::ty_bool => {
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
ty::mk_bool(tcx)
self: AC, rscope: RS, a: ast::arg,
expected_ty: option<ty::arg>) -> ty::arg {
- let ty = alt a.ty.node {
+ let ty = match a.ty.node {
ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty,
ast::ty_infer => self.ty_infer(a.ty.span),
_ => ast_ty_to_ty(self, rscope, a.ty)
};
let mode = {
- alt a.mode {
+ match a.mode {
ast::infer(_) if expected_ty.is_some() => {
result::get(ty::unify_mode(self.tcx(), a.mode,
expected_ty.get().mode))
}
ast::infer(_) => {
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
// If the type is not specified, then this must be a fn expr.
// Leave the mode as infer(_), it will get inferred based
// on constraints elsewhere.
};
let expected_ret_ty = expected_tys.map(|e| e.output);
- let output_ty = alt decl.output.node {
+ let output_ty = match decl.output.node {
ast::ty_infer if expected_ret_ty.is_some() => expected_ret_ty.get(),
ast::ty_infer => self.ty_infer(decl.output.span),
_ => ast_ty_to_ty(self, rb, decl.output)
id: ast::node_id,
self_info: option<self_info>) {
let fty = ty::node_id_to_type(ccx.tcx, id);
- let fn_ty = alt check ty::get(fty).struct { ty::ty_fn(f) => f };
+ let fn_ty = match check ty::get(fty).struct { ty::ty_fn(f) => f };
check_fn(ccx, self_info, fn_ty, decl, body, false, none);
}
// in the case of function expressions, based on the outer context.
let fcx: @fn_ctxt = {
let {infcx, locals, purity, node_types, node_type_substs} =
- alt old_fcx {
+ match old_fcx {
none => {
{infcx: infer::new_infer_ctxt(tcx),
locals: int_hash(),
let indirect_ret_ty = if indirect_ret {
let ofcx = option::get(old_fcx);
- alt ofcx.indirect_ret_ty {
+ match ofcx.indirect_ret_ty {
some(t) => some(t),
none => some(ofcx.ret_ty)
}
// We unify the tail expr's type with the
// function result type, if there is a tail expr.
- alt body.node.expr {
+ match body.node.expr {
some(tail_expr) => {
let tail_expr_ty = fcx.expr_ty(tail_expr);
demand::suptype(fcx, tail_expr.span, fcx.ret_ty, tail_expr_ty);
let assign = fn@(nid: ast::node_id, ty_opt: option<ty::t>) {
let var_id = fcx.infcx.next_ty_var_id();
fcx.locals.insert(nid, var_id);
- alt ty_opt {
+ match ty_opt {
none => {/* nothing to do */ }
some(typ) => {
infer::mk_eqty(fcx.infcx, ty::mk_var(tcx, var_id), typ);
// Add explicitly-declared locals.
let visit_local = fn@(local: @ast::local,
&&e: (), v: visit::vt<()>) {
- let o_ty = alt local.node.ty.node {
+ let o_ty = match local.node.ty.node {
ast::ty_infer => none,
_ => some(fcx.to_ty(local.node.ty))
};
// Add pattern bindings.
let visit_pat = fn@(p: @ast::pat, &&e: (), v: visit::vt<()>) {
- alt p.node {
+ match p.node {
ast::pat_ident(_, path, _)
if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) => {
assign(p.id, none);
fn check_class_member(ccx: @crate_ctxt, class_t: self_info,
cm: @ast::class_member) {
- alt cm.node {
+ match cm.node {
ast::instance_var(_,t,_,_,_) => (),
ast::class_method(m) => check_method(ccx, m, class_t)
}
|x,y| str::eq(*x, *y));
for fields.each |p| {
let (id, sp) = p;
- alt field_names.find(id) {
+ match field_names.find(id) {
some(orig_sp) => {
tcx.sess.span_err(sp, fmt!{"Duplicate field \
name %s in record type declaration",
}
fn check_item(ccx: @crate_ctxt, it: @ast::item) {
- alt it.node {
+ match it.node {
ast::item_const(_, e) => check_const(ccx, it.span, e, it.id),
ast::item_enum(vs, _) => {
check_enum_variants(ccx, it.span, vs, it.id);
}
ast::item_trait(_, _, trait_methods) => {
for trait_methods.each |trait_method| {
- alt trait_method {
+ match trait_method {
required(ty_m) => {
// Nothing to do, since required methods don't have
// bodies to check.
let tpt_ty = ty::node_id_to_type(ccx.tcx, it.id);
check_bounds_are_used(ccx, t.span, tps, tpt_ty);
// If this is a record ty, check for duplicate fields
- alt t.node {
+ match t.node {
ast::ty_rec(fields) => {
check_no_duplicate_fields(ccx.tcx, fields.map(|f|
(f.node.ident, f.span)));
}
fn named_region(id: ast::ident) -> result<ty::region, ~str> {
do empty_rscope.named_region(id).chain_err |_e| {
- alt self.in_scope_regions.find(ty::br_named(id)) {
+ match self.in_scope_regions.find(ty::br_named(id)) {
some(r) => result::ok(r),
none if *id == ~"blk" => self.block_region(),
none => {
}
fn expr_ty(ex: @ast::expr) -> ty::t {
- alt self.node_types.find(ex.id) {
+ match self.node_types.find(ex.id) {
some(t) => t,
none => {
self.tcx().sess.bug(fmt!{"no type for expr %d (%s) in fcx %s",
}
}
fn node_ty(id: ast::node_id) -> ty::t {
- alt self.node_types.find(id) {
+ match self.node_types.find(id) {
some(t) => t,
none => {
self.tcx().sess.bug(
}
}
fn node_ty_substs(id: ast::node_id) -> ty::substs {
- alt self.node_type_substs.find(id) {
+ match self.node_type_substs.find(id) {
some(ts) => ts,
none => {
self.tcx().sess.bug(
}
fn require_unsafe(sp: span, op: ~str) {
- alt self.purity {
+ match self.purity {
ast::unsafe_fn => {/*ok*/}
_ => {
self.ccx.tcx.sess.span_err(
let sty = structure_of(fcx, sp, t1);
// Some extra checks to detect weird cycles and so forth:
- alt sty {
+ match sty {
ty::ty_box(inner) | ty::ty_uniq(inner) | ty::ty_rptr(_, inner) => {
- alt ty::get(t1).struct {
+ match ty::get(t1).struct {
ty::ty_var(v1) => {
ty::occurs_check(fcx.ccx.tcx, sp, v1,
ty::mk_box(fcx.ccx.tcx, inner));
}
// Otherwise, deref if type is derefable:
- alt ty::deref_sty(fcx.ccx.tcx, sty, false) {
+ match ty::deref_sty(fcx.ccx.tcx, sty, false) {
none => return t1,
some(mt) => t1 = mt.ty
}
fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
let tcx = fcx.ccx.tcx;
- alt lit.node {
+ match lit.node {
ast::lit_str(s) => ty::mk_estr(tcx, ty::vstore_slice(ty::re_static)),
ast::lit_int(_, t) => ty::mk_mach_int(tcx, t),
ast::lit_uint(_, t) => ty::mk_mach_uint(tcx, t),
let {n_tps, rp, raw_ty} = if did.crate == ast::local_crate {
let rp = fcx.tcx().region_paramd_items.contains_key(did.node);
- alt check tcx.items.find(did.node) {
+ match check tcx.items.find(did.node) {
some(ast_map::node_item(@{node: ast::item_impl(ts, _, st, _),
_}, _)) => {
{n_tps: ts.len(),
// process the types bound by the function but not by any nested
// functions. Therefore, we match one level of structure.
let fn_ty =
- alt structure_of(fcx, sp, in_fty) {
+ match structure_of(fcx, sp, in_fty) {
sty @ ty::ty_fn(fn_ty) => {
replace_bound_regions_in_fn_ty(
fcx.ccx.tcx, @nil, none, fn_ty,
// right way to do this.
for [false, true]/_.each |check_blocks| {
for args.eachi |i, a| {
- let is_block = alt a.node {
+ let is_block = match a.node {
ast::expr_fn_block(*) => true,
_ => false
};
// Index expressions need to be handled seperately, to inform
// them that they appear in call position.
- let mut bot = alt f.node {
+ let mut bot = match f.node {
ast::expr_field(base, field, tys) => {
check_field(fcx, f, true, base, field, tys)
}
};
// Pull the return type out of the type of the function.
- alt structure_of(fcx, sp, fty) {
+ match structure_of(fcx, sp, fty) {
ty::ty_fn(f) => {
bot |= (f.ret_style == ast::noreturn);
fcx.write_ty(call_expr_id, f.output);
elsopt: option<@ast::expr>, id: ast::node_id,
_sp: span) -> bool {
let (if_t, if_bot) =
- alt elsopt {
+ match elsopt {
some(els) => {
let if_t = fcx.infcx.next_ty_var();
let thn_bot = check_block(fcx, thn);
-> option<(ty::t, bool)> {
let lkup = method::lookup(fcx, op_ex, self_ex, op_ex.id,
op_ex.callee_id, @opname, self_t, ~[], false);
- alt lkup.method() {
+ match lkup.method() {
some(origin) => {
let {fty: method_ty, bot: bot} = {
let method_ty = fcx.node_ty(op_ex.callee_id);
let lhs_bot = check_expr(fcx, lhs, none);
let lhs_t = fcx.expr_ty(lhs);
let lhs_t = structurally_resolved_type(fcx, lhs.span, lhs_t);
- return alt (op, ty::get(lhs_t).struct) {
+ return match (op, ty::get(lhs_t).struct) {
(_, _) if ty::type_is_integral(lhs_t) &&
ast_util::is_shift_binop(op) => {
// Shift is a special case: rhs can be any integral type
let tvar = fcx.infcx.next_ty_var();
demand::suptype(fcx, expr.span, tvar, lhs_t);
let rhs_bot = check_expr_with(fcx, rhs, tvar);
- let rhs_t = alt op {
+ let rhs_t = match op {
ast::eq | ast::lt | ast::le | ast::ne | ast::ge |
ast::gt => {
// these comparison operators are handled in a
lhs_expr: @ast::expr, lhs_resolved_t: ty::t,
op: ast::binop, rhs: @ast::expr) -> (ty::t, bool) {
let tcx = fcx.ccx.tcx;
- alt ast_util::binop_to_method_name(op) {
+ match ast_util::binop_to_method_name(op) {
some(name) => {
- alt lookup_op_method(fcx, ex,
+ match lookup_op_method(fcx, ex,
lhs_expr, lhs_resolved_t,
name, ~[rhs]) {
some(pair) => return pair,
// If the or operator is used it might be that the user forgot to
// supply the do keyword. Let's be more helpful in that situation.
if op == ast::or {
- alt ty::get(lhs_resolved_t).struct {
+ match ty::get(lhs_resolved_t).struct {
ty::ty_fn(f) => {
tcx.sess.span_note(
ex.span, ~"did you forget the 'do' keyword for the call?");
fn check_user_unop(fcx: @fn_ctxt, op_str: ~str, mname: ~str,
ex: @ast::expr,
rhs_expr: @ast::expr, rhs_t: ty::t) -> ty::t {
- alt lookup_op_method(fcx, ex, rhs_expr, rhs_t, mname, ~[]) {
+ match lookup_op_method(fcx, ex, rhs_expr, rhs_t, mname, ~[]) {
some((ret_ty, _)) => ret_ty,
_ => {
fcx.ccx.tcx.sess.span_err(
fn unpack_expected<O: copy>(fcx: @fn_ctxt, expected: option<ty::t>,
unpack: fn(ty::sty) -> option<O>)
-> option<O> {
- alt expected {
+ match expected {
some(t) => {
- alt resolve_type(fcx.infcx, t, force_tvar) {
+ match resolve_type(fcx.infcx, t, force_tvar) {
result::ok(t) => unpack(ty::get(t).struct),
_ => none
}
// def'n of br_cap_avoid() for a more lengthy explanation of
// what's going on here.
let expected_tys = do unpack_expected(fcx, expected) |sty| {
- alt sty {
+ match sty {
ty::ty_fn(fn_ty) => {
let {fn_ty, _} =
replace_bound_regions_in_fn_ty(
let base_t = do_autoderef(fcx, expr.span, expr_t);
let mut handled = false;
let n_tys = vec::len(tys);
- alt structure_of(fcx, expr.span, base_t) {
+ match structure_of(fcx, expr.span, base_t) {
ty::ty_rec(fields) => {
- alt ty::field_idx(field, fields) {
+ match ty::field_idx(field, fields) {
some(ix) => {
if n_tys > 0u {
tcx.sess.span_err(expr.span,
else {
lookup_public_fields(tcx, base_id)
};
- alt lookup_field_ty(tcx, base_id, cls_items, field, substs) {
+ match lookup_field_ty(tcx, base_id, cls_items, field, substs) {
some(field_ty) => {
// (2) look up what field's type is, and return it
fcx.write_ty(expr.id, field_ty);
let lkup = method::lookup(fcx, expr, base, borrow_lb,
expr.id, field, expr_t, tps,
is_self_ref);
- alt lkup.method() {
+ match lkup.method() {
some(entry) => {
fcx.ccx.method_map.insert(expr.id, entry);
let tcx = fcx.ccx.tcx;
let id = expr.id;
let mut bot = false;
- alt expr.node {
+ match expr.node {
ast::expr_vstore(ev, vst) => {
- let typ = alt ev.node {
+ let typ = match ev.node {
ast::expr_lit(@{node: ast::lit_str(s), span:_}) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, str::len(*s), vst);
ty::mk_estr(tcx, tt)
}
ast::expr_unary(unop, oprnd) => {
let exp_inner = do unpack_expected(fcx, expected) |sty| {
- alt unop {
- ast::box(_) | ast::uniq(_) => alt sty {
+ match unop {
+ ast::box(_) | ast::uniq(_) => match sty {
ty::ty_box(mt) | ty::ty_uniq(mt) => some(mt.ty),
_ => none
}
};
bot = check_expr(fcx, oprnd, exp_inner);
let mut oprnd_t = fcx.expr_ty(oprnd);
- alt unop {
+ match unop {
ast::box(mutbl) => {
oprnd_t = ty::mk_box(tcx, {ty: oprnd_t, mutbl: mutbl});
}
// deref'ing an unsafe pointer requires that we be in an unsafe
// context
- alt sty {
+ match sty {
ty::ty_ptr(*) => {
fcx.require_unsafe(
expr.span,
_ => { /*ok*/ }
}
- alt ty::deref_sty(tcx, sty, true) {
+ match ty::deref_sty(tcx, sty, true) {
some(mt) => { oprnd_t = mt.ty }
none => {
- alt sty {
+ match sty {
ty::ty_enum(*) => {
tcx.sess.span_err(
expr.span,
}
ast::expr_addr_of(mutbl, oprnd) => {
bot = check_expr(fcx, oprnd, unpack_expected(fcx, expected, |ty|
- alt ty { ty::ty_rptr(_, mt) => some(mt.ty), _ => none }
+ match ty { ty::ty_rptr(_, mt) => some(mt.ty), _ => none }
));
//let region = region_of(fcx, oprnd);
let region = fcx.infcx.next_region_var_with_scope_lb(expr.id);
ast::expr_mac(_) => tcx.sess.bug(~"unexpanded macro"),
ast::expr_fail(expr_opt) => {
bot = true;
- alt expr_opt {
+ match expr_opt {
none => {/* do nothing */ }
some(e) => {
check_expr_with(fcx, e,
ast::expr_again => { fcx.write_bot(id); bot = true; }
ast::expr_ret(expr_opt) => {
bot = true;
- let ret_ty = alt fcx.indirect_ret_ty {
+ let ret_ty = match fcx.indirect_ret_ty {
some(t) => t, none => fcx.ret_ty
};
- alt expr_opt {
- none => alt fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) {
+ match expr_opt {
+ none => match fcx.mk_eqty(ret_ty, ty::mk_nil(tcx)) {
result::ok(_) => { /* fall through */ }
result::err(_) => {
tcx.sess.span_err(
ast::expr_fn_block(decl, body, cap_clause) => {
// Take the prototype from the expected type, but default to block:
let proto = unpack_expected(fcx, expected, |sty|
- alt sty { ty::ty_fn({proto, _}) => some(proto), _ => none }
+ match sty { ty::ty_fn({proto, _}) => some(proto), _ => none }
).get_default(ast::proto_box);
check_expr_fn(fcx, expr, proto, decl, body, false, expected);
capture::check_capture_clause(tcx, expr.id, cap_clause);
// 1. a closure that returns a bool is expected
// 2. the cloure that was given returns unit
let expected_sty = unpack_expected(fcx, expected, |x| some(x));
- let (inner_ty, proto) = alt expected_sty {
+ let (inner_ty, proto) = match expected_sty {
some(ty::ty_fn(fty)) => {
- alt infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) {
+ match infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) {
result::ok(_) => (),
result::err(err) => {
tcx.sess.span_fatal(
type");
}
};
- alt check b.node {
+ match check b.node {
ast::expr_fn_block(decl, body, cap_clause) => {
check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
}
let block_ty = structurally_resolved_type(
fcx, expr.span, fcx.node_ty(b.id));
- alt check ty::get(block_ty).struct {
+ match check ty::get(block_ty).struct {
ty::ty_fn(fty) => {
fcx.write_ty(expr.id, ty::mk_fn(tcx, {output: ty::mk_bool(tcx)
with fty}));
}
ast::expr_do_body(b) => {
let expected_sty = unpack_expected(fcx, expected, |x| some(x));
- let (inner_ty, proto) = alt expected_sty {
+ let (inner_ty, proto) = match expected_sty {
some(ty::ty_fn(fty)) => {
(ty::mk_fn(tcx, fty), fty.proto)
}
passed to a `do` function");
}
};
- alt check b.node {
+ match check b.node {
ast::expr_fn_block(decl, body, cap_clause) => {
check_expr_fn(fcx, b, proto, decl, body, true, some(inner_ty));
demand::suptype(fcx, b.span, inner_ty, fcx.expr_ty(b));
}
let block_ty = structurally_resolved_type(
fcx, expr.span, fcx.node_ty(b.id));
- alt check ty::get(block_ty).struct {
+ match check ty::get(block_ty).struct {
ty::ty_fn(fty) => {
fcx.write_ty(expr.id, ty::mk_fn(tcx, fty));
}
// If this is an unchecked block, turn off purity-checking
bot = check_block(fcx, b);
let typ =
- alt b.node.expr {
+ match b.node.expr {
some(expr) => fcx.expr_ty(expr),
none => ty::mk_nil(tcx)
};
debug!{"t_1=%s", fcx.infcx.ty_to_str(t_1)};
debug!{"t_e=%s", fcx.infcx.ty_to_str(t_e)};
- alt ty::get(t_1).struct {
+ match ty::get(t_1).struct {
// This will be looked up later on
ty::ty_trait(*) => (),
let mut elt_ts = ~[];
vec::reserve(elt_ts, vec::len(elts));
let flds = unpack_expected(fcx, expected, |sty| {
- alt sty { ty::ty_tup(flds) => some(flds), _ => none }
+ match sty { ty::ty_tup(flds) => some(flds), _ => none }
});
for elts.eachi |i, e| {
check_expr(fcx, e, flds.map(|fs| fs[i]));
some(fcx.expr_ty(base.get()))
} else { expected };
let flds = unpack_expected(fcx, expected, |sty|
- alt sty { ty::ty_rec(flds) => some(flds), _ => none }
+ match sty { ty::ty_rec(flds) => some(flds), _ => none }
);
let fields_t = vec::map(fields, |f| {
bot |= check_expr(fcx, f.node.expr, flds.chain(|flds|
// should be f.node.expr.span, not f.span
respan(f.node.expr.span, {ident: f.node.ident, mt: expr_mt})
});
- alt base {
+ match base {
none => {
fn get_node(f: spanned<field>) -> field { f.node }
let typ = ty::mk_rec(tcx, vec::map(fields_t, get_node));
}
some(bexpr) => {
let bexpr_t = fcx.expr_ty(bexpr);
- let base_fields = alt structure_of(fcx, expr.span, bexpr_t) {
+ let base_fields = match structure_of(fcx, expr.span, bexpr_t) {
ty::ty_rec(flds) => flds,
_ => {
tcx.sess.span_fatal(expr.span,
ast::expr_struct(path, fields, base_expr) => {
// Resolve the path.
let class_id;
- alt tcx.def_map.find(id) {
+ match tcx.def_map.find(id) {
some(ast::def_class(type_def_id, _)) => {
class_id = type_def_id;
}
if class_id.crate == ast::local_crate {
region_parameterized =
tcx.region_paramd_items.contains_key(class_id.node);
- alt tcx.items.find(class_id.node) {
+ match tcx.items.find(class_id.node) {
some(ast_map::node_item(@{
node: ast::item_class(type_parameters, _, _, _, _),
_
// Typecheck each field.
for fields.each |field| {
- alt class_field_map.find(*field.node.ident) {
+ match class_field_map.find(*field.node.ident) {
none => {
tcx.sess.span_err(field.span,
fmt!{"structure has no field named \
let base_t = do_autoderef(fcx, expr.span, raw_base_t);
bot |= check_expr(fcx, idx, none);
let idx_t = fcx.expr_ty(idx);
- alt ty::index_sty(tcx, structure_of(fcx, expr.span, base_t)) {
+ match ty::index_sty(tcx, structure_of(fcx, expr.span, base_t)) {
some(mt) => {
require_integral(fcx, idx.span, idx_t);
fcx.write_ty(id, mt.ty);
none => {
let resolved = structurally_resolved_type(fcx, expr.span,
raw_base_t);
- alt lookup_op_method(fcx, expr, base, resolved, ~"index",
+ match lookup_op_method(fcx, expr, base, resolved, ~"index",
~[idx]) {
some((ret_ty, _)) => fcx.write_ty(id, ret_ty),
_ => {
debug!{"type of expr %s is %s, expected is %s",
syntax::print::pprust::expr_to_str(expr),
ty_to_str(tcx, fcx.expr_ty(expr)),
- alt expected {
+ match expected {
some(t) => ty_to_str(tcx, t),
_ => ~"empty"
}};
let t = ty::mk_var(fcx.ccx.tcx, fcx.locals.get(local.node.id));
fcx.write_ty(local.node.id, t);
- alt local.node.init {
+ match local.node.init {
some(init) => {
bot = check_decl_initializer(fcx, local.node.id, init);
}
fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
let mut node_id;
let mut bot = false;
- alt stmt.node {
+ match stmt.node {
ast::stmt_decl(decl, id) => {
node_id = id;
- alt decl.node {
+ match decl.node {
ast::decl_local(ls) => for ls.each |l| {
bot |= check_decl_local(fcx, l);
}
}
fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
- let fcx = alt blk.node.rules {
+ let fcx = match blk.node.rules {
ast::unchecked_blk => @fn_ctxt_({purity: ast::impure_fn with **fcx0}),
ast::unsafe_blk => @fn_ctxt_({purity: ast::unsafe_fn with **fcx0}),
ast::default_blk => fcx0
let mut warned = false;
for blk.node.stmts.each |s| {
if bot && !warned &&
- alt s.node {
+ match s.node {
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) => {
true
}
bot |= check_stmt(fcx, s);
}
- alt blk.node.expr {
+ match blk.node.expr {
none => fcx.write_nil(blk.node.id),
some(e) => {
if bot && !warned {
let mut disr_val = 0;
let mut variants = ~[];
for vs.each |v| {
- alt v.node.disr_expr {
+ match v.node.disr_expr {
some(e) => {
let fcx = blank_fn_ctxt(ccx, rty, e.id);
check_expr(fcx, e, none);
// Also, check_expr (from check_const pass) doesn't guarantee that
// the expression in an form that eval_const_expr can handle, so
// we may still get an internal compiler error
- alt const_eval::eval_const_expr(ccx.tcx, e) {
+ match const_eval::eval_const_expr(ccx.tcx, e) {
const_eval::const_int(val) => {
disr_val = val as int;
}
// Check that it is possible to represent this enum:
let mut outer = true, did = local_def(id);
if ty::type_structurally_contains(ccx.tcx, rty, |sty| {
- alt sty {
+ match sty {
ty::ty_enum(id, _) if id == did => {
if outer { outer = false; false }
else { true }
}
fn lookup_local(fcx: @fn_ctxt, sp: span, id: ast::node_id) -> tv_vid {
- alt fcx.locals.find(id) {
+ match fcx.locals.find(id) {
some(x) => x,
_ => {
fcx.ccx.tcx.sess.span_fatal(sp,
fn ty_param_bounds_and_ty_for_def(fcx: @fn_ctxt, sp: span, defn: ast::def) ->
ty_param_bounds_and_ty {
- alt defn {
+ match defn {
ast::def_arg(nid, _) => {
assert (fcx.locals.contains_key(nid));
let typ = ty::mk_var(fcx.ccx.tcx, lookup_local(fcx, sp, nid));
return no_params(typ);
}
ast::def_self(_) => {
- alt fcx.self_info {
+ match fcx.self_info {
some(self_info) => {
return no_params(self_info.self_ty);
}
// determine the region bound, using the value given by the user
// (if any) and otherwise using a fresh region variable
- let self_r = alt pth.rp {
+ let self_r = match pth.rp {
some(r) if !tpt.rp => {
fcx.ccx.tcx.sess.span_err
(sp, ~"this item is not region-parameterized");
// Resolves `typ` by a single level if `typ` is a type variable. If no
// resolution is possible, then an error is reported.
fn structurally_resolved_type(fcx: @fn_ctxt, sp: span, tp: ty::t) -> ty::t {
- alt infer::resolve_type(fcx.infcx, tp, force_tvar) {
+ match infer::resolve_type(fcx.infcx, tp, force_tvar) {
result::ok(t_s) if !ty::type_is_var(t_s) => return t_s,
_ => {
fcx.ccx.tcx.sess.span_fatal
fn ast_expr_vstore_to_vstore(fcx: @fn_ctxt, e: @ast::expr, n: uint,
v: ast::vstore) -> ty::vstore {
- alt v {
+ match v {
ast::vstore_fixed(none) => ty::vstore_fixed(n),
ast::vstore_fixed(some(u)) => {
if n != u {
}
ast::vstore_uniq => ty::vstore_uniq,
ast::vstore_box => ty::vstore_box,
- ast::vstore_slice(a_r) => alt fcx.block_region() {
+ ast::vstore_slice(a_r) => match fcx.block_region() {
result::ok(b_r) => {
let rscope = in_anon_rscope(fcx, b_r);
let r = astconv::ast_region_to_region(fcx, rscope, e.span, a_r);
ccx.tcx, ty,
|_r| {},
|t| {
- alt ty::get(t).struct {
+ match ty::get(t).struct {
ty::ty_param({idx, _}) => { tps_used[idx] = true; }
_ => ()
}
{mode: ast::expl(m), ty: ty}
}
let tcx = ccx.tcx;
- let (n_tps, inputs, output) = alt *it.ident {
+ let (n_tps, inputs, output) = match *it.ident {
~"size_of" |
~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint(ccx.tcx)),
~"init" => (1u, ~[], param(ccx, 0u)),
let mut result_ty = fcx.infcx.next_ty_var();
let mut arm_non_bot = false;
for arms.each |arm| {
- alt arm.guard {
+ match arm.guard {
some(e) => { check_expr_with(fcx, e, ty::mk_bool(tcx)); },
none => ()
}
instantiate_path(pcx.fcx, path, enum_tpt, pat.span, pat.id);
// Take the enum type params out of `expected`.
- alt structure_of(pcx.fcx, pat.span, expected) {
+ match structure_of(pcx.fcx, pat.span, expected) {
ty::ty_enum(_, expected_substs) => {
// check that the type of the value being matched is a subtype
// of the type of the pattern:
tcx, v_def_ids.enm, v_def_ids.var);
vinfo.args.map(|t| { ty::subst(tcx, expected_substs, t) })
};
- let arg_len = arg_types.len(), subpats_len = alt subpats {
+ let arg_len = arg_types.len(), subpats_len = match subpats {
none => arg_len,
some(ps) => ps.len()
};
let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx;
- alt pat.node {
+ match pat.node {
ast::pat_wild => {
fcx.write_ty(pat.id, expected);
}
demand::suptype(fcx, pat.span, ct, typ);
}
fcx.write_ty(pat.id, typ);
- alt sub {
+ match sub {
some(p) => check_pat(pcx, p, expected),
_ => ()
}
check_pat_variant(pcx, pat, path, subpats, expected);
}
ast::pat_rec(fields, etc) => {
- let ex_fields = alt structure_of(fcx, pat.span, expected) {
+ let ex_fields = match structure_of(fcx, pat.span, expected) {
ty::ty_rec(fields) => fields,
_ => {
tcx.sess.span_fatal
str::eq(name, f.ident)
}
for fields.each |f| {
- alt vec::find(ex_fields, |a| matches(f.ident, a)) {
+ match vec::find(ex_fields, |a| matches(f.ident, a)) {
some(field) => {
check_pat(pcx, f.pat, field.mt.ty);
}
fcx.write_ty(pat.id, expected);
}
ast::pat_tup(elts) => {
- let ex_elts = alt structure_of(fcx, pat.span, expected) {
+ let ex_elts = match structure_of(fcx, pat.span, expected) {
ty::ty_tup(elts) => elts,
_ => {
tcx.sess.span_fatal
fcx.write_ty(pat.id, expected);
}
ast::pat_box(inner) => {
- alt structure_of(fcx, pat.span, expected) {
+ match structure_of(fcx, pat.span, expected) {
ty::ty_box(e_inner) => {
check_pat(pcx, inner, e_inner.ty);
fcx.write_ty(pat.id, expected);
}
}
ast::pat_uniq(inner) => {
- alt structure_of(fcx, pat.span, expected) {
+ match structure_of(fcx, pat.span, expected) {
ty::ty_uniq(e_inner) => {
check_pat(pcx, inner, e_inner.ty);
fcx.write_ty(pat.id, expected);
expected: ty::t, actual: ty::t) {
// n.b.: order of actual, expected is reversed
- alt infer::mk_subty(fcx.infcx, actual, expected) {
+ match infer::mk_subty(fcx.infcx, actual, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
fn eqtype(fcx: @fn_ctxt, sp: span,
expected: ty::t, actual: ty::t) {
- alt infer::mk_eqty(fcx.infcx, actual, expected) {
+ match infer::mk_eqty(fcx.infcx, actual, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
fcx.report_mismatched_types(sp, expected, actual, err);
fn assign(fcx: @fn_ctxt, sp: span, borrow_lb: ast::node_id,
expected: ty::t, expr: @ast::expr) {
let expr_ty = fcx.expr_ty(expr);
- alt fcx.mk_assignty(expr, borrow_lb, expr_ty, expected) {
+ match fcx.mk_assignty(expr, borrow_lb, expr_ty, expected) {
result::ok(()) => { /* ok */ }
result::err(err) => {
fcx.report_mismatched_types(sp, expected, expr_ty, err);
impl_ty: ty::t,
method_info: MethodInfo)
-> ty::t {
- alt method_info.self_type {
+ match method_info.self_type {
sty_by_ref | sty_value => {
impl_ty
}
// Determine if there are any inherent methods we can call.
let optional_inherent_methods;
- alt get_base_type_def_id(self.fcx.infcx,
+ match get_base_type_def_id(self.fcx.infcx,
self.self_expr.span,
self.self_ty) {
none => {
loop {
// First, see whether this is a bounded parameter.
- alt ty::get(self.self_ty).struct {
+ match ty::get(self.self_ty).struct {
ty::ty_param(p) => {
self.add_candidates_from_param(p.idx, p.def_id);
}
if self.candidates.len() > 0u { break; }
// check whether we can autoderef and if so loop around again.
- alt ty::deref(self.tcx(), self.self_ty, false) {
+ match ty::deref(self.tcx(), self.self_ty, false) {
none => break,
some(mt) => {
self.self_ty = mt.ty;
~"multiple applicable methods in scope");
for self.candidates.eachi |i, candidate| {
- alt candidate.entry.origin {
+ match candidate.entry.origin {
method_static(did) => {
self.report_static_candidate(i, did);
}
fn report_static_candidate(idx: uint, did: ast::def_id) {
let span = if did.crate == ast::local_crate {
- alt check self.tcx().items.get(did.node) {
+ match check self.tcx().items.get(did.node) {
ast_map::node_method(m, _, _) => m.span,
}
} else {
let mut trait_bnd_idx = 0u; // count only trait bounds
let bounds = tcx.ty_param_bounds.get(did.node);
for vec::each(*bounds) |bound| {
- let (iid, bound_substs) = alt bound {
+ let (iid, bound_substs) = match bound {
ty::bound_copy | ty::bound_send | ty::bound_const |
ty::bound_owned => {
again; /* ok */
}
ty::bound_trait(bound_t) => {
- alt check ty::get(bound_t).struct {
+ match check ty::get(bound_t).struct {
ty::ty_trait(i, substs) => (i, substs)
}
}
};
let trt_methods = ty::trait_methods(tcx, iid);
- alt vec::position(*trt_methods, |m| m.ident == self.m_name) {
+ match vec::position(*trt_methods, |m| m.ident == self.m_name) {
none => {
/* check next bound */
trait_bnd_idx += 1u;
}
fn ty_from_did(did: ast::def_id) -> ty::t {
- alt check ty::get(ty::lookup_item_type(self.tcx(), did).ty).struct {
+ match check ty::get(ty::lookup_item_type(self.tcx(), did).ty).struct {
ty::ty_fn(fty) => {
ty::mk_fn(self.tcx(), {proto: ast::proto_box with fty})
}
}
/*
if did.crate == ast::local_crate {
- alt check self.tcx().items.get(did.node) {
+ match check self.tcx().items.get(did.node) {
ast_map::node_method(m, _, _) {
// NDM trait/impl regions
let mt = ty_of_method(self.fcx.ccx, m, ast::rp_none);
}
}
} else {
- alt check ty::get(csearch::get_type(self.tcx(), did).ty).struct {
+ match check ty::get(csearch::get_type(self.tcx(), did).ty)
+ .struct {
+
ty::ty_fn(fty) {
ty::mk_fn(self.tcx(), {proto: ast::proto_box with fty})
}
self.fcx.can_mk_subty(self.self_ty, impl_ty)
};
debug!{"matches = %?", matches};
- alt matches {
+ match matches {
result::err(_) => { /* keep looking */ }
result::ok(_) => {
if !self.candidate_impls.contains_key(im.did) {
use_assignability: bool) {
// Add inherent methods.
- alt optional_inherent_methods {
+ match optional_inherent_methods {
none => {
// Continue.
}
}
// Add trait methods.
- alt self.fcx.ccx.trait_map.find(self.expr.id) {
+ match self.fcx.ccx.trait_map.find(self.expr.id) {
none => {
// Should only happen for placement new right now.
}
self.def_id_to_str(trait_id)};
let coherence_info = self.fcx.ccx.coherence_info;
- alt coherence_info.extension_methods.find(trait_id) {
+ match coherence_info.extension_methods.find(trait_id) {
none => {
// Do nothing.
}
// Make the actual receiver type (cand.self_ty) assignable to the
// required receiver type (cand.rcvr_ty). If this method is not
// from an impl, this'll basically be a no-nop.
- alt self.fcx.mk_assignty(self.self_expr, self.borrow_lb,
+ match self.fcx.mk_assignty(self.self_expr, self.borrow_lb,
cand.self_ty, cand.rcvr_ty) {
result::ok(_) => (),
result::err(_) => {
fn visit_pat(p: @ast::pat, &&rcx: @rcx, v: rvt) {
let fcx = rcx.fcx;
- alt p.node {
+ match p.node {
ast::pat_ident(_, path, _)
if !pat_util::pat_is_variant(fcx.ccx.tcx.def_map, p) => {
debug!{"visit_pat binding=%s", *path.idents[0]};
fn visit_expr(e: @ast::expr, &&rcx: @rcx, v: rvt) {
debug!{"visit_expr(e=%s)", pprust::expr_to_str(e)};
- alt e.node {
+ match e.node {
ast::expr_path(*) => {
// Avoid checking the use of local variables, as we already
// check their definitions. The def'n always encloses the
// use. So if the def'n is enclosed by the region, then the
// uses will also be enclosed (and otherwise, an error will
// have been reported at the def'n site).
- alt lookup_def(rcx.fcx, e.span, e.id) {
+ match lookup_def(rcx.fcx, e.span, e.id) {
ast::def_local(*) | ast::def_arg(*) | ast::def_upvar(*) => return,
_ => ()
}
// is an extensive comment on the function
// check_cast_for_escaping_regions() in kind.rs explaining how
// it goes about doing that.
- alt rcx.resolve_node_type(e.id) {
+ match rcx.resolve_node_type(e.id) {
result::err(_) => { return; /* typeck will fail anyhow */ }
result::ok(target_ty) => {
- alt ty::get(target_ty).struct {
+ match ty::get(target_ty).struct {
ty::ty_trait(_, substs) => {
- let trait_region = alt substs.self_r {
+ let trait_region = match substs.self_r {
some(r) => {r}
none => {ty::re_static}
};
// Try to resolve the type. If we encounter an error, then typeck
// is going to fail anyway, so just stop here and let typeck
// report errors later on in the writeback phase.
- let ty = alt rcx.resolve_node_type(id) {
+ let ty = match rcx.resolve_node_type(id) {
result::err(_) => return true,
result::ok(ty) => ty
};
ppaux::region_to_str(tcx, encl_region),
ppaux::region_to_str(tcx, region)};
- alt region {
+ match region {
ty::re_bound(_) => {
// a bound region is one which appears inside an fn type.
// (e.g., the `&` in `fn(&T)`). Such regions need not be
_ => ()
}
- alt rcx.fcx.mk_subr(encl_region, region) {
+ match rcx.fcx.mk_subr(encl_region, region) {
result::err(_) => {
let region1 = rcx.fcx.infcx.resolve_region_if_possible(region);
tcx.sess.span_err(
// Take self_info apart; the self_ty part is the only one we want
// to update here.
- let self_ty = alt self_info {
+ let self_ty = match self_info {
some(s) => some(s.self_ty),
none => none
};
// Glue updated self_ty back together with its original node_id.
- let new_self_info = alt self_info {
- some(s) => alt check t_self {
+ let new_self_info = match self_info {
+ some(s) => match check t_self {
some(t) => some({self_ty: t, node_id: s.node_id})
// this 'none' case shouldn't happen
}
return {isr: isr,
self_info: new_self_info,
- fn_ty: alt check ty::get(t_fn).struct { ty::ty_fn(o) => o }};
+ fn_ty: match check ty::get(t_fn).struct { ty::ty_fn(o) => o }};
// Takes `isr`, a (possibly empty) mapping from in-scope region
fn append_isr(isr: isr_alist,
to_r: fn(ty::bound_region) -> ty::region,
r: ty::region) -> isr_alist {
- alt r {
+ match r {
ty::re_free(_, _) | ty::re_static | ty::re_scope(_) |
ty::re_var(_) => {
isr
}
ty::re_bound(br) => {
- alt isr.find(br) {
+ match isr.find(br) {
some(_) => isr,
none => @cons((br, to_r(br)), isr)
}
ty: ty::t) -> ty::t {
do ty::fold_regions(tcx, ty) |r, in_fn| {
- alt r {
+ match r {
// As long as we are not within a fn() type, `&T` is
// mapped to the free region anon_r. But within a fn
// type, it remains bound.
ty::re_bound(ty::br_anon) if in_fn => r,
ty::re_bound(br) => {
- alt isr.find(br) {
+ match isr.find(br) {
// In most cases, all named, bound regions will be
// mapped to some free region.
some(fr) => fr,
fn has_trait_bounds(tps: ~[ty::param_bounds]) -> bool {
vec::any(tps, |bs| {
vec::any(*bs, |b| {
- alt b { ty::bound_trait(_) => true, _ => false }
+ match b { ty::bound_trait(_) => true, _ => false }
})
})
}
let mut result = ~[], i = 0u;
for substs.tps.each |ty| {
for vec::each(*bounds[i]) |bound| {
- alt bound {
+ match bound {
ty::bound_trait(i_ty) => {
let i_ty = ty::subst(tcx, substs, i_ty);
vec::push(result, lookup_vtable(fcx, sp, ty, i_ty,
// use a dummy type just to package up the substs that need fixing up
let t = ty::mk_trait(tcx, id, substs);
let t_f = fixup_ty(fcx, sp, t);
- alt check ty::get(t_f).struct {
+ match check ty::get(t_f).struct {
ty::ty_trait(_, substs_f) => substs_f,
}
}
let _i = indenter();
let tcx = fcx.ccx.tcx;
- let (trait_id, trait_substs) = alt check ty::get(trait_ty).struct {
+ let (trait_id, trait_substs) = match check ty::get(trait_ty).struct {
ty::ty_trait(did, substs) => (did, substs)
};
let ty = fixup_ty(fcx, sp, ty);
- alt ty::get(ty).struct {
+ match ty::get(ty).struct {
ty::ty_param({idx: n, def_id: did}) => {
let mut n_bound = 0u;
for vec::each(*tcx.ty_param_bounds.get(did.node)) |bound| {
- alt bound {
+ match bound {
ty::bound_send | ty::bound_copy | ty::bound_const |
ty::bound_owned => {
/* ignore */
}
ty::bound_trait(ity) => {
- alt check ty::get(ity).struct {
+ match check ty::get(ity).struct {
ty::ty_trait(idid, substs) => {
if trait_id == idid {
debug!{"(checking vtable) @0 relating ty to trait ty
let mut impls_seen = new_def_hash();
- alt fcx.ccx.coherence_info.extension_methods.find(trait_id) {
+ match fcx.ccx.coherence_info.extension_methods.find(trait_id) {
none => {
// Nothing found. Continue.
}
// find the trait that im implements (if any)
for vec::each(ty::impl_traits(tcx, im.did)) |of_ty| {
// it must have the same id as the expected one
- alt ty::get(of_ty).struct {
+ match ty::get(of_ty).struct {
ty::ty_trait(id, _) if id != trait_id => again,
_ => { /* ok */ }
}
let {substs: substs, ty: for_ty} =
impl_self_ty(fcx, im.did);
let im_bs = ty::lookup_item_type(tcx, im.did).bounds;
- alt fcx.mk_subty(ty, for_ty) {
+ match fcx.mk_subty(ty, for_ty) {
result::err(_) => again,
result::ok(()) => ()
}
}
}
- alt found.len() {
+ match found.len() {
0u => { /* fallthrough */ }
1u => { return found[0]; }
_ => {
fn fixup_ty(fcx: @fn_ctxt, sp: span, ty: ty::t) -> ty::t {
let tcx = fcx.ccx.tcx;
- alt resolve_type(fcx.infcx, ty, resolve_all | force_all) {
+ match resolve_type(fcx.infcx, ty, resolve_all | force_all) {
result::ok(new_type) => new_type,
result::err(e) => {
tcx.sess.span_fatal(
let trait_ty = ty::subst_tps(tcx, impl_tys, ity);
debug!{"(connect trait tps) trait type is %?, impl did is %?",
ty::get(trait_ty).struct, impl_did};
- alt check ty::get(trait_ty).struct {
+ match check ty::get(trait_ty).struct {
ty::ty_trait(_, substs) => {
vec::iter2(substs.tps, trait_tys,
|a, b| demand::suptype(fcx, sp, a, b));
fn resolve_expr(ex: @ast::expr, &&fcx: @fn_ctxt, v: visit::vt<@fn_ctxt>) {
let cx = fcx.ccx;
- alt ex.node {
+ match ex.node {
ast::expr_path(*) => {
- alt fcx.opt_node_ty_substs(ex.id) {
+ match fcx.opt_node_ty_substs(ex.id) {
some(substs) => {
let did = ast_util::def_id_of_def(cx.tcx.def_map.get(ex.id));
let item_ty = ty::lookup_item_type(cx.tcx, did);
ast::expr_field(*) | ast::expr_binary(*) |
ast::expr_unary(*) | ast::expr_assign_op(*) |
ast::expr_index(*) => {
- alt cx.method_map.find(ex.id) {
+ match cx.method_map.find(ex.id) {
some({origin: method_static(did), _}) => {
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
if has_trait_bounds(*bounds) {
- let callee_id = alt ex.node {
+ let callee_id = match ex.node {
ast::expr_field(_, _, _) => ex.id,
_ => ex.callee_id
};
}
ast::expr_cast(src, _) => {
let target_ty = fcx.expr_ty(ex);
- alt ty::get(target_ty).struct {
+ match ty::get(target_ty).struct {
ty::ty_trait(*) => {
/*
Look up vtables for the type we're casting to,
fn resolve_type_vars_in_type(fcx: @fn_ctxt, sp: span, typ: ty::t) ->
option<ty::t> {
if !ty::type_needs_infer(typ) { return some(typ); }
- alt resolve_type(fcx.infcx, typ, resolve_all | force_all) {
+ match resolve_type(fcx.infcx, typ, resolve_all | force_all) {
result::ok(new_type) => return some(new_type),
result::err(e) => {
if !fcx.ccx.tcx.sess.has_errors() {
-> option<ty::t> {
let fcx = wbcx.fcx, tcx = fcx.ccx.tcx;
let n_ty = fcx.node_ty(id);
- alt resolve_type_vars_in_type(fcx, sp, n_ty) {
+ match resolve_type_vars_in_type(fcx, sp, n_ty) {
none => {
wbcx.success = false;
return none;
debug!{"resolve_type_vars_for_node(id=%d, n_ty=%s, t=%s)",
id, ty_to_str(tcx, n_ty), ty_to_str(tcx, t)};
write_ty_to_tcx(tcx, id, t);
- alt fcx.opt_node_ty_substs(id) {
+ match fcx.opt_node_ty_substs(id) {
some(substs) => {
let mut new_tps = ~[];
for substs.tps.each |subst| {
- alt resolve_type_vars_in_type(fcx, sp, subst) {
+ match resolve_type_vars_in_type(fcx, sp, subst) {
some(t) => vec::push(new_tps, t),
none => { wbcx.success = false; return none; }
}
fn visit_expr(e: @ast::expr, wbcx: wb_ctxt, v: wb_vt) {
if !wbcx.success { return; }
resolve_type_vars_for_node(wbcx, e.span, e.id);
- alt e.node {
+ match e.node {
ast::expr_fn(_, decl, _, _) |
ast::expr_fn_block(decl, _, _) => {
do vec::iter(decl.inputs) |input| {
// Just in case we never constrained the mode to anything,
// constrain it to the default for the type in question.
- alt (r_ty, input.mode) {
+ match (r_ty, input.mode) {
(some(t), ast::infer(_)) => {
let tcx = wbcx.fcx.ccx.tcx;
let m_def = ty::default_arg_mode_for_ty(t);
if !wbcx.success { return; }
let var_id = lookup_local(wbcx.fcx, l.span, l.node.id);
let var_ty = ty::mk_var(wbcx.fcx.tcx(), var_id);
- alt resolve_type(wbcx.fcx.infcx, var_ty, resolve_all | force_all) {
+ match resolve_type(wbcx.fcx.infcx, var_ty, resolve_all | force_all) {
result::ok(lty) => {
debug!{"Type for local %s (id %d) resolved to %s",
pat_to_str(l.node.pat), l.node.id,
-> option<t> {
let resolved_type;
- alt resolve_type(inference_context,
+ match resolve_type(inference_context,
original_type,
resolve_ivar) {
ok(resulting_type) if !type_is_var(resulting_type) => {
}
}
- alt get(resolved_type).struct {
+ match get(resolved_type).struct {
ty_box(base_mutability_and_type) |
ty_uniq(base_mutability_and_type) |
ty_ptr(base_mutability_and_type) |
original_type: t)
-> option<def_id> {
- alt get_base_type(inference_context, span, original_type) {
+ match get_base_type(inference_context, span, original_type) {
none => {
return none;
}
some(base_type) => {
- alt get(base_type).struct {
+ match get(base_type).struct {
ty_enum(def_id, _) |
ty_class(def_id, _) |
ty_trait(def_id, _) => {
visit_item: |item| {
debug!{"(checking coherence) item '%s'", *item.ident};
- alt item.node {
+ match item.node {
item_impl(_, associated_traits, _, _) => {
self.check_implementation(item, associated_traits);
}
'%s'",
*item.ident};
- alt get_base_type_def_id(self.inference_context,
+ match get_base_type_def_id(self.inference_context,
item.span,
self_type.ty) {
none => {
// Add the implementation to the mapping from implementation to base
// type def ID, if there is a base type for this implementation.
- alt get_base_type_def_id(self.inference_context,
+ match get_base_type_def_id(self.inference_context,
item.span,
self_type.ty) {
none => {
fn add_inherent_method(base_def_id: def_id, implementation: @Impl) {
let implementation_list;
- alt self.crate_context.coherence_info.inherent_methods
+ match self.crate_context.coherence_info.inherent_methods
.find(base_def_id) {
none => {
fn add_trait_method(trait_id: def_id, implementation: @Impl) {
let implementation_list;
- alt self.crate_context.coherence_info.extension_methods
+ match self.crate_context.coherence_info.extension_methods
.find(trait_id) {
none => {
visit_crate(*crate, (), mk_vt(@{
visit_item: |item, _context, visitor| {
- alt item.node {
+ match item.node {
item_mod(module_) => {
// First, gather up all privileged types.
let privileged_types =
}
}
item_impl(_, associated_traits, _, _) => {
- alt self.base_type_def_ids.find(local_def(item.id)) {
+ match self.base_type_def_ids.find(
+ local_def(item.id)) {
+
none => {
// Nothing to do.
}
fn gather_privileged_types(items: ~[@item]) -> @dvec<def_id> {
let results = @dvec();
for items.each |item| {
- alt item.node {
+ match item.node {
item_class(*) | item_enum(*) | item_trait(*) => {
results.push(local_def(item.id));
}
// Converts an implementation in the AST to an Impl structure.
fn create_impl_from_item(item: @item) -> @Impl {
- alt item.node {
+ match item.node {
item_impl(ty_params, _, _, ast_methods) => {
let mut methods = ~[];
for ast_methods.each |ast_method| {
item_class(ty_params, _, class_members, _, _) => {
let mut methods = ~[];
for class_members.each |class_member| {
- alt class_member.node {
+ match class_member.node {
instance_var(*) => {
// Nothing to do.
}
fn span_of_impl(implementation: @Impl) -> span {
assert implementation.did.crate == local_crate;
- alt self.crate_context.tcx.items.find(implementation.did.node) {
+ match self.crate_context.tcx.items.find(implementation.did.node) {
some(node_item(item, _)) => {
return item.span;
}
for (*implementations).each |implementation| {
// Make sure we don't visit the same implementation
// multiple times.
- alt impls_seen.find(implementation.did) {
+ match impls_seen.find(implementation.did) {
none => {
// Good. Continue.
impls_seen.insert(implementation.did, ());
// types.
if associated_traits.len() == 0 {
- alt get_base_type_def_id(self.inference_context,
+ match get_base_type_def_id(self.inference_context,
dummy_sp(),
self_type.ty) {
none => {
// Record all the trait methods.
for associated_traits.each |trait_type| {
- alt get(trait_type).struct {
+ match get(trait_type).struct {
ty_trait(trait_id, _) => {
self.add_trait_method(trait_id, implementation);
}
// implementation to base type def ID, if there is a base
// type for this implementation.
- alt get_base_type_def_id(self.inference_context,
+ match get_base_type_def_id(self.inference_context,
dummy_sp(),
self_type.ty) {
none => {
for each_path(crate_store, crate_number) |path_entry| {
let module_def_id;
- alt path_entry.def_like {
+ match path_entry.def_like {
dl_def(def_mod(def_id)) => {
module_def_id = def_id;
}
for crate.node.module.items.each |crate_item| {
if *crate_item.ident == ~"intrinsic" {
- alt crate_item.node {
+ match crate_item.node {
ast::item_mod(m) => {
for m.items.each |intrinsic_item| {
let def_id = { crate: ast::local_crate,
node: intrinsic_item.id };
let substs = {self_r: none, self_ty: none, tps: ~[]};
- alt intrinsic_item.node {
+ match intrinsic_item.node {
ast::item_trait(*) => {
let ty = ty::mk_trait(ccx.tcx, def_id, substs);
ccx.tcx.intrinsic_defs.insert
if id.crate != ast::local_crate {
csearch::get_type(self.tcx, id)
} else {
- alt self.tcx.items.find(id.node) {
+ match self.tcx.items.find(id.node) {
some(ast_map::node_item(item, _)) => {
ty_of_item(self, item)
}
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.contains_key(id);
- alt check tcx.items.get(id) {
+ match check tcx.items.get(id) {
ast_map::node_item(@{node: ast::item_trait(_, _, ms), _}, _) => {
store_methods::<ast::trait_method>(ccx, id, ms, |m| {
- alt m {
+ match m {
required(ty_m) => {
ty_of_ty_method(ccx, ty_m, rp)
}
ensure_trait_methods(ccx, did.node);
}
for vec::each(*ty::trait_methods(tcx, did)) |trait_m| {
- alt vec::find(impl_ms, |impl_m| trait_m.ident == impl_m.mty.ident) {
+ match vec::find(impl_ms, |impl_m| trait_m.ident == impl_m.mty.ident) {
some({mty: impl_m, id, span}) => {
if impl_m.purity != trait_m.purity {
ccx.tcx.sess.span_err(
// implementation in the trait itself. If not, raise a
// "missing method" error.
- alt tcx.items.get(did.node) {
+ match tcx.items.get(did.node) {
ast_map::node_item(
@{node: ast::item_trait(_, _, trait_methods), _}, _) => {
let (_, provided_methods) =
split_trait_methods(trait_methods);
- alt vec::find(provided_methods, |provided_method|
+ match vec::find(provided_methods, |provided_method|
provided_method.ident == trait_m.ident) {
some(m) => {
// If there's a provided method with the name we
let tcx = ccx.tcx;
let rp = tcx.region_paramd_items.contains_key(it.id);
debug!{"convert: item %s with id %d rp %b", *it.ident, it.id, rp};
- alt it.node {
+ match it.node {
// These don't define types.
ast::item_foreign_mod(_) | ast::item_mod(_) => {}
ast::item_enum(variants, ty_params) => {
// type of the foreign item. We simply write it into the node type
// table.
let tpt = ty_of_foreign_item(ccx, i);
- alt i.node {
+ match i.node {
ast::foreign_item_fn(_, _) => {
write_ty_to_tcx(ccx.tcx, i.id, tpt.ty);
ccx.tcx.tcache.insert(local_def(i.id), tpt);
let rscope = type_rscope(rp);
- alt lookup_def_tcx(ccx.tcx, t.path.span, t.ref_id) {
+ match lookup_def_tcx(ccx.tcx, t.path.span, t.ref_id) {
ast::def_ty(t_id) => {
let tpt = astconv::ast_path_to_ty(ccx, rscope, t_id, t.path,
t.ref_id);
- alt ty::get(tpt.ty).struct {
+ match ty::get(tpt.ty).struct {
ty::ty_trait(*) => {
(t_id, tpt)
}
let def_id = local_def(it.id);
let tcx = ccx.tcx;
- alt tcx.tcache.find(def_id) {
+ match tcx.tcache.find(def_id) {
some(tpt) => return tpt,
_ => {}
}
let rp = tcx.region_paramd_items.contains_key(it.id);
- alt it.node {
+ match it.node {
ast::item_const(t, _) => {
let typ = ccx.to_ty(empty_rscope, t);
let tpt = no_params(typ);
return tpt;
}
ast::item_ty(t, tps) => {
- alt tcx.tcache.find(local_def(it.id)) {
+ match tcx.tcache.find(local_def(it.id)) {
some(tpt) => return tpt,
none => { }
}
fn ty_of_foreign_item(ccx: @crate_ctxt, it: @ast::foreign_item)
-> ty::ty_param_bounds_and_ty {
- alt it.node {
+ match it.node {
ast::foreign_item_fn(fn_decl, params) => {
return ty_of_foreign_fn_decl(ccx, fn_decl, params,
local_def(it.id));
fn compute_bounds(ccx: @crate_ctxt,
param: ast::ty_param) -> ty::param_bounds {
@do vec::flat_map(*param.bounds) |b| {
- alt b {
+ match b {
ast::bound_send => ~[ty::bound_send],
ast::bound_copy => ~[ty::bound_copy],
ast::bound_const => ~[ty::bound_const],
ast::bound_owned => ~[ty::bound_owned],
ast::bound_trait(t) => {
let ity = ast_ty_to_ty(ccx, empty_rscope, t);
- alt ty::get(ity).struct {
+ match ty::get(ity).struct {
ty::ty_trait(*) => {
~[ty::bound_trait(ity)]
}
}
@do params.map |param| {
- alt ccx.tcx.ty_param_bounds.find(param.id) {
+ match ccx.tcx.ty_param_bounds.find(param.id) {
some(bs) => bs,
none => {
let bounds = compute_bounds(ccx, param);
fn convert_integral_ty_to_int_ty_set(tcx: ty::ctxt, t: ty::t)
-> int_ty_set {
- alt get(t).struct {
- ty_int(int_ty) => alt int_ty {
+ match get(t).struct {
+ ty_int(int_ty) => match int_ty {
ast::ty_i8 => int_ty_set(INT_TY_SET_i8),
ast::ty_i16 => int_ty_set(INT_TY_SET_i16),
ast::ty_i32 => int_ty_set(INT_TY_SET_i32),
ast::ty_char => tcx.sess.bug(
~"char type passed to convert_integral_ty_to_int_ty_set()")
}
- ty_uint(uint_ty) => alt uint_ty {
+ ty_uint(uint_ty) => match uint_ty {
ast::ty_u8 => int_ty_set(INT_TY_SET_u8),
ast::ty_u16 => int_ty_set(INT_TY_SET_u16),
ast::ty_u32 => int_ty_set(INT_TY_SET_u32),
}
fn fixup_err_to_str(f: fixup_err) -> ~str {
- alt f {
+ match f {
unresolved_int_ty(_) => ~"unconstrained integral type",
unresolved_ty(_) => ~"unconstrained type",
cyclic_ty(_) => ~"cyclic type of infinite size",
fn resolve_borrowings(cx: infer_ctxt) {
for cx.borrowings.each |item| {
- alt resolve_region(cx, item.scope, resolve_all|force_all) {
+ match resolve_region(cx, item.scope, resolve_all|force_all) {
ok(region) => {
debug!{"borrowing for expr %d resolved to region %?, mutbl %?",
item.expr_id, region, item.mutbl};
impl methods<T:copy> of cres_helpers<T> for cres<T> {
fn to_ures() -> ures {
- alt self {
+ match self {
ok(_v) => ok(()),
err(e) => err(e)
}
impl<V:copy to_str> of to_str for bound<V> {
fn to_str(cx: infer_ctxt) -> ~str {
- alt self {
+ match self {
some(v) => v.to_str(cx),
none => ~"none"
}
impl of to_str for int_ty_set {
fn to_str(_cx: infer_ctxt) -> ~str {
- alt self {
+ match self {
int_ty_set(v) => uint::to_str(v, 10u)
}
}
impl<V:copy vid, T:copy to_str> of to_str for var_value<V,T> {
fn to_str(cx: infer_ctxt) -> ~str {
- alt self {
+ match self {
redirect(vid) => fmt!{"redirect(%s)", vid.to_str()},
root(pt, rk) => fmt!{"root(%s, %s)", pt.to_str(cx),
uint::to_str(rk, 10u)}
debug!{"try(tvbl=%u, rbl=%u)", tvbl, rbl};
let r <- f();
- alt r {
+ match r {
result::ok(_) => debug!{"try--ok"},
result::err(_) => {
debug!{"try--rollback"};
}
fn resolve_type_vars_if_possible(typ: ty::t) -> ty::t {
- alt resolve_type(self, typ, resolve_all) {
+ match resolve_type(self, typ, resolve_all) {
result::ok(new_type) => return new_type,
result::err(_) => return typ
}
}
fn resolve_region_if_possible(oldr: ty::region) -> ty::region {
- alt resolve_region(self, oldr, resolve_all) {
+ match resolve_region(self, oldr, resolve_all) {
result::ok(newr) => return newr,
result::err(_) => return oldr
}
-> node<V, T> {
let vid_u = vid.to_uint();
- alt vb.vals.find(vid_u) {
+ match vb.vals.find(vid_u) {
none => {
self.tcx.sess.bug(fmt!{"failed lookup of vid `%u`", vid_u});
}
some(var_val) => {
- alt var_val {
+ match var_val {
redirect(vid) => {
let nde = self.get(vb, vid);
if nde.root != vid {
debug!{"merge_bnd(%s,%s)", a.to_str(self), b.to_str(self)};
let _r = indenter();
- alt (a, b) {
+ match (a, b) {
(none, none) => ok(none),
(some(_), none) => ok(a),
(none, some(_)) => ok(b),
// If both A's UB and B's LB have already been bound to types,
// see if we can make those types subtypes.
- alt (a_bounds.ub, b_bounds.lb) {
+ match (a_bounds.ub, b_bounds.lb) {
(some(a_ub), some(b_lb)) => {
let r = self.try(|| a_ub.sub(self, b_lb));
- alt r {
+ match r {
ok(()) => return result::ok(()),
err(_) => { /*fallthrough */ }
}
debug!{"bnds(%s <: %s)", a.to_str(self), b.to_str(self)};
do indent {
- alt (a, b) {
+ match (a, b) {
(none, none) |
(some(_), none) |
(none, some(_)) => {
assert vec::is_empty(self.v_seen);
let rty = indent(|| self.resolve_type(typ) );
assert vec::is_empty(self.v_seen);
- alt self.err {
+ match self.err {
none => {
debug!{"Resolved to %s (modes=%x)",
ty_to_str(self.infcx.tcx, rty),
fn resolve_region_chk(orig: ty::region) -> fres<ty::region> {
self.err = none;
let resolved = indent(|| self.resolve_region(orig) );
- alt self.err {
+ match self.err {
none => ok(resolved),
some(e) => err(e)
}
indent(fn&() -> ty::t {
if !ty::type_needs_infer(typ) { return typ; }
- alt ty::get(typ).struct {
+ match ty::get(typ).struct {
ty::ty_var(vid) => {
self.resolve_ty_var(vid)
}
fn resolve_region(orig: ty::region) -> ty::region {
debug!{"Resolve_region(%s)", orig.to_str(self.infcx)};
- alt orig {
+ match orig {
ty::re_var(rid) => self.resolve_region_var(rid),
_ => orig
}
}
let nde = self.infcx.get(self.infcx.rb, rid);
let bounds = nde.possible_types;
- alt bounds {
+ match bounds {
{ ub:_, lb:some(r) } => { self.assert_not_rvar(rid, r); r }
{ ub:some(r), lb:_ } => { self.assert_not_rvar(rid, r); r }
{ ub:none, lb:none } => {
}
fn assert_not_rvar(rid: region_vid, r: ty::region) {
- alt r {
+ match r {
ty::re_var(rid2) => {
self.err = some(region_var_bound_by_region_var(rid, rid2));
}
let nde = self.infcx.get(self.infcx.tvb, vid);
let bounds = nde.possible_types;
- let t1 = alt bounds {
+ let t1 = match bounds {
{ ub:_, lb:some(t) } if !type_is_bot(t) => self.resolve_type(t),
{ ub:some(t), lb:_ } => self.resolve_type(t),
{ ub:_, lb:some(t) } => self.resolve_type(t),
// If there's only one type in the set of possible types, then
// that's the answer.
- alt single_type_contained_in(self.infcx.tcx, pt) {
+ match single_type_contained_in(self.infcx.tcx, pt) {
some(t) => t,
none => {
if self.should(force_ivar) {
fn assign_tys(anmnt: assignment, a: ty::t, b: ty::t) -> ures {
fn select(fst: option<ty::t>, snd: option<ty::t>) -> option<ty::t> {
- alt fst {
+ match fst {
some(t) => some(t),
- none => alt snd {
+ none => match snd {
some(t) => some(t),
none => none
}
anmnt, a.to_str(self), b.to_str(self)};
let _r = indenter();
- alt (ty::get(a).struct, ty::get(b).struct) {
+ match (ty::get(a).struct, ty::get(b).struct) {
(ty::ty_bot, _) => {
uok()
}
let _r = indenter();
fn is_borrowable(v: ty::vstore) -> bool {
- alt v {
+ match v {
ty::vstore_fixed(_) | ty::vstore_uniq | ty::vstore_box => true,
ty::vstore_slice(_) => false
}
}
- alt (a_bnd, b_bnd) {
+ match (a_bnd, b_bnd) {
(some(a_bnd), some(b_bnd)) => {
- alt (ty::get(a_bnd).struct, ty::get(b_bnd).struct) {
+ match (ty::get(a_bnd).struct, ty::get(b_bnd).struct) {
(ty::ty_box(mt_a), ty::ty_rptr(r_b, mt_b)) => {
let nr_b = ty::mk_box(self.tcx, {ty: mt_b.ty,
mutbl: m_const});
fn eq_opt_regions(infcx: infer_ctxt,
a: option<ty::region>,
b: option<ty::region>) -> cres<option<ty::region>> {
- alt (a, b) {
+ match (a, b) {
(none, none) => {
ok(none)
}
// Note: the self type parameter is (currently) always treated as
// *invariant* (otherwise the type system would be unsound).
- alt (a, b) {
+ match (a, b) {
(none, none) => {
ok(none)
}
self: C, vk: ty::terr_vstore_kind,
a: ty::vstore, b: ty::vstore) -> cres<ty::vstore> {
- alt (a, b) {
+ match (a, b) {
(ty::vstore_slice(a_r), ty::vstore_slice(b_r)) => {
do self.contraregions(a_r, b_r).chain |r| {
ok(ty::vstore_slice(r))
self: C, a: ty::t, b: ty::t) -> cres<ty::t> {
let tcx = self.infcx().tcx;
- alt (ty::get(a).struct, ty::get(b).struct) {
+ match (ty::get(a).struct, ty::get(b).struct) {
// The "subtype" ought to be handling cases involving bot or var:
(ty::ty_bot, _) |
(_, ty::ty_bot) |
a.to_str(self.infcx()),
b.to_str(self.infcx())};
do indent {
- alt (a, b) {
+ match (a, b) {
(ty::re_var(a_id), ty::re_var(b_id)) => {
do self.infcx().vars(self.rb, a_id, b_id).then {
ok(a)
return err(ty::terr_mutability);
}
- alt b.mutbl {
+ match b.mutbl {
m_mutbl => {
// If supertype is mut, subtype must match exactly
// (i.e., invariant if mut):
a.to_str(*self), b.to_str(*self)};
if a == b { return ok(a); }
do indent {
- alt (ty::get(a).struct, ty::get(b).struct) {
+ match (ty::get(a).struct, ty::get(b).struct) {
(ty::ty_bot, _) => {
ok(a)
}
m_const
};
- alt m {
+ match m {
m_imm | m_const => {
self.tys(a.ty, b.ty).chain(|t| ok({ty: t, mutbl: m}) )
}
}
fn purities(f1: purity, f2: purity) -> cres<purity> {
- alt (f1, f2) {
+ match (f1, f2) {
(unsafe_fn, _) | (_, unsafe_fn) => ok(unsafe_fn),
(impure_fn, _) | (_, impure_fn) => ok(impure_fn),
(extern_fn, _) | (_, extern_fn) => ok(extern_fn),
}
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
- alt (r1, r2) {
+ match (r1, r2) {
(ast::return_val, _) |
(_, ast::return_val) => ok(ast::return_val),
(ast::noreturn, ast::noreturn) => ok(ast::noreturn)
b.to_str(self.infcx())};
do indent {
- alt (a, b) {
+ match (a, b) {
(ty::re_static, _) | (_, ty::re_static) => {
ok(ty::re_static) // nothing lives longer than static
}
// at least as big as the block f_id". So, we can
// reasonably compare free regions and scopes:
let rm = self.infcx().tcx.region_map;
- alt region::nearest_common_ancestor(rm, f_id, s_id) {
+ match region::nearest_common_ancestor(rm, f_id, s_id) {
// if the free region's scope `f_id` is bigger than
// the scope region `s_id`, then the LUB is the free
// region itself:
// subtype of the region corresponding to an inner
// block.
let rm = self.infcx().tcx.region_map;
- alt region::nearest_common_ancestor(rm, a_id, b_id) {
+ match region::nearest_common_ancestor(rm, a_id, b_id) {
some(r_id) => ok(ty::re_scope(r_id)),
_ => ok(ty::re_static)
}
mt_to_str(tcx, a),
mt_to_str(tcx, b)};
- alt (a.mutbl, b.mutbl) {
+ match (a.mutbl, b.mutbl) {
// If one side or both is mut, then the GLB must use
// the precise type from the mut side.
(m_mutbl, m_const) => {
}
fn purities(f1: purity, f2: purity) -> cres<purity> {
- alt (f1, f2) {
+ match (f1, f2) {
(pure_fn, _) | (_, pure_fn) => ok(pure_fn),
(extern_fn, _) | (_, extern_fn) => ok(extern_fn),
(impure_fn, _) | (_, impure_fn) => ok(impure_fn),
}
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
- alt (r1, r2) {
+ match (r1, r2) {
(ast::return_val, ast::return_val) => {
ok(ast::return_val)
}
b.to_str(self.infcx())};
do indent {
- alt (a, b) {
+ match (a, b) {
(ty::re_static, r) | (r, ty::re_static) => {
// static lives longer than everything else
ok(r)
// is the scope `s_id`. Otherwise, as we do not know
// big the free region is precisely, the GLB is undefined.
let rm = self.infcx().tcx.region_map;
- alt region::nearest_common_ancestor(rm, f_id, s_id) {
+ match region::nearest_common_ancestor(rm, f_id, s_id) {
some(r_id) if r_id == f_id => ok(s),
_ => err(ty::terr_regions_differ(b, a))
}
// these: so, if one of these scopes is a subscope of the
// other, return it. Otherwise fail.
let rm = self.infcx().tcx.region_map;
- alt region::nearest_common_ancestor(rm, a_id, b_id) {
+ match region::nearest_common_ancestor(rm, a_id, b_id) {
some(r_id) if a_id == r_id => ok(b),
some(r_id) if b_id == r_id => ok(a),
_ => err(ty::terr_regions_differ(b, a))
b.to_str(self.infcx())};
if a == b { return ok(a); }
do indent {
- alt (ty::get(a).struct, ty::get(b).struct) {
+ match (ty::get(a).struct, ty::get(b).struct) {
(ty::ty_bot, _) => self.ty_bot(b),
(_, ty::ty_bot) => self.ty_bot(a),
fn lattice_rvars<L:lattice_ops combine>(
self: L, a: ty::region, b: ty::region) -> cres<ty::region> {
- alt (a, b) {
+ match (a, b) {
(ty::re_var(a_id), ty::re_var(b_id)) => {
lattice_vars(self, self.infcx().rb,
a, a_id, b_id,
// If both A and B have an UB type, then we can just compute the
// LUB of those types:
let a_bnd = self.bnd(a_bounds), b_bnd = self.bnd(b_bounds);
- alt (a_bnd, b_bnd) {
+ match (a_bnd, b_bnd) {
(some(a_ty), some(b_ty)) => {
- alt self.infcx().try(|| c_ts(a_ty, b_ty) ) {
+ match self.infcx().try(|| c_ts(a_ty, b_ty) ) {
ok(t) => return ok(t),
err(_) => { /*fallthrough */ }
}
a_id.to_str(), a_bounds.to_str(self.infcx()),
b.to_str(self.infcx())};
- alt self.bnd(a_bounds) {
+ match self.bnd(a_bounds) {
some(a_bnd) => {
// If a has an upper bound, return the LUB(a.ub, b)
debug!{"bnd=some(%s)", a_bnd.to_str(self.infcx())};
let visit_expr =
|e: @ast::expr, &&flag: @mut bool, v: visit::vt<@mut bool>| {
*flag |= p(e.node);
- alt e.node {
+ match e.node {
// Skip inner loops, since a break in the inner loop isn't a
// break inside the outer loop
ast::expr_loop(*) | ast::expr_while(*)
fn has_nonlocal_exits(b: ast::blk) -> bool {
do loop_query(b) |e| {
- alt e {
+ match e {
ast::expr_break | ast::expr_again => true,
_ => false
}
fn may_break(b: ast::blk) -> bool {
do loop_query(b) |e| {
- alt e {
+ match e {
ast::expr_break => true,
_ => false
}
}
fn local_rhs_span(l: @ast::local, def: span) -> span {
- alt l.node.init {
+ match l.node.init {
some(i) => return i.expr.span,
_ => return def
}
/// that attempts to explain a lifetime in a way it might plausibly be
/// understood.
fn explain_region(cx: ctxt, region: ty::region) -> ~str {
- return alt region {
+ return match region {
re_scope(node_id) => {
- let scope_str = alt cx.items.find(node_id) {
+ let scope_str = match cx.items.find(node_id) {
some(ast_map::node_block(blk)) => {
explain_span(cx, ~"block", blk.span)
}
some(ast_map::node_expr(expr)) => {
- alt expr.node {
+ match expr.node {
ast::expr_call(*) => { explain_span(cx, ~"call", expr.span) }
ast::expr_alt(*) => { explain_span(cx, ~"alt", expr.span) }
_ => { explain_span(cx, ~"expression", expr.span) }
}
re_free(id, br) => {
- alt cx.items.find(id) {
+ match cx.items.find(id) {
some(ast_map::node_block(blk)) => {
fmt!{"reference with lifetime %s as defined on %s",
bound_region_to_str(cx, br),
}
fn bound_region_to_str(cx: ctxt, br: bound_region) -> ~str {
- alt br {
+ match br {
br_anon => { ~"&" }
br_named(str) => { fmt!{"&%s", *str} }
br_self if cx.sess.ppregions() => { ~"&<self>" }
}
fn re_scope_id_to_str(cx: ctxt, node_id: ast::node_id) -> ~str {
- alt cx.items.find(node_id) {
+ match cx.items.find(node_id) {
some(ast_map::node_block(blk)) => {
fmt!{"<block at %s>",
codemap::span_to_str(blk.span, cx.sess.codemap)}
}
some(ast_map::node_expr(expr)) => {
- alt expr.node {
+ match expr.node {
ast::expr_call(*) => {
fmt!{"<call at %s>",
codemap::span_to_str(expr.span, cx.sess.codemap)}
}
fn region_to_str(cx: ctxt, region: region) -> ~str {
- alt region {
+ match region {
re_scope(node_id) => {
if cx.sess.ppregions() {
fmt!{"&%s", re_scope_id_to_str(cx, node_id)}
}
fn mt_to_str(cx: ctxt, m: mt) -> ~str {
- let mstr = alt m.mutbl {
+ let mstr = match m.mutbl {
ast::m_mutbl => ~"mut ",
ast::m_imm => ~"",
ast::m_const => ~"const "
}
fn vstore_to_str(cx: ctxt, vs: ty::vstore) -> ~str {
- alt vs {
+ match vs {
ty::vstore_fixed(n) => fmt!{"%u", n},
ty::vstore_uniq => ~"~",
ty::vstore_box => ~"@",
}
fn vstore_ty_to_str(cx: ctxt, ty: ~str, vs: ty::vstore) -> ~str {
- alt vs {
+ match vs {
ty::vstore_fixed(_) => {
fmt!{"%s/%s", ty, vstore_to_str(cx, vs)}
}
fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
~str {
let {mode, ty} = input;
- let modestr = alt canon_mode(cx, mode) {
+ let modestr = match canon_mode(cx, mode) {
ast::infer(_) => ~"",
ast::expl(m) => {
if !ty::type_needs_infer(ty) &&
inputs: ~[arg], output: t, cf: ast::ret_style) -> ~str {
let mut s;
- s = alt purity {
+ s = match purity {
ast::impure_fn => ~"",
_ => purity_to_str(purity) + ~" "
};
s += proto_to_str(proto);
- alt ident {
+ match ident {
some(i) => { s += ~" "; s += *i; }
_ => { }
}
s += ~")";
if ty::get(output).struct != ty_nil {
s += ~" -> ";
- alt cf {
+ match cf {
ast::noreturn => { s += ~"!"; }
ast::return_val => { s += ty_to_str(cx, output); }
}
}
// pretty print the structural type representation:
- return alt ty::get(typ).struct {
+ return match ty::get(typ).struct {
ty_nil => ~"()",
ty_bot => ~"_|_",
ty_bool => ~"bool",
self_r: option<ty::region>,
tps: ~[ty::t]) -> ~str {
- let r_str = alt self_r {
+ let r_str = match self_r {
none => ~"",
some(r) => {
fmt!{"/%s", region_to_str(cx, r)}
let mut keep_going = true;
while keep_going {
- alt comm::recv(po) {
+ match comm::recv(po) {
handle_request(f) => {
f(ctxt);
}
}
fn parse_desc(attrs: ~[ast::attribute]) -> option<~str> {
- alt doc_meta(attrs) {
+ match doc_meta(attrs) {
some(meta) => {
attr::get_meta_item_value_str(meta).map(|x| *x )
}
}
fn parse_hidden(attrs: ~[ast::attribute]) -> bool {
- alt doc_meta(attrs) {
+ match doc_meta(attrs) {
some(meta) => {
- alt attr::get_meta_item_list(meta) {
+ match attr::get_meta_item_list(meta) {
some(metas) => {
let hiddens = attr::find_meta_items_by_name(metas, ~"hidden");
vec::is_not_empty(hiddens)
id: doc::ast_id,
+parse_attrs: fn~(~[ast::attribute]) -> T) -> T {
do astsrv::exec(srv) |ctxt| {
- let attrs = alt ctxt.ast_map.get(id) {
+ let attrs = match ctxt.ast_map.get(id) {
ast_map::node_item(item, _) => item.attrs,
ast_map::node_foreign_item(item, _, _) => item.attrs,
_ => fail ~"parse_item_attrs: not an item"
{
variants: do par::map(doc.variants) |variant| {
let desc = do astsrv::exec(srv) |ctxt| {
- alt check ctxt.ast_map.get(doc_id) {
+ match check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _), _
}, _) => {
// Create an assoc list from method name to attributes
let attrs: ~[(~str, option<~str>)] = do astsrv::exec(srv) |ctxt| {
- alt ctxt.ast_map.get(item_id) {
+ match ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_trait(_, _, methods), _
}, _) => {
vec::map(methods, |method| {
- alt method {
+ match method {
ast::required(ty_m) => {
(*ty_m.ident, attr_parser::parse_desc(ty_m.attrs))
}
) -> result<config, ~str> {
let args = vec::tail(args);
let opts = vec::unzip(opts()).first();
- alt getopts::getopts(args, opts) {
+ match getopts::getopts(args, opts) {
result::ok(matches) => {
if vec::len(matches.free) == 1u {
let input_crate = vec::head(matches.free);
}
fn parse_output_format(output_format: ~str) -> result<output_format, ~str> {
- alt output_format {
+ match output_format {
~"markdown" => result::ok(markdown),
~"html" => result::ok(pandoc_html),
_ => result::err(fmt!{"unknown output format '%s'", output_format})
}
fn parse_output_style(output_style: ~str) -> result<output_style, ~str> {
- alt output_style {
+ match output_style {
~"doc-per-crate" => result::ok(doc_per_crate),
~"doc-per-mod" => result::ok(doc_per_mod),
_ => result::err(fmt!{"unknown output style '%s'", output_style})
return result::ok(maybe_pandoc_cmd);
}
- let possible_pandocs = alt maybe_pandoc_cmd {
+ let possible_pandocs = match maybe_pandoc_cmd {
some(pandoc_cmd) => ~[pandoc_cmd],
none => {
- ~[~"pandoc"] + alt os::homedir() {
+ ~[~"pandoc"] + match os::homedir() {
some(dir) => {
~[path::connect(dir, ~".cabal/bin/pandoc")]
}
const max_brief_len: uint = 120u;
- alt first_sentence(desc) {
+ match first_sentence(desc) {
some(first_sentence) => {
if str::len(first_sentence) <= max_brief_len {
some(first_sentence)
}
}
};
- alt idx {
+ match idx {
some(idx) if idx > 2u => {
str::slice(s, 0u, idx - 1u)
}
impl util for doc {
fn cratedoc() -> cratedoc {
option::get(vec::foldl(none, self.pages, |_m, page| {
- alt page {
+ match page {
doc::cratepage(doc) => some(doc),
_ => none
}
fn mods() -> ~[moddoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
modtag(moddoc) => some(moddoc),
_ => none
}
fn nmods() -> ~[nmoddoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
nmodtag(nmoddoc) => some(nmoddoc),
_ => none
}
fn fns() -> ~[fndoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
fntag(fndoc) => some(fndoc),
_ => none
}
fn consts() -> ~[constdoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
consttag(constdoc) => some(constdoc),
_ => none
}
fn enums() -> ~[enumdoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
enumtag(enumdoc) => some(enumdoc),
_ => none
}
fn traits() -> ~[traitdoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
traittag(traitdoc) => some(traitdoc),
_ => none
}
fn impls() -> ~[impldoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
impltag(impldoc) => some(impldoc),
_ => none
}
fn types() -> ~[tydoc] {
do vec::filter_map(self.items) |itemtag| {
- alt itemtag {
+ match itemtag {
tytag(tydoc) => some(tydoc),
_ => none
}
fn mods() -> ~[moddoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(modtag(moddoc)) => some(moddoc),
_ => none
}
fn nmods() -> ~[nmoddoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(nmodtag(nmoddoc)) => some(nmoddoc),
_ => none
}
fn fns() -> ~[fndoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(fntag(fndoc)) => some(fndoc),
_ => none
}
fn consts() -> ~[constdoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(consttag(constdoc)) => some(constdoc),
_ => none
}
fn enums() -> ~[enumdoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(enumtag(enumdoc)) => some(enumdoc),
_ => none
}
fn traits() -> ~[traitdoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(traittag(traitdoc)) => some(traitdoc),
_ => none
}
fn impls() -> ~[impldoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(impltag(impldoc)) => some(impldoc),
_ => none
}
fn types() -> ~[tydoc] {
do vec::filter_map(self) |page| {
- alt page {
+ match page {
itempage(tytag(tydoc)) => some(tydoc),
_ => none
}
impl of item for itemtag {
pure fn item() -> itemdoc {
- alt self {
+ match self {
doc::modtag(doc) => doc.item,
doc::nmodtag(doc) => doc.item,
doc::fntag(doc) => doc.item,
item: itemdoc,
items: do vec::filter_map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
- alt item.node {
+ match item.node {
ast::item_mod(m) => {
some(doc::modtag(
moddoc_from_mod(itemdoc, m)
item: itemdoc,
fns: do vec::map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
- alt item.node {
+ match item.node {
ast::foreign_item_fn(_, _) => {
fndoc_from_fn(itemdoc)
}
{
item: itemdoc,
methods: do vec::map(methods) |method| {
- alt method {
+ match method {
ast::required(ty_m) => {
{
name: *ty_m.ident,
fn default_seq_fold_doc<T>(fold: fold<T>, doc: doc::doc) -> doc::doc {
doc::doc_({
pages: do vec::map(doc.pages) |page| {
- alt page {
+ match page {
doc::cratepage(doc) => {
doc::cratepage(fold.fold_crate(fold, doc))
}
}
fn fold_itemtag<T>(fold: fold<T>, doc: doc::itemtag) -> doc::itemtag {
- alt doc {
+ match doc {
doc::modtag(moddoc) => {
doc::modtag(fold.fold_mod(fold, moddoc))
}
doc: doc::itemtag,
config: config::config
) -> doc::index_entry {
- let link = alt doc {
+ let link = match doc {
doc::modtag(_) | doc::nmodtag(_)
if config.output_style == config::doc_per_mod => {
markdown_writer::make_filename(config, doc::itempage(doc))
pure fn mods_last(item1: &doc::itemtag, item2: &doc::itemtag) -> bool {
pure fn is_mod(item: &doc::itemtag) -> bool {
- alt *item {
+ match *item {
doc::modtag(_) => true,
_ => false
}
fn write_page(ctxt: ctxt, page: doc::page) {
write_title(ctxt, page);
- alt page {
+ match page {
doc::cratepage(doc) => {
write_crate(ctxt, doc);
}
}
fn make_title(page: doc::page) -> ~str {
- let item = alt page {
+ let item = match page {
doc::cratepage(cratedoc) => {
doc::modtag(cratedoc.topmod)
}
write_markdown(doc, writer_factory);
for iter::repeat(2u) {
let (page, markdown) = comm::recv(po);
- alt page {
+ match page {
doc::cratepage(_) => {
assert str::contains(markdown, ~"% Crate core");
}
}
fn header_kind(doc: doc::itemtag) -> ~str {
- alt doc {
+ match doc {
doc::modtag(_) => {
if doc.id() == syntax::ast::crate_node_id {
~"Crate"
fn header_name(doc: doc::itemtag) -> ~str {
let fullpath = str::connect(doc.path() + ~[doc.name()], ~"::");
- alt doc {
+ match doc {
doc::modtag(_) if doc.id() != syntax::ast::crate_node_id => {
fullpath
}
ctxt: ctxt,
desc: option<~str>
) {
- alt desc {
+ match desc {
some(desc) => {
ctxt.w.write_line(desc);
ctxt.w.write_line(~"");
write_item_header(ctxt, doc);
}
- alt doc {
+ match doc {
doc::modtag(moddoc) => write_mod(ctxt, moddoc),
doc::nmodtag(nmoddoc) => write_nmod(ctxt, nmoddoc),
doc::fntag(fndoc) => write_fn(ctxt, fndoc),
}
fn item_header_lvl(doc: doc::itemtag) -> hlvl {
- alt doc {
+ match doc {
doc::modtag(_) | doc::nmodtag(_) => h1,
_ => h2
}
}
fn write_sig(ctxt: ctxt, sig: option<~str>) {
- alt sig {
+ match sig {
some(sig) => {
ctxt.w.write_line(code_block_indent(sig));
ctxt.w.write_line(~"");
fn write_variant(ctxt: ctxt, doc: doc::variantdoc) {
assert option::is_some(doc.sig);
let sig = option::get(doc.sig);
- alt doc.desc {
+ match doc.desc {
some(desc) => {
ctxt.w.write_line(fmt!{"* `%s` - %s", sig, desc});
}
}
fn make_writer_factory(config: config::config) -> writer_factory {
- alt config.output_format {
+ match config.output_format {
config::markdown => {
markdown_writer_factory(config)
}
let mut markdown = ~"";
let mut keep_going = true;
while keep_going {
- alt comm::recv(po) {
+ match comm::recv(po) {
write(s) => markdown += s,
done => keep_going = false
}
page: doc::page
) -> ~str {
let filename = {
- alt page {
+ match page {
doc::cratepage(doc) => {
if config.output_format == config::pandoc_html &&
config.output_style == config::doc_per_mod {
}
}
};
- let ext = alt config.output_format {
+ let ext = match config.output_format {
config::markdown => ~"md",
config::pandoc_html => ~"html"
};
fn write_file(path: ~str, s: ~str) {
import io::writer_util;
- alt io::file_writer(path, ~[io::create, io::truncate]) {
+ match io::file_writer(path, ~[io::create, io::truncate]) {
result::ok(writer) => {
writer.write_str(s);
}
let future = do future::from_fn {
let mut res = ~"";
loop {
- alt comm::recv(port) {
+ match comm::recv(port) {
write(s) => res += s,
done => break
}
fn strip_mod(doc: doc::moddoc) -> doc::moddoc {
doc::moddoc_({
items: do vec::filter(doc.items) |item| {
- alt item {
+ match item {
doc::modtag(_) => false,
doc::nmodtag(_) => false,
_ => true
let id = doc.id;
do astsrv::exec(srv) |ctxt| {
- let attrs = alt ctxt.ast_map.get(id) {
+ let attrs = match ctxt.ast_map.get(id) {
ast_map::node_item(item, _) => item.attrs,
_ => ~[]
};
return;
}
- let config = alt config::parse_config(args) {
+ let config = match config::parse_config(args) {
result::ok(config) => config,
result::err(err) => {
io::println(fmt!{"error: %s", err});
let mut sections = ~[];
for lines.each |line| {
- alt parse_header(line) {
+ match parse_header(line) {
some(header) => {
if option::is_some(current_section) {
sections += ~[option::get(current_section)];
});
}
none => {
- alt copy current_section {
+ match copy current_section {
some(section) => {
current_section = some({
body: section.body + ~"\n" + line
});
}
none => {
- new_desc = alt new_desc {
+ new_desc = match new_desc {
some(desc) => {
some(desc + ~"\n" + line)
}
fn mk_pass() -> pass {
pure fn by_score(item1: &doc::itemtag, item2: &doc::itemtag) -> bool {
pure fn score(item: &doc::itemtag) -> int {
- alt *item {
+ match *item {
doc::consttag(_) => 0,
doc::tytag(_) => 1,
doc::enumtag(_) => 2,
fn get_fn_sig(srv: astsrv::srv, fn_id: doc::ast_id) -> option<~str> {
do astsrv::exec(srv) |ctxt| {
- alt check ctxt.ast_map.get(fn_id) {
+ match check ctxt.ast_map.get(fn_id) {
ast_map::node_item(@{
ident: ident,
node: ast::item_fn(decl, tys, _), _
{
sig: some(do astsrv::exec(srv) |ctxt| {
- alt check ctxt.ast_map.get(doc.id()) {
+ match check ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_const(ty, _), _
}, _) => {
{
variants: do par::map(doc.variants) |variant| {
let sig = do astsrv::exec(srv) |ctxt| {
- alt check ctxt.ast_map.get(doc_id) {
+ match check ctxt.ast_map.get(doc_id) {
ast_map::node_item(@{
node: ast::item_enum(ast_variants, _), _
}, _) => {
method_name: ~str
) -> option<~str> {
do astsrv::exec(srv) |ctxt| {
- alt check ctxt.ast_map.get(item_id) {
+ match check ctxt.ast_map.get(item_id) {
ast_map::node_item(@{
node: ast::item_trait(_, _, methods), _
}, _) => {
- alt check vec::find(methods, |method| {
- alt method {
+ match check vec::find(methods, |method| {
+ match method {
ast::required(ty_m) => *ty_m.ident == method_name,
ast::provided(m) => *m.ident == method_name,
}
}) {
some(method) => {
- alt method {
+ match method {
ast::required(ty_m) => {
some(pprust::fun_to_str(
ty_m.decl,
ast_map::node_item(@{
node: ast::item_impl(_, _, _, methods), _
}, _) => {
- alt check vec::find(methods, |method| {
+ match check vec::find(methods, |method| {
*method.ident == method_name
}) {
some(method) => {
let srv = fold.ctxt;
let (trait_types, self_ty) = do astsrv::exec(srv) |ctxt| {
- alt ctxt.ast_map.get(doc.id()) {
+ match ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
node: ast::item_impl(_, trait_types, self_ty, _), _
}, _) => {
{
sig: do astsrv::exec(srv) |ctxt| {
- alt ctxt.ast_map.get(doc.id()) {
+ match ctxt.ast_map.get(doc.id()) {
ast_map::node_item(@{
ident: ident,
node: ast::item_ty(ty, params), _
impl methods<T:copy> for maybe<T> {
fn ~[](idx: uint) -> T {
- alt self {
+ match self {
just(t) { t }
nothing { fail; }
}
let mut found = 0;
for int::range(0, 1000) |_i| {
- alt s.find(r.gen_str(10)) {
+ match s.find(r.gen_str(10)) {
some(_) => { found += 1; }
none => { }
}
};
fn is_gray(c: color) -> bool {
- alt c {
+ match c {
gray(_) => { true }
_ => { false }
}
i += 1u;
colors = do colors.mapi() |i, c| {
let c : color = c;
- alt c {
+ match c {
white => {
let i = i as node_id;
// Convert the results.
do vec::map(colors) |c| {
- alt c {
+ match c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail ~"Found remaining gray nodes in BFS" }
#[inline(always)]
fn is_gray(c: color) -> bool {
- alt c {
+ match c {
gray(_) => { true }
_ => { false }
}
let c : color = c;
let colors = arc::get(&colors);
let graph = arc::get(&graph);
- alt c {
+ match c {
white => {
let i = i as node_id;
// Convert the results.
do par::map(colors) |c| {
- alt c {
+ match c {
white => { -1i64 }
black(parent) => { parent }
_ => { fail ~"Found remaining gray nodes in BFS" }
let mut count = 0u;
let mut done = false;
while !done {
- alt requests.try_recv() {
+ match requests.try_recv() {
some(get_count) => { responses.send(copy count); }
some(bytes(b)) => {
//error!{"server: received %? bytes", b};
let mut count = 0u;
let mut done = false;
while !done {
- alt requests.try_recv() {
+ match requests.try_recv() {
some(get_count) => { responses.send(copy count); }
some(bytes(b)) => {
//error!{"server: received %? bytes", b};
num_port2 <-> num_port;
num_chan = some(ring::client::num(option::unwrap(num_chan2), i * j));
let port = option::unwrap(num_port2);
- alt recv(port) {
+ match recv(port) {
ring::num(_n, p) => {
//log(error, _n);
num_port = some(move_out!{p});
let mut count = 0u;
let mut done = false;
while !done {
- alt comm::recv(requests) {
+ match comm::recv(requests) {
get_count => { comm::send(responses, copy count); }
bytes(b) => { count += b; }
stop => { done = true; }
{
$($message:path($($x: ident),+) -> $next:ident $e:expr)+
} => (
- |m| alt move m {
+ |m| match move m {
$(some($message($($x,)* next)) => {
// FIXME (#2329) use regular move here once move out of
// enums is supported.
{
$($message:path -> $next:ident $e:expr)+
} => (
- |m| alt move m {
+ |m| match move m {
$(some($message(next)) => {
// FIXME (#2329) use regular move here once move out of
// enums is supported.
enum tree/& { nil, node(&tree, &tree, int), }
fn item_check(t: &tree) -> int {
- alt *t {
+ match *t {
nil => { return 0; }
node(left, right, item) => {
return item + item_check(left) - item_check(right);
type creature_info = { name: uint, color: color };
fn show_color(cc: color) -> ~str {
- alt (cc) {
+ match (cc) {
Red => {~"red"}
Yellow => {~"yellow"}
Blue => {~"blue"}
}
fn show_digit(nn: uint) -> ~str {
- alt (nn) {
+ match (nn) {
0 => {~"zero"}
1 => {~"one"}
2 => {~"two"}
}
fn transform(aa: color, bb: color) -> color {
- alt (aa, bb) {
+ match (aa, bb) {
(Red, Red ) => { Red }
(Red, Yellow) => { Blue }
(Red, Blue ) => { Yellow }
let resp = comm::recv(from_rendezvous);
// log and change, or print and quit
- alt resp {
+ match resp {
option::some(other_creature) => {
color = transform(color, other_creature.color);
// given a map, search for the frequency of a pattern
fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint {
- alt mm.find(str::bytes(str::to_lower(key))) {
+ match mm.find(str::bytes(str::to_lower(key))) {
option::none => { return 0u; }
option::some(num) => { return num; }
}
// given a map, increment the counter for a key
fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len());
- alt mm.find(key) {
+ match mm.find(key) {
option::none => { mm.insert(key, 1u ); }
option::some(val) => { mm.insert(key, 1u + val); }
}
});
}
- let buffer = alt sz {
+ let buffer = match sz {
1u => { sort_and_fmt(freqs, total) }
2u => { sort_and_fmt(freqs, total) }
3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
if str::len(line) == 0u { again; }
- alt (line[0], proc_mode) {
+ match (line[0], proc_mode) {
// start processing if this is the one
('>' as u8, false) => {
- alt str::find_str_from(line, ~"THREE", 1u) {
+ match str::find_str_from(line, ~"THREE", 1u) {
option::some(_) => { proc_mode = true; }
option::none => { }
}
// given a map, search for the frequency of a pattern
fn find(mm: hashmap<~[u8], uint>, key: ~str) -> uint {
- alt mm.find(str::bytes(str::to_lower(key))) {
+ match mm.find(str::bytes(str::to_lower(key))) {
option::none => { return 0u; }
option::some(num) => { return num; }
}
// given a map, increment the counter for a key
fn update_freq(mm: hashmap<~[u8], uint>, key: &[u8]) {
let key = vec::slice(key, 0, key.len());
- alt mm.find(key) {
+ match mm.find(key) {
option::none => { mm.insert(key, 1u ); }
option::some(val) => { mm.insert(key, 1u + val); }
}
});
}
- let buffer = alt sz {
+ let buffer = match sz {
1u => { sort_and_fmt(freqs, total) }
2u => { sort_and_fmt(freqs, total) }
3u => { fmt!{"%u\t%s", find(freqs, ~"GGT"), ~"GGT"} }
if str::len(line) == 0u { again; }
- alt (line[0], proc_mode) {
+ match (line[0], proc_mode) {
// start processing if this is the one
('>' as u8, false) => {
- alt str::find_str_from(line, ~"THREE", 1u) {
+ match str::find_str_from(line, ~"THREE", 1u) {
option::some(_) => proc_mode = true,
option::none => ()
}
let p: comm::port<line> = comm::port();
let ch = comm::chan(p);
comm::send(writech, ch);
- let cout: io::writer = alt path {
+ let cout: io::writer = match path {
~"" => {
{dn: 0} as io::writer
}
let opt_args = vec::slice(argv, 1u, vec::len(argv));
- alt getopts::getopts(opt_args, opts) {
+ match getopts::getopts(opt_args, opts) {
ok(m) => { return {stress: getopts::opt_present(m, ~"stress")} }
err(_) => { fail; }
}
fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) {
while (true) {
- alt comm::recv(p) {
+ match comm::recv(p) {
1 => {
io::println(fmt!{"%d\n", id});
return;
} else {
let depth = depth - 1;
- let st = alt st {
+ let st = match st {
none => {
st_({
box: @nil,
}
for iter::repeat (children) {
- alt check comm::recv(port) {
+ match check comm::recv(port) {
ready(child_ch) => {
vec::push(child_chs, child_ch);
}
comm::send(parent_ch, ready(chan));
- alt check comm::recv(port) {
+ match check comm::recv(port) {
start => {
do vec::iter (child_chs) |child_ch| {
comm::send(child_ch, start);
}
for iter::repeat (children) {
- alt check comm::recv(port) {
+ match check comm::recv(port) {
done(child_sum) => { sum += child_sum; }
}
}
do task::spawn {
calc(children, chan);
};
- alt check comm::recv(port) {
+ match check comm::recv(port) {
ready(chan) => {
comm::send(chan, start);
}
}
- let sum = alt check comm::recv(port) {
+ let sum = match check comm::recv(port) {
done(sum) => { sum }
};
error!{"How many tasks? %d tasks.", sum};
}
fn file_word_reader(filename: ~str) -> word_reader {
- alt io::file_reader(filename) {
+ match io::file_reader(filename) {
result::ok(f) => { f as word_reader }
result::err(e) => { fail fmt!{"%?", e} }
}
fn map(f: fn~() -> word_reader, emit: map_reduce::putter<~str, int>) {
let f = f();
loop {
- alt f.read_word() {
+ match f.read_word() {
some(w) => { emit(w, 1); }
none => { break; }
}
fn reduce(&&word: ~str, get: map_reduce::getter<int>) {
let mut count = 0;
- loop { alt get() { some(_) => { count += 1; } none => { break; } } }
+ loop { match get() { some(_) => { count += 1; } none => { break; } } }
io::println(fmt!{"%s\t%?", word, count});
}
do map(input) |key, val| {
let mut c = none;
- alt intermediates.find(key) {
+ match intermediates.find(key) {
some(_c) => { c = some(_c); }
none => {
do ctrl.swap |ctrl| {
let ctrl = ctrl_proto::client::find_reducer(ctrl, key);
- alt pipes::recv(ctrl) {
+ match pipes::recv(ctrl) {
ctrl_proto::reducer(c_, ctrl) => {
c = some(c_);
move_out!{ctrl}
&ref_count: int, &is_done: bool)
-> option<V> {
while !is_done || ref_count > 0 {
- alt recv(p) {
+ match recv(p) {
emit_val(v) => {
// error!{"received %d", v};
return some(v);
while num_mappers > 0 {
let (_ready, message, ctrls) = pipes::select(ctrl);
- alt option::unwrap(message) {
+ match option::unwrap(message) {
ctrl_proto::mapper_done => {
// error!{"received mapper terminated."};
num_mappers -= 1;
ctrl_proto::find_reducer(k, cc) => {
let c;
// log(error, "finding reducer for " + k);
- alt reducers.find(k) {
+ match reducers.find(k) {
some(_c) => {
// log(error,
// "reusing existing reducer for " + k);
fn main() {
- alt 0 {
+ match 0 {
0 => {
} + 5 //~ ERROR unexpected token: `+`
}
fn my_fail() -> ! { fail; }
fn main() {
- alt true { false => { my_fail(); } true => { } }
+ match true { false => { my_fail(); } true => { } }
log(debug, x); //~ ERROR unresolved name: x
let x: int;
}
fn foo(c: color) {
- alt c {
+ match c {
rgb(_, _, _) => { }
cmyk(_, _, _, _) => { }
no_color(_) => { }
}
fn foo(c: color) {
- alt c {
+ match c {
rgb(_, _) => { }
//~^ ERROR this pattern has 2 fields, but the corresponding variant has 3 fields
cmyk(_, _, _, _) => { }
//error-pattern: unreachable
fn main() {
- alt check 5u {
+ match check 5u {
1u to 10u => { }
5u to 6u => { }
};
- alt check 5u {
+ match check 5u {
3u to 6u => { }
4u to 6u => { }
};
- alt check 5u {
+ match check 5u {
4u to 6u => { }
4u to 6u => { }
};
- alt check 'c' {
+ match check 'c' {
'A' to 'z' => {}
'a' to 'z' => {}
};
- alt check 1.0 {
+ match check 1.0 {
0.01 to 6.5 => {}
0.02 => {}
};
//error-pattern: mismatched types
fn main() {
- alt 5u {
+ match 5u {
6u to 1u => { }
_ => { }
};
- alt "wow" {
+ match "wow" {
"bar" to "foo" => { }
};
- alt 5u {
+ match 5u {
'c' to 100u => { }
_ => { }
};
enum a { A, }
enum b { B, }
-fn main() { let x: a = A; alt x { B => { } } }
+fn main() { let x: a = A; match x { B => { } } }
enum a { A(int), }
enum b { B(int), }
-fn main() { let x: a = A(0); alt x { B(y) => { } } }
+fn main() { let x: a = A(0); match x { B(y) => { } } }
fn main() {
let int x = 5;
- alt x;
+ match x;
}
// error-pattern:did not expect a record with a field `q`
-fn main() { alt {x: 1, y: 2} { {x: x, q: q} => { } } }
+fn main() { match {x: 1, y: 2} { {x: x, q: q} => { } } }
// error-pattern:expected a record with 2 fields, found one with 1
-fn main() { alt {x: 1, y: 2} { {x: x} => { } } }
+fn main() { match {x: 1, y: 2} { {x: x} => { } } }
fn main() {
let red: color = rgb(255, 0, 0);
- alt red {
+ match red {
rgb(r, g, b) => { debug!{"rgb"}; }
hsl(h, s, l) => { debug!{"hsl"}; }
}
fn main() {
let x = {mut f: ~[3]};
- alt x {
+ match x {
{f: v} => {
impure(v); //~ ERROR illegal borrow unless pure: unique value in aliasable, mutable location
//~^ NOTE impure due to access to impure function
fn main() {
let x = some(~1);
-alt x { //~ NOTE loan of immutable local variable granted here
+match x { //~ NOTE loan of immutable local variable granted here
some(y) => {
let _a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
}
fn main() {
let x = some(~1);
-alt x {
+match x {
some(y) => {
let _b <- y; //~ ERROR moving out of pattern binding
}
fn main() {
let x = ~node({mut a: ~empty});
// Create a cycle!
- alt check *x { //~ NOTE loan of immutable local variable granted here
+ match check *x { //~ NOTE loan of immutable local variable granted here
node(y) => {
y.a <- x; //~ ERROR moving out of immutable local variable prohibited due to outstanding loan
}
fn match_imm_box(v: &const @option<int>) -> int {
- alt *v {
+ match *v {
@some(i) => {i}
@none => {0}
}
}
fn match_const_box(v: &const @const option<int>) -> int {
- alt *v {
+ match *v {
@some(i) => { i } // ok because this is pure
@none => {0}
}
pure fn pure_process(_i: int) {}
fn match_const_box_and_do_pure_things(v: &const @const option<int>) {
- alt *v {
+ match *v {
@some(i) => {
pure_process(i)
}
fn process(_i: int) {}
fn match_const_box_and_do_bad_things(v: &const @const option<int>) {
- alt *v {
+ match *v {
@some(i) => { //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
process(i) //~ NOTE impure due to access to impure function
}
fn match_ref(&&v: option<int>) -> int {
- alt v {
+ match v {
some(i) => {
i
}
}
fn match_ref_unused(&&v: option<int>) {
- alt v {
+ match v {
some(_) => {}
none => {}
}
}
fn match_const_reg(v: &const option<int>) -> int {
- alt *v {
+ match *v {
some(i) => {i} // OK because this is pure
none => {0}
}
}
fn match_const_reg_unused(v: &const option<int>) {
- alt *v {
+ match *v {
some(_) => {impure(0)} // OK because nothing is captured
none => {}
}
}
fn match_const_reg_impure(v: &const option<int>) {
- alt *v {
+ match *v {
some(i) => {impure(i)} //~ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
//~^ NOTE impure due to access to impure function
none => {}
}
fn match_imm_reg(v: &option<int>) {
- alt *v {
+ match *v {
some(i) => {impure(i)} // OK because immutable
none => {}
}
fn main() {
let mut x: option<int> = none;
- alt x { //~ NOTE loan of mutable local variable granted here
+ match x { //~ NOTE loan of mutable local variable granted here
none => {}
some(i) => {
// Not ok: i is an outstanding ptr into x.
fn main() {
let mut x = none;
- alt x { //~ NOTE loan of mutable local variable granted here
+ match x { //~ NOTE loan of mutable local variable granted here
none => {
// It is ok to reassign x here, because there is in
// fact no outstanding loan of x!
// check that unchecked alone does not override borrowck:
fn foo(v: &const option<int>) {
- alt *v {
+ match *v {
some(i) => {
//~^ ERROR illegal borrow unless pure: enum variant in aliasable, mutable location
unchecked {
}
fn bar(v: &const option<int>) {
- alt *v {
+ match *v {
some(i) => {
unsafe {
impure(i);
// error-pattern:cannot be dereferenced
fn main() {
- alt *1 {
+ match *1 {
_ => { fail; }
}
}
\ No newline at end of file
const b : t = 1u8;
fn bar(v: t) -> bool {
- alt v {
+ match v {
a => { return true; }
b => { return false; }
}
fn foo(a: option<uint>, b: option<uint>) {
- alt (a,b) { //~ ERROR: non-exhaustive patterns: none not covered
+ match (a,b) { //~ ERROR: non-exhaustive patterns: none not covered
(some(a), some(b)) if a == b => { }
(some(_), none) |
(none, some(_)) => { }
xfailed for now (see Issue #2354)
*/
fn foo() { //~ ERROR this open brace is not closed
- alt some(x) {
+ match some(x) {
some(y) { fail; }
none { fail; }
}
fn main() {
import bar::{alpha, charlie};
- alt alpha {
+ match alpha {
alpha | beta => {} //~ ERROR: inconsistent number of bindings
charlie => {}
}
enum foo { alpha, beta(int) }
fn main() {
- alt alpha {
+ match alpha {
alpha | beta(i) => {} //~ ERROR inconsistent number of bindings
}
}
fn main()
{
- let _z = alt g(1, 2) {
+ let _z = match g(1, 2) {
g(x, x) => { log(debug, x + x); }
//~^ ERROR Identifier x is bound more than once in the same pattern
};
- let _z = alt i(l(1, 2), m(3, 4)) {
+ let _z = match i(l(1, 2), m(3, 4)) {
i(l(x, _), m(_, x)) //~ ERROR Identifier x is bound more than once in the same pattern
=> { log(error, x + x); }
};
- let _z = alt (1, 2) {
+ let _z = match (1, 2) {
(x, x) => { x } //~ ERROR Identifier x is bound more than once in the same pattern
};
// error-pattern: not all control paths return a value
fn f() -> int {
- // Make sure typestate doesn't interpreturn this alt expression
+ // Make sure typestate doesn't interpreturn this match expression
// as the function result
- alt check true { true => { } };
+ match check true { true => { } };
}
fn main() { }
}
fn f4() {
- alt some(3) {
+ match some(3) {
some(i) => {
}
none => {}
fn main() {
let x = a(c);
- alt x {
+ match x {
a(d) => { fail ~"hello"; }
b => { fail ~"goodbye"; }
}
fn main() {
let x = a;
- alt x { b => { } } //~ ERROR non-exhaustive patterns
- alt true { //~ ERROR non-exhaustive patterns
+ match x { b => { } } //~ ERROR non-exhaustive patterns
+ match true { //~ ERROR non-exhaustive patterns
true => {}
}
- alt @some(10) { //~ ERROR non-exhaustive patterns
+ match @some(10) { //~ ERROR non-exhaustive patterns
@none => {}
}
- alt (2, 3, 4) { //~ ERROR non-exhaustive patterns
+ match (2, 3, 4) { //~ ERROR non-exhaustive patterns
(_, _, 4) => {}
}
- alt (a, a) { //~ ERROR non-exhaustive patterns
+ match (a, a) { //~ ERROR non-exhaustive patterns
(a, b) => {}
(b, a) => {}
}
- alt a { //~ ERROR b not covered
+ match a { //~ ERROR b not covered
a => {}
}
// This is exhaustive, though the algorithm got it wrong at one point
- alt (a, b) {
+ match (a, b) {
(a, _) => {}
(_, a) => {}
(b, b) => {}
// error-pattern:mismatched types
// From Issue #778
enum clam<T> { a(T), }
-fn main() { let c; c = a(c); alt c { a::<int>(_) => { } } }
+fn main() { let c; c = a(c); match c { a::<int>(_) => { } } }
enum blah { a(int, int, uint), b(int, int), }
-fn main() { alt a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } }
+fn main() { match a(1, 1, 2u) { a(_, x, y) | b(x, y) => { } } }
enum bar { t1((), option<~[int]>), t2, }
-fn foo(t: bar) -> int { alt t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } }
+fn foo(t: bar) -> int { match t { t1(_, some(x)) => { return x * 3; } _ => { fail; } } }
fn main() { }
enum bar { t1((), option<~[int]>), t2, }
fn foo(t: bar) {
- alt t {
+ match t {
t1(_, some::<int>(x)) => {
log(debug, x);
}
}
fn compute(x: &ast) -> uint {
- alt *x {
+ match *x {
num(x) => { x }
add(x, y) => { compute(x) + compute(y) }
}
}
fn map_nums(x: &ast, f: fn(uint) -> uint) -> &ast {
- alt *x {
+ match *x {
num(x) => {
return &num(f(x)); //~ ERROR illegal borrow
}
// error-pattern:found `let` in restricted position
fn main() {
- alt true {
+ match true {
{let} { }
}
}
enum foo { a(@foo, int), b(uint), }
-fn main() { alt b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } }
+fn main() { match b(1u) { b(_) | a(@_, 1) => { } a(_, 1) => { } } }
fn main() {
let x = some(3);
let y =
- alt x {
+ match x {
some(_) =>
~"some" + ~"very" + ~"very" + ~"very" + ~"very" + ~"very" +
~"very" + ~"very" + ~"very" + ~"long" + ~"string",
fn main() {
let x = some(3);
let _y =
- alt x {
+ match x {
some(_) => ~[~"some(_)", ~"not", ~"SO", ~"long", ~"string"],
none => ~[~"none"]
};
fn main() {
let x = some(3);
- let y = alt x { some(_) => ~"some(_)", none => ~"none" };
+ let y = match x { some(_) => ~"some(_)", none => ~"none" };
assert y == ~"some(_)";
}
fn test3() {
let regs = @{mut eax: 0};
- alt check true { true => { } }
+ match check true { true => { } }
(*regs).eax = 1;
}
fn test7() -> uint {
let regs = @0;
- alt check true { true => { } }
+ match check true { true => { } }
(*regs < 2) as uint
}
fn test8() -> int {
let val = @0;
- alt check true {
+ match check true {
true => { }
}
if *val < 1 {
}
}
-fn test9() { let regs = @mut 0; alt check true { true => { } } *regs += 1; }
+fn test9() { let regs = @mut 0; match check true { true => { } } *regs += 1; }
fn test10() -> int {
let regs = @mut ~[0];
- alt check true { true => { } }
+ match check true { true => { } }
(*regs)[0]
}
fn if_nosemi() -> int { (if true { 0 } else { 0 }) - 1 }
-fn alt_semi() -> int { alt check true { true => { f() } }; -1 }
+fn alt_semi() -> int { match check true { true => { f() } }; -1 }
-fn alt_no_semi() -> int { (alt check true { true => { 0 } }) - 1 }
+fn alt_no_semi() -> int { (match check true { true => { 0 } }) - 1 }
fn stmt() { { f() }; -1; }
fn main() {
let i =
- alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { fail } };
+ match some::<int>(3) { none::<int> => { fail } some::<int>(_) => { fail } };
foo(i);
}
// error-pattern:quux
fn f() -> ! { fail ~"quux" }
-fn g() -> int { alt f() { true => { 1 } false => { 0 } } }
+fn g() -> int { match f() { true => { 1 } false => { 0 } } }
fn main() { g(); }
// error-pattern:squirrelcupcake
fn cmp() -> int {
- alt check (option::some('a'), option::none::<char>) {
+ match check (option::some('a'), option::none::<char>) {
(option::some(_), _) => { fail ~"squirrelcupcake"; }
(_, option::some(_)) => { fail; }
}
// error-pattern:explicit failure
fn f() -> ! { fail }
-fn g() -> int { let x = alt true { true => { f() } false => { 10 } }; return x; }
+fn g() -> int { let x = match true { true => { f() } false => { 10 } }; return x; }
fn main() { g(); }
// error-pattern:explicit failure
-fn main() { let x = alt true { false => { 0 } true => { fail } }; }
+fn main() { let x = match true { false => { 0 } true => { fail } }; }
fn bigfail() {
do { while (fail) { if (fail) {
- alt (fail) { _ {
+ match (fail) { _ {
}}
}}} while fail;
}
fn main() {
do io::with_str_reader(~"") |rdr| {
- alt rdr.read_char() { '=' => { } _ => { fail } }
+ match rdr.read_char() { '=' => { } _ => { fail } }
}
}
@0;
}
fn test_str() {
- let res = alt check false { true => { ~"happy" } };
+ let res = match check false { true => { ~"happy" } };
assert res == ~"happy";
}
fn main() {
// no-reformat
// Testing the presense or absense of commas separating block-structure
-// alt arm expressions
+// match arm expressions
fn fun(_f: fn()) {
}
fn main() {
- alt 0 {
+ match 0 {
00 => {
}
01 => if true {
} else {
}
- 03 => alt 0 {
+ 03 => match 0 {
_ => ()
}
04 => do fun {
11 => if true {
} else {
},
- 13 => alt 0 {
+ 13 => match 0 {
_ => ()
},
14 => do fun {
// n.b. This was only ever failing with optimization disabled.
-fn a() -> int { alt check return 1 { 2 => 3 } }
+fn a() -> int { match check return 1 { 2 => 3 } }
fn main() { a(); }
fn main() {
let i: int =
- alt some::<int>(3) { none::<int> => { fail } some::<int>(_) => { 5 } };
+ match some::<int>(3) { none::<int> => { fail } some::<int>(_) => { 5 } };
log(debug, i);
}
fn main() {
let x = ~{mut a: ~10, b: ~20};
- alt x {
+ match x {
~{a, b} => { assert *a == 10; (*x).a = ~30; assert *a == 30; }
}
}
fn main() {
let x = @{mut a: @10, b: @20};
- alt x {
+ match x {
@{a, b} => { assert *a == 10; (*x).a = @30; assert *a == 30; }
}
}
if true {
} else {
- alt y {
+ match y {
none::<T> => x = 17,
_ => x = 42
}
fn main() {
- let x = alt 0 {
+ let x = match 0 {
_ => {
x: 0
}.x
fn main() {
- let x = alt 0 {
+ let x = match 0 {
_ => {
x: 0
}
enum foo { foo1, foo2, }
}
-fn bar(x: m1::foo) { alt x { m1::foo1 => { } m1::foo2 => { } } }
+fn bar(x: m1::foo) { match x { m1::foo1 => { } m1::foo2 => { } } }
fn main() { }
let count = sys::refcount(s);
let x: t = make_t(s); // ref up
- alt x {
+ match x {
make_t(y) => {
log(debug, y); // ref up then down
fn altlit(f: int) -> int {
- alt check f {
+ match check f {
10 => { debug!{"case 10"}; return 20; }
11 => { debug!{"case 11"}; return 22; }
}
enum maybe<T> { nothing, just(T), }
fn foo(x: maybe<int>) {
- alt x { nothing => { error!{"A"}; } just(a) => { error!{"B"}; } }
+ match x { nothing => { error!{"A"}; } just(a) => { error!{"B"}; } }
}
fn main() { }
-fn altsimple(f: int) { alt f { x => () } }
+fn altsimple(f: int) { match f { x => () } }
fn main() { }
fn main() {
let mut x = true;
- alt a {
+ match a {
a => { x = true; foo(|_i| { } ) }
b => { x = false; }
c => { x = false; }
fn main() {
- alt 5u {
+ match 5u {
1u to 5u => {}
_ => fail ~"should match range",
}
- alt 5u {
+ match 5u {
6u to 7u => fail ~"shouldn't match range",
_ => {}
}
- alt check 5u {
+ match check 5u {
1u => fail ~"should match non-first range",
2u to 6u => {}
}
- alt 'c' {
+ match 'c' {
'a' to 'z' => {}
_ => fail ~"should suppport char ranges"
}
- alt -3 {
+ match -3 {
-7 to 5 => {}
_ => fail ~"should match signed range"
}
- alt 3.0 {
+ match 3.0 {
1.0 to 5.0 => {}
_ => fail ~"should match float range"
}
- alt -1.5 {
+ match -1.5 {
-3.6 to 3.6 => {}
_ => fail ~"should match negative float range"
}
// Issue #53
fn main() {
- alt check ~"test" { ~"not-test" => fail, ~"test" => (), _ => fail }
+ match check ~"test" { ~"not-test" => fail, ~"test" => (), _ => fail }
enum t { tag1(~str), tag2, }
- alt tag1(~"test") {
+ match tag1(~"test") {
tag2 => fail,
tag1(~"not-test") => fail,
tag1(~"test") => (),
_ => fail
}
- let x = alt check ~"a" { ~"a" => 1, ~"b" => 2 };
+ let x = match check ~"a" { ~"a" => 1, ~"b" => 2 };
assert (x == 1);
- alt check ~"a" { ~"a" => { } ~"b" => { } }
+ match check ~"a" { ~"a" => { } ~"b" => { } }
}
fn process(c: color) -> int {
let mut x: int;
- alt c {
+ match c {
rgb(r, _, _) => { debug!{"rgb"}; log(debug, r); x = r; }
rgba(_, _, _, a) => { debug!{"rgba"}; log(debug, a); x = a; }
hsl(_, s, _) => { debug!{"hsl"}; log(debug, s); x = s; }
// xfail-test
fn altsimple(any x) {
- alt type (f) {
+ match type (f) {
case (int i) { print("int"); }
case (str s) { print("str"); }
}
fn main() {
- alt ~100 {
+ match ~100 {
~x => {
debug!{"%?", x};
assert x == 100;
// sometimes we have had trouble finding
// the right type for f, as we unified
// bot and u32 here
- let f = alt uint::from_str(~"1234") {
+ let f = match uint::from_str(~"1234") {
none => return (),
some(num) => num as u32
};
// Check that issue #954 stays fixed
fn main() {
- alt check -1 { -1 => {} }
+ match check -1 { -1 => {} }
assert 1-1 == 0;
}
if !do vec::any(v) |e| { float::is_positive(e) } {
assert false;
}
- alt do vec::all(v) |e| { float::is_negative(e) } {
+ match do vec::all(v) |e| { float::is_negative(e) } {
true => { fail ~"incorrect answer."; }
false => { }
}
- alt 3 {
+ match 3 {
_ if do vec::any(v) |e| { float::is_negative(e) } => {
}
_ => {
fn main() {
let mut x = none;
- alt x {
+ match x {
none => {
// It is ok to reassign x here, because there is in
// fact no outstanding loan of x!
fn main() {
let x: @mut @option<~int> = @mut @none;
- alt x {
+ match x {
@@some(y) => {
// here, the refcount of `*x` is bumped so
// `y` remains valid even if `*x` is modified.
fn main() {
let mut x = @{f: ~3};
- alt *x {
+ match *x {
{f: b_x} => {
assert *b_x == 3;
assert ptr::addr_of(*x.f) == ptr::addr_of(*b_x);
fn main() {
let mut x = @mut @{f: ~3};
- alt x {
+ match x {
@@{f: b_x} => {
assert *b_x == 3;
assert ptr::addr_of(x.f) == ptr::addr_of(b_x);
fn switcher(x: option<@int>) {
let mut x = x;
- alt x {
+ match x {
some(@y) => { copy y; x = none; }
none => { }
}
let x = @mut 5;
let y = @mut newtype(3);
- let z = alt *y {
+ let z = match *y {
newtype(b) => {
*x += 1;
*x * b
enum bar { u(@foo), w(int), }
fn main() {
- assert (alt u(@{a: 10, b: 40u}) {
+ assert (match u(@{a: 10, b: 40u}) {
u(@{a: a, b: b}) => { a + (b as int) }
_ => { 66 }
} == 50);
fn contains_key(+k: int) -> bool { k <= self.meows }
fn contains_key_ref(k: &int) -> bool { self.contains_key(*k) }
- fn get(+k:int) -> T { alt self.find(k) {
+ fn get(+k:int) -> T { match self.find(k) {
some(v) => { v }
none => { fail ~"epic fail"; }
}
}
fn remove(+k:int) -> option<T> {
- alt self.find(k) {
+ match self.find(k) {
some(x) => {
self.meows -= k; some(x)
}
enum t { foo(@int), }
-fn main() { let tt = foo(@10); alt tt { foo(z) => { } } }
+fn main() { let tt = foo(@10); match tt { foo(z) => { } } }
// -*- rust -*-
-// Tests for alt as expressions resulting in boxed types
+// Tests for match as expressions resulting in boxed types
fn test_box() {
- let res = alt check true { true => { @100 } };
+ let res = match check true { true => { @100 } };
assert (*res == 100);
}
fn test_str() {
- let res = alt check true { true => { ~"happy" } };
+ let res = match check true { true => { ~"happy" } };
assert (res == ~"happy");
}
-// When all branches of an alt expression result in fail, the entire
-// alt expression results in fail.
+// When all branches of an match expression result in fail, the entire
+// match expression results in fail.
fn main() {
let x =
- alt true {
+ match true {
true => { 10 }
- false => { alt true { true => { fail } false => { fail } } }
+ false => { match true { true => { fail } false => { fail } } }
};
}
fn test_simple() {
- let r = alt true { true => { true } false => { fail } };
+ let r = match true { true => { true } false => { fail } };
assert (r == true);
}
fn test_box() {
- let r = alt true { true => { ~[10] } false => { fail } };
+ let r = match true { true => { ~[10] } false => { fail } };
assert (r[0] == 10);
}
type compare<T> = fn@(@T, @T) -> bool;
fn test_generic<T>(expected: @T, eq: compare<T>) {
- let actual: @T = alt check true { true => { expected } };
+ let actual: @T = match check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true => { expected } };
+ let actual: T = match check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(~T, ~T) -> bool;
fn test_generic<T: copy>(expected: ~T, eq: compare<T>) {
- let actual: ~T = alt check true { true => { expected } };
+ let actual: ~T = match check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true => { expected } };
+ let actual: T = match check true { true => { expected } };
assert (eq(expected, actual));
}
type compare<T> = fn@(T, T) -> bool;
fn test_generic<T: copy>(expected: T, eq: compare<T>) {
- let actual: T = alt check true { true => { expected } };
+ let actual: T = match check true { true => { expected } };
assert (eq(expected, actual));
}
// -*- rust -*-
-// Tests for alt as expressions resulting in structural types
+// Tests for match as expressions resulting in structural types
fn test_rec() {
- let rs = alt check true { true => { {i: 100} } };
+ let rs = match check true { true => { {i: 100} } };
assert (rs == {i: 100});
}
fn test_tag() {
enum mood { happy, sad, }
- let rs = alt true { true => { happy } false => { sad } };
+ let rs = match true { true => { happy } false => { sad } };
assert (rs == happy);
}
// -*- rust -*-
-// Tests for alt as expressions resulting in boxed types
+// Tests for match as expressions resulting in boxed types
fn test_box() {
- let res = alt check true { true => { ~100 } };
+ let res = match check true { true => { ~100 } };
assert (*res == 100);
}
// -*- rust -*-
-// Tests for using alt as an expression
+// Tests for using match as an expression
fn test_basic() {
- let mut rs: bool = alt true { true => { true } false => { false } };
+ let mut rs: bool = match true { true => { true } false => { false } };
assert (rs);
- rs = alt false { true => { false } false => { true } };
+ rs = match false { true => { false } false => { true } };
assert (rs);
}
fn test_inferrence() {
- let mut rs = alt true { true => { true } false => { false } };
+ let mut rs = match true { true => { true } false => { false } };
assert (rs);
}
// Yeah, this is kind of confusing ...
let rs =
- alt alt false { true => { true } false => { false } } {
+ match match false { true => { true } false => { false } } {
true => { false }
false => { true }
};
fn test_alt_as_block_result() {
let rs =
- alt false {
+ match false {
true => { false }
- false => { alt true { true => { true } false => { false } } }
+ false => { match true { true => { true } false => { false } } }
};
assert (rs);
}
// Issue #521
-fn f() { let x = alt true { true => { 10 } false => { return } }; }
+fn f() { let x = match true { true => { 10 } false => { return } }; }
fn main() { }
}
fn test_alt() {
- fn f() -> int { alt true { false => { 10 } true => { 20 } } }
+ fn f() -> int { match true { false => { 10 } true => { 20 } } }
assert (f() == 20);
}
}
fn main() {
- log(error, alt red {
+ log(error, match red {
red => { 1 }
green => { 2 }
blue => { 3 }
fn altfoo<T>(f: foo<T>) {
let mut hit = false;
- alt f { arm::<T>(x) => { debug!{"in arm"}; hit = true; } }
+ match f { arm::<T>(x) => { debug!{"in arm"}; hit = true; } }
assert (hit);
}
fn main() {
let nop: noption<int> = some::<int>(5);
- alt nop { some::<int>(n) => { log(debug, n); assert (n == 5); } }
+ match nop { some::<int>(n) => { log(debug, n); assert (n == 5); } }
let nop2: noption<{x: int, y: int}> = some({x: 17, y: 42});
- alt nop2 {
+ match nop2 {
some(t) => {
log(debug, t.x);
log(debug, t.y);
fn main() {
let a =
- alt 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
+ match 10 { x if x < 7 => { 1 } x if x < 11 => { 2 } 10 => { 3 } _ => { 4 } };
assert (a == 2);
let b =
- alt {x: 10, y: 20} {
+ match {x: 10, y: 20} {
x if x.x < 5 && x.y < 5 => { 1 }
{x: x, y: y} if x == 10 && y == 20 => { 2 }
{x: x, y: y} => { 3 }
fn emit(im: map::hashmap<~str, int>, ctrl: chan<ctrl_proto>, key: ~str,
val: ~str) {
let mut c;
- alt im.find(key) {
+ match im.find(key) {
some(_c) => { c = _c }
none => {
let p = port();
let mut num_mappers = vec::len(inputs) as int;
while num_mappers > 0 {
- alt recv(ctrl) {
+ match recv(ctrl) {
mapper_done => { num_mappers -= 1; }
find_reducer(k, cc) => {
let mut c;
- alt reducers.find(str::from_bytes(k)) {
+ match reducers.find(str::from_bytes(k)) {
some(_c) => { c = _c; }
none => { c = 0; }
}
fn main() {
let x = 2;
- let x_message = alt x {
+ let x_message = match x {
0 to 1 => { ~"not many" }
_ => { ~"lots" }
};
assert x_message == ~"lots";
let y = 2i;
- let y_message = alt y {
+ let y_message = match y {
0 to 1 => { ~"not many" }
_ => { ~"lots" }
};
assert y_message == ~"lots";
let z = 1u64;
- let z_message = alt z {
+ let z_message = match z {
0 to 1 => { ~"not many" }
_ => { ~"lots" }
};
enum animal { cat(pattern), dog(breed), rabbit(name, ear_kind), tiger }
fn noise(a: animal) -> option<~str> {
- alt a {
+ match a {
cat(*) => { some(~"meow") }
dog(*) => { some(~"woof") }
rabbit(*) => { none }
fn main(args: ~[str]) {
let ar = arena::arena();
let leak = init(&ar, args[0]);
- alt *leak {
+ match *leak {
s(astr) {
io::println(fmt!{"%?", astr});
}
assert (*p).payload == none;
(*p).payload <- some(payload);
let old_state = swap_state_rel((*p).state, full);
- alt old_state {
+ match old_state {
empty => {
// Yay, fastpath.
loop {
let old_state = swap_state_acq((*p).state,
blocked);
- alt old_state {
+ match old_state {
empty | blocked => { task::yield(); }
full => {
let mut payload = none;
fn sender_terminate<T: send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
- alt swap_state_rel((*p).state, terminated) {
+ match swap_state_rel((*p).state, terminated) {
empty | blocked => {
// The receiver will eventually clean up.
unsafe { forget(p) }
fn receiver_terminate<T: send>(p: *packet<T>) {
let p = unsafe { uniquify(p) };
- alt swap_state_rel((*p).state, terminated) {
+ match swap_state_rel((*p).state, terminated) {
empty => {
// the sender will clean up
unsafe { forget(p) }
enum pong = pipes::send_packet<ping>;
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
- let addr : *pipes::send_packet<pong> = alt p {
+ let addr : *pipes::send_packet<pong> = match p {
ping(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
};
let liberated_value <- *addr;
}
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
- let addr : *pipes::send_packet<ping> = alt p {
+ let addr : *pipes::send_packet<ping> = match p {
pong(x) => { unsafe::reinterpret_cast(ptr::addr_of(x)) }
};
let liberated_value <- *addr;
fn lookup(table: std::map::hashmap<~str, std::json::json>, key: ~str, default: ~str) -> ~str
{
- alt table.find(key)
+ match table.find(key)
{
option::some(std::json::string(s)) =>
{
fn add_interface(store: int, managed_ip: ~str, data: std::json::json) -> (~str, object)
{
- alt data
+ match data
{
std::json::dict(interface) =>
{
fn add_interfaces(store: int, managed_ip: ~str, device: std::map::hashmap<~str, std::json::json>) -> ~[(~str, object)]
{
- alt device[~"interfaces"]
+ match device[~"interfaces"]
{
std::json::list(interfaces) =>
{
fn f(pat: pat) -> bool { true }
fn num_bindings(pat: pat) -> uint {
- alt pat {
+ match pat {
pat_ident(_) if f(pat) { 0 }
pat_ident(none) { 1 }
pat_ident(some(sub)) { sub }
impl of to_str::to_str for square {
fn to_str() -> ~str {
- alt self {
+ match self {
bot => { ~"R" }
wall => { ~"#" }
rock => { ~"*" }
}
fn square_from_char(c: char) -> square {
- alt c {
+ match c {
'R' => { bot }
'#' => { wall }
'*' => { rock }
fn what_to_str(x: what) -> ~str
{
- alt x {
+ match x {
}
}
loop {
let msg = recv(p);
- alt msg {
+ match msg {
closed => { debug!{"Got close message"}; break; }
received(data) => {
debug!{"Got data. Length is:"};
// return -> return
// mod -> module
-// alt -> match
+// match -> match
fn main() {
}
fn main() {
let p = test_comm::port();
- alt none::<int> {
+ match none::<int> {
none => {}
some(_) =>{
if test_comm::recv(p) == 0 {
{$fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path} =>
{
fn $fnname($arg: $ty) -> option<$ty> $body
- alt $fnname($val) {
+ match $fnname($val) {
some($pat) => {
$res
}
fn animal() -> ~str { ~"cat" }
fn talk(c: cat) -> ~str {
- alt c {
+ match c {
howlycat => { ~"howl" }
meowlycat => { ~"meow" }
}
impl monad<A> of option_monad<A> for option<A> {
fn bind<B>(f: fn(A) -> option<B>) -> option<B> {
- alt self {
+ match self {
some(a) => { f(a) }
none => { none }
}
fn main() {
- alt -5 {
+ match -5 {
-5 => {}
_ => { fail }
}
fn baz() -> ! { fail; }
fn foo() {
- alt some::<int>(5) {
+ match some::<int>(5) {
some::<int>(x) => {
let mut bar;
- alt none::<int> { none::<int> => { bar = 5; } _ => { baz(); } }
+ match none::<int> { none::<int> => { bar = 5; } _ => { baz(); } }
log(debug, bar);
}
none::<int> => { debug!{"hello"}; }
fn main() {
- alt @{foo: true, bar: some(10), baz: 20} {
+ match @{foo: true, bar: some(10), baz: 20} {
@{foo: true, bar: some(_), _} => {}
@{foo: false, bar: none, _} => {}
@{foo: true, bar: none, _} => {}
enum t { foo(int, uint), bar(int, option<int>), }
fn nested(o: t) {
- alt o {
+ match o {
bar(i, some::<int>(_)) => { error!{"wrong pattern matched"}; fail; }
_ => { error!{"succeeded"}; }
}
fn main() {
- alt {a: 10, b: @20} {
+ match {a: 10, b: @20} {
x@{a, b: @20} => { assert x.a == 10; assert a == 10; }
{b, _} => { fail; }
}
-fn main() { let x = (); alt x { () => { } } }
+fn main() { let x = (); match x { () => { } } }
import std::list::*;
pure fn pure_length_go<T: copy>(ls: @list<T>, acc: uint) -> uint {
- alt *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
+ match *ls { nil => { acc } cons(_, tl) => { pure_length_go(tl, acc + 1u) } }
}
pure fn pure_length<T: copy>(ls: @list<T>) -> uint { pure_length_go(ls, 0u) }
enum blah { a, b, }
fn or_alt(q: blah) -> int {
- alt q { a | b => { 42 } }
+ match q { a | b => { 42 } }
}
fn main() {
enum blah { a(int, int, uint), b(int, int), c, }
fn or_alt(q: blah) -> int {
- alt q { a(x, y, _) | b(x, y) => { return x + y; } c => { return 0; } }
+ match q { a(x, y, _) | b(x, y) => { return x + y; } c => { return 0; } }
}
fn main() {
fn main() {
let x = true;
if x { let mut i = 10; while i > 0 { i -= 1; } }
- alt x { true => { debug!{"right"}; } false => { debug!{"wrong"}; } }
+ match x { true => { debug!{"right"}; } false => { debug!{"wrong"}; } }
}
fn foo(src: uint) {
- alt some(src) {
+ match some(src) {
some(src_id) => {
for uint::range(0u, 10u) |i| {
let yyy = src_id;
{
$($message:path($($x: ident),+) => $next:ident $e:expr)+
} => (
- |m| alt move_it(m) {
+ |m| match move_it(m) {
$(some($message($($x,)* next)) {
let $next = move_it!{next};
$e })+
{
$($message:path => $next:ident $e:expr)+
} => (
- |m| alt move_it(m) {
+ |m| match move_it(m) {
$(some($message(next)) {
let $next = move_it!{next};
$e })+
let bank = client::deposit(bank, 100.00);
let bank = client::withdrawal(bank, 50.00);
- alt try_recv(bank) {
+ match try_recv(bank) {
some(money(m, _)) {
io::println(~"Yay! I got money!");
}
import bank::*;
let bank = client::login(bank, ~"theincredibleholk", ~"1234");
- let bank = alt try_recv(bank) {
+ let bank = match try_recv(bank) {
some(ok(connected)) => {
move_it!{connected}
}
let bank = client::deposit(bank, 100.00);
let bank = client::withdrawal(bank, 50.00);
- alt try_recv(bank) {
+ match try_recv(bank) {
some(money(m, _)) => {
io::println(~"Yay! I got money!");
}
let iotask = uv::global_loop::get();
pipes::spawn_service(oneshot::init, |p| {
- alt try_recv(p) {
+ match try_recv(p) {
some(*) => { fail }
none => { }
}
stream::client::send(ac, 42);
- alt pipes::select2(ap, bp) {
+ match pipes::select2(ap, bp) {
either::left(*) => { }
either::right(*) => { fail }
}
stream::client::send(bc, ~"abc");
- alt pipes::select2(ap, bp) {
+ match pipes::select2(ap, bp) {
either::left(*) => { fail }
either::right(*) => { }
}
enum t3 { c(t2, uint), }
fn m(in: t3) -> int {
- alt in {
+ match in {
c({x: a(m), _}, _) => { return m; }
c({x: b(m), y: y}, z) => { return ((m + z) as int) + y; }
}
// below. note that it would it you
// naively borrowed &x for the lifetime
// of the variable x, as we once did
- alt i {
+ match i {
i => {
let y = &x;
assert i < *y;
let x = 3;
let y = int_wrapper_ctor(&x);
let mut z : ∫
- alt y {
+ match y {
int_wrapper_ctor(zz) => { z = zz; }
}
log(debug, *z);
let mut b: ~[int] = ~[];
- alt none::<int> {
+ match none::<int> {
some::<int>(_) => {
for c.each |i| {
log(debug, a);
fn main() {
let x = none::<int>;
- alt x { none::<int> => { debug!{"hello world"}; } }
+ match x { none::<int> => { debug!{"hello world"}; } }
}
enum clam<T> { a(T), }
-fn main() { let c = a(2); alt c { a::<int>(_) => { } } }
+fn main() { let c = a(2); match c { a::<int>(_) => { } } }
enum clam<T> { a(T, int), b, }
fn uhoh<T>(v: ~[clam<T>]) {
- alt v[1] {
+ match v[1] {
a::<T>(t, u) => { debug!{"incorrect"}; log(debug, u); fail; }
b::<T> => { debug!{"correct"}; }
}
}
fn variant_data_is_aligned<A,B>(amnt: uint, &&u: a_tag<A,B>) -> bool {
- alt u {
+ match u {
varA(a) { is_aligned(amnt, a) }
varB(b) { is_aligned(amnt, b) }
}
}
fn get_color_alt(color: color) -> ~str {
- alt color {
+ match color {
red => {~"red"}
green => {~"green"}
blue => {~"blue"}
impl <T: to_str> of to_str for option<T> {
fn to_str() -> ~str {
- alt self {
+ match self {
none => { ~"none" }
some(t) => { ~"some(" + t.to_str() + ~")" }
}
fn f() {
let x = 10; let mut y = 11;
- if true { alt x { _ => { y = x; } } } else { }
+ if true { match x { _ => { y = x; } } } else { }
}
fn main() {
// Issue #961
fn altsimple() {
- alt ~true {
+ match ~true {
_ => { }
}
}
enum bar { u(~int), w(int), }
let x = u(~10);
- assert alt x {
+ assert match x {
u(a) => {
log(error, a);
*a
enum bar { u(~foo), w(int), }
fn main() {
- assert (alt u(~{a: 10, b: 40u}) {
+ assert (match u(~{a: 10, b: 40u}) {
u(~{a: a, b: b}) => { a + (b as int) }
_ => { 66 }
} == 50);
enum bar { u(~int), w(int), }
fn main() {
- assert alt u(~10) {
+ assert match u(~10) {
u(a) => {
log(error, a);
*a
fn simple() {
- alt ~true {
+ match ~true {
~true => { }
_ => { fail; }
}
fn ret_ret() -> int { return (return 2) + 3; }
fn ret_guard() {
- alt 2 {
+ match 2 {
x if (return) => { x; }
_ => {}
}
fn foo<T>(o: myoption<T>) -> int {
let mut x: int = 5;
- alt o { none::<T> => { } some::<T>(t) => { x += 1; } }
+ match o { none::<T> => { } some::<T>(t) => { x += 1; } }
return x;
}
fn foo<T>(o: myoption<T>) -> int {
let mut x: int;
- alt o { none::<T> => { fail; } some::<T>(t) => { x = 5; } }
+ match o { none::<T> => { fail; } some::<T>(t) => { x = 5; } }
return x;
}
loop {
while (return) {
if (return) {
- alt (return) {
+ match (return) {
1 => {
if (return) {
return
fn angrydome() {
loop { if break { } }
let mut i = 0;
- loop { i += 1; if i == 1 { alt check again { 1 => { } } } break; }
+ loop { i += 1; if i == 1 { match check again { 1 => { } } } break; }
}
fn evil_lincoln() { let evil <- debug!{"lincoln"}; }