librustc: Disallow multiple patterns from appearing in a "let" declaration.

You can still initialize multiple variables at once with "let (x, y) = (1, 2)".
This commit is contained in:
Patrick Walton 2013-06-04 21:43:41 -07:00
parent 16086ecff7
commit 8114d0e950
80 changed files with 425 additions and 263 deletions

View file

@ -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

View file

@ -159,8 +159,8 @@ pub struct Unique<T> {
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));
@ -171,12 +171,12 @@ pub impl<T: Owned> Unique<T> {
}
// 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) }
}
}

View file

@ -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 {

View file

@ -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>();

View file

@ -194,8 +194,8 @@ pub fn from_vec_raw(files: ~[Option<Path>])
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 @@ pub fn next_file(&self) -> bool {
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 @@ fn make_file(path : &Path, contents: &[~str]) {
#[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 @@ fn test_empty_files() {
#[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");

View file

@ -58,9 +58,9 @@ fn rot(r: int, x: u32) -> u32 {
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) +

View file

@ -416,7 +416,7 @@ enum State {
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 //

View file

@ -125,7 +125,7 @@ fn gt(&self, other: &BigUint) -> bool {
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<BigUint, BigUint> 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 @@ fn div_estimate(a: &BigUint, b: &BigUint, n: uint)
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 @@ fn mod_floor(&self, other: &BigInt) -> 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),

View file

@ -160,7 +160,9 @@
/// 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;

View file

@ -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,

View file

@ -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()))

View file

@ -372,11 +372,9 @@ fn walk_decl(&mut self,
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(_) => {}

View file

@ -948,14 +948,10 @@ pub fn propagate_through_stmt(&self, stmt: @stmt, succ: LiveNode)
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,
}
}

View file

@ -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<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),
@ -348,7 +350,7 @@ pub fn resolve_arm(arm: &ast::arm, cx: Context, visitor: visit::vt<Context>) {
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);
}
@ -359,7 +361,7 @@ pub fn resolve_stmt(stmt: @ast::stmt, cx: Context, visitor: visit::vt<Context>)
}
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<Context>)
}
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);
@ -410,7 +412,7 @@ pub fn resolve_local(local: @ast::local,
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);
}
@ -423,12 +425,18 @@ pub fn resolve_item(item: @ast::item, cx: Context, visitor: visit::vt<Context>)
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),

View file

@ -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]);

View file

@ -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<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());
@ -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);

View file

@ -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| {

View file

@ -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) => {

View file

@ -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));

View file

@ -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<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>>(

View file

@ -436,7 +436,8 @@ fn build_direct_fn(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 @@ fn build_fast_ffi_fn(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);

View file

@ -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,

View file

@ -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 }

View file

@ -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 <expected>, it's an error if it

View file

@ -1896,7 +1896,9 @@ fn check_struct_constructor(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 @@ fn check_struct_enum_variant(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 */ }
}
}

View file

@ -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...

View file

@ -107,7 +107,8 @@ fn resolve_origin(fcx: @mut FnCtxt,
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) {

View file

@ -220,7 +220,9 @@ fn generalize_region(this: &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() {

View file

@ -422,7 +422,7 @@ pub fn lattice_vars<L:LatticeDir + Combine,
// 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) ) {

View file

@ -928,7 +928,8 @@ pub fn tainted(&mut self, snapshot: uint, r0: Region) -> ~[Region] {
// `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];

View file

@ -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;

View file

@ -771,7 +771,7 @@ fn read_lines(&self) -> ~[~str] {
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 @@ fn read_le_int_n(&self, nbytes: uint) -> i64 {
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<T>(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;

View file

@ -40,14 +40,14 @@ pub struct BoxRepr {
/// 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
}

View file

@ -400,7 +400,7 @@ fn div_rem(&self, other: &$T) -> ($T,$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;

View file

@ -237,7 +237,7 @@ fn div_mod_floor(&self, other: &$T) -> ($T,$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;

View file

@ -658,13 +658,14 @@ pub fn new_unseeded() -> 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 @@ macro_rules! memloop (
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)]

View file

@ -89,7 +89,7 @@ fn zero_case<R:Rng>(rng: &mut R, u: f64) -> f64 {
// 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 {

View file

@ -342,7 +342,7 @@ impl<T: Reader> 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 @@ fn read_le_int_n(&mut self, nbytes: uint) -> i64 {
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;

View file

@ -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);

View file

@ -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 @@ enum LengthLimit {
* 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<T>(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);

View file

@ -53,7 +53,7 @@ fn to_str(&self) -> ~str {
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;
@ -73,18 +73,18 @@ fn to_str(&self) -> ~str {
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;
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 @@ fn to_str(&self) -> ~str {
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 @@ fn to_str(&self) -> ~str {
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;
@ -157,7 +157,7 @@ fn to_str(&self) -> ~str {
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;

View file

@ -412,7 +412,7 @@ fn test_n_tuple() {
#[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);

View file

@ -749,7 +749,7 @@ pub fn truncate<T>(v: &mut ~[T], newlen: uint) {
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)
@ -1365,7 +1365,7 @@ pub fn bsearch_elem<T:TotalOrd>(v: &[T], x: &T) -> Option<uint> {
* 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);
@ -1383,7 +1383,7 @@ pub fn unzip_slice<T:Copy,U:Copy>(v: &[(T, U)]) -> (~[T], ~[U]) {
* 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);

View file

@ -413,7 +413,10 @@ pub struct local_ {
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 {

View file

@ -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),

View file

@ -385,7 +385,7 @@ fn stmt_let(&self, sp: span, mutbl: bool, ident: ast::ident, ex: @ast::expr) ->
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()))
}

View file

@ -416,7 +416,9 @@ fn split_self_nonself_args(&self, cx: @ExtCtxt, span: span,
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 @@ fn expand_struct_method_body(&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,

View file

@ -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)));

View file

@ -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<stmt_>, span))
-> (Option<stmt_>, 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)
}

View file

@ -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<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,
@ -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<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))
}
}
@ -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<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,
}
}
}
@ -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 @@ fn fold_block(@self, x: &blk) -> blk {
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 @@ fn fold_pat(@self, x: @pat) -> @pat {
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);

View file

@ -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;
}

View file

@ -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);

View file

@ -64,6 +64,7 @@ pub enum ObsoleteSyntax {
ObsoleteConstItem,
ObsoleteFixedLengthVectorType,
ObsoleteNamedExternModule,
ObsoleteMultipleLocalDecl,
}
impl to_bytes::IterBytes for ObsoleteSyntax {
@ -224,6 +225,11 @@ pub fn obsolete(&self, sp: span, kind: 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);

View file

@ -84,7 +84,7 @@
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 @@ fn parse_local(&self, is_mutbl: bool) -> @local {
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 @@ fn parse_struct_def(&self) -> @struct_def {
// 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 @@ fn parse_view_paths(&self) -> ~[@view_path] {
}
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);

View file

@ -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 @@ fn print_local(s: @ps, loc: @ast::local) {
_ => ()
}
}
commasep(s, consistent, *locs, print_local);
print_local(s, *loc);
end(s);
}
ast::decl_item(item) => print_item(s, item)

View file

@ -430,11 +430,7 @@ pub fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
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)
}
}

View file

@ -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 {

View file

@ -99,7 +99,9 @@ fn make(&mut self, n: uint) {
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 @@ fn nextc(&mut self) -> u8 {
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 {

View file

@ -10,7 +10,8 @@
#[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;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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`

View file

@ -23,8 +23,8 @@ struct SipState {
fn mk_result(st : SipState) -> u64 {
let v0 = st.v0,
v1 = st.v1;
let v0 = st.v0;
let v1 = st.v1;
return v0 ^ v1;
}

View file

@ -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

View file

@ -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,

View file

@ -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";

View file

@ -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);

View file

@ -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);

View file

@ -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;

View file

@ -16,7 +16,11 @@ enum E<T> {
}
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);

View file

@ -15,7 +15,8 @@ struct S<T> {
}
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);
}
}
}
}

View file

@ -13,7 +13,8 @@
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);
}
}
}
}

View file

@ -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);

View file

@ -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));
}

View file

@ -14,7 +14,8 @@
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);
}

View file

@ -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<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;

View file

@ -14,7 +14,8 @@
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;

View file

@ -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));
}

View file

@ -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);