From 17b3712487a4cf2be30e6bd43e89a736a7d86908 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 20 Jun 2013 15:11:20 -0400 Subject: Update existing tests to account for stricter, more correct handling of irrefutable patterns --- .../compile-fail/borrowck-move-out-of-vec-tail.rs | 2 +- .../compile-fail/borrowck-vec-pattern-nesting.rs | 37 ++++++++++++++++++++++ src/test/run-pass/borrowck-newtype-issue-2573.rs | 32 ------------------- ...oderef-and-autoborrowvec-combined-issue-6272.rs | 12 +++---- src/test/run-pass/match-pattern-drop.rs | 4 ++- src/test/run-pass/vec-tail-matching.rs | 2 +- 6 files changed, 48 insertions(+), 41 deletions(-) delete mode 100644 src/test/run-pass/borrowck-newtype-issue-2573.rs (limited to 'src/test') diff --git a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs index dec976e0a60..91a3d843cd4 100644 --- a/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck-move-out-of-vec-tail.rs @@ -11,7 +11,7 @@ pub fn main() { Foo { string: ~"baz" } ]; match x { - [first, ..tail] => { + [_, ..tail] => { match tail { [Foo { string: a }, Foo { string: b }] => { //~^ ERROR cannot move out of dereference of & pointer diff --git a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs index 81f052918ed..36ae5f88208 100644 --- a/src/test/compile-fail/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck-vec-pattern-nesting.rs @@ -17,4 +17,41 @@ fn b() { } } +fn c() { + let mut vec = [~1, ~2, ~3]; + match vec { + [_a, .._b] => { + //~^ ERROR cannot move out + + // Note: `_a` is *moved* here, but `b` is borrowing, + // hence illegal. + // + // See comment in middle/borrowck/gather_loans/mod.rs + // in the case covering these sorts of vectors. + } + _ => {} + } + let a = vec[0]; //~ ERROR use of partially moved value: `vec` +} + +fn d() { + let mut vec = [~1, ~2, ~3]; + match vec { + [.._a, _b] => { + //~^ ERROR cannot move out + } + _ => {} + } + let a = vec[0]; //~ ERROR use of partially moved value: `vec` +} + +fn e() { + let mut vec = [~1, ~2, ~3]; + match vec { + [_a, _b, _c] => {} + _ => {} + } + let a = vec[0]; //~ ERROR use of partially moved value: `vec` +} + fn main() {} diff --git a/src/test/run-pass/borrowck-newtype-issue-2573.rs b/src/test/run-pass/borrowck-newtype-issue-2573.rs deleted file mode 100644 index 5f0c7cad619..00000000000 --- a/src/test/run-pass/borrowck-newtype-issue-2573.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -struct foo {bar: baz} - -struct baz_ {baz: int} - -type baz = @mut baz_; - -trait frob { - fn frob(&self); -} - -impl frob for foo { - fn frob(&self) { - really_impure(self.bar); - } -} - -// Override default mode so that we are passing by value -fn really_impure(bar: baz) { - bar.baz = 3; -} - -pub fn main() {} 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 056397f55ff..c3432582647 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 @@ -28,14 +28,14 @@ fn main() { - let a = @mut [3i]; - let b = @mut [a]; - let c = @mut b; + let a = @mut 3i; + // let b = @mut [a]; + // let c = @mut [3]; // this should freeze `a` only - let _x: &mut [int] = c[0]; + 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]; } diff --git a/src/test/run-pass/match-pattern-drop.rs b/src/test/run-pass/match-pattern-drop.rs index 71bbb1768e8..3ce4ef8a94c 100644 --- a/src/test/run-pass/match-pattern-drop.rs +++ b/src/test/run-pass/match-pattern-drop.rs @@ -14,8 +14,11 @@ enum t { make_t(@int), clam, } fn foo(s: @int) { + debug!(::std::sys::refcount(s)); let count = ::std::sys::refcount(s); let x: t = make_t(s); // ref up + assert_eq!(::std::sys::refcount(s), count + 1u); + debug!(::std::sys::refcount(s)); match x { make_t(y) => { @@ -38,6 +41,5 @@ pub fn main() { debug!("%u", ::std::sys::refcount(s)); let count2 = ::std::sys::refcount(s); - let _ = ::std::sys::refcount(s); // don't get bitten by last-use. assert_eq!(count, count2); } diff --git a/src/test/run-pass/vec-tail-matching.rs b/src/test/run-pass/vec-tail-matching.rs index 6e1a47ad2df..27f4fc83351 100644 --- a/src/test/run-pass/vec-tail-matching.rs +++ b/src/test/run-pass/vec-tail-matching.rs @@ -9,7 +9,7 @@ pub fn main() { Foo { string: ~"baz" } ]; match x { - [first, ..tail] => { + [ref first, ..tail] => { assert!(first.string == ~"foo"); assert_eq!(tail.len(), 2); assert!(tail[0].string == ~"bar"); -- cgit 1.4.1-3-g733a5 From 1670a8cfb13fd384d9fd4ca47034cef99118c7a7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 20 Jun 2013 15:11:47 -0400 Subject: Add new tests for irrefutable patterns used in various tricky ways --- .../compile-fail/borrowck-move-in-irrefut-pat.rs | 16 +++++++++++++ .../borrowck-move-out-of-struct-with-dtor.rs | 22 ++++++++++++++++++ .../borrowck-move-out-of-tuple-struct-with-dtor.rs | 22 ++++++++++++++++++ src/test/compile-fail/regions-ref-in-fn-arg.rs | 11 +++++++++ src/test/run-pass/func-arg-incomplete-pattern.rs | 20 +++++++++++++++++ src/test/run-pass/func-arg-ref-pattern.rs | 24 ++++++++++++++++++++ src/test/run-pass/func-arg-wild-pattern.rs | 10 +++++++++ src/test/run-pass/let-destruct-ref.rs | 5 +++++ src/test/run-pass/match-drop-strs-issue-4541.rs | 26 ++++++++++++++++++++++ 9 files changed, 156 insertions(+) create mode 100644 src/test/compile-fail/borrowck-move-in-irrefut-pat.rs create mode 100644 src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs create mode 100644 src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs create mode 100644 src/test/compile-fail/regions-ref-in-fn-arg.rs create mode 100644 src/test/run-pass/func-arg-incomplete-pattern.rs create mode 100644 src/test/run-pass/func-arg-ref-pattern.rs create mode 100644 src/test/run-pass/func-arg-wild-pattern.rs create mode 100644 src/test/run-pass/let-destruct-ref.rs create mode 100644 src/test/run-pass/match-drop-strs-issue-4541.rs (limited to 'src/test') diff --git a/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs new file mode 100644 index 00000000000..c99a1ee60d7 --- /dev/null +++ b/src/test/compile-fail/borrowck-move-in-irrefut-pat.rs @@ -0,0 +1,16 @@ +fn with(f: &fn(&~str)) {} + +fn arg_item(&_x: &~str) {} + //~^ ERROR cannot move out of dereference of & pointer + +fn arg_closure() { + with(|&_x| ()) + //~^ ERROR cannot move out of dereference of & pointer +} + +fn let_pat() { + let &_x = &~"hi"; + //~^ ERROR cannot move out of dereference of & pointer +} + +pub fn main() {} \ No newline at end of file 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 new file mode 100644 index 00000000000..827e35e0c83 --- /dev/null +++ b/src/test/compile-fail/borrowck-move-out-of-struct-with-dtor.rs @@ -0,0 +1,22 @@ +struct S {f:~str} +impl Drop for S { + fn finalize(&self) { println(self.f); } +} + +fn move_in_match() { + match S {f:~"foo"} { + S {f:_s} => {} + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + } +} + +fn move_in_let() { + let S {f:_s} = S {f:~"foo"}; + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait +} + +fn move_in_fn_arg(S {f:_s}: S) { + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait +} + +fn main() {} 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 new file mode 100644 index 00000000000..6013999d835 --- /dev/null +++ b/src/test/compile-fail/borrowck-move-out-of-tuple-struct-with-dtor.rs @@ -0,0 +1,22 @@ +struct S(~str); +impl Drop for S { + fn finalize(&self) { println(**self); } +} + +fn move_in_match() { + match S(~"foo") { + S(_s) => {} + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait + } +} + +fn move_in_let() { + let S(_s) = S(~"foo"); + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait +} + +fn move_in_fn_arg(S(_s): S) { + //~^ ERROR cannot move out of type `S`, which defines the `Drop` trait +} + +fn main() {} diff --git a/src/test/compile-fail/regions-ref-in-fn-arg.rs b/src/test/compile-fail/regions-ref-in-fn-arg.rs new file mode 100644 index 00000000000..f90fe924587 --- /dev/null +++ b/src/test/compile-fail/regions-ref-in-fn-arg.rs @@ -0,0 +1,11 @@ +fn arg_item(~ref x: ~int) -> &'static int { + x //~^ ERROR borrowed value does not live long enough +} + +fn with(f: &fn(~int) -> R) -> R { f(~3) } + +fn arg_closure() -> &'static int { + with(|~ref x| x) //~ ERROR borrowed value does not live long enough +} + +fn main() {} \ No newline at end of file diff --git a/src/test/run-pass/func-arg-incomplete-pattern.rs b/src/test/run-pass/func-arg-incomplete-pattern.rs new file mode 100644 index 00000000000..b08d3beae1b --- /dev/null +++ b/src/test/run-pass/func-arg-incomplete-pattern.rs @@ -0,0 +1,20 @@ +// Test that we do not leak when the arg pattern must drop part of the +// argument (in this case, the `y` field). + +struct Foo { + x: ~uint, + y: ~uint, +} + +fn foo(Foo {x, _}: Foo) -> *uint { + let addr: *uint = &*x; + addr +} + +fn main() { + let obj = ~1; + let objptr: *uint = &*obj; + let f = Foo {x: obj, y: ~2}; + let xptr = foo(f); + assert_eq!(objptr, xptr); +} \ No newline at end of file diff --git a/src/test/run-pass/func-arg-ref-pattern.rs b/src/test/run-pass/func-arg-ref-pattern.rs new file mode 100644 index 00000000000..84c2b3acf35 --- /dev/null +++ b/src/test/run-pass/func-arg-ref-pattern.rs @@ -0,0 +1,24 @@ +// exec-env:RUST_POISON_ON_FREE=1 + +// Test argument patterns where we create refs to the inside of `~` +// boxes. Make sure that we don't free the box as we match the +// pattern. + +fn getaddr(~ref x: ~uint) -> *uint { + let addr: *uint = &*x; + addr +} + +fn checkval(~ref x: ~uint) -> uint { + *x +} + +fn main() { + let obj = ~1; + let objptr: *uint = &*obj; + let xptr = getaddr(obj); + assert_eq!(objptr, xptr); + + let obj = ~22; + assert_eq!(checkval(obj), 22); +} diff --git a/src/test/run-pass/func-arg-wild-pattern.rs b/src/test/run-pass/func-arg-wild-pattern.rs new file mode 100644 index 00000000000..c2d60c85329 --- /dev/null +++ b/src/test/run-pass/func-arg-wild-pattern.rs @@ -0,0 +1,10 @@ +// Test that we can compile code that uses a `_` in function argument +// patterns. + +fn foo((x, _): (int, int)) -> int { + x +} + +fn main() { + assert_eq!(foo((22, 23)), 22); +} diff --git a/src/test/run-pass/let-destruct-ref.rs b/src/test/run-pass/let-destruct-ref.rs new file mode 100644 index 00000000000..7f3f9110b1c --- /dev/null +++ b/src/test/run-pass/let-destruct-ref.rs @@ -0,0 +1,5 @@ +fn main() { + let x = ~"hello"; + let ref y = x; + assert_eq!(x.slice(0, x.len()), y.slice(0, y.len())); +} diff --git a/src/test/run-pass/match-drop-strs-issue-4541.rs b/src/test/run-pass/match-drop-strs-issue-4541.rs new file mode 100644 index 00000000000..ec65f36dc06 --- /dev/null +++ b/src/test/run-pass/match-drop-strs-issue-4541.rs @@ -0,0 +1,26 @@ +// Tests a tricky scenario involving string matching, +// copying, and moving to ensure that we don't segfault +// or double-free, as we were wont to do in the past. + +use std::io; + +fn parse_args() -> ~str { + let args = std::os::args(); + let mut n = 0; + + while n < args.len() { + match copy args[n] { + ~"-v" => (), + s => { + return s; + } + } + n += 1; + } + + return ~"" +} + +fn main() { + io::println(parse_args()); +} -- 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/test') 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 50e95ea481af78516e3852687bc63d6d1a94dcd0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 21 Jun 2013 12:19:22 -0400 Subject: Fix pretty printer, which was ignoring `ref` in irrefutable patterns --- src/libsyntax/print/pprust.rs | 61 ++++++++++----------------- src/test/bench/shootout-k-nucleotide-pipes.rs | 4 +- src/test/run-pass-fulldeps/qquote.rs | 2 +- 3 files changed, 26 insertions(+), 41 deletions(-) (limited to 'src/test') diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index b545c56778e..73ee8768ca3 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -147,7 +147,7 @@ pub fn ty_to_str(ty: &ast::Ty, intr: @ident_interner) -> ~str { } pub fn pat_to_str(pat: &ast::pat, intr: @ident_interner) -> ~str { - to_str(pat, print_irrefutable_pat, intr) + to_str(pat, print_pat, intr) } pub fn expr_to_str(e: &ast::expr, intr: @ident_interner) -> ~str { @@ -1240,7 +1240,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { if first { first = false; } else { space(s.s); word_space(s, "|"); } - print_refutable_pat(s, *p); + print_pat(s, *p); } space(s.s); match arm.guard { @@ -1434,7 +1434,7 @@ pub fn print_expr(s: @ps, expr: &ast::expr) { } pub fn print_local_decl(s: @ps, loc: &ast::local) { - print_irrefutable_pat(s, loc.node.pat); + print_pat(s, loc.node.pat); match loc.node.ty.node { ast::ty_infer => (), _ => { word_space(s, ":"); print_type(s, &loc.node.ty); } @@ -1521,20 +1521,7 @@ pub fn print_path(s: @ps, path: &ast::Path, colons_before_params: bool) { print_path_(s, path, colons_before_params, &None) } -pub fn print_bounded_path(s: @ps, path: &ast::Path, - bounds: &Option>) { - print_path_(s, path, false, bounds) -} - -pub fn print_irrefutable_pat(s: @ps, pat: &ast::pat) { - print_pat(s, pat, false) -} - -pub fn print_refutable_pat(s: @ps, pat: &ast::pat) { - print_pat(s, pat, true) -} - -pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { +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); @@ -1543,20 +1530,18 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { match pat.node { ast::pat_wild => word(s.s, "_"), ast::pat_ident(binding_mode, ref path, sub) => { - if refutable { - match binding_mode { - ast::bind_by_ref(mutbl) => { - word_nbsp(s, "ref"); - print_mutability(s, mutbl); - } - ast::bind_infer => {} + match binding_mode { + ast::bind_by_ref(mutbl) => { + word_nbsp(s, "ref"); + print_mutability(s, mutbl); } + ast::bind_infer => {} } print_path(s, path, true); match sub { Some(p) => { word(s.s, "@"); - print_pat(s, p, refutable); + print_pat(s, p); } None => () } @@ -1569,7 +1554,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { if !args.is_empty() { popen(s); commasep(s, inconsistent, *args, - |s, &p| print_pat(s, p, refutable)); + |s, &p| print_pat(s, p)); pclose(s); } else { } } @@ -1578,16 +1563,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { ast::pat_struct(ref path, ref fields, etc) => { print_path(s, path, true); word(s.s, "{"); - fn print_field(s: @ps, f: &ast::field_pat, refutable: bool) { + fn print_field(s: @ps, f: &ast::field_pat) { cbox(s, indent_unit); print_ident(s, f.ident); word_space(s, ":"); - print_pat(s, f.pat, refutable); + print_pat(s, f.pat); end(s); } fn get_span(f: &ast::field_pat) -> codemap::span { return f.pat.span; } commasep_cmnt(s, consistent, *fields, - |s, f| print_field(s,f,refutable), + |s, f| print_field(s,f), get_span); if etc { if fields.len() != 0u { word_space(s, ","); } @@ -1597,7 +1582,7 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { } ast::pat_tup(ref elts) => { popen(s); - commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p, refutable)); + commasep(s, inconsistent, *elts, |s, &p| print_pat(s, p)); if elts.len() == 1 { word(s.s, ","); } @@ -1605,15 +1590,15 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { } ast::pat_box(inner) => { word(s.s, "@"); - print_pat(s, inner, refutable); + print_pat(s, inner); } ast::pat_uniq(inner) => { word(s.s, "~"); - print_pat(s, inner, refutable); + print_pat(s, inner); } ast::pat_region(inner) => { word(s.s, "&"); - print_pat(s, inner, refutable); + print_pat(s, inner); } ast::pat_lit(e) => print_expr(s, e), ast::pat_range(begin, end) => { @@ -1625,16 +1610,16 @@ pub fn print_pat(s: @ps, pat: &ast::pat, refutable: bool) { ast::pat_vec(ref before, slice, ref after) => { word(s.s, "["); do commasep(s, inconsistent, *before) |s, &p| { - print_pat(s, p, refutable); + print_pat(s, p); } for slice.iter().advance |&p| { if !before.is_empty() { word_space(s, ","); } word(s.s, ".."); - print_pat(s, p, refutable); + print_pat(s, p); if !after.is_empty() { word_space(s, ","); } } do commasep(s, inconsistent, *after) |s, &p| { - print_pat(s, p, refutable); + print_pat(s, p); } word(s.s, "]"); } @@ -1888,7 +1873,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) { word_space(s, "mut"); } match input.ty.node { - ast::ty_infer => print_irrefutable_pat(s, input.pat), + ast::ty_infer => print_pat(s, input.pat), _ => { match input.pat.node { ast::pat_ident(_, ref path, _) if @@ -1897,7 +1882,7 @@ pub fn print_arg(s: @ps, input: &ast::arg) { // Do nothing. } _ => { - print_irrefutable_pat(s, input.pat); + print_pat(s, input.pat); word(s.s, ":"); space(s.s); } diff --git a/src/test/bench/shootout-k-nucleotide-pipes.rs b/src/test/bench/shootout-k-nucleotide-pipes.rs index 974cdb0a0ef..919c4daeb25 100644 --- a/src/test/bench/shootout-k-nucleotide-pipes.rs +++ b/src/test/bench/shootout-k-nucleotide-pipes.rs @@ -56,8 +56,8 @@ fn sort_and_fmt(mm: &HashMap<~[u8], uint>, total: uint) -> ~str { let mut pairs = ~[]; // map -> [(k,%)] - for mm.iter().advance |(&key, &val)| { - pairs.push((key, pct(val, total))); + for mm.iter().advance |(key, &val)| { + pairs.push((copy *key, pct(val, total))); } let pairs_sorted = sortKV(pairs); diff --git a/src/test/run-pass-fulldeps/qquote.rs b/src/test/run-pass-fulldeps/qquote.rs index 9a3ba32390c..92344aae73e 100644 --- a/src/test/run-pass-fulldeps/qquote.rs +++ b/src/test/run-pass-fulldeps/qquote.rs @@ -68,7 +68,7 @@ fn main() { check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;"); let pat = quote_pat!(Some(_)); - check_pp(ext_cx, pat, pprust::print_refutable_pat, ~"Some(_)"); + check_pp(ext_cx, pat, pprust::print_pat, ~"Some(_)"); } -- 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/test') 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 b5fc4ae9189f8ffe52fd6ec7b228d803f594b48b Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 1 Jul 2013 19:59:53 -0400 Subject: Correct match-drop-strs-issue-4541 when used in check-fast --- src/test/run-pass/match-drop-strs-issue-4541.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/test') diff --git a/src/test/run-pass/match-drop-strs-issue-4541.rs b/src/test/run-pass/match-drop-strs-issue-4541.rs index ec65f36dc06..2a629b62534 100644 --- a/src/test/run-pass/match-drop-strs-issue-4541.rs +++ b/src/test/run-pass/match-drop-strs-issue-4541.rs @@ -3,9 +3,10 @@ // or double-free, as we were wont to do in the past. use std::io; +use std::os; fn parse_args() -> ~str { - let args = std::os::args(); + let args = os::args(); let mut n = 0; while n < args.len() { -- cgit 1.4.1-3-g733a5