Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,13 +473,6 @@ The comparison operators are the traditional `==`, `!=`, `<`, `>`,
`<=`, and `>=`. Short-circuiting (lazy) boolean operators are written
`&&` (and) and `||` (or).

Rust has a ternary conditional operator `?:`, as in:

~~~~
let badness = 12;
let message = badness < 10 ? "error" : "FATAL ERROR";
~~~~

For type casting, Rust uses the binary `as` operator, which has a
precedence between the bitwise combination operators (`&`, `|`, `^`)
and the comparison operators. It takes an expression on the left side,
Expand Down
6 changes: 5 additions & 1 deletion src/comp/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ fn host_triple() -> str {
// grabbing (at compile time) the target triple that this rustc is
// built with and calling that (at runtime) the host triple.
let ht = #env("CFG_HOST_TRIPLE");
ret ht != "" ? ht : fail "rustc built without CFG_HOST_TRIPLE";
ret if ht != "" {
ht
} else {
fail "rustc built without CFG_HOST_TRIPLE"
};
}

fn build_session_options(match: getopts::match,
Expand Down
2 changes: 1 addition & 1 deletion src/comp/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ fn mk_path(cx: test_ctxt, path: [ast::ident]) -> [ast::ident] {
_ { false }
}
};
(is_std ? [] : ["std"]) + path
(if is_std { [] } else { ["std"] }) + path
}

// The ast::ty of [std::test::test_desc]
Expand Down
15 changes: 9 additions & 6 deletions src/comp/middle/alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,23 +602,26 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
ast::pat_rec(fs, _) {
let ty = ty::node_id_to_type(tcx, pat.id);
for f in fs {
let m = ty::get_field(tcx, ty, f.ident).mt.mut != ast::imm;
walk(tcx, m ? some(contains(ty)) : mut, f.pat, set);
let m = ty::get_field(tcx, ty, f.ident).mt.mut != ast::imm,
c = if m { some(contains(ty)) } else { mut };
walk(tcx, c, f.pat, set);
}
}
ast::pat_box(p) {
let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::struct(tcx, ty) {
ty::ty_box(mt) { mt.mut != ast::imm }
};
walk(tcx, m ? some(contains(ty)) : mut, p, set);
},
c = if m {some(contains(ty)) } else { mut };
walk(tcx, c, p, set);
}
ast::pat_uniq(p) {
let ty = ty::node_id_to_type(tcx, pat.id);
let m = alt ty::struct(tcx, ty) {
ty::ty_uniq(mt) { mt.mut != ast::imm }
};
walk(tcx, m ? some(contains(ty)) : mut, p, set);
},
c = if m { some(contains(ty)) } else { mut };
walk(tcx, c, p, set);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/comp/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ fn check_expr(sess: session, method_map: typeck::method_map, e: @expr,
expr_lit(@{node: lit_int(v, t), _}) {
if t != ty_char {
if (v as u64) > ast_util::int_ty_max(
t == ty_i ? sess.targ_cfg.int_type : t) {
if t == ty_i { sess.targ_cfg.int_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type");
}
}
}
expr_lit(@{node: lit_uint(v, t), _}) {
if v > ast_util::uint_ty_max(
t == ty_u ? sess.targ_cfg.uint_type : t) {
if t == ty_u { sess.targ_cfg.uint_type } else { t }) {
sess.span_err(e.span, "literal out of range for its type");
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/comp/middle/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,10 +465,16 @@ fn create_composite_type(type_tag: int, name: str, file: ValueRef, line: int,
lli64(align), // align
lli64(offset), // offset
lli32(0), // flags
option::is_none(derived) ? llnull() : // derived from
option::get(derived),
option::is_none(members) ? llnull() : // members
llmdnode(option::get(members)),
if option::is_none(derived) {
llnull()
} else { // derived from
option::get(derived)
},
if option::is_none(members) {
llnull()
} else { //members
llmdnode(option::get(members))
},
lli32(0), // runtime language
llnull()
];
Expand Down Expand Up @@ -776,7 +782,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
let loc = codemap::lookup_char_pos(cx.sess.codemap,
sp.lo);
let file_node = create_file(cx, loc.filename).node;
let key = cx.item_symbols.contains_key(fcx.id) ? fcx.id : id;
let key = if cx.item_symbols.contains_key(fcx.id) { fcx.id } else { id };
let mangled = cx.item_symbols.get(key);
let ty_node = if cx.sess.opts.extra_debuginfo {
alt ret_ty.node {
Expand Down
1 change: 0 additions & 1 deletion src/comp/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
none {}
}
}
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
expr_fn(_, _, _, cap_clause) {
check_fn_cap_clause(cx, e.id, *cap_clause);
}
Expand Down
3 changes: 0 additions & 3 deletions src/comp/middle/last_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
v.visit_expr(coll, cx, v);
visit_block(loop, cx) {|| visit::visit_block(blk, cx, v);}
}
expr_ternary(_, _, _) {
v.visit_expr(ast_util::ternary_to_if(ex), cx, v);
}
expr_alt(input, arms) {
v.visit_expr(input, cx, v);
let before = cx.current, sets = [];
Expand Down
9 changes: 6 additions & 3 deletions src/comp/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ fn visit_block_with_impl_scope(e: @env, b: ast::blk, sc: iscopes,
_ {}
}
}
let sc = vec::len(impls) > 0u ? cons(@impls, @sc) : sc;
let sc = if vec::len(impls) > 0u { cons(@impls, @sc) } else { sc };
visit::visit_block(b, sc, v);
}

Expand All @@ -1998,8 +1998,11 @@ fn visit_mod_with_impl_scope(e: @env, m: ast::_mod, s: span, id: node_id,
}
for i in m.items { find_impls_in_item(*e, i, impls, none, none); }
let impls = @impls;
visit::visit_mod(m, s, id,
vec::len(*impls) > 0u ? cons(impls, @sc) : sc, v);
visit::visit_mod(m, s, id, if vec::len(*impls) > 0u {
cons(impls, @sc)
} else {
sc
}, v);
e.impl_map.insert(id, cons(impls, @nil));
}

Expand Down
15 changes: 11 additions & 4 deletions src/comp/middle/trans/alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,11 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,

let col = pick_col(m);
let val = vals[col];
let m = has_nested_bindings(m, col) ?
expand_nested_bindings(m, col, val) : m;
let m = if has_nested_bindings(m, col) {
expand_nested_bindings(m, col, val)
} else {
m
};

let vals_left =
vec::slice(vals, 0u, col) +
Expand Down Expand Up @@ -492,8 +495,12 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
}
lit(l) {
test_val = Load(bcx, val);
let pty = ty::node_id_to_type(ccx.tcx, pat_id);
kind = ty::type_is_integral(ccx.tcx, pty) ? switch : compare;
let pty = ty::node_id_to_monotype(ccx.tcx, pat_id);
kind = if ty::type_is_integral(ccx.tcx, pty) {
switch
} else {
compare
};
}
range(_, _) {
test_val = Load(bcx, val);
Expand Down
24 changes: 14 additions & 10 deletions src/comp/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn type_of_explicit_args(cx: @crate_ctxt, inputs: [ty::arg]) ->
// that would obviate the need for this check
check non_ty_var(cx, arg_ty);
let llty = type_of_inner(cx, arg_ty);
atys += [arg.mode == ast::by_val ? llty : T_ptr(llty)];
atys += [if arg.mode == ast::by_val { llty } else { T_ptr(llty) }];
}
ret atys;
}
Expand Down Expand Up @@ -2015,8 +2015,11 @@ fn store_temp_expr(cx: @block_ctxt, action: copy_action, dst: ValueRef,
-> @block_ctxt {
// Lvals in memory are not temporaries. Copy them.
if src.kind != temporary && !last_use {
let v = src.kind == owned ? load_if_immediate(cx, src.val, t)
: src.val;
let v = if src.kind == owned {
load_if_immediate(cx, src.val, t)
} else {
src.val
};
ret copy_val(cx, action, dst, v, t);
}
ret move_val(cx, action, dst, src, t);
Expand Down Expand Up @@ -3417,7 +3420,7 @@ fn trans_expr_save_in(bcx: @block_ctxt, e: @ast::expr, dest: ValueRef)
-> @block_ctxt {
let tcx = bcx_tcx(bcx), t = ty::expr_ty(tcx, e);
let do_ignore = ty::type_is_bot(tcx, t) || ty::type_is_nil(tcx, t);
ret trans_expr(bcx, e, do_ignore ? ignore : save_in(dest));
ret trans_expr(bcx, e, if do_ignore { ignore } else { save_in(dest) });
}

// Call this to compile an expression that you need as an intermediate value,
Expand Down Expand Up @@ -3475,9 +3478,6 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
ast::expr_if(cond, thn, els) | ast::expr_if_check(cond, thn, els) {
ret trans_if(bcx, cond, thn, els, dest);
}
ast::expr_ternary(_, _, _) {
ret trans_expr(bcx, ast_util::ternary_to_if(e), dest);
}
ast::expr_alt(expr, arms) {
// tcx.sess.span_note(e.span, "about to call trans_alt");
ret alt::trans_alt(bcx, expr, arms, dest);
Expand Down Expand Up @@ -4256,7 +4256,7 @@ fn trans_block_dps(bcx: @block_ctxt, b: ast::blk, dest: dest)
some(e) {
let bt = ty::type_is_bot(bcx_tcx(bcx), ty::expr_ty(bcx_tcx(bcx), e));
debuginfo::update_source_pos(bcx, e.span);
bcx = trans_expr(bcx, e, bt ? ignore : dest);
bcx = trans_expr(bcx, e, if bt { ignore } else { dest });
}
_ { assert dest == ignore || bcx.unreachable; }
}
Expand Down Expand Up @@ -4493,7 +4493,11 @@ fn trans_fn(cx: @local_ctxt, sp: span, decl: ast::fn_decl, body: ast::blk,
llfndecl: ValueRef, ty_self: self_arg, ty_params: [ast::ty_param],
id: ast::node_id) {
let do_time = cx.ccx.sess.opts.stats;
let start = do_time ? time::get_time() : {sec: 0u32, usec: 0u32};
let start = if do_time {
time::get_time()
} else {
{sec: 0u32, usec: 0u32}
};
let fcx = option::none;
trans_closure(cx, sp, decl, body, llfndecl, ty_self, ty_params, id,
{|new_fcx| fcx = option::some(new_fcx);});
Expand Down Expand Up @@ -5396,7 +5400,7 @@ fn decl_crate_map(sess: session::session, mapname: str,
let n_subcrates = 1;
let cstore = sess.cstore;
while cstore::have_crate_data(cstore, n_subcrates) { n_subcrates += 1; }
let mapname = sess.building_library ? mapname : "toplevel";
let mapname = if sess.building_library { mapname } else { "toplevel" };
let sym_name = "_rust_crate_map_" + mapname;
let arrtype = T_array(int_type, n_subcrates as uint);
let maptype = T_struct([int_type, arrtype]);
Expand Down
23 changes: 17 additions & 6 deletions src/comp/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,13 @@ fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
let ccx = bcx_ccx(cx);
let unit_ty = ty::sequence_element_type(bcx_tcx(cx), vec_ty);
let dynamic = ty::type_has_dynamic_size(bcx_tcx(cx), unit_ty);
let (lhsptr, rhs) = !dynamic ? (lhsptr, rhs) :
(PointerCast(cx, lhsptr, T_ptr(T_ptr(ccx.opaque_vec_type))),
PointerCast(cx, rhs, T_ptr(ccx.opaque_vec_type)));
let (lhsptr, rhs) =
if !dynamic {
(lhsptr, rhs)
} else {
(PointerCast(cx, lhsptr, T_ptr(T_ptr(ccx.opaque_vec_type))),
PointerCast(cx, rhs, T_ptr(ccx.opaque_vec_type)))
};
let strings = alt ty::struct(bcx_tcx(cx), vec_ty) {
ty::ty_str { true }
ty::ty_vec(_) { false }
Expand Down Expand Up @@ -187,7 +191,11 @@ fn trans_append(cx: @block_ctxt, vec_ty: ty::t, lhsptr: ValueRef,
copy_val(bcx, INIT, write_ptr,
load_if_immediate(bcx, addr, unit_ty),
unit_ty);
let incr = dynamic ? unit_sz : C_int(ccx, 1);
let incr = if dynamic {
unit_sz
} else {
C_int(ccx, 1)
};
Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]),
write_ptr_ptr);
ret bcx;
Expand Down Expand Up @@ -244,8 +252,11 @@ fn trans_add(bcx: @block_ctxt, vec_ty: ty::t, lhs: ValueRef,
let bcx = copy_val(bcx, INIT, write_ptr,
load_if_immediate(bcx, addr, unit_ty), unit_ty);
let incr =
ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) ?
llunitsz : C_int(ccx, 1);
if ty::type_has_dynamic_size(bcx_tcx(bcx), unit_ty) {
llunitsz
} else {
C_int(ccx, 1)
};
Store(bcx, InBoundsGEP(bcx, write_ptr, [incr]),
write_ptr_ptr);
ret bcx;
Expand Down
1 change: 0 additions & 1 deletion src/comp/middle/tstate/pre_post_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
expr_if(antec, conseq, maybe_alt) {
join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if);
}
expr_ternary(_, _, _) { find_pre_post_expr(fcx, ternary_to_if(e)); }
expr_binary(bop, l, r) {
if lazy_binop(bop) {
find_pre_post_expr(fcx, l);
Expand Down
3 changes: 0 additions & 3 deletions src/comp/middle/tstate/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,6 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
ret join_then_else(fcx, antec, conseq, maybe_alt, e.id, plain_if,
pres);
}
expr_ternary(_, _, _) {
ret find_pre_post_state_expr(fcx, pres, ternary_to_if(e));
}
expr_binary(bop, l, r) {
if lazy_binop(bop) {
let changed = find_pre_post_state_expr(fcx, pres, l);
Expand Down
15 changes: 10 additions & 5 deletions src/comp/middle/typeck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,17 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
fcx.ccx.tcx.sess.span_err(
sp, #fmt["this function takes %u parameter%s but %u \
parameter%s supplied", expected_arg_count,
expected_arg_count == 1u ? "" : "s",
if expected_arg_count == 1u {
""
} else {
"s"
},
supplied_arg_count,
supplied_arg_count == 1u ? " was" : "s were"]);
if supplied_arg_count == 1u {
" was"
} else {
"s were"
}]);
// HACK: build an arguments list with dummy arguments to
// check against
let dummy = {mode: ast::by_ref, ty: ty::mk_bot(fcx.ccx.tcx)};
Expand Down Expand Up @@ -1913,9 +1921,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
check_pred_expr(fcx, cond) |
check_then_else(fcx, thn, elsopt, id, expr.span);
}
ast::expr_ternary(_, _, _) {
bot = check_expr(fcx, ast_util::ternary_to_if(expr));
}
ast::expr_assert(e) {
bot = check_expr_with(fcx, e, ty::mk_bool(tcx));
write_nil(tcx, id);
Expand Down
1 change: 0 additions & 1 deletion src/comp/syntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ enum expr_ {
expr_lit(@lit),
expr_cast(@expr, @ty),
expr_if(@expr, blk, option::t<@expr>),
expr_ternary(@expr, @expr, @expr),
expr_while(@expr, blk),
expr_for(@local, @expr, blk),
expr_do_while(blk, @expr),
Expand Down
Loading