You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
~~~~
# type foo = int;
# fn bar(f: foo) { }
-# let a = 0, b = 0, c = 0;
+# let a = 0;
+# let b = 0;
+# let c = 0;
let v: &[foo] = &[a, b, c];
Local variables are immutable unless declared with `let mut`. The
`mut` keyword applies to all local variables declared within that
-declaration (so `let mut x, y` declares two mutable variables, `x` and
+declaration (so `let mut (x, y) = ...` declares two mutable variables, `x` and
`y`).
Function parameters are immutable unless declared with `mut`. The
priv ptr: *mut T
}
-pub impl<T: Owned> Unique<T> {
- fn new(value: T) -> Unique<T> {
+impl<T: Owned> Unique<T> {
+ pub fn new(value: T) -> Unique<T> {
unsafe {
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;
assert!(!ptr::is_null(ptr));
}
// the 'r lifetime results in the same semantics as `&*x` with ~T
- fn borrow<'r>(&'r self) -> &'r T {
+ pub fn borrow<'r>(&'r self) -> &'r T {
unsafe { cast::copy_lifetime(self, &*self.ptr) }
}
// the 'r lifetime results in the same semantics as `&mut *x` with ~T
- fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
+ pub fn borrow_mut<'r>(&'r mut self) -> &'r mut T {
unsafe { cast::copy_mut_lifetime(self, &mut *self.ptr) }
}
}
~~~~
# enum t { special_a(uint), special_b(uint) };
# fn f() -> uint {
-# let input_1 = special_a(0), input_2 = special_a(0);
+# let input_1 = special_a(0);
+# let input_2 = special_a(0);
match input_1 {
special_a(x) => { return x; }
_ => {}
~~~~
# enum t { special_a(uint), special_b(uint) };
# fn f() -> uint {
-# let input_1 = special_a(0), input_2 = special_a(0);
+# let input_1 = special_a(0);
+# let input_2 = special_a(0);
macro_rules! early_return(
($inp:expr $sp:ident) => ( // invoke it like `(input_5 special_e)`
match $inp {
~~~~
# enum t { special_a(uint),special_b(uint),special_c(uint),special_d(uint)};
# fn f() -> uint {
-# let input_1 = special_a(0), input_2 = special_a(0);
+# let input_1 = special_a(0);
+# let input_2 = special_a(0);
macro_rules! early_return(
($inp:expr, [ $($sp:ident)|+ ]) => (
match $inp {
while idx < fill {
let tydesc_data: *uint = transmute(ptr::offset(buf, idx));
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
- let size = (*tydesc).size, align = (*tydesc).align;
+ let (size, align) = ((*tydesc).size, (*tydesc).align);
let after_tydesc = idx + sys::size_of::<*TypeDesc>();
arguments. `"-"` represents `stdin`.
*/
pub fn from_args() -> FileInput {
- let args = os::args(),
- pathed = pathify(args.tail(), true);
+ let args = os::args();
+ let pathed = pathify(args.tail(), true);
FileInput::from_vec(pathed)
}
return false;
}
- let path_option = self.fi.files.shift(),
- file = match path_option {
- None => io::stdin(),
- Some(ref path) => io::file_reader(path).get()
- };
+ let path_option = self.fi.files.shift();
+ let file = match path_option {
+ None => io::stdin(),
+ Some(ref path) => io::file_reader(path).get()
+ };
self.fi.current_reader = Some(file);
self.fi.state.current_path = path_option;
#[test]
fn test_pathify() {
let strs = [~"some/path",
- ~"some/other/path"],
- paths = ~[Some(Path("some/path")),
+ ~"some/other/path"];
+ let paths = ~[Some(Path("some/path")),
Some(Path("some/other/path"))];
assert_eq!(pathify(strs, true), copy paths);
#[test]
fn test_no_trailing_newline() {
- let f1 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp")),
- f2 = Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
+ let f1 =
+ Some(Path("tmp/lib-fileinput-test-no-trailing-newline-1.tmp"));
+ let f2 =
+ Some(Path("tmp/lib-fileinput-test-no-trailing-newline-2.tmp"));
let wr = io::file_writer(f1.get_ref(), [io::Create, io::Truncate]).get();
wr.write_str("1\n2");
let e = msg.len();
let mut x = vec::from_elem(16u, 0u32);
while i < e {
- let aa = a, bb = b, cc = c, dd = d;
+ let (aa, bb, cc, dd) = (a, b, c, d);
- let mut j = 0u, base = i;
+ let mut (j, base) = (0u, i);
while j < 16u {
x[j] = (msg[base] as u32) + (msg[base + 1u] as u32 << 8u32) +
(msg[base + 2u] as u32 << 16u32) +
let mut port = None;
let mut colon_count = 0;
- let mut pos = 0, begin = 2, end = len;
+ let mut (pos, begin, end) = (0, 2, len);
for str::each_chari(rawurl) |i,c| {
if i < 2 { loop; } // ignore the leading //
impl TotalOrd for BigUint {
fn cmp(&self, other: &BigUint) -> Ordering {
- let s_len = self.data.len(), o_len = other.data.len();
+ let (s_len, o_len) = (self.data.len(), other.data.len());
if s_len < o_len { return Less; }
if s_len > o_len { return Greater; }
fn mul(&self, other: &BigUint) -> BigUint {
if self.is_zero() || other.is_zero() { return Zero::zero(); }
- let s_len = self.data.len(), o_len = other.data.len();
+ let (s_len, o_len) = (self.data.len(), other.data.len());
if s_len == 1 { return mul_digit(other, self.data[0]); }
if o_len == 1 { return mul_digit(self, other.data[0]); }
fn gcd(&self, other: &BigUint) -> BigUint {
// Use Euclid's algorithm
- let mut m = copy *self, n = copy *other;
+ let mut (m, n) = (copy *self, copy *other);
while !m.is_zero() {
let temp = m;
m = n % temp;
fn div_mod_floor(&self, other: &BigInt) -> (BigInt, BigInt) {
// m.sign == other.sign
let (d_ui, m_ui) = self.data.div_rem(&other.data);
- let d = BigInt::from_biguint(Plus, d_ui),
- m = BigInt::from_biguint(Plus, m_ui);
+ let d = BigInt::from_biguint(Plus, d_ui);
+ let m = BigInt::from_biguint(Plus, m_ui);
match (self.sign, other.sign) {
(_, Zero) => fail!(),
(Plus, Plus) | (Zero, Plus) => (d, m),
/// Parse a compiled terminfo entry, using long capability names if `longnames` is true
pub fn parse(file: @Reader, longnames: bool) -> Result<~TermInfo, ~str> {
- let bnames, snames, nnames;
+ let bnames;
+ let snames;
+ let nnames;
if longnames {
bnames = boolfnames;
b.stmts.filter_mapped(|a| filter_stmt(cx, *a));
let filtered_view_items =
b.view_items.filter_mapped(|a| filter_view_item(cx, *a));
+ let filtered_view_items =
+ filtered_view_items.map(|x| fld.fold_view_item(*x));
+ let mut resulting_stmts = ~[];
+ for filtered_stmts.each |stmt| {
+ match fld.fold_stmt(*stmt) {
+ None => {}
+ Some(stmt) => resulting_stmts.push(stmt),
+ }
+ }
ast::blk_ {
- view_items: vec::map(filtered_view_items, |x| fld.fold_view_item(*x)),
- stmts: vec::map(filtered_stmts, |x| fld.fold_stmt(*x)),
+ view_items: filtered_view_items,
+ stmts: resulting_stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)),
id: b.id,
rules: b.rules,
}
ty::ty_nil => None,
ty::ty_bool => {
- let mut true_found = false, false_found = false;
+ let mut true_found = false;
+ let mut false_found = false;
for m.each |r| {
match pat_ctor_id(cx, r[0]) {
None => (),
}
},
range(ref c_lo, ref c_hi) => {
- let m1 = compare_const_vals(c_lo, &e_v),
- m2 = compare_const_vals(c_hi, &e_v);
+ let m1 = compare_const_vals(c_lo, &e_v);
+ let m2 = compare_const_vals(c_hi, &e_v);
match (m1, m2) {
- (Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
+ (Some(val1), Some(val2)) => {
+ (val1 >= 0 && val2 <= 0)
+ }
_ => {
cx.tcx.sess.span_err(pat_span,
"mismatched types between ranges");
}
},
range(ref c_lo, ref c_hi) => {
- let m1 = compare_const_vals(c_lo, &e_v),
- m2 = compare_const_vals(c_hi, &e_v);
+ let m1 = compare_const_vals(c_lo, &e_v);
+ let m2 = compare_const_vals(c_hi, &e_v);
match (m1, m2) {
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
_ => {
}
_ => {
// Grab the class data that we care about.
- let class_fields, class_id;
+ let class_fields;
+ let class_id;
match ty::get(left_ty).sty {
ty::ty_struct(cid, _) => {
class_id = cid;
}
},
range(ref c_lo, ref c_hi) => {
- let m1 = compare_const_vals(c_lo, &e_v),
- m2 = compare_const_vals(c_hi, &e_v);
+ let m1 = compare_const_vals(c_lo, &e_v);
+ let m2 = compare_const_vals(c_hi, &e_v);
match (m1, m2) {
(Some(val1), Some(val2)) => (val1 >= 0 && val2 <= 0),
_ => {
single => return Some(vec::to_owned(r.tail())),
_ => fail!("type error")
};
- let v_lo = eval_const_expr(cx.tcx, lo),
- v_hi = eval_const_expr(cx.tcx, hi);
+ let v_lo = eval_const_expr(cx.tcx, lo);
+ let v_hi = eval_const_expr(cx.tcx, hi);
- let m1 = compare_const_vals(&c_lo, &v_lo),
- m2 = compare_const_vals(&c_hi, &v_hi);
+ let m1 = compare_const_vals(&c_lo, &v_lo);
+ let m2 = compare_const_vals(&c_hi, &v_hi);
match (m1, m2) {
(Some(val1), Some(val2)) if val1 >= 0 && val2 <= 0 => {
Some(vec::to_owned(r.tail()))
in_out: &mut [uint],
loop_scopes: &mut ~[LoopScope]) {
match decl.node {
- ast::decl_local(ref locals) => {
- for locals.each |local| {
- self.walk_pat(local.node.pat, in_out, loop_scopes);
- self.walk_opt_expr(local.node.init, in_out, loop_scopes);
- }
+ ast::decl_local(local) => {
+ self.walk_pat(local.node.pat, in_out, loop_scopes);
+ self.walk_opt_expr(local.node.init, in_out, loop_scopes);
}
ast::decl_item(_) => {}
pub fn propagate_through_decl(&self, decl: @decl, succ: LiveNode)
-> LiveNode {
match decl.node {
- decl_local(ref locals) => {
- do locals.foldr(succ) |local, succ| {
+ decl_local(ref local) => {
self.propagate_through_local(*local, succ)
}
- }
- decl_item(_) => {
- succ
- }
+ decl_item(_) => succ,
}
}
}
/// Records the current parent (if any) as the parent of `child_id`.
-pub fn parent_to_expr(cx: Context, child_id: ast::node_id) {
+pub fn parent_to_expr(cx: Context, child_id: ast::node_id, sp: span) {
+ debug!("region::parent_to_expr(span=%?)",
+ cx.sess.codemap.span_to_str(sp));
for cx.parent.each |parent_id| {
cx.region_maps.record_parent(child_id, *parent_id);
}
pub fn resolve_block(blk: &ast::blk, cx: Context, visitor: visit::vt<Context>) {
// Record the parent of this block.
- parent_to_expr(cx, blk.node.id);
+ parent_to_expr(cx, blk.node.id, blk.span);
// Descend.
let new_cx = Context {var_parent: Some(blk.node.id),
pub fn resolve_pat(pat: @ast::pat, cx: Context, visitor: visit::vt<Context>) {
assert_eq!(cx.var_parent, cx.parent);
- parent_to_expr(cx, pat.id);
+ parent_to_expr(cx, pat.id, pat.span);
visit::visit_pat(pat, cx, visitor);
}
}
ast::stmt_expr(_, stmt_id) |
ast::stmt_semi(_, stmt_id) => {
- parent_to_expr(cx, stmt_id);
+ parent_to_expr(cx, stmt_id, stmt.span);
let expr_cx = Context {parent: Some(stmt_id), ..cx};
visit::visit_stmt(stmt, expr_cx, visitor);
}
}
pub fn resolve_expr(expr: @ast::expr, cx: Context, visitor: visit::vt<Context>) {
- parent_to_expr(cx, expr.id);
+ parent_to_expr(cx, expr.id, expr.span);
let mut new_cx = cx;
new_cx.parent = Some(expr.id);
cx: Context,
visitor: visit::vt<Context>) {
assert_eq!(cx.var_parent, cx.parent);
- parent_to_expr(cx, local.node.id);
+ parent_to_expr(cx, local.node.id, local.span);
visit::visit_local(local, cx, visitor);
}
pub fn resolve_fn(fk: &visit::fn_kind,
decl: &ast::fn_decl,
body: &ast::blk,
- _sp: span,
+ sp: span,
id: ast::node_id,
cx: Context,
visitor: visit::vt<Context>) {
- debug!("region::resolve_fn(id=%?, body.node.id=%?, cx.parent=%?)",
- id, body.node.id, cx.parent);
+ debug!("region::resolve_fn(id=%?, \
+ span=%?, \
+ body.node.id=%?, \
+ cx.parent=%?)",
+ id,
+ cx.sess.codemap.span_to_str(sp),
+ body.node.id,
+ cx.parent);
// The arguments and `self` are parented to the body of the fn.
let decl_cx = Context {parent: Some(body.node.id),
assert!((m.len() > 0u || chk.is_some()));
let _icx = bcx.insn_ctxt("match::compile_submatch");
let mut bcx = bcx;
- let tcx = bcx.tcx(), dm = tcx.def_map;
+ let tcx = bcx.tcx();
+ let dm = tcx.def_map;
if m.len() == 0u {
Br(bcx, chk.get()());
return;
let variable_ty = node_id_type(bcx, p_id);
let llvariable_ty = type_of::type_of(ccx, variable_ty);
- let llmatch, trmode;
+ let llmatch;
+ let trmode;
match bm {
ast::bind_infer => {
// in this case, the final type of the variable will be T,
return bcx;
}
- let mut arm_datas = ~[], matches = ~[];
+ let mut arm_datas = ~[];
+ let mut matches = ~[];
for vec::each(arms) |arm| {
let body = scope_block(bcx, arm.body.info(), "case_body");
let bindings_map = create_bindings_map(bcx, arm.pats[0]);
pub fn get_landing_pad(bcx: block) -> BasicBlockRef {
let _icx = bcx.insn_ctxt("get_landing_pad");
- let mut cached = None, pad_bcx = bcx; // Guaranteed to be set below
+ let mut cached = None;
+ let mut 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
match inf.landing_pad {
}
ast::stmt_decl(d, _) => {
match d.node {
- ast::decl_local(ref locals) => {
- for locals.each |local| {
- bcx = init_local(bcx, *local);
- if cx.sess().opts.extra_debuginfo
- && fcx_has_nonzero_span(bcx.fcx) {
- debuginfo::create_local_var(bcx, *local);
- }
+ ast::decl_local(ref local) => {
+ bcx = init_local(bcx, *local);
+ if cx.sess().opts.extra_debuginfo
+ && fcx_has_nonzero_span(bcx.fcx) {
+ debuginfo::create_local_var(bcx, *local);
}
}
ast::decl_item(i) => trans_item(*cx.fcx.ccx, i)
upto: Option<BasicBlockRef>,
leave: Option<BasicBlockRef>) {
let _icx = bcx.insn_ctxt("cleanup_and_leave");
- let mut cur = bcx, bcx = bcx;
+ let mut cur = bcx;
+ let mut bcx = bcx;
let is_lpad = leave == None;
loop {
debug!("cleanup_and_leave: leaving %s", cur.to_str());
match s.node {
ast::stmt_decl(d, _) => {
match d.node {
- ast::decl_local(ref locals) => {
- for locals.each |local| {
- it(*local);
- }
- }
- _ => {/* fall through */ }
+ ast::decl_local(ref local) => it(*local),
+ _ => {} /* fall through */
}
}
- _ => {/* fall through */ }
+ _ => {} /* fall through */
}
}
}
None);
let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args);
- let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
+ let bcx = top_scope_block(fcx, None);
+ let lltop = bcx.llbb;
let arg_tys = ty::ty_fn_args(node_id_type(bcx, variant.node.id));
let bcx = copy_args_to_allocas(fcx, bcx, fn_args, raw_llargs, arg_tys);
pub fn allocate_cbox(bcx: block, sigil: ast::Sigil, cdata_ty: ty::t)
-> Result {
let _icx = bcx.insn_ctxt("closure::allocate_cbox");
- let ccx = bcx.ccx(), tcx = ccx.tcx;
+ let ccx = bcx.ccx();
+ let tcx = ccx.tcx;
fn nuke_ref_count(bcx: block, llbox: ValueRef) {
let _icx = bcx.insn_ctxt("closure::nuke_ref_count");
bound_values: ~[EnvValue],
sigil: ast::Sigil) -> ClosureResult {
let _icx = bcx.insn_ctxt("closure::store_environment");
- let ccx = bcx.ccx(), tcx = ccx.tcx;
+ let ccx = bcx.ccx();
+ let tcx = ccx.tcx;
// compute the shape of the closure
let cdata_ty = mk_closure_tys(tcx, bound_values);
}
// ~fn requires a deep copy.
- let ccx = bcx.ccx(), tcx = ccx.tcx;
+ let ccx = bcx.ccx();
+ let tcx = ccx.tcx;
let llopaquecboxty = T_opaque_box_ptr(ccx);
let cbox_in = Load(bcx, cboxptr);
do with_cond(bcx, IsNotNull(bcx, cbox_in)) |bcx| {
}
pub fn path_str(sess: session::Session, p: &[path_elt]) -> ~str {
- let mut r = ~"", first = true;
+ let mut r = ~"";
+ let mut first = true;
for p.each |e| {
match *e {
ast_map::path_name(s) | ast_map::path_mod(s) => {
let mut bcx = bcx;
match fail_expr {
Some(arg_expr) => {
- let ccx = bcx.ccx(), tcx = ccx.tcx;
+ let ccx = bcx.ccx();
+ let tcx = ccx.tcx;
let arg_datum = unpack_datum!(
bcx, expr::trans_to_datum(bcx, arg_expr));
pub fn create_arg(bcx: block, arg: ast::arg, sp: span)
-> Option<@Metadata<ArgumentMetadata>> {
- let fcx = bcx.fcx, cx = *fcx.ccx;
+ let fcx = bcx.fcx;
+ let cx = *fcx.ccx;
let cache = get_cache(cx);
let tg = ArgVariableTag;
match cached_metadata::<@Metadata<ArgumentMetadata>>(
debug!("build_direct_fn(%s)", *link_name(ccx, item));
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
- let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
+ let bcx = top_scope_block(fcx, None);
+ let lltop = bcx.llbb;
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
let ty = ty::lookup_item_type(ccx.tcx,
ast_util::local_def(item.id)).ty;
debug!("build_fast_ffi_fn(%s)", *link_name(ccx, item));
let fcx = new_fn_ctxt(ccx, ~[], decl, tys.fn_sig.output, None);
- let bcx = top_scope_block(fcx, None), lltop = bcx.llbb;
+ let bcx = top_scope_block(fcx, None);
+ let lltop = bcx.llbb;
let llbasefn = base_fn(ccx, *link_name(ccx, item), tys, cc);
set_no_inline(fcx.llfn);
set_fixed_stack_segment(fcx.llfn);
// Find the bounds for the method, which are the tail of the
// bounds found in the item type, as the item type combines the
// rcvr + method bounds.
- let ccx = bcx.ccx(), tcx = bcx.tcx();
+ let ccx = bcx.ccx();
+ let tcx = bcx.tcx();
let n_m_tps = method_ty_param_count(ccx, mth_did, impl_did);
let ty::ty_param_bounds_and_ty {
generics: r_m_generics,
pub fn make_drop_glue_unboxed(bcx: block, vptr: ValueRef, vec_ty: ty::t) ->
block {
let _icx = bcx.insn_ctxt("tvec::make_drop_glue_unboxed");
- let tcx = bcx.tcx(), unit_ty = ty::sequence_element_type(tcx, vec_ty);
+ let tcx = bcx.tcx();
+ let unit_ty = ty::sequence_element_type(tcx, vec_ty);
if ty::type_needs_drop(tcx, unit_ty) {
iter_vec_unboxed(bcx, vptr, vec_ty, glue::drop_ty)
} else { bcx }
let fcx = pcx.fcx;
let tcx = pcx.fcx.ccx.tcx;
- let arg_types, kind_name;
+ let arg_types;
+ let kind_name;
// structure_of requires type variables to be resolved.
// So when we pass in <expected>, it's an error if it
// Look up the number of type parameters and the raw type, and
// determine whether the class is region-parameterized.
- let type_parameter_count, region_parameterized, raw_type;
+ let type_parameter_count;
+ let region_parameterized;
+ let raw_type;
if class_id.crate == ast::local_crate {
region_parameterized =
tcx.region_paramd_items.find(&class_id.node).
// Look up the number of type parameters and the raw type, and
// determine whether the enum is region-parameterized.
- let type_parameter_count, region_parameterized, raw_type;
+ let type_parameter_count;
+ let region_parameterized;
+ let raw_type;
if enum_id.crate == ast::local_crate {
region_parameterized =
tcx.region_paramd_items.find(&enum_id.node).map_consume(|x| *x);
ast::stmt_decl(decl, id) => {
node_id = id;
match decl.node {
- ast::decl_local(ref ls) => for ls.each |l| {
+ ast::decl_local(ref l) => {
check_decl_local(fcx, *l);
let l_t = fcx.node_ty(l.node.id);
saw_bot = saw_bot || ty::type_is_bot(l_t);
saw_err = saw_err || ty::type_is_error(l_t);
- },
+ }
ast::decl_item(_) => {/* ignore for now */ }
}
}
let _i = indenter();
let tcx = vcx.tcx();
- let mut result = ~[], i = 0u;
+ let mut result = ~[];
+ let mut i = 0u;
for substs.tps.each |ty| {
// ty is the value supplied for the type parameter A...
fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id)
-> Option<ty::t> {
- let fcx = wbcx.fcx, tcx = fcx.ccx.tcx;
+ let fcx = wbcx.fcx;
+ let tcx = fcx.ccx.tcx;
// Resolve any borrowings for the node with id `id`
match fcx.inh.adjustments.find(&id) {
let tainted = this.infcx.region_vars.tainted(snapshot, r0);
- let mut a_r = None, b_r = None, only_new_vars = true;
+ let mut a_r = None;
+ let mut b_r = None;
+ let mut only_new_vars = true;
for tainted.each |r| {
if is_var_in_set(a_vars, *r) {
if a_r.is_some() {
// If both A and B have an UB type, then we can just compute the
// LUB of those types:
- let a_bnd = this.bnd(a_bounds), b_bnd = this.bnd(b_bounds);
+ let (a_bnd, b_bnd) = (this.bnd(a_bounds), this.bnd(b_bounds));
match (a_bnd, b_bnd) {
(Some(ref a_ty), Some(ref b_ty)) => {
match this.infcx().try(|| lattice_dir_op(a_ty, b_ty) ) {
// `result_set` acts as a worklist: we explore all outgoing
// edges and add any new regions we find to result_set. This
// is not a terribly efficient implementation.
- let mut result_set = ~[r0], result_index = 0;
+ let mut result_set = ~[r0];
+ let mut result_index = 0;
while result_index < result_set.len() {
// nb: can't use uint::range() here because result_set grows
let r = result_set[result_index];
t2: ty::t,
msg: &fn() -> ~str) -> bool {
- let l_tcx, l_infcx;
+ let l_tcx;
+ let l_infcx;
match maybe_infcx {
None => {
l_tcx = tcx;
fn read_le_uint_n(&self, nbytes: uint) -> u64 {
assert!(nbytes > 0 && nbytes <= 8);
- let mut val = 0u64, pos = 0, i = nbytes;
+ let mut (val, pos, i) = (0u64, 0, nbytes);
while i > 0 {
val += (self.read_u8() as u64) << pos;
pos += 8;
fn read_be_uint_n(&self, nbytes: uint) -> u64 {
assert!(nbytes > 0 && nbytes <= 8);
- let mut val = 0u64, i = nbytes;
+ let mut (val, i) = (0u64, nbytes);
while i > 0 {
i -= 1;
val += (self.read_u8() as u64) << i * 8;
(n >> 56) as u8]),
_ => {
- let mut bytes: ~[u8] = ~[], i = size, n = n;
+ let mut bytes: ~[u8] = ~[];
+ let mut i = size;
+ let mut n = n;
while i > 0u {
bytes.push((n & 255_u64) as u8);
n >>= 8_u64;
/// Determine if two shared boxes point to the same object
#[inline(always)]
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
- let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+ let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
a_ptr == b_ptr
}
/// Determine if two mutable shared boxes point to the same object
#[inline(always)]
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
- let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
+ let (a_ptr, b_ptr): (*T, *T) = (to_unsafe_ptr(&*a), to_unsafe_ptr(&*b));
a_ptr == b_ptr
}
#[inline(always)]
fn gcd(&self, other: &$T) -> $T {
// Use Euclid's algorithm
- let mut m = *self, n = *other;
+ let mut (m, n) = (*self, *other);
while m != 0 {
let temp = m;
m = n % temp;
#[inline(always)]
fn gcd(&self, other: &$T) -> $T {
// Use Euclid's algorithm
- let mut m = *self, n = *other;
+ let mut (m, n) = (*self, *other);
while m != 0 {
let temp = m;
m = n % temp;
/// of `rsl` as a seed, otherwise construct one algorithmically (not
/// randomly).
fn init(&mut self, use_rsl: bool) {
- macro_rules! init_mut_many (
- ($( $var:ident ),* = $val:expr ) => {
- let mut $( $var = $val ),*;
- }
- );
- init_mut_many!(a, b, c, d, e, f, g, h = 0x9e3779b9);
-
+ let mut a = 0x9e3779b9;
+ let mut b = a;
+ let mut c = a;
+ let mut d = a;
+ let mut e = a;
+ let mut f = a;
+ let mut g = a;
+ let mut h = a;
macro_rules! mix(
() => {{
fn isaac(&mut self) {
self.c += 1;
// abbreviations
- let mut a = self.a, b = self.b + self.c;
+ let mut (a, b) = (self.a, self.b + self.c);
- static midpoint: uint = RAND_SIZE as uint / 2;
+ static midpoint: uint = RAND_SIZE as uint / 2;
macro_rules! ind (($x:expr) => {
self.mem[($x >> 2) & (RAND_SIZE - 1)]
// do-while, so the condition should be true on the first
// run, they get overwritten anyway (0 < 1, so these are
// good).
- let mut x = 1.0, y = 0.0;
+ let mut (x, y) = (1.0, 0.0);
// XXX infinities?
while -2.0*y < x * x {
fn read_le_uint_n(&mut self, nbytes: uint) -> u64 {
assert!(nbytes > 0 && nbytes <= 8);
- let mut val = 0u64, pos = 0, i = nbytes;
+ let mut (val, pos, i) = (0u64, 0, nbytes);
while i > 0 {
val += (self.read_u8() as u64) << pos;
pos += 8;
fn read_be_uint_n(&mut self, nbytes: uint) -> u64 {
assert!(nbytes > 0 && nbytes <= 8);
- let mut val = 0u64, i = nbytes;
+ let mut (val, i) = (0u64, nbytes);
while i > 0 {
i -= 1;
val += (self.read_u8() as u64) << i * 8;
// XXX: Could go in str::raw
unsafe fn c_str_to_static_slice(s: *libc::c_char) -> &'static str {
let s = s as *u8;
- let mut curr = s, len = 0u;
+ let mut (curr, len) = (s, 0u);
while *curr != 0u8 {
len += 1u;
curr = ptr::offset(s, len);
allow_trailing_empty: bool,
it: &fn(&'a str) -> bool) -> bool {
if sep < 128u as char {
- let b = sep as u8, l = len(s);
+ let (b, l) = (sep as u8, len(s));
let mut done = 0u;
- let mut i = 0u, start = 0u;
+ let mut (i, start) = (0u, 0u);
while i < l && done < count {
if s[i] == b {
if allow_empty || start < i {
allow_trailing_empty: bool,
it: &fn(&'a str) -> bool) -> bool {
let l = len(s);
- let mut i = 0u, start = 0u, done = 0u;
+ let mut (i, start, done) = (0u, 0u, 0u);
while i < l && done < count {
let CharRange {ch, next} = char_range_at(s, i);
if sepfn(ch) {
// See Issue #1932 for why this is a naive search
fn iter_matches<'a,'b>(s: &'a str, sep: &'b str,
f: &fn(uint, uint) -> bool) -> bool {
- let sep_len = len(sep), l = len(s);
+ let (sep_len, l) = (len(sep), len(s));
assert!(sep_len > 0u);
- let mut i = 0u, match_start = 0u, match_i = 0u;
+ let mut (i, match_start, match_i) = (0u, 0u, 0u);
while i < l {
if s[i] == sep[match_i] {
* The original string with all occurances of `from` replaced with `to`
*/
pub fn replace(s: &str, from: &str, to: &str) -> ~str {
- let mut result = ~"", first = true;
+ let mut (result, first) = (~"", true);
for iter_between_matches(s, from) |start, end| {
if first {
first = false;
* * needle - The string to look for
*/
pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
- let haystack_len = len(haystack), needle_len = len(needle);
+ let (haystack_len, needle_len) = (len(haystack), len(needle));
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
else { match_at(haystack, needle, 0u) }
* * needle - The string to look for
*/
pub fn ends_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool {
- let haystack_len = len(haystack), needle_len = len(needle);
+ let (haystack_len, needle_len) = (len(haystack), len(needle));
if needle_len == 0u { true }
else if needle_len > haystack_len { false }
else { match_at(haystack, needle, haystack_len - needle_len) }
pub fn count_chars(s: &str, start: uint, end: uint) -> uint {
assert!(is_char_boundary(s, start));
assert!(is_char_boundary(s, end));
- let mut i = start, len = 0u;
+ let mut (i, len) = (start, 0u);
while i < end {
let next = char_range_at(s, i).next;
len += 1u;
/// starting from `start`.
pub fn count_bytes<'b>(s: &'b str, start: uint, n: uint) -> uint {
assert!(is_char_boundary(s, start));
- let mut end = start, cnt = n;
+ let mut (end, cnt) = (start, n);
let l = len(s);
while cnt > 0u {
assert!(end < l);
pub fn subslice_offset(outer: &str, inner: &str) -> uint {
do as_buf(outer) |a, a_len| {
do as_buf(inner) |b, b_len| {
- let a_start: uint, a_end: uint, b_start: uint, b_end: uint;
+ let a_start: uint;
+ let a_end: uint;
+ let b_start: uint;
+ let b_end: uint;
unsafe {
a_start = cast::transmute(a); a_end = a_len + cast::transmute(a);
b_start = cast::transmute(b); b_end = b_len + cast::transmute(b);
/// Create a Rust string from a null-terminated *u8 buffer
pub unsafe fn from_buf(buf: *u8) -> ~str {
- let mut curr = buf, i = 0u;
+ let mut (curr, i) = (buf, 0u);
while *curr != 0u8 {
i += 1u;
curr = ptr::offset(buf, i);
impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
#[inline(always)]
fn to_str(&self) -> ~str {
- let mut acc = ~"{", first = true;
+ let mut (acc, first) = (~"{", true);
for self.each |key, value| {
if first {
first = false;
impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
#[inline(always)]
fn to_str(&self) -> ~str {
- let mut acc = ~"{", first = true;
- for self.each |element| {
- if first {
- first = false;
- }
- else {
- acc.push_str(", ");
+ let mut (acc, first) = (~"{", true);
+ for self.each |element| {
+ if first {
+ first = false;
+ }
+ else {
+ acc.push_str(", ");
+ }
+ acc.push_str(element.to_str());
}
- acc.push_str(element.to_str());
- }
- acc.push_char('}');
- acc
+ acc.push_char('}');
+ acc
}
}
impl<'self,A:ToStr> ToStr for &'self [A] {
#[inline(always)]
fn to_str(&self) -> ~str {
- let mut acc = ~"[", first = true;
+ let mut (acc, first) = (~"[", true);
for self.each |elt| {
if first {
first = false;
impl<A:ToStr> ToStr for ~[A] {
#[inline(always)]
fn to_str(&self) -> ~str {
- let mut acc = ~"[", first = true;
+ let mut (acc, first) = (~"[", true);
for self.each |elt| {
if first {
first = false;
impl<A:ToStr> ToStr for @[A] {
#[inline(always)]
fn to_str(&self) -> ~str {
- let mut acc = ~"[", first = true;
+ let mut (acc, first) = (~"[", true);
for self.each |elt| {
if first {
first = false;
#[test]
fn test_tuple_cmp() {
- let small = (1u, 2u, 3u), big = (3u, 2u, 1u);
+ let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
// Eq
assert_eq!(small, small);
pub fn dedup<T:Eq>(v: &mut ~[T]) {
unsafe {
if v.len() < 1 { return; }
- let mut last_written = 0, next_to_read = 1;
+ let mut (last_written, next_to_read) = (0, 1);
do as_const_buf(*v) |p, ln| {
// We have a mutable reference to v, so we can make arbitrary
// changes. (cf. push and pop)
* Convert a vector of pairs into a pair of vectors, by reference. As unzip().
*/
pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
- let mut ts = ~[], us = ~[];
+ let mut (ts, us) = (~[], ~[]);
for each(v) |p| {
let (t, u) = *p;
ts.push(t);
* of the i-th tuple of the input vector.
*/
pub fn unzip<T,U>(v: ~[(T, U)]) -> (~[T], ~[U]) {
- let mut ts = ~[], us = ~[];
+ let mut (ts, us) = (~[], ~[]);
do consume(v) |_i, p| {
let (t, u) = p;
ts.push(t);
pub type decl = spanned<decl_>;
#[deriving(Eq, Encodable, Decodable)]
-pub enum decl_ { decl_local(~[@local]), decl_item(@item), }
+pub enum decl_ {
+ decl_local(@local),
+ decl_item(@item),
+}
#[deriving(Eq, Encodable, Decodable)]
pub struct arm {
pub fn split_trait_methods(trait_methods: &[trait_method])
-> (~[ty_method], ~[@method]) {
- let mut reqd = ~[], provd = ~[];
+ let mut reqd = ~[];
+ let mut provd = ~[];
for trait_methods.each |trt_method| {
match *trt_method {
required(ref tm) => reqd.push(copy *tm),
init: Some(ex),
id: self.next_id(),
});
- let decl = respan(sp, ast::decl_local(~[local]));
+ let decl = respan(sp, ast::decl_local(local));
@respan(sp, ast::stmt_decl(@decl, self.next_id()))
}
type_ident: ident, generics: &Generics)
-> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) {
- let mut self_args = ~[], nonself_args = ~[], arg_tys = ~[];
+ let mut self_args = ~[];
+ let mut nonself_args = ~[];
+ let mut arg_tys = ~[];
let mut nonstatic = false;
let ast_explicit_self = match self.explicit_self {
nonself_args: &[@expr])
-> @expr {
- let mut raw_fields = ~[], // ~[[fields of self], [fields of next Self arg], [etc]]
- patterns = ~[];
+ let mut raw_fields = ~[]; // ~[[fields of self],
+ // [fields of next Self arg], [etc]]
+ let mut patterns = ~[];
for uint::range(0, self_args.len()) |i| {
let (pat, ident_expr) = create_struct_pattern(cx, span,
type_ident, struct_def,
let matching_path = cx.path(span, ~[ struct_ident ]);
- let mut paths = ~[], ident_expr = ~[];
-
+ let mut paths = ~[];
+ let mut ident_expr = ~[];
let mut struct_type = Unknown;
for struct_def.fields.eachi |i, struct_field| {
let matching_path = cx.path_ident(span, variant_ident);
- let mut paths = ~[], ident_expr = ~[];
+ let mut paths = ~[];
+ let mut ident_expr = ~[];
for uint::range(0, variant_args.len()) |i| {
let path = cx.path_ident(span,
cx.ident_of(fmt!("%s_%u", prefix, i)));
s: &stmt_,
sp: span,
fld: @ast_fold,
- orig: @fn(&stmt_, span, @ast_fold) -> (stmt_, span))
- -> (stmt_, span) {
+ orig: @fn(&stmt_, span, @ast_fold)
+ -> (Option<stmt_>, span))
+ -> (Option<stmt_>, span) {
let (mac, pth, tts, semi) = match *s {
stmt_mac(ref mac, semi) => {
match mac.node {
};
//keep going, outside-in
- let fully_expanded = copy fld.fold_stmt(expanded).node;
- cx.bt_pop();
+ let fully_expanded = match fld.fold_stmt(expanded) {
+ Some(stmt) => {
+ let fully_expanded = &stmt.node;
+ cx.bt_pop();
+ copy *fully_expanded
+ }
+ None => {
+ cx.span_fatal(pth.span,
+ "macro didn't expand to a statement")
+ }
+ };
(fully_expanded, sp)
}
};
(match fully_expanded {
- stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id),
- _ => { fully_expanded } /* might already have a semi */
+ stmt_expr(e, stmt_id) if semi => Some(stmt_semi(e, stmt_id)),
+ _ => { Some(fully_expanded) } /* might already have a semi */
}, sp)
}
fn fold_item_underscore(@self, &item_) -> item_;
fn fold_method(@self, @method) -> @method;
fn fold_block(@self, &blk) -> blk;
- fn fold_stmt(@self, &stmt) -> @stmt;
+ fn fold_stmt(@self, &stmt) -> Option<@stmt>;
fn fold_arm(@self, &arm) -> arm;
fn fold_pat(@self, @pat) -> @pat;
- fn fold_decl(@self, @decl) -> @decl;
+ fn fold_decl(@self, @decl) -> Option<@decl>;
fn fold_expr(@self, @expr) -> @expr;
fn fold_ty(@self, @Ty) -> @Ty;
fn fold_mod(@self, &_mod) -> _mod;
fold_item_underscore: @fn(&item_, @ast_fold) -> item_,
fold_method: @fn(@method, @ast_fold) -> @method,
fold_block: @fn(&blk_, span, @ast_fold) -> (blk_, span),
- fold_stmt: @fn(&stmt_, span, @ast_fold) -> (stmt_, span),
+ fold_stmt: @fn(&stmt_, span, @ast_fold) -> (Option<stmt_>, span),
fold_arm: @fn(&arm, @ast_fold) -> arm,
fold_pat: @fn(&pat_, span, @ast_fold) -> (pat_, span),
- fold_decl: @fn(&decl_, span, @ast_fold) -> (decl_, span),
+ fold_decl: @fn(&decl_, span, @ast_fold) -> (Option<decl_>, span),
fold_expr: @fn(&expr_, span, @ast_fold) -> (expr_, span),
fold_ty: @fn(&ty_, span, @ast_fold) -> (ty_, span),
fold_mod: @fn(&_mod, @ast_fold) -> _mod,
pub fn noop_fold_block(b: &blk_, fld: @ast_fold) -> blk_ {
+ let view_items = b.view_items.map(|x| fld.fold_view_item(*x));
+ let mut stmts = ~[];
+ for b.stmts.each |stmt| {
+ match fld.fold_stmt(*stmt) {
+ None => {}
+ Some(stmt) => stmts.push(stmt)
+ }
+ }
ast::blk_ {
- view_items: b.view_items.map(|x| fld.fold_view_item(*x)),
- stmts: b.stmts.map(|x| fld.fold_stmt(*x)),
+ view_items: view_items,
+ stmts: stmts,
expr: b.expr.map(|x| fld.fold_expr(*x)),
id: fld.new_id(b.id),
rules: b.rules,
}
}
-fn noop_fold_stmt(s: &stmt_, fld: @ast_fold) -> stmt_ {
+fn noop_fold_stmt(s: &stmt_, fld: @ast_fold) -> Option<stmt_> {
let fold_mac = |x| fold_mac_(x, fld);
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)),
- stmt_mac(ref mac, semi) => stmt_mac(fold_mac(mac), semi)
+ stmt_decl(d, nid) => {
+ match fld.fold_decl(d) {
+ Some(d) => Some(stmt_decl(d, fld.new_id(nid))),
+ None => None,
+ }
+ }
+ stmt_expr(e, nid) => {
+ Some(stmt_expr(fld.fold_expr(e), fld.new_id(nid)))
+ }
+ stmt_semi(e, nid) => {
+ Some(stmt_semi(fld.fold_expr(e), fld.new_id(nid)))
+ }
+ stmt_mac(ref mac, semi) => Some(stmt_mac(fold_mac(mac), semi))
}
}
}
}
-fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> decl_ {
+fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> Option<decl_> {
match *d {
- decl_local(ref ls) => decl_local(ls.map(|x| fld.fold_local(*x))),
+ decl_local(ref l) => Some(decl_local(fld.fold_local(*l))),
decl_item(it) => {
match fld.fold_item(it) {
- Some(it_folded) => decl_item(it_folded),
- None => decl_local(~[]),
+ Some(it_folded) => Some(decl_item(it_folded)),
+ None => None,
}
}
}
fold_item_underscore: noop_fold_item_underscore,
fold_method: noop_fold_method,
fold_block: wrap(noop_fold_block),
- fold_stmt: wrap(noop_fold_stmt),
+ fold_stmt: |x, s, fld| (noop_fold_stmt(x, fld), s),
fold_arm: noop_fold_arm,
fold_pat: wrap(noop_fold_pat),
- fold_decl: wrap(noop_fold_decl),
+ fold_decl: |x, s, fld| (noop_fold_decl(x, fld), s),
fold_expr: wrap(noop_fold_expr),
fold_ty: wrap(noop_fold_ty),
fold_mod: noop_fold_mod,
let (n, s) = (self.fold_block)(&x.node, x.span, self as @ast_fold);
spanned { node: n, span: (self.new_span)(s) }
}
- fn fold_stmt(@self, x: &stmt) -> @stmt {
- let (n, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold);
- @spanned { node: n, span: (self.new_span)(s) }
+ fn fold_stmt(@self, x: &stmt) -> Option<@stmt> {
+ let (n_opt, s) = (self.fold_stmt)(&x.node, x.span, self as @ast_fold);
+ match n_opt {
+ Some(n) => Some(@spanned { node: n, span: (self.new_span)(s) }),
+ None => None,
+ }
}
fn fold_arm(@self, x: &arm) -> arm {
(self.fold_arm)(x, self as @ast_fold)
span: (self.new_span)(s),
}
}
- fn fold_decl(@self, x: @decl) -> @decl {
- let (n, s) = (self.fold_decl)(&x.node, x.span, self as @ast_fold);
- @spanned { node: n, span: (self.new_span)(s) }
+ fn fold_decl(@self, x: @decl) -> Option<@decl> {
+ let (n_opt, s) = (self.fold_decl)(&x.node, x.span, self as @ast_fold);
+ match n_opt {
+ Some(n) => Some(@spanned { node: n, span: (self.new_span)(s) }),
+ None => None,
+ }
}
fn fold_expr(@self, x: @expr) -> @expr {
let (n, s) = (self.fold_expr)(&x.node, x.span, self as @ast_fold);
/// remove whitespace-only lines from the start/end of lines
fn vertical_trim(lines: ~[~str]) -> ~[~str] {
- let mut i = 0u, j = lines.len();
+ let mut i = 0u;
+ let mut j = lines.len();
while i < j && lines[i].trim().is_empty() {
i += 1u;
}
}
fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
- let mut num_str, base = 10u, c = c, n = nextch(rdr);
+ let mut num_str;
+ let mut base = 10u;
+ let mut c = c;
+ let mut n = nextch(rdr);
if c == '0' && n == 'x' {
bump(rdr);
bump(rdr);
}
fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char {
- let mut accum_int = 0, i = n_hex_digits;
+ let mut accum_int = 0;
+ let mut i = n_hex_digits;
while i != 0u {
let n = rdr.curr;
bump(rdr);
ObsoleteConstItem,
ObsoleteFixedLengthVectorType,
ObsoleteNamedExternModule,
+ ObsoleteMultipleLocalDecl,
}
impl to_bytes::IterBytes for ObsoleteSyntax {
"instead of `extern mod foo { ... }`, write `mod foo { \
extern { ... } }`"
),
+ ObsoleteMultipleLocalDecl => (
+ "declaration of multiple locals at once",
+ "instead of e.g. `let a = 1, b = 2`, write \
+ `let (a, b) = (1, 2)`."
+ ),
};
self.report(sp, kind, kind_str, desc);
use parse::obsolete::{ObsoleteLifetimeNotation, ObsoleteConstManagedPointer};
use parse::obsolete::{ObsoletePurity, ObsoleteStaticMethod};
use parse::obsolete::{ObsoleteConstItem, ObsoleteFixedLengthVectorType};
-use parse::obsolete::{ObsoleteNamedExternModule};
+use parse::obsolete::{ObsoleteNamedExternModule, ObsoleteMultipleLocalDecl};
use parse::token::{can_begin_expr, is_ident, is_ident_or_path};
use parse::token::{is_plain_ident, INTERPOLATED, keywords, special_idents, token_to_binop};
use parse::token;
fn parse_let(&self) -> @decl {
let is_mutbl = self.eat_keyword(keywords::Mut);
let lo = self.span.lo;
- let mut locals = ~[self.parse_local(is_mutbl)];
+ let mut local = self.parse_local(is_mutbl);
while self.eat(&token::COMMA) {
- locals.push(self.parse_local(is_mutbl));
+ let _ = self.parse_local(is_mutbl);
+ self.obsolete(*self.span, ObsoleteMultipleLocalDecl);
}
- return @spanned(lo, self.last_span.hi, decl_local(locals));
+ return @spanned(lo, self.last_span.hi, decl_local(local));
}
// parse a structure field
// parse the part of an "enum" decl following the '{'
fn parse_enum_def(&self, _generics: &ast::Generics) -> enum_def {
let mut variants = ~[];
- let mut all_nullary = true, have_disr = false;
+ let mut all_nullary = true;
+ let mut have_disr = false;
while *self.token != token::RBRACE {
let variant_attrs = self.parse_outer_attributes();
let vlo = self.span.lo;
let vis = self.parse_visibility();
- let ident, kind;
- let mut args = ~[], disr_expr = None;
+ let ident;
+ let kind;
+ let mut args = ~[];
+ let mut disr_expr = None;
ident = self.parse_ident();
if self.eat(&token::LBRACE) {
// Parse a struct variant.
}
fn is_view_item(&self) -> bool {
- let tok, next_tok;
+ let tok;
+ let next_tok;
if !self.is_keyword(keywords::Pub) && !self.is_keyword(keywords::Priv) {
tok = copy *self.token;
next_tok = self.look_ahead(1);
pub fn print_decl(s: @ps, decl: @ast::decl) {
maybe_print_comment(s, decl.span.lo);
match decl.node {
- ast::decl_local(ref locs) => {
+ ast::decl_local(ref loc) => {
space_if_not_bol(s);
ibox(s, indent_unit);
word_nbsp(s, "let");
- // if any are mut, all are mut
- if locs.any(|l| l.node.is_mutbl) {
- assert!(locs.all(|l| l.node.is_mutbl));
+ if loc.node.is_mutbl {
word_nbsp(s, "mut");
}
_ => ()
}
}
- commasep(s, consistent, *locs, print_local);
+
+ print_local(s, *loc);
end(s);
}
ast::decl_item(item) => print_item(s, item)
pub fn visit_decl<E: Copy>(d: @decl, e: E, v: vt<E>) {
match d.node {
- decl_local(ref locs) => {
- for locs.each |loc| {
- (v.visit_local)(*loc, e, v)
- }
- },
+ decl_local(ref loc) => (v.visit_local)(*loc, e, v),
decl_item(it) => (v.visit_item)(it, e, v)
}
}
let mut perm = vec::from_elem(n as uint, 0i32);
let mut perm1 = vec::from_fn(n as uint, |i| i as i32);
let mut count = vec::from_elem(n as uint, 0i32);
- let mut max_flips_count = 0i32, perm_count = 0i32, checksum = 0i32;
+ let mut max_flips_count = 0i32;
+ let mut perm_count = 0i32;
+ let mut checksum = 0i32;
let mut r = n;
loop {
alu,
LINE_LEN);
- let mut pos = 0, bytes, n = n;
+ let mut pos = 0;
+ let mut bytes;
+ let mut n = n;
while n > 0 {
bytes = min(LINE_LEN, n);
fwrite(transmute(&buf[pos]), bytes as size_t, 1, stdout);
fn make(&mut self, n: uint) {
unsafe {
- let lines = n / LINE_LEN, chars_left = n % LINE_LEN;
+ let lines = n / LINE_LEN;
+ let chars_left = n % LINE_LEN;
let mut buf = [0, ..LINE_LEN + 1];
for lines.times {
#[fixed_stack_segment]
fn main() {
unsafe {
- let w: i32 = FromStr::from_str(os::args()[1]).get(), h = w;
+ let w: i32 = FromStr::from_str(os::args()[1]).get();
+ let h = w;
let mut byte_acc: i8 = 0;
let mut bit_num: i32 = 0;
let d2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
let mag = dt / (d2 * f64::sqrt(d2));
- let a_mass = bodies[i].mass, b_mass = bodies[j].mass;
+ let a_mass = bodies[i].mass;
+ let b_mass = bodies[j].mass;
bodies[i].v[0] -= d[0] * b_mass * mag;
bodies[i].v[1] -= d[1] * b_mass * mag;
bodies[i].v[2] -= d[2] * b_mass * mag;
#[fixed_stack_segment]
fn main() {
let n: uint = FromStr::from_str(os::args()[1]).get();
- let mut u = vec::from_elem(n, 1f64), v = u.clone(), tmp = u.clone();
+ let mut u = vec::from_elem(n, 1f64);
+ let mut v = u.clone();
+ let mut tmp = u.clone();
for 8.times {
mult_AtAv(u, v, tmp);
mult_AtAv(v, u, tmp);
fn loop_aliased_mut() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
loop {
borrow_mut(v); //~ ERROR cannot borrow
fn while_aliased_mut() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
while cond() {
borrow_mut(v); //~ ERROR cannot borrow
fn for_loop_aliased_mut() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
for for_func {
borrow_mut(v); //~ ERROR cannot borrow
fn loop_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
loop {
borrow_mut(v);
fn while_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
while cond() {
borrow_mut(v);
fn for_aliased_mut_break() {
// In this instance, the borrow is carried through the loop.
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &w;
for for_func {
// here we cannot be sure that `for_func` respects the break below
}
fn while_aliased_mut_cond(cond: bool, cond2: bool) {
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut x = &mut w;
while cond {
**x += 1;
}
fn aliased_other() {
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let _x = &mut w;
borrow(v);
}
fn aliased_other_reassign() {
- let mut v = ~3, w = ~4;
+ let mut v = ~3;
+ let mut w = ~4;
let mut _x = &mut w;
_x = &mut v;
borrow(v); //~ ERROR cannot borrow `*v`
fn mk_result(st : SipState) -> u64 {
- let v0 = st.v0,
- v1 = st.v1;
+ let v0 = st.v0;
+ let v1 = st.v1;
return v0 ^ v1;
}
fn main() {
// negative cases
let mut a = 3; //~ ERROR: variable does not need to be mutable
- let mut a = 2, b = 3; //~ ERROR: variable does not need to be mutable
- //~^ ERROR: variable does not need to be mutable
+ let mut a = 2; //~ ERROR: variable does not need to be mutable
+ let mut b = 3; //~ ERROR: variable does not need to be mutable
let mut a = ~[3]; //~ ERROR: variable does not need to be mutable
// positive cases
}
fn f30(cond: bool) {
- let x = ~"hi", y = ~"ho";
+ let x = ~"hi";
+ let y = ~"ho";
let _y = if cond {
x
} else {
}
fn f40(cond: bool) {
- let x = ~"hi", y = ~"ho";
+ let x = ~"hi";
+ let y = ~"ho";
let _y = match cond {
true => x,
false => y
}
fn f50(cond: bool) {
- let x = ~"hi", y = ~"ho";
+ let x = ~"hi";
+ let y = ~"ho";
let _y = match cond {
_ if guard(x) => 10,
true => 10,
// error-pattern:so long
fn main() {
- let x = ~[], y = ~[3];
+ let x = ~[];
+ let y = ~[3];
fail!("so long");
x += y;
~"good" + ~"bye";
}
fn main() {
- let a = 'a' as u8, j = 'j' as u8, k = 1, l = 9;
+ let a = 'a' as u8;
+ let j = 'j' as u8;
+ let k = 1;
+ let l = 9;
let chars = enum_chars(a, j);
let ints = enum_uints(k, l);
fn f2(a: int, f: &fn(int)) -> int { f(1); return a; }
pub fn main() {
- let mut a = X {x: 1}, b = 2, c = 3;
+ let mut a = X {x: 1};
+ let mut b = 2;
+ let mut c = 3;
assert_eq!(f1(&mut a, &mut b, c), 6);
assert_eq!(a.x, 0);
assert_eq!(b, 10);
// borrow x and y
let mut r_x = &*x;
let mut r_y = &*y;
- let mut r = r_x, exp = 3;
+ let mut r = r_x;
+ let mut exp = 3;
if cond {
r = r_y;
}
pub fn main() {
- let e0 = E0, e11 = E1(1), e12 = E1(2), e21 = E2(1,1), e22 = E2(1, 2);
+ let e0 = E0;
+ let e11 = E1(1);
+ let e12 = E1(2);
+ let e21 = E2(1, 1);
+ let e22 = E2(1, 2);
// in order for both Ord and TotalOrd
let es = [e0, e11, e12, e21, e22];
let ord = i.cmp(&j);
let eq = i == j;
- let lt = i < j, le = i <= j;
- let gt = i > j, ge = i >= j;
+ let lt = i < j;
+ let le = i <= j;
+ let gt = i > j;
+ let ge = i >= j;
// Eq
assert_eq!(*e1 == *e2, eq);
}
pub fn main() {
- let s1 = S {x: 1, y: 1}, s2 = S {x: 1, y: 2};
+ let s1 = S {x: 1, y: 1};
+ let s2 = S {x: 1, y: 2};
// in order for both Ord and TotalOrd
let ss = [s1, s2];
let ord = i.cmp(&j);
let eq = i == j;
- let lt = i < j, le = i <= j;
- let gt = i > j, ge = i >= j;
+ let lt = i < j;
+ let le = i <= j;
+ let gt = i > j;
+ let ge = i >= j;
// Eq
assert_eq!(*s1 == *s2, eq);
assert_eq!(s1.cmp(s2), ord);
}
}
-}
\ No newline at end of file
+}
pub fn main() {
- let ts1 = TS(1, 1), ts2 = TS(1,2);
+ let ts1 = TS(1, 1);
+ let ts2 = TS(1, 2);
// in order for both Ord and TotalOrd
let tss = [ts1, ts2];
let ord = i.cmp(&j);
let eq = i == j;
- let lt = i < j, le = i <= j;
- let gt = i > j, ge = i >= j;
+ let lt = i < j;
+ let le = i <= j;
+ let gt = i > j;
+ let ge = i >= j;
// Eq
assert_eq!(*ts1 == *ts2, eq);
assert_eq!(ts1.cmp(ts2), ord);
}
}
-}
\ No newline at end of file
+}
}
fn main() {
- let a = A { x: &1 }, b = A { x: &2 };
+ let a = A { x: &1 };
+ let b = A { x: &2 };
assert_eq!(a, a);
assert_eq!(b, b);
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub fn main() { let x = 10, y = x; assert!((y == 10)); }
+pub fn main() {
+ let x = 10;
+ let y = x;
+ assert!((y == 10));
+}
+
struct A { a: @int }
pub fn main() {
- let a = A {a: @10}, b = @10;
+ let a = A {a: @10};
+ let b = @10;
magic(a); magic(A {a: @20});
magic2(b); magic2(@20);
}
// Check that functions can modify local state.
fn sums_to(v: ~[int], sum: int) -> bool {
- let mut i = 0u, sum0 = 0;
+ let mut i = 0u;
+ let mut sum0 = 0;
while i < v.len() {
sum0 += v[i];
i += 1u;
}
fn sums_to_using_uniq(v: ~[int], sum: int) -> bool {
- let mut i = 0u, sum0 = ~0;
+ let mut i = 0u;
+ let mut sum0 = ~0;
while i < v.len() {
*sum0 += v[i];
i += 1u;
}
fn sums_to_using_rec(v: ~[int], sum: int) -> bool {
- let mut i = 0u, sum0 = F {f: 0};
+ let mut i = 0u;
+ let mut sum0 = F {f: 0};
while i < v.len() {
sum0.f += v[i];
i += 1u;
struct F<T> { f: T }
fn sums_to_using_uniq_rec(v: ~[int], sum: int) -> bool {
- let mut i = 0u, sum0 = F {f: ~0};
+ let mut i = 0u;
+ let mut sum0 = F {f: ~0};
while i < v.len() {
*sum0.f += v[i];
i += 1u;
use std::vec;
fn iter<T>(v: ~[T], it: &fn(&T) -> bool) -> bool {
- let mut i = 0u, l = v.len();
+ let mut i = 0u;
+ let mut l = v.len();
while i < l {
if !it(&v[i]) { return false; }
i += 1u;
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-pub fn main() { let x = 10, y = 20; let z = x + y; assert!((z == 30)); }
+pub fn main() {
+ let (x, y) = (10, 20);
+ let z = x + y;
+ assert!((z == 30));
+}
}
pub fn main() {
- let a = 'a' as u8, j = 'j' as u8, k = 1u, l = 10u;
+ let a = 'a' as u8;
+ let j = 'j' as u8;
+ let k = 1u;
+ let l = 10u;
let chars = enum_chars(a, j);
let ints = enum_uints(k, l);