From 8114d0e9505b44856b822dd587293fd7895320e4 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 4 Jun 2013 21:43:41 -0700 Subject: [PATCH] librustc: Disallow multiple patterns from appearing in a "let" declaration. You can still initialize multiple variables at once with "let (x, y) = (1, 2)". --- doc/rust.md | 6 +- doc/tutorial-ffi.md | 8 +-- doc/tutorial-macros.md | 9 ++- src/libextra/arena.rs | 2 +- src/libextra/fileinput.rs | 24 ++++--- src/libextra/md4.rs | 4 +- src/libextra/net_url.rs | 2 +- src/libextra/num/bigint.rs | 10 +-- src/libextra/terminfo/parser/compiled.rs | 4 +- src/librustc/front/config.rs | 13 +++- src/librustc/middle/check_match.rs | 30 ++++---- src/librustc/middle/dataflow.rs | 8 +-- src/librustc/middle/liveness.rs | 8 +-- src/librustc/middle/region.rs | 26 ++++--- src/librustc/middle/trans/_match.rs | 9 ++- src/librustc/middle/trans/base.rs | 31 ++++----- src/librustc/middle/trans/closure.rs | 9 ++- src/librustc/middle/trans/common.rs | 3 +- src/librustc/middle/trans/controlflow.rs | 3 +- src/librustc/middle/trans/debuginfo.rs | 3 +- src/librustc/middle/trans/foreign.rs | 6 +- src/librustc/middle/trans/meth.rs | 3 +- src/librustc/middle/trans/tvec.rs | 3 +- src/librustc/middle/typeck/check/_match.rs | 3 +- src/librustc/middle/typeck/check/mod.rs | 12 ++-- src/librustc/middle/typeck/check/vtable.rs | 3 +- src/librustc/middle/typeck/check/writeback.rs | 3 +- src/librustc/middle/typeck/infer/glb.rs | 4 +- src/librustc/middle/typeck/infer/lattice.rs | 2 +- .../middle/typeck/infer/region_inference.rs | 3 +- src/librustc/middle/typeck/mod.rs | 3 +- src/libstd/io.rs | 8 ++- src/libstd/managed.rs | 4 +- src/libstd/num/int_macros.rs | 2 +- src/libstd/num/uint_macros.rs | 2 +- src/libstd/rand.rs | 19 ++--- src/libstd/rand/distributions.rs | 2 +- src/libstd/rt/io/extensions.rs | 4 +- src/libstd/rt/uv/mod.rs | 2 +- src/libstd/str.rs | 27 ++++---- src/libstd/to_str.rs | 30 ++++---- src/libstd/tuple.rs | 2 +- src/libstd/vec.rs | 6 +- src/libsyntax/ast.rs | 5 +- src/libsyntax/ast_util.rs | 3 +- src/libsyntax/ext/build.rs | 2 +- src/libsyntax/ext/deriving/generic.rs | 9 ++- src/libsyntax/ext/deriving/mod.rs | 7 +- src/libsyntax/ext/expand.rs | 22 ++++-- src/libsyntax/fold.rs | 69 ++++++++++++------- src/libsyntax/parse/comments.rs | 3 +- src/libsyntax/parse/lexer.rs | 8 ++- src/libsyntax/parse/obsolete.rs | 6 ++ src/libsyntax/parse/parser.rs | 21 +++--- src/libsyntax/print/pprust.rs | 9 ++- src/libsyntax/visit.rs | 6 +- src/test/bench/shootout-fannkuch-redux.rs | 4 +- src/test/bench/shootout-fasta-redux.rs | 7 +- src/test/bench/shootout-mandelbrot.rs | 3 +- src/test/bench/shootout-nbody.rs | 3 +- src/test/bench/shootout-spectralnorm.rs | 4 +- .../compile-fail/borrowck-lend-flow-loop.rs | 21 ++++-- .../compile-fail/borrowck-uniq-via-lend.rs | 6 +- src/test/compile-fail/issue-3021-d.rs | 4 +- .../compile-fail/lint-unused-mut-variables.rs | 4 +- .../compile-fail/moves-based-on-type-exprs.rs | 9 ++- src/test/run-fail/issue-3029.rs | 3 +- src/test/run-fail/zip-different-lengths.rs | 5 +- src/test/run-pass/argument-passing.rs | 4 +- .../run-pass/borrowck-preserve-cond-box.rs | 3 +- .../run-pass/deriving-cmp-generic-enum.rs | 12 +++- .../run-pass/deriving-cmp-generic-struct.rs | 11 +-- .../deriving-cmp-generic-tuple-struct.rs | 11 +-- src/test/run-pass/deriving-self-lifetime.rs | 3 +- src/test/run-pass/multi-let.rs | 7 +- src/test/run-pass/pass-by-copy.rs | 3 +- src/test/run-pass/pure-sum.rs | 12 ++-- src/test/run-pass/ret-break-cont-in-block.rs | 3 +- src/test/run-pass/typestate-multi-decl.rs | 6 +- src/test/run-pass/zip-same-length.rs | 5 +- 80 files changed, 425 insertions(+), 263 deletions(-) diff --git a/doc/rust.md b/doc/rust.md index f2cb9ef5e0e..787d0191b09 100644 --- a/doc/rust.md +++ b/doc/rust.md @@ -2325,7 +2325,9 @@ An example of a for loop over the contents of a vector: ~~~~ # 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]; @@ -3000,7 +3002,7 @@ allocated within the stack's memory. The value is a part of the stack frame. 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 diff --git a/doc/tutorial-ffi.md b/doc/tutorial-ffi.md index 186522f3fb9..d3c682ce1ad 100644 --- a/doc/tutorial-ffi.md +++ b/doc/tutorial-ffi.md @@ -159,8 +159,8 @@ pub struct Unique { priv ptr: *mut T } -pub impl Unique { - fn new(value: T) -> Unique { +impl Unique { + pub fn new(value: T) -> Unique { unsafe { let ptr = malloc(std::sys::size_of::() as size_t) as *mut T; assert!(!ptr::is_null(ptr)); @@ -171,12 +171,12 @@ pub impl Unique { } // 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) } } } diff --git a/doc/tutorial-macros.md b/doc/tutorial-macros.md index 7e8ad2f582d..f1f4ade0542 100644 --- a/doc/tutorial-macros.md +++ b/doc/tutorial-macros.md @@ -13,7 +13,8 @@ doing nothing otherwise: ~~~~ # 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; } _ => {} @@ -38,7 +39,8 @@ the pattern in the above code: ~~~~ # 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 { @@ -155,7 +157,8 @@ instead of `*` to mean "at least one". ~~~~ # 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 { diff --git a/src/libextra/arena.rs b/src/libextra/arena.rs index 57c2152490f..2926d5958f1 100644 --- a/src/libextra/arena.rs +++ b/src/libextra/arena.rs @@ -134,7 +134,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) { 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>(); diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index 5cc0875cb51..3afa9b51c59 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -194,8 +194,8 @@ impl FileInput { 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) } @@ -222,11 +222,11 @@ impl FileInput { 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; @@ -431,8 +431,8 @@ mod test { #[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); @@ -561,8 +561,10 @@ mod test { #[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"); diff --git a/src/libextra/md4.rs b/src/libextra/md4.rs index 0f05e50ea70..f12c9d6573e 100644 --- a/src/libextra/md4.rs +++ b/src/libextra/md4.rs @@ -58,9 +58,9 @@ pub fn md4(msg: &[u8]) -> Quad { 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) + diff --git a/src/libextra/net_url.rs b/src/libextra/net_url.rs index 58930692965..08540775864 100644 --- a/src/libextra/net_url.rs +++ b/src/libextra/net_url.rs @@ -416,7 +416,7 @@ fn get_authority(rawurl: &str) -> 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 // diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 82f706e8f3f..77eef1d67ef 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -125,7 +125,7 @@ impl Ord for BigUint { 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; } @@ -255,7 +255,7 @@ impl Mul for BigUint { 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]); } @@ -447,7 +447,7 @@ impl Integer for BigUint { 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; @@ -1002,8 +1002,8 @@ impl Integer for BigInt { 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), diff --git a/src/libextra/terminfo/parser/compiled.rs b/src/libextra/terminfo/parser/compiled.rs index 10b6d386085..61c68c27fe5 100644 --- a/src/libextra/terminfo/parser/compiled.rs +++ b/src/libextra/terminfo/parser/compiled.rs @@ -160,7 +160,9 @@ pub static stringnames: &'static[&'static str] = &'static[ "cbt", "_", "cr", "cs /// 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; diff --git a/src/librustc/front/config.rs b/src/librustc/front/config.rs index f7ce376ca28..b942bcf4b95 100644 --- a/src/librustc/front/config.rs +++ b/src/librustc/front/config.rs @@ -140,9 +140,18 @@ fn fold_block( 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, diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index 035d6a5cc45..b50c158f37a 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -380,7 +380,8 @@ pub fn missing_ctor(cx: @MatchCheckCtxt, } 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 => (), @@ -513,10 +514,12 @@ pub fn specialize(cx: @MatchCheckCtxt, } }, 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"); @@ -560,8 +563,8 @@ pub fn specialize(cx: @MatchCheckCtxt, } }, 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), _ => { @@ -622,7 +625,8 @@ pub fn specialize(cx: @MatchCheckCtxt, } _ => { // 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; @@ -667,8 +671,8 @@ pub fn specialize(cx: @MatchCheckCtxt, } }, 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), _ => { @@ -691,11 +695,11 @@ pub fn specialize(cx: @MatchCheckCtxt, 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())) diff --git a/src/librustc/middle/dataflow.rs b/src/librustc/middle/dataflow.rs index aedc0e1db5e..349deef2998 100644 --- a/src/librustc/middle/dataflow.rs +++ b/src/librustc/middle/dataflow.rs @@ -372,11 +372,9 @@ impl<'self, O:DataFlowOperator> PropagationContext<'self, O> { 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(_) => {} diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 6e60851ad14..d3a563ca312 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -948,14 +948,10 @@ impl Liveness { 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, } } diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index ce229092323..5478d0900f9 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -325,7 +325,9 @@ pub fn parent_id(cx: Context, span: span) -> ast::node_id { } /// 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); } @@ -333,7 +335,7 @@ pub fn parent_to_expr(cx: Context, child_id: ast::node_id) { pub fn resolve_block(blk: &ast::blk, cx: Context, visitor: visit::vt) { // 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), @@ -348,7 +350,7 @@ pub fn resolve_arm(arm: &ast::arm, cx: Context, visitor: visit::vt) { pub fn resolve_pat(pat: @ast::pat, cx: Context, visitor: visit::vt) { 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); } @@ -359,7 +361,7 @@ pub fn resolve_stmt(stmt: @ast::stmt, cx: Context, visitor: visit::vt) } 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); } @@ -368,7 +370,7 @@ pub fn resolve_stmt(stmt: @ast::stmt, cx: Context, visitor: visit::vt) } pub fn resolve_expr(expr: @ast::expr, cx: Context, visitor: visit::vt) { - 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); @@ -410,7 +412,7 @@ pub fn resolve_local(local: @ast::local, cx: Context, visitor: visit::vt) { 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); } @@ -423,12 +425,18 @@ pub fn resolve_item(item: @ast::item, cx: Context, visitor: visit::vt) 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) { - 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), diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index b142dc1ef28..a42e1cd0647 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1282,7 +1282,8 @@ pub fn compile_submatch(bcx: block, 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; @@ -1638,7 +1639,8 @@ fn create_bindings_map(bcx: block, pat: @ast::pat) -> BindingsMap { 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, @@ -1676,7 +1678,8 @@ pub fn trans_match_inner(scope_cx: block, 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]); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 9b9f80c741b..c2dffa265ad 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -950,7 +950,8 @@ pub fn in_lpad_scope_cx(bcx: block, f: &fn(si: &mut scope_info)) { 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 { @@ -1154,13 +1155,11 @@ pub fn trans_stmt(cx: block, s: &ast::stmt) -> block { } 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) @@ -1296,7 +1295,8 @@ pub fn cleanup_and_leave(bcx: block, upto: Option, leave: Option) { 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()); @@ -1402,15 +1402,11 @@ pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) { 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 */ } } } @@ -1987,7 +1983,8 @@ pub fn trans_enum_variant(ccx: @CrateContext, 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); diff --git a/src/librustc/middle/trans/closure.rs b/src/librustc/middle/trans/closure.rs index a5b44d1a43f..c8405c929cb 100644 --- a/src/librustc/middle/trans/closure.rs +++ b/src/librustc/middle/trans/closure.rs @@ -161,7 +161,8 @@ pub fn mk_closure_tys(tcx: ty::ctxt, 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"); @@ -204,7 +205,8 @@ pub fn store_environment(bcx: block, 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); @@ -500,7 +502,8 @@ pub fn make_opaque_cbox_take_glue( } // ~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| { diff --git a/src/librustc/middle/trans/common.rs b/src/librustc/middle/trans/common.rs index 717cae096f6..a5e04832d69 100644 --- a/src/librustc/middle/trans/common.rs +++ b/src/librustc/middle/trans/common.rs @@ -1438,7 +1438,8 @@ pub fn align_to(cx: block, off: ValueRef, align: ValueRef) -> ValueRef { } 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) => { diff --git a/src/librustc/middle/trans/controlflow.rs b/src/librustc/middle/trans/controlflow.rs index 5ef4376e811..8c6dbb009f5 100644 --- a/src/librustc/middle/trans/controlflow.rs +++ b/src/librustc/middle/trans/controlflow.rs @@ -332,7 +332,8 @@ pub fn trans_fail_expr(bcx: block, 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)); diff --git a/src/librustc/middle/trans/debuginfo.rs b/src/librustc/middle/trans/debuginfo.rs index 6d78e8e0379..88b7f7e70de 100644 --- a/src/librustc/middle/trans/debuginfo.rs +++ b/src/librustc/middle/trans/debuginfo.rs @@ -881,7 +881,8 @@ pub fn create_local_var(bcx: block, local: @ast::local) pub fn create_arg(bcx: block, arg: ast::arg, sp: span) -> Option<@Metadata> { - 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>( diff --git a/src/librustc/middle/trans/foreign.rs b/src/librustc/middle/trans/foreign.rs index f7fdd043094..81ce0dcdad4 100644 --- a/src/librustc/middle/trans/foreign.rs +++ b/src/librustc/middle/trans/foreign.rs @@ -436,7 +436,8 @@ pub fn trans_foreign_mod(ccx: @CrateContext, 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; @@ -462,7 +463,8 @@ pub fn trans_foreign_mod(ccx: @CrateContext, 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); diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 023d931a60b..f05165fe256 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -566,7 +566,8 @@ pub fn combine_impl_and_methods_origins(bcx: block, // 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, diff --git a/src/librustc/middle/trans/tvec.rs b/src/librustc/middle/trans/tvec.rs index e3c0c3a04d8..c009b03e5c2 100644 --- a/src/librustc/middle/trans/tvec.rs +++ b/src/librustc/middle/trans/tvec.rs @@ -136,7 +136,8 @@ pub fn duplicate_uniq(bcx: block, vptr: ValueRef, vec_ty: ty::t) -> Result { 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 } diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 13102093cd6..03803a64fc3 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -106,7 +106,8 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: @ast::pat, path: @ast::Path, 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 , it's an error if it diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 439ff1f413b..dc8a47ca209 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1896,7 +1896,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // 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). @@ -1983,7 +1985,9 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt, // 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); @@ -2876,12 +2880,12 @@ pub fn check_stmt(fcx: @mut FnCtxt, stmt: @ast::stmt) { 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 */ } } } diff --git a/src/librustc/middle/typeck/check/vtable.rs b/src/librustc/middle/typeck/check/vtable.rs index 1ef905de0c2..4bf40d1c18e 100644 --- a/src/librustc/middle/typeck/check/vtable.rs +++ b/src/librustc/middle/typeck/check/vtable.rs @@ -88,7 +88,8 @@ fn lookup_vtables(vcx: &VtableContext, 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... diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 9c8c83d35c4..68f9a43d6e6 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -107,7 +107,8 @@ fn resolve_vtable_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) { fn resolve_type_vars_for_node(wbcx: @mut WbCtxt, sp: span, id: ast::node_id) -> Option { - 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) { diff --git a/src/librustc/middle/typeck/infer/glb.rs b/src/librustc/middle/typeck/infer/glb.rs index d6e3f2dae5d..700a78699b1 100644 --- a/src/librustc/middle/typeck/infer/glb.rs +++ b/src/librustc/middle/typeck/infer/glb.rs @@ -220,7 +220,9 @@ impl Combine for Glb { 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() { diff --git a/src/librustc/middle/typeck/infer/lattice.rs b/src/librustc/middle/typeck/infer/lattice.rs index cf3c64e5cd6..820bb2f86b0 100644 --- a/src/librustc/middle/typeck/infer/lattice.rs +++ b/src/librustc/middle/typeck/infer/lattice.rs @@ -422,7 +422,7 @@ pub fn lattice_vars { match this.infcx().try(|| lattice_dir_op(a_ty, b_ty) ) { diff --git a/src/librustc/middle/typeck/infer/region_inference.rs b/src/librustc/middle/typeck/infer/region_inference.rs index b004e608046..9d6176af0ba 100644 --- a/src/librustc/middle/typeck/infer/region_inference.rs +++ b/src/librustc/middle/typeck/infer/region_inference.rs @@ -928,7 +928,8 @@ impl RegionVarBindings { // `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]; diff --git a/src/librustc/middle/typeck/mod.rs b/src/librustc/middle/typeck/mod.rs index 5aa19ed5875..dc561f413c7 100644 --- a/src/librustc/middle/typeck/mod.rs +++ b/src/librustc/middle/typeck/mod.rs @@ -242,7 +242,8 @@ pub fn require_same_types( 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; diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 8fe592db403..e3977ca0067 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -771,7 +771,7 @@ impl ReaderUtil for T { 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; @@ -787,7 +787,7 @@ impl ReaderUtil for T { 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; @@ -1304,7 +1304,9 @@ pub fn u64_to_le_bytes(n: u64, size: uint, (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; diff --git a/src/libstd/managed.rs b/src/libstd/managed.rs index fb6ac7603ca..7d0defea05a 100644 --- a/src/libstd/managed.rs +++ b/src/libstd/managed.rs @@ -40,14 +40,14 @@ pub mod raw { /// Determine if two shared boxes point to the same object #[inline(always)] pub fn ptr_eq(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(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 } diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index 023f44c433c..3583e2f366f 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -400,7 +400,7 @@ impl Integer for $T { #[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; diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index bdb74f7e191..a7aebf1f176 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -237,7 +237,7 @@ impl Integer for $T { #[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; diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 40d1744f0fb..a6c1dca4342 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -658,13 +658,14 @@ impl IsaacRng { /// 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( () => {{ @@ -718,9 +719,9 @@ impl IsaacRng { 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)] diff --git a/src/libstd/rand/distributions.rs b/src/libstd/rand/distributions.rs index cf2733976c4..f08d967cbe0 100644 --- a/src/libstd/rand/distributions.rs +++ b/src/libstd/rand/distributions.rs @@ -89,7 +89,7 @@ impl Rand for StandardNormal { // 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 { diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index 7d6d89ce997..727ab13a4f6 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -342,7 +342,7 @@ impl ReaderByteConversions for T { 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; @@ -358,7 +358,7 @@ impl ReaderByteConversions for T { 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; diff --git a/src/libstd/rt/uv/mod.rs b/src/libstd/rt/uv/mod.rs index 84d1e65454f..10c8b84bc51 100644 --- a/src/libstd/rt/uv/mod.rs +++ b/src/libstd/rt/uv/mod.rs @@ -242,7 +242,7 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError { // 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); diff --git a/src/libstd/str.rs b/src/libstd/str.rs index b7de9e20559..da9ee21583d 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -661,9 +661,9 @@ fn each_split_char_inner<'a>(s: &'a str, 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 { @@ -725,7 +725,7 @@ fn each_split_inner<'a>(s: &'a str, 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) { @@ -748,9 +748,9 @@ fn each_split_inner<'a>(s: &'a str, // 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] { @@ -977,7 +977,7 @@ pub fn each_split_within<'a>(ss: &'a str, * 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; @@ -1761,7 +1761,7 @@ pub fn contains_char(haystack: &str, needle: char) -> bool { * * 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) } @@ -1776,7 +1776,7 @@ pub fn starts_with<'a,'b>(haystack: &'a str, needle: &'b str) -> bool { * * 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) } @@ -1951,7 +1951,7 @@ pub fn with_capacity(capacity: uint) -> ~str { 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; @@ -1964,7 +1964,7 @@ pub fn count_chars(s: &str, start: uint, end: uint) -> uint { /// 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); @@ -2300,7 +2300,10 @@ pub fn as_buf(s: &str, f: &fn(*u8, uint) -> T) -> T { 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); @@ -2404,7 +2407,7 @@ pub mod raw { /// 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); diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index fecfdbf3b11..3cc64147964 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -53,7 +53,7 @@ impl ToStr for (A,) { impl ToStr for HashMap { #[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; @@ -73,18 +73,18 @@ impl ToStr for HashMap { impl ToStr for HashSet { #[inline(always)] fn to_str(&self) -> ~str { - let mut acc = ~"{", first = true; - for self.each |element| { - if first { - first = false; + let mut (acc, first) = (~"{", true); + for self.each |element| { + if first { + first = false; + } + else { + acc.push_str(", "); + } + acc.push_str(element.to_str()); } - else { - acc.push_str(", "); - } - acc.push_str(element.to_str()); - } - acc.push_char('}'); - acc + acc.push_char('}'); + acc } } @@ -121,7 +121,7 @@ impl ToStr for (A, B, C) { 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; @@ -139,7 +139,7 @@ impl<'self,A:ToStr> ToStr for &'self [A] { impl 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; @@ -157,7 +157,7 @@ impl ToStr for ~[A] { impl 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; diff --git a/src/libstd/tuple.rs b/src/libstd/tuple.rs index da2c52014e8..589c18de0ab 100644 --- a/src/libstd/tuple.rs +++ b/src/libstd/tuple.rs @@ -412,7 +412,7 @@ mod tests { #[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); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 9aeee4ba7b7..f078cd3bda3 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -749,7 +749,7 @@ pub fn truncate(v: &mut ~[T], newlen: uint) { pub fn dedup(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) @@ -1365,7 +1365,7 @@ pub fn bsearch_elem(v: &[T], x: &T) -> Option { * Convert a vector of pairs into a pair of vectors, by reference. As unzip(). */ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { - let mut ts = ~[], us = ~[]; + let mut (ts, us) = (~[], ~[]); for each(v) |p| { let (t, u) = *p; ts.push(t); @@ -1383,7 +1383,7 @@ pub fn unzip_slice(v: &[(T, U)]) -> (~[T], ~[U]) { * of the i-th tuple of the input vector. */ pub fn unzip(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); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f694e37d42f..625bcd4ec9c 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -413,7 +413,10 @@ pub type local = spanned; pub type decl = spanned; #[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 { diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 95dce88d450..e2b8677d5a4 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -279,7 +279,8 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method { 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), diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index c2fa888995a..324b909fbb0 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -385,7 +385,7 @@ impl AstBuilder for @ExtCtxt { 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())) } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index d4b3488cc4f..2e6cac1876b 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -416,7 +416,9 @@ impl<'self> MethodDef<'self> { 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 { @@ -522,8 +524,9 @@ impl<'self> MethodDef<'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, diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 796ccd304ff..13c552388e1 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -264,8 +264,8 @@ pub fn create_struct_pattern(cx: @ExtCtxt, 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| { @@ -326,7 +326,8 @@ pub fn create_enum_variant_pattern(cx: @ExtCtxt, 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))); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 89ed9b7294d..45b9be07a98 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -302,8 +302,9 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, s: &stmt_, sp: span, fld: @ast_fold, - orig: @fn(&stmt_, span, @ast_fold) -> (stmt_, span)) - -> (stmt_, span) { + orig: @fn(&stmt_, span, @ast_fold) + -> (Option, span)) + -> (Option, span) { let (mac, pth, tts, semi) = match *s { stmt_mac(ref mac, semi) => { match mac.node { @@ -342,8 +343,17 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, }; //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) } @@ -355,8 +365,8 @@ pub fn expand_stmt(extsbox: @mut SyntaxEnv, }; (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) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 5800254eaa4..d419ce6f188 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -26,10 +26,10 @@ pub trait ast_fold { 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; @@ -55,10 +55,10 @@ pub struct AstFoldFns { 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, 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, 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, @@ -340,22 +340,39 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method { 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 { 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)) } } @@ -411,13 +428,13 @@ pub fn noop_fold_pat(p: &pat_, fld: @ast_fold) -> pat_ { } } -fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> decl_ { +fn noop_fold_decl(d: &decl_, fld: @ast_fold) -> Option { 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, } } } @@ -738,10 +755,10 @@ pub fn default_ast_fold() -> ast_fold_fns { 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, @@ -799,9 +816,12 @@ impl ast_fold for AstFoldFns { 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) @@ -814,9 +834,12 @@ impl ast_fold for AstFoldFns { 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); diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 001a693d1ae..2f166ae89ef 100644 --- a/src/libsyntax/parse/comments.rs +++ b/src/libsyntax/parse/comments.rs @@ -58,7 +58,8 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { /// 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; } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 0e04e719020..0eb933e6c3a 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -387,7 +387,10 @@ fn scan_digits(rdr: @mut StringReader, radix: uint) -> ~str { } 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); @@ -510,7 +513,8 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token { } 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); diff --git a/src/libsyntax/parse/obsolete.rs b/src/libsyntax/parse/obsolete.rs index f37b430b480..61b7f1403e6 100644 --- a/src/libsyntax/parse/obsolete.rs +++ b/src/libsyntax/parse/obsolete.rs @@ -64,6 +64,7 @@ pub enum ObsoleteSyntax { ObsoleteConstItem, ObsoleteFixedLengthVectorType, ObsoleteNamedExternModule, + ObsoleteMultipleLocalDecl, } impl to_bytes::IterBytes for ObsoleteSyntax { @@ -224,6 +225,11 @@ impl Parser { "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); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index dd966815ad2..23e3f145398 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -84,7 +84,7 @@ use parse::obsolete::ObsoleteMode; 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; @@ -2573,11 +2573,12 @@ impl Parser { 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 @@ -3840,15 +3841,18 @@ impl Parser { // 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. @@ -4352,7 +4356,8 @@ impl Parser { } 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); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 7ab38a6ba5f..7a3eddbd573 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1444,14 +1444,12 @@ pub fn print_local_decl(s: @ps, loc: @ast::local) { 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"); } @@ -1468,7 +1466,8 @@ pub fn print_decl(s: @ps, decl: @ast::decl) { _ => () } } - commasep(s, consistent, *locs, print_local); + + print_local(s, *loc); end(s); } ast::decl_item(item) => print_item(s, item) diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 0cb22737a53..bf75efb805f 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -430,11 +430,7 @@ pub fn visit_stmt(s: @stmt, e: E, v: vt) { pub fn visit_decl(d: @decl, e: E, v: vt) { 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) } } diff --git a/src/test/bench/shootout-fannkuch-redux.rs b/src/test/bench/shootout-fannkuch-redux.rs index 1dd346a2813..b1db5843b7c 100644 --- a/src/test/bench/shootout-fannkuch-redux.rs +++ b/src/test/bench/shootout-fannkuch-redux.rs @@ -17,7 +17,9 @@ fn fannkuch_redux(n: i32) -> i32 { 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 { diff --git a/src/test/bench/shootout-fasta-redux.rs b/src/test/bench/shootout-fasta-redux.rs index 9ea58d9970d..cb9972a709f 100644 --- a/src/test/bench/shootout-fasta-redux.rs +++ b/src/test/bench/shootout-fasta-redux.rs @@ -99,7 +99,9 @@ impl RepeatFasta { 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); @@ -158,7 +160,8 @@ impl RandomFasta { 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 { diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 69eff07093b..70f56f5c5a3 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -10,7 +10,8 @@ static LIMIT: f64 = 2.0; #[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; diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index 744e3041c8f..242b3a3f7a4 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -92,7 +92,8 @@ fn advance(bodies: &mut [Planet, ..N_BODIES], dt: f64, steps: i32) { 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; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 77aaa2782d8..1623eaaa7d3 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -45,7 +45,9 @@ fn mult_AtAv(v: &mut [f64], out: &mut [f64], tmp: &mut [f64]) { #[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); diff --git a/src/test/compile-fail/borrowck-lend-flow-loop.rs b/src/test/compile-fail/borrowck-lend-flow-loop.rs index f7a72d6e610..e66acddd05e 100644 --- a/src/test/compile-fail/borrowck-lend-flow-loop.rs +++ b/src/test/compile-fail/borrowck-lend-flow-loop.rs @@ -49,7 +49,8 @@ fn block_overarching_alias_mut() { 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 @@ -60,7 +61,8 @@ fn loop_aliased_mut() { 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 @@ -71,7 +73,8 @@ fn while_aliased_mut() { 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 @@ -82,7 +85,8 @@ fn for_loop_aliased_mut() { 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); @@ -95,7 +99,8 @@ fn loop_aliased_mut_break() { 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); @@ -108,7 +113,8 @@ fn while_aliased_mut_break() { 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 @@ -120,7 +126,8 @@ fn for_aliased_mut_break() { } 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; diff --git a/src/test/compile-fail/borrowck-uniq-via-lend.rs b/src/test/compile-fail/borrowck-uniq-via-lend.rs index 80ba1968bc7..43459acaaf1 100644 --- a/src/test/compile-fail/borrowck-uniq-via-lend.rs +++ b/src/test/compile-fail/borrowck-uniq-via-lend.rs @@ -48,13 +48,15 @@ fn aliased_mut() { } 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` diff --git a/src/test/compile-fail/issue-3021-d.rs b/src/test/compile-fail/issue-3021-d.rs index fd08d556bef..c6b5d8c42d5 100644 --- a/src/test/compile-fail/issue-3021-d.rs +++ b/src/test/compile-fail/issue-3021-d.rs @@ -23,8 +23,8 @@ fn siphash(k0 : u64, k1 : u64) -> siphash { fn mk_result(st : SipState) -> u64 { - let v0 = st.v0, - v1 = st.v1; + let v0 = st.v0; + let v1 = st.v1; return v0 ^ v1; } diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index d1223cd8893..9b0249bdc2a 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -17,8 +17,8 @@ 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 diff --git a/src/test/compile-fail/moves-based-on-type-exprs.rs b/src/test/compile-fail/moves-based-on-type-exprs.rs index d39b2e06e69..38718006d8b 100644 --- a/src/test/compile-fail/moves-based-on-type-exprs.rs +++ b/src/test/compile-fail/moves-based-on-type-exprs.rs @@ -26,7 +26,8 @@ fn f21() { } fn f30(cond: bool) { - let x = ~"hi", y = ~"ho"; + let x = ~"hi"; + let y = ~"ho"; let _y = if cond { x } else { @@ -37,7 +38,8 @@ fn f30(cond: bool) { } fn f40(cond: bool) { - let x = ~"hi", y = ~"ho"; + let x = ~"hi"; + let y = ~"ho"; let _y = match cond { true => x, false => y @@ -47,7 +49,8 @@ fn f40(cond: bool) { } 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, diff --git a/src/test/run-fail/issue-3029.rs b/src/test/run-fail/issue-3029.rs index 1743d9a6d40..6f4a3f5ab1d 100644 --- a/src/test/run-fail/issue-3029.rs +++ b/src/test/run-fail/issue-3029.rs @@ -10,7 +10,8 @@ // error-pattern:so long fn main() { - let x = ~[], y = ~[3]; + let x = ~[]; + let y = ~[3]; fail!("so long"); x += y; ~"good" + ~"bye"; diff --git a/src/test/run-fail/zip-different-lengths.rs b/src/test/run-fail/zip-different-lengths.rs index 355a2ce93ed..f31fea52639 100644 --- a/src/test/run-fail/zip-different-lengths.rs +++ b/src/test/run-fail/zip-different-lengths.rs @@ -31,7 +31,10 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] { } 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); diff --git a/src/test/run-pass/argument-passing.rs b/src/test/run-pass/argument-passing.rs index 7e56edbedf6..90a17625195 100644 --- a/src/test/run-pass/argument-passing.rs +++ b/src/test/run-pass/argument-passing.rs @@ -24,7 +24,9 @@ fn f1(a: &mut X, b: &mut int, c: int) -> int { 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); diff --git a/src/test/run-pass/borrowck-preserve-cond-box.rs b/src/test/run-pass/borrowck-preserve-cond-box.rs index d9adcbb06f1..4483c7fa4e9 100644 --- a/src/test/run-pass/borrowck-preserve-cond-box.rs +++ b/src/test/run-pass/borrowck-preserve-cond-box.rs @@ -17,7 +17,8 @@ fn testfn(cond: bool) { // 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; diff --git a/src/test/run-pass/deriving-cmp-generic-enum.rs b/src/test/run-pass/deriving-cmp-generic-enum.rs index a2651ddac3d..e3cca832b75 100644 --- a/src/test/run-pass/deriving-cmp-generic-enum.rs +++ b/src/test/run-pass/deriving-cmp-generic-enum.rs @@ -16,7 +16,11 @@ enum E { } 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]; @@ -26,8 +30,10 @@ pub fn main() { 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); diff --git a/src/test/run-pass/deriving-cmp-generic-struct.rs b/src/test/run-pass/deriving-cmp-generic-struct.rs index bd3e02ba29b..4e49ecb8991 100644 --- a/src/test/run-pass/deriving-cmp-generic-struct.rs +++ b/src/test/run-pass/deriving-cmp-generic-struct.rs @@ -15,7 +15,8 @@ struct S { } 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]; @@ -25,8 +26,10 @@ pub fn main() { 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); @@ -46,4 +49,4 @@ pub fn main() { assert_eq!(s1.cmp(s2), ord); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs b/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs index 733b19a9ae2..f119b8b1c48 100644 --- a/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs +++ b/src/test/run-pass/deriving-cmp-generic-tuple-struct.rs @@ -13,7 +13,8 @@ struct TS(T,T); 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]; @@ -23,8 +24,10 @@ pub fn main() { 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); @@ -44,4 +47,4 @@ pub fn main() { assert_eq!(ts1.cmp(ts2), ord); } } -} \ No newline at end of file +} diff --git a/src/test/run-pass/deriving-self-lifetime.rs b/src/test/run-pass/deriving-self-lifetime.rs index 549a9b398a2..e65e189ea93 100644 --- a/src/test/run-pass/deriving-self-lifetime.rs +++ b/src/test/run-pass/deriving-self-lifetime.rs @@ -14,7 +14,8 @@ struct A<'self> { } 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); diff --git a/src/test/run-pass/multi-let.rs b/src/test/run-pass/multi-let.rs index a7c3c80fba7..8e6865adce9 100644 --- a/src/test/run-pass/multi-let.rs +++ b/src/test/run-pass/multi-let.rs @@ -8,4 +8,9 @@ // 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)); +} + diff --git a/src/test/run-pass/pass-by-copy.rs b/src/test/run-pass/pass-by-copy.rs index c4f328940c4..63196128ba5 100644 --- a/src/test/run-pass/pass-by-copy.rs +++ b/src/test/run-pass/pass-by-copy.rs @@ -14,7 +14,8 @@ fn magic2(x: @int) { debug!(x); } 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); } diff --git a/src/test/run-pass/pure-sum.rs b/src/test/run-pass/pure-sum.rs index 6327a3f238d..17eab78f820 100644 --- a/src/test/run-pass/pure-sum.rs +++ b/src/test/run-pass/pure-sum.rs @@ -11,7 +11,8 @@ // 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; @@ -20,7 +21,8 @@ fn sums_to(v: ~[int], sum: int) -> bool { } 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; @@ -29,7 +31,8 @@ fn sums_to_using_uniq(v: ~[int], sum: int) -> bool { } 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; @@ -40,7 +43,8 @@ fn sums_to_using_rec(v: ~[int], sum: int) -> bool { struct F { 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; diff --git a/src/test/run-pass/ret-break-cont-in-block.rs b/src/test/run-pass/ret-break-cont-in-block.rs index d9d4b332f5f..80e6293bf50 100644 --- a/src/test/run-pass/ret-break-cont-in-block.rs +++ b/src/test/run-pass/ret-break-cont-in-block.rs @@ -14,7 +14,8 @@ use std::cmp::Eq; use std::vec; fn iter(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; diff --git a/src/test/run-pass/typestate-multi-decl.rs b/src/test/run-pass/typestate-multi-decl.rs index b4ca326fb57..42910c47005 100644 --- a/src/test/run-pass/typestate-multi-decl.rs +++ b/src/test/run-pass/typestate-multi-decl.rs @@ -8,4 +8,8 @@ // 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)); +} diff --git a/src/test/run-pass/zip-same-length.rs b/src/test/run-pass/zip-same-length.rs index 83759dd82e6..d97148746d0 100644 --- a/src/test/run-pass/zip-same-length.rs +++ b/src/test/run-pass/zip-same-length.rs @@ -30,7 +30,10 @@ fn enum_uints(start: uint, end: uint) -> ~[uint] { } 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);