From ba13482dfabe4d0022f1fc2375b500cce53a05ce Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 20 Jun 2013 15:13:22 -0400 Subject: update ptr intrinsics and rewrite vec routines to be more correct. In particular, it is not valid to go around passing uninitialized or zero'd memory as arguments. Rust should generally be free to assume that the arguments it gets are valid input values, but the output of intrinsics::uninit() and intrinsics::init() are not (e.g., an @T is just null, leading to an error if we should try to increment the ref count). --- src/libstd/ptr.rs | 50 ++++++++++++++++++++ src/libstd/vec.rs | 134 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 144 insertions(+), 40 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index aee6f1bd204..add2bbd7d44 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -142,6 +142,30 @@ pub unsafe fn set_memory(dst: *mut T, c: u8, count: uint) { memset64(dst, c, count as u64); } +/** + * Zeroes out `count` bytes of memory at `dst` + */ +#[inline] +#[cfg(not(stage0))] +pub unsafe fn zero_memory(dst: *mut T, count: uint) { + set_memory(dst, 0, count); +} + +/** + * Zeroes out `count * size_of::` bytes of memory at `dst` + */ +#[inline] +#[cfg(stage0)] +pub unsafe fn zero_memory(dst: *mut T, count: uint) { + let mut count = count * sys::size_of::(); + let mut dst = dst as *mut u8; + while count > 0 { + *dst = 0; + dst = mut_offset(dst, 1); + count -= 1; + } +} + /** * Swap the values at two mutable locations of the same type, without * deinitialising or copying either one. @@ -172,6 +196,32 @@ pub unsafe fn replace_ptr(dest: *mut T, mut src: T) -> T { src } +/** + * Reads the value from `*src` and returns it. Does not copy `*src`. + */ +#[inline(always)] +pub unsafe fn read_ptr(src: *mut T) -> T { + let mut tmp: T = intrinsics::uninit(); + let t: *mut T = &mut tmp; + copy_memory(t, src, 1); + tmp +} + +/** + * Reads the value from `*src` and nulls it out. + * This currently prevents destructors from executing. + */ +#[inline(always)] +pub unsafe fn read_and_zero_ptr(dest: *mut T) -> T { + // Copy the data out from `dest`: + let tmp = read_ptr(dest); + + // Now zero out `dest`: + zero_memory(dest, 1); + + tmp +} + /// Transform a region pointer - &T - to an unsafe pointer - *T. #[inline] pub fn to_unsafe_ptr(thing: &T) -> *T { diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 33857556548..cacb3156b75 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1256,16 +1256,15 @@ impl OwnedVector for ~[T] { /// ~~~ #[inline] fn push_all_move(&mut self, mut rhs: ~[T]) { - let new_len = self.len() + rhs.len(); + let self_len = self.len(); + let rhs_len = rhs.len(); + let new_len = self_len + rhs_len; self.reserve(new_len); - unsafe { - do rhs.as_mut_buf |p, len| { - for uint::range(0, len) |i| { - let x = ptr::replace_ptr(ptr::mut_offset(p, i), - intrinsics::uninit()); - self.push(x); - } - } + unsafe { // Note: infallible. + let self_p = vec::raw::to_mut_ptr(*self); + let rhs_p = vec::raw::to_ptr(rhs); + ptr::copy_memory(ptr::mut_offset(self_p, self_len), rhs_p, rhs_len); + raw::set_len(self, new_len); raw::set_len(&mut rhs, 0); } } @@ -1277,9 +1276,8 @@ impl OwnedVector for ~[T] { ln => { let valptr = ptr::to_mut_unsafe_ptr(&mut self[ln - 1u]); unsafe { - let val = ptr::replace_ptr(valptr, intrinsics::init()); - raw::set_len(self, ln - 1u); - Some(val) + raw::set_len(v, ln - 1u); + ptr::read_ptr(valptr) } } } @@ -1410,7 +1408,7 @@ impl OwnedVector for ~[T] { unsafe { // This loop is optimized out for non-drop types. for uint::range(newlen, oldlen) |i| { - ptr::replace_ptr(ptr::mut_offset(p, i), intrinsics::uninit()); + ptr::read_and_zero_ptr(ptr::mut_offset(p, i)) } } } @@ -1555,37 +1553,93 @@ pub trait OwnedEqVector { impl OwnedEqVector for ~[T] { /** - * Remove consecutive repeated elements from a vector; if the vector is - * sorted, this removes all duplicates. - */ - pub fn dedup(&mut self) { + * Remove consecutive repeated elements from a vector; if the vector is + * sorted, this removes all duplicates. + */ + pub fn dedup(&mut self) { unsafe { - if self.len() == 0 { return; } - let mut last_written = 0; - let mut next_to_read = 1; - do self.as_mut_buf |p, ln| { - // last_written < next_to_read <= ln - while next_to_read < ln { - // last_written < next_to_read < ln - if *ptr::mut_offset(p, next_to_read) == - *ptr::mut_offset(p, last_written) { - ptr::replace_ptr(ptr::mut_offset(p, next_to_read), - intrinsics::uninit()); - } else { - last_written += 1; - // last_written <= next_to_read < ln - if next_to_read != last_written { - ptr::swap_ptr(ptr::mut_offset(p, last_written), - ptr::mut_offset(p, next_to_read)); - } + // Although we have a mutable reference to `self`, we cannot make + // *arbitrary* changes. There exists the possibility that this + // vector is contained with an `@mut` box and hence is still + // readable by the outside world during the `Eq` comparisons. + // Moreover, those comparisons could fail, so we must ensure + // that the vector is in a valid state at all time. + // + // The way that we handle this is by using swaps; we iterate + // over all the elements, swapping as we go so that at the end + // the elements we wish to keep are in the front, and those we + // wish to reject are at the back. We can then truncate the + // vector. This operation is still O(n). + // + // Example: We start in this state, where `r` represents "next + // read" and `w` represents "next_write`. + // + // r + // +---+---+---+---+---+---+ + // | 0 | 1 | 1 | 2 | 3 | 3 | + // +---+---+---+---+---+---+ + // w + // + // Comparing self[r] against self[w-1], tis is not a duplicate, so + // we swap self[r] and self[w] (no effect as r==w) and then increment both + // r and w, leaving us with: + // + // r + // +---+---+---+---+---+---+ + // | 0 | 1 | 1 | 2 | 3 | 3 | + // +---+---+---+---+---+---+ + // w + // + // Comparing self[r] against self[w-1], this value is a duplicate, + // so we increment `r` but leave everything else unchanged: + // + // r + // +---+---+---+---+---+---+ + // | 0 | 1 | 1 | 2 | 3 | 3 | + // +---+---+---+---+---+---+ + // w + // + // Comparing self[r] against self[w-1], this is not a duplicate, + // so swap self[r] and self[w] and advance r and w: + // + // r + // +---+---+---+---+---+---+ + // | 0 | 1 | 2 | 1 | 3 | 3 | + // +---+---+---+---+---+---+ + // w + // + // Not a duplicate, repeat: + // + // r + // +---+---+---+---+---+---+ + // | 0 | 1 | 2 | 3 | 1 | 3 | + // +---+---+---+---+---+---+ + // w + // + // Duplicate, advance r. End of vec. Truncate to w. + + let ln = self.len(); + if ln < 1 { return; } + + // Avoid bounds checks by using unsafe pointers. + let p = vec::raw::to_mut_ptr(*self); + let mut r = 1; + let mut w = 1; + + while r < ln { + let p_r = ptr::mut_offset(p, r); + let p_wm1 = ptr::mut_offset(p, w - 1); + if *p_r != *p_wm1 { + if r != w { + let p_w = ptr::mut_offset(p_wm1, 1); + util::swap(&mut *p_r, &mut *p_w); } - // last_written <= next_to_read < ln - next_to_read += 1; - // last_written < next_to_read <= ln + w += 1; } + r += 1; } - // last_written < next_to_read == ln - raw::set_len(self, last_written + 1); + + self.truncate(w); } } } -- cgit 1.4.1-3-g733a5 From 9999622e44558a6b138e7d5e3e98ba5db2eb1465 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 20 Jun 2013 15:14:30 -0400 Subject: Patch up some code that was using irrefutable patterns incorrectly. --- src/libstd/run.rs | 18 ++++++++++++------ src/libstd/vec.rs | 6 +++--- 2 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 7e051b62171..b7bec95e655 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -715,10 +715,16 @@ fn with_envp(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T { let mut tmps = ~[]; let mut ptrs = ~[]; - for es.iter().advance |&(k, v)| { - let kv = @fmt!("%s=%s", k, v); - tmps.push(kv); - ptrs.push(str::as_c_str(*kv, |b| b)); + for es.iter().advance |pair| { + // Use of match here is just to workaround limitations + // in the stage0 irrefutable pattern impl. + match pair { + &(ref k, ref v) => { + let kv = @fmt!("%s=%s", *k, *v); + tmps.push(kv); + ptrs.push(str::as_c_str(*kv, |b| b)); + } + } } ptrs.push(ptr::null()); @@ -1294,9 +1300,9 @@ mod tests { let output = str::from_bytes(prog.finish_with_output().output); let r = os::env(); - for r.iter().advance |&(k, v)| { + for r.iter().advance |&(ref k, ref v)| { // don't check windows magical empty-named variables - assert!(k.is_empty() || output.contains(fmt!("%s=%s", k, v))); + assert!(k.is_empty() || output.contains(fmt!("%s=%s", *k, *v))); } } #[test] diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index cacb3156b75..b4e891414f6 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -281,16 +281,16 @@ pub trait VectorVector { impl<'self, T:Copy> VectorVector for &'self [~[T]] { /// Flattens a vector of slices of T into a single vector of T. pub fn concat_vec(&self) -> ~[T] { - self.flat_map(|&inner| inner) + self.flat_map(|inner| copy *inner) } /// Concatenate a vector of vectors, placing a given separator between each. pub fn connect_vec(&self, sep: &T) -> ~[T] { let mut r = ~[]; let mut first = true; - for self.iter().advance |&inner| { + for self.iter().advance |inner| { if first { first = false; } else { r.push(copy *sep); } - r.push_all(inner); + r.push_all(copy *inner); } r } -- cgit 1.4.1-3-g733a5 From 59083d2c6aedcbab469e263850c717cd958c24e6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 21 Jun 2013 05:56:35 -0400 Subject: Address nits by @catamorphism --- src/libstd/ptr.rs | 2 +- src/rt/boxed_region.cpp | 4 ---- ...borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs | 8 ++++---- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index add2bbd7d44..2b42c085009 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -143,7 +143,7 @@ pub unsafe fn set_memory(dst: *mut T, c: u8, count: uint) { } /** - * Zeroes out `count` bytes of memory at `dst` + * Zeroes out `count * size_of::` bytes of memory at `dst` */ #[inline] #[cfg(not(stage0))] diff --git a/src/rt/boxed_region.cpp b/src/rt/boxed_region.cpp index 533a2a04755..012333b931e 100644 --- a/src/rt/boxed_region.cpp +++ b/src/rt/boxed_region.cpp @@ -39,10 +39,6 @@ rust_opaque_box *boxed_region::malloc(type_desc *td, size_t body_size) { rust_opaque_box *boxed_region::realloc(rust_opaque_box *box, size_t new_size) { - // We also get called on the unique-vec-in-managed-heap path. - // assert(box->ref_count == 1 || - // box->ref_count == (size_t)(-2)); - size_t total_size = new_size + sizeof(rust_opaque_box); rust_opaque_box *new_box = (rust_opaque_box*)backing_region->realloc(box, total_size); diff --git a/src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs b/src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs index c3432582647..5da7a6f2b56 100644 --- a/src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs +++ b/src/test/run-pass/borrowck-wg-autoderef-and-autoborrowvec-combined-issue-6272.rs @@ -29,13 +29,13 @@ fn main() { let a = @mut 3i; - // let b = @mut [a]; - // let c = @mut [3]; + let b = @mut [a]; + let c = @mut [3]; // this should freeze `a` only let _x: &mut int = a; // hence these writes should not fail: - // b[0] = b[0]; - // c[0] = c[0]; + b[0] = b[0]; + c[0] = c[0]; } -- cgit 1.4.1-3-g733a5 From 979d3a54f9e1eea483734059a2f594278787e16a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 24 Jun 2013 13:30:35 -0400 Subject: Correct merge failures --- src/libextra/fileinput.rs | 2 +- src/libextra/num/bigint.rs | 2 +- src/libextra/term.rs | 4 +- src/librustc/middle/borrowck/gather_loans/mod.rs | 2 +- src/librustc/middle/moves.rs | 11 +--- src/librustc/middle/trans/_match.rs | 9 ++-- src/librustc/middle/trans/base.rs | 60 +++------------------- src/librustc/middle/trans/callee.rs | 5 +- src/librustc/middle/trans/meth.rs | 3 +- src/libstd/vec.rs | 6 +-- src/libsyntax/print/pprust.rs | 7 ++- .../borrowck-move-out-of-struct-with-dtor.rs | 2 +- .../borrowck-move-out-of-tuple-struct-with-dtor.rs | 2 +- src/test/run-pass/reflect-visit-type.rs | 4 +- 14 files changed, 34 insertions(+), 85 deletions(-) (limited to 'src/libstd') diff --git a/src/libextra/fileinput.rs b/src/libextra/fileinput.rs index de6edd54094..27c8051afac 100644 --- a/src/libextra/fileinput.rs +++ b/src/libextra/fileinput.rs @@ -418,7 +418,7 @@ mod test { fn make_file(path : &Path, contents: &[~str]) { let file = io::file_writer(path, [io::Create, io::Truncate]).get(); - for contents.iter().advance |&str| { + for contents.iter().advance |str| { file.write_str(*str); file.write_char('\n'); } diff --git a/src/libextra/num/bigint.rs b/src/libextra/num/bigint.rs index 91842474899..5867b13f556 100644 --- a/src/libextra/num/bigint.rs +++ b/src/libextra/num/bigint.rs @@ -1586,7 +1586,7 @@ mod biguint_tests { let &(ref n, ref rs) = num_pair; for rs.iter().advance |str_pair| { let &(ref radix, ref str) = str_pair; - assert_eq!(&n, &FromStrRadix::from_str_radix(*str, *radix).get()); + assert_eq!(n, &FromStrRadix::from_str_radix(*str, *radix).get()); } } diff --git a/src/libextra/term.rs b/src/libextra/term.rs index 55626622775..cd226e2ad32 100644 --- a/src/libextra/term.rs +++ b/src/libextra/term.rs @@ -119,8 +119,8 @@ impl Terminal { pub fn reset(&self) { let mut vars = Variables::new(); let s = do self.ti.strings.find_equiv(&("op")) - .map_consume_default(Err(~"can't find terminfo capability `op`")) |&op| { - expand(op, [], &mut vars) + .map_consume_default(Err(~"can't find terminfo capability `op`")) |op| { + expand(copy *op, [], &mut vars) }; if s.is_ok() { self.out.write(s.unwrap()); diff --git a/src/librustc/middle/borrowck/gather_loans/mod.rs b/src/librustc/middle/borrowck/gather_loans/mod.rs index 86baf535284..23451e0f36e 100644 --- a/src/librustc/middle/borrowck/gather_loans/mod.rs +++ b/src/librustc/middle/borrowck/gather_loans/mod.rs @@ -617,7 +617,7 @@ impl GatherLoanCtxt { */ let mc_ctxt = self.bccx.mc_ctxt(); - for decl.inputs.each |arg| { + for decl.inputs.iter().advance |arg| { let arg_ty = ty::node_id_to_type(self.tcx(), arg.pat.id); let arg_cmt = mc_ctxt.cat_rvalue( diff --git a/src/librustc/middle/moves.rs b/src/librustc/middle/moves.rs index e9a73a513c8..07bdee07c0f 100644 --- a/src/librustc/middle/moves.rs +++ b/src/librustc/middle/moves.rs @@ -190,15 +190,8 @@ enum UseMode { pub fn compute_moves(tcx: ty::ctxt, method_map: method_map, -<<<<<<< HEAD crate: &crate) -> MoveMaps { -||||||| merged common ancestors - crate: @crate) -> MoveMaps -{ -======= - crate: @crate) -> MoveMaps { ->>>>>>> Modify borrow checker to visit irrefutable patterns that appear in let visitor = visit::mk_vt(@visit::Visitor { visit_fn: compute_modes_for_fn, visit_expr: compute_modes_for_expr, @@ -248,7 +241,7 @@ fn compute_modes_for_fn(fk: &visit::fn_kind, id: node_id, (cx, v): (VisitContext, vt)) { - for decl.inputs.each |a| { + for decl.inputs.iter().advance |a| { cx.use_pat(a.pat); } visit::visit_fn(fk, decl, body, span, id, (cx, v)); @@ -554,7 +547,7 @@ impl VisitContext { } expr_fn_block(ref decl, ref body) => { - for decl.inputs.each |a| { + for decl.inputs.iter().advance |a| { self.use_pat(a.pat); } let cap_vars = self.compute_captures(expr.id); diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index f5bb075aafc..74f1e372c07 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1738,7 +1738,7 @@ pub fn store_local(bcx: block, * Generates code for a local variable declaration like * `let ;` or `let = `. */ - let _icx = bcx.insn_ctxt("match::store_local"); + let _icx = push_ctxt("match::store_local"); let mut bcx = bcx; return match opt_init_expr { @@ -1813,7 +1813,7 @@ pub fn store_arg(mut bcx: block, * if the argument type is `T`, then `llval` is a `T*`). In some * cases, this code may zero out the memory `llval` points at. */ - let _icx = bcx.insn_ctxt("match::store_arg"); + let _icx = push_ctxt("match::store_arg"); // We always need to cleanup the argument as we exit the fn scope. // Note that we cannot do it before for fear of a fn like @@ -1882,10 +1882,9 @@ fn bind_irrefutable_pat(bcx: block, * - binding_mode: is this for an argument or a local variable? */ - debug!("bind_irrefutable_pat(bcx=%s, pat=%s, val=%s, binding_mode=%?)", + debug!("bind_irrefutable_pat(bcx=%s, pat=%s, binding_mode=%?)", bcx.to_str(), pat_to_str(pat, bcx.sess().intr()), - val_str(bcx.ccx().tn, val), binding_mode); if bcx.sess().asm_comments() { @@ -1895,7 +1894,7 @@ fn bind_irrefutable_pat(bcx: block, let _indenter = indenter(); - let _icx = bcx.insn_ctxt("alt::bind_irrefutable_pat"); + let _icx = push_ctxt("alt::bind_irrefutable_pat"); let mut bcx = bcx; let tcx = bcx.tcx(); let ccx = bcx.ccx(); diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 75d9f89a8d7..c8117ed64a7 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -112,8 +112,8 @@ impl Drop for _InsnCtxt { fn drop(&self) { unsafe { do local_data::local_data_modify(task_local_insn_key) |c| { - do c.map_consume |@ctx| { - let mut ctx = ctx; + do c.map_consume |ctx| { + let mut ctx = copy *ctx; ctx.pop(); @ctx } @@ -126,8 +126,8 @@ pub fn push_ctxt(s: &'static str) -> _InsnCtxt { debug!("new InsnCtxt: %s", s); unsafe { do local_data::local_data_modify(task_local_insn_key) |c| { - do c.map_consume |@ctx| { - let mut ctx = ctx; + do c.map_consume |ctx| { + let mut ctx = copy *ctx; ctx.push(s); @ctx } @@ -1438,54 +1438,6 @@ pub fn block_locals(b: &ast::blk, it: &fn(@ast::local)) { } } -<<<<<<< variant A -pub fn alloc_local(cx: block, local: &ast::local) -> block { - let _icx = push_ctxt("alloc_local"); - let t = node_id_type(cx, local.node.id); - let simple_name = match local.node.pat.node { - ast::pat_ident(_, ref pth, None) => Some(path_to_ident(pth)), - _ => None - }; - let val = alloc_ty(cx, t); - if cx.sess().opts.debuginfo { - for simple_name.iter().advance |name| { - str::as_c_str(cx.ccx().sess.str_of(*name), |buf| { - unsafe { - llvm::LLVMSetValueName(val, buf) - } - }); - } - } - cx.fcx.lllocals.insert(local.node.id, val); - cx -} - - ->>>>>>> variant B -####### Ancestor -pub fn alloc_local(cx: block, local: @ast::local) -> block { - let _icx = push_ctxt("alloc_local"); - let t = node_id_type(cx, local.node.id); - let simple_name = match local.node.pat.node { - ast::pat_ident(_, pth, None) => Some(path_to_ident(pth)), - _ => None - }; - let val = alloc_ty(cx, t); - if cx.sess().opts.debuginfo { - for simple_name.iter().advance |name| { - str::as_c_str(cx.ccx().sess.str_of(*name), |buf| { - unsafe { - llvm::LLVMSetValueName(val, buf) - } - }); - } - } - cx.fcx.lllocals.insert(local.node.id, val); - cx -} - - -======= end pub fn with_cond(bcx: block, val: ValueRef, f: &fn(block) -> block) -> block { let _icx = push_ctxt("with_cond"); let next_cx = base::sub_block(bcx, "next"); @@ -1763,7 +1715,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt, let self_val = if slf.is_copy && datum::appropriate_mode(bcx.tcx(), slf.t).is_by_value() { let tmp = BitCast(bcx, slf.v, type_of(bcx.ccx(), slf.t)); - let alloc = alloc_ty(bcx, slf.t); + let alloc = alloc_ty(bcx, slf.t, "__self"); Store(bcx, tmp, alloc); alloc } else { @@ -3030,7 +2982,7 @@ pub fn trans_crate(sess: session::Session, } } if ccx.sess.count_llvm_insns() { - for ccx.stats.llvm_insns.each |k, v| { + for ccx.stats.llvm_insns.iter().advance |(k, v)| { io::println(fmt!("%-7u %s", *v, *k)); } } diff --git a/src/librustc/middle/trans/callee.rs b/src/librustc/middle/trans/callee.rs index 216338e1117..22adc4aa24b 100644 --- a/src/librustc/middle/trans/callee.rs +++ b/src/librustc/middle/trans/callee.rs @@ -873,10 +873,10 @@ pub fn trans_arg_expr(bcx: block, // &arg_expr.id); debug!("by ref arg with type %s, storing to scratch", bcx.ty_to_str(arg_datum.ty)); - let scratch = scratch_datum(bcx, arg_datum.ty, false); + let scratch = scratch_datum(bcx, arg_datum.ty, + "__self", false); arg_datum.store_to_datum(bcx, - arg_expr.id, INIT, scratch); @@ -897,7 +897,6 @@ pub fn trans_arg_expr(bcx: block, "__arg", false); arg_datum.store_to_datum(bcx, - arg_expr.id, INIT, scratch); diff --git a/src/librustc/middle/trans/meth.rs b/src/librustc/middle/trans/meth.rs index 14cc822b5a5..0914e61d58f 100644 --- a/src/librustc/middle/trans/meth.rs +++ b/src/librustc/middle/trans/meth.rs @@ -614,7 +614,8 @@ pub fn trans_trait_callee_from_llval(bcx: block, } llself = PointerCast(bcx, llself, Type::opaque_box(ccx).ptr_to()); - let scratch = scratch_datum(bcx, ty::mk_opaque_box(bcx.tcx()), false); + let scratch = scratch_datum(bcx, ty::mk_opaque_box(bcx.tcx()), + "__trait_callee", false); Store(bcx, llself, scratch.val); scratch.add_clean(bcx); diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index b4e891414f6..c546be63138 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1276,7 +1276,7 @@ impl OwnedVector for ~[T] { ln => { let valptr = ptr::to_mut_unsafe_ptr(&mut self[ln - 1u]); unsafe { - raw::set_len(v, ln - 1u); + raw::set_len(self, ln - 1u); ptr::read_ptr(valptr) } } @@ -1408,7 +1408,7 @@ impl OwnedVector for ~[T] { unsafe { // This loop is optimized out for non-drop types. for uint::range(newlen, oldlen) |i| { - ptr::read_and_zero_ptr(ptr::mut_offset(p, i)) + ptr::read_and_zero_ptr(ptr::mut_offset(p, i)); } } } @@ -1556,7 +1556,7 @@ impl OwnedEqVector for ~[T] { * Remove consecutive repeated elements from a vector; if the vector is * sorted, this removes all duplicates. */ - pub fn dedup(&mut self) { + pub fn dedup(&mut self) { unsafe { // Although we have a mutable reference to `self`, we cannot make // *arbitrary* changes. There exists the possibility that this diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 73ee8768ca3..f9504a696ce 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1521,7 +1521,12 @@ pub fn print_path(s: @ps, path: &ast::Path, colons_before_params: bool) { print_path_(s, path, colons_before_params, &None) } -pub fn print_pat(s: @ps, pat: &ast::pat) { +pub fn print_bounded_path(s: @ps, path: &ast::Path, + bounds: &Option>) { + print_path_(s, path, false, bounds) +} + +pub fn print_pat(s: @ps, pat: @ast::pat) { maybe_print_comment(s, pat.span.lo); let ann_node = node_pat(s, pat); (s.ann.pre)(ann_node); diff --git a/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs index 827e35e0c83..4407329f497 100644 --- a/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs @@ -1,6 +1,6 @@ struct S {f:~str} impl Drop for S { - fn finalize(&self) { println(self.f); } + fn drop(&self) { println(self.f); } } fn move_in_match() { diff --git a/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs index 6013999d835..400a4f07951 100644 --- a/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs +++ b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs @@ -1,6 +1,6 @@ struct S(~str); impl Drop for S { - fn finalize(&self) { println(**self); } + fn drop(&self) { println(**self); } } fn move_in_match() { diff --git a/src/test/run-pass/reflect-visit-type.rs b/src/test/run-pass/reflect-visit-type.rs index 4ce229526ff..f8c369c2e5f 100644 --- a/src/test/run-pass/reflect-visit-type.rs +++ b/src/test/run-pass/reflect-visit-type.rs @@ -163,8 +163,8 @@ pub fn main() { visit_ty::(vv); visit_ty::<~[int]>(vv); - for v.types.iter().advance |&s| { - println(fmt!("type: %s", s)); + for v.types.iter().advance |s| { + println(fmt!("type: %s", copy *s)); } assert_eq!((*v.types).clone(), ~[~"bool", ~"int", ~"i8", ~"i16", ~"[", ~"int", ~"]"]); } -- cgit 1.4.1-3-g733a5 From a6d64df6720328289ccde67a8685b79ad6780a9d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 1 Jul 2013 14:45:24 -0400 Subject: Correct illegal pattern in windows-only code --- src/libstd/run.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libstd') diff --git a/src/libstd/run.rs b/src/libstd/run.rs index b7bec95e655..17dc604a178 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -744,8 +744,8 @@ fn with_envp(env: Option<&[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T { match env { Some(es) => { let mut blk = ~[]; - for es.iter().advance |&(k, v)| { - let kv = fmt!("%s=%s", k, v); + for es.iter().advance |pair| { + let kv = fmt!("%s=%s", pair.first(), pair.second()); blk.push_all(kv.as_bytes_with_null_consume()); } blk.push(0); -- cgit 1.4.1-3-g733a5 From 0c6d02f391aa668b2ead91e8a4ed545475ac2c90 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 8 Jul 2013 11:05:52 -0400 Subject: Correct merge errors --- src/librustc/middle/trans/_match.rs | 8 ++++---- src/librustc/middle/trans/base.rs | 16 ++++++++++------ src/librustc/middle/typeck/coherence.rs | 4 ++-- src/libstd/vec.rs | 2 +- src/libsyntax/ext/deriving/generic.rs | 8 ++++---- src/libsyntax/ext/pipes/pipec.rs | 2 +- src/libsyntax/parse/parser.rs | 2 +- src/libsyntax/print/pprust.rs | 2 +- 8 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src/libstd') diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index 74f1e372c07..d5d0cde1ee0 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -1842,7 +1842,7 @@ pub fn store_arg(mut bcx: block, fn mk_binding_alloca(mut bcx: block, p_id: ast::node_id, - path: @ast::Path, + path: &ast::Path, binding_mode: IrrefutablePatternBindingMode, populate: &fn(block, ty::t, ValueRef) -> block) -> block { let var_ty = node_id_type(bcx, p_id); @@ -1899,7 +1899,7 @@ fn bind_irrefutable_pat(bcx: block, let tcx = bcx.tcx(); let ccx = bcx.ccx(); match pat.node { - ast::pat_ident(pat_binding_mode, path, inner) => { + ast::pat_ident(pat_binding_mode, ref path, inner) => { if pat_is_binding(tcx.def_map, pat) { // Allocate the stack slot where the value of this // binding will live and place it into the appropriate @@ -2017,9 +2017,9 @@ fn bind_irrefutable_pat(bcx: block, return bcx; } -fn simple_identifier(pat: @ast::pat) -> Option<@ast::Path> { +fn simple_identifier<'a>(pat: &'a ast::pat) -> Option<&'a ast::Path> { match pat.node { - ast::pat_ident(ast::bind_infer, path, None) => { + ast::pat_ident(ast::bind_infer, ref path, None) => { Some(path) } _ => { diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index c8117ed64a7..80fc3803ae7 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -1969,17 +1969,17 @@ pub fn trans_tuple_struct(ccx: @mut CrateContext, trait IdAndTy { fn id(&self) -> ast::node_id; - fn ty(&self) -> @ast::Ty; + fn ty<'a>(&'a self) -> &'a ast::Ty; } impl IdAndTy for ast::variant_arg { fn id(&self) -> ast::node_id { self.id } - fn ty(&self) -> @ast::Ty { self.ty } + fn ty<'a>(&'a self) -> &'a ast::Ty { &self.ty } } impl IdAndTy for @ast::struct_field { fn id(&self) -> ast::node_id { self.node.id } - fn ty(&self) -> @ast::Ty { self.node.ty } + fn ty<'a>(&'a self) -> &'a ast::Ty { &self.node.ty } } pub fn trans_enum_variant_or_tuple_like_struct( @@ -1994,7 +1994,7 @@ pub fn trans_enum_variant_or_tuple_like_struct( let fn_args = do args.map |varg| { ast::arg { is_mutbl: false, - ty: varg.ty(), + ty: copy *varg.ty(), pat: ast_util::ident_to_pat( ccx.tcx.sess.next_node_id(), codemap::dummy_sp(), @@ -2977,8 +2977,12 @@ pub fn trans_crate(sess: session::Session, do sort::quick_sort(ccx.stats.fn_stats) |&(_, _, insns_a), &(_, _, insns_b)| { insns_a > insns_b } - for ccx.stats.fn_stats.iter().advance |&(name, ms, insns)| { - io::println(fmt!("%u insns, %u ms, %s", insns, ms, name)); + for ccx.stats.fn_stats.iter().advance |tuple| { + match *tuple { + (ref name, ms, insns) => { + io::println(fmt!("%u insns, %u ms, %s", insns, ms, *name)); + } + } } } if ccx.sess.count_llvm_insns() { diff --git a/src/librustc/middle/typeck/coherence.rs b/src/librustc/middle/typeck/coherence.rs index 473d5b8e6e8..7ee731d4f46 100644 --- a/src/librustc/middle/typeck/coherence.rs +++ b/src/librustc/middle/typeck/coherence.rs @@ -209,7 +209,7 @@ impl CoherenceChecker { match item.node { item_impl(_, ref opt_trait, _, _) => { let opt_trait : ~[trait_ref] = opt_trait.iter() - .transform(|&x| x) + .transform(|x| copy *x) .collect(); self.check_implementation(item, opt_trait); } @@ -270,7 +270,7 @@ impl CoherenceChecker { // We only want to generate one Impl structure. When we generate one, // we store it here so that we don't recreate it. let mut implementation_opt = None; - for associated_traits.iter().advance |&associated_trait| { + for associated_traits.iter().advance |associated_trait| { let trait_ref = ty::node_id_to_trait_ref( self.crate_context.tcx, diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index c546be63138..a69ffca026b 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1277,7 +1277,7 @@ impl OwnedVector for ~[T] { let valptr = ptr::to_mut_unsafe_ptr(&mut self[ln - 1u]); unsafe { raw::set_len(self, ln - 1u); - ptr::read_ptr(valptr) + Some(ptr::read_ptr(valptr)) } } } diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index d3554d6b27c..3bc16477c80 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -519,8 +519,8 @@ impl<'self> MethodDef<'self> { // create the generics that aren't for Self let fn_generics = self.generics.to_generics(cx, span, type_ident, generics); - let args = do arg_types.map |&(id, ty)| { - cx.arg(span, id, ty) + let args = do arg_types.map |pair| { + cx.arg(span, pair.first(), pair.second()) }; let ret_type = self.get_ret_ty(cx, span, generics, type_ident); @@ -896,8 +896,8 @@ pub fn create_subpatterns(cx: @ExtCtxt, field_paths: ~[ast::Path], mutbl: ast::mutability) -> ~[@ast::pat] { - do field_paths.map |&path| { - cx.pat(span, ast::pat_ident(ast::bind_by_ref(mutbl), path, None)) + do field_paths.map |path| { + cx.pat(span, ast::pat_ident(ast::bind_by_ref(mutbl), copy *path, None)) } } diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs index 98fc9aa6178..478c0861990 100644 --- a/src/libsyntax/ext/pipes/pipec.rs +++ b/src/libsyntax/ext/pipes/pipec.rs @@ -137,7 +137,7 @@ impl gen_send for message { let arg_names = vec::from_fn(tys.len(), |i| "x_" + i.to_str()); let args_ast: ~[ast::arg] = arg_names.iter().zip(tys.iter()) - .transform(|(&n, t)| cx.arg(span, cx.ident_of(n), copy *t)).collect(); + .transform(|(n, t)| cx.arg(span, cx.ident_of(*n), copy *t)).collect(); let args_ast = vec::append( ~[cx.arg(span, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index c43b350abdb..8666c84bbef 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3914,7 +3914,7 @@ impl Parser { }; let full_path = full_path.normalize(); - let maybe_i = do self.sess.included_mod_stack.iter().position |&p| { p == full_path }; + let maybe_i = do self.sess.included_mod_stack.iter().position |p| { *p == full_path }; match maybe_i { Some(i) => { let stack = &self.sess.included_mod_stack; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index f9504a696ce..c3710853615 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1526,7 +1526,7 @@ pub fn print_bounded_path(s: @ps, path: &ast::Path, print_path_(s, path, false, bounds) } -pub fn print_pat(s: @ps, pat: @ast::pat) { +pub fn print_pat(s: @ps, pat: &ast::pat) { maybe_print_comment(s, pat.span.lo); let ann_node = node_pat(s, pat); (s.ann.pre)(ann_node); -- cgit 1.4.1-3-g733a5