From 17b3712487a4cf2be30e6bd43e89a736a7d86908 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 20 Jun 2013 15:11:20 -0400 Subject: [PATCH] Update existing tests to account for stricter, more correct handling of irrefutable patterns --- .../borrowck-move-out-of-vec-tail.rs | 2 +- .../borrowck-vec-pattern-nesting.rs | 37 +++++++++++++++++++ .../run-pass/borrowck-newtype-issue-2573.rs | 32 ---------------- ...f-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 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");