From cf9c586fccb1063ea6f75609c702df909d4ac3f1 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 18 Sep 2014 09:33:31 +1200 Subject: [PATCH] reviewer changes --- src/test/compile-fail/slice-1.rs | 2 +- src/test/compile-fail/slice-2.rs | 2 +- src/test/run-pass/slice-fail-1.rs | 31 +++++++++++++++++++++++++++ src/test/run-pass/slice-fail-2.rs | 35 +++++++++++++++++++++++++++++++ src/test/run-pass/slice.rs | 2 +- 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/slice-fail-1.rs create mode 100644 src/test/run-pass/slice-fail-2.rs diff --git a/src/test/compile-fail/slice-1.rs b/src/test/compile-fail/slice-1.rs index 622195a41c2..d0339745c9e 100644 --- a/src/test/compile-fail/slice-1.rs +++ b/src/test/compile-fail/slice-1.rs @@ -16,4 +16,4 @@ fn main() { let x = Foo; x[..]; //~ ERROR incorrect slicing expression: `[..]` //~^ NOTE use `expr[]` to construct a slice of the whole of expr -} \ No newline at end of file +} diff --git a/src/test/compile-fail/slice-2.rs b/src/test/compile-fail/slice-2.rs index da00aa48ae0..fbfc438321c 100644 --- a/src/test/compile-fail/slice-2.rs +++ b/src/test/compile-fail/slice-2.rs @@ -22,4 +22,4 @@ fn main() { x[mut Foo..]; //~ ERROR cannot take a mutable slice of a value with type `Foo` x[mut ..Foo]; //~ ERROR cannot take a mutable slice of a value with type `Foo` x[mut Foo..Foo]; //~ ERROR cannot take a mutable slice of a value with type `Foo` -} \ No newline at end of file +} diff --git a/src/test/run-pass/slice-fail-1.rs b/src/test/run-pass/slice-fail-1.rs new file mode 100644 index 00000000000..f6972023a72 --- /dev/null +++ b/src/test/run-pass/slice-fail-1.rs @@ -0,0 +1,31 @@ +// Copyright 2014 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. + +// Test that is a slicing expr[..] fails, the correct cleanups happen. + +use std::task; + +struct Foo; + +static mut DTOR_COUNT: int = 0; + +impl Drop for Foo { + fn drop(&mut self) { unsafe { DTOR_COUNT += 1; } } +} + +fn foo() { + let x: &[_] = &[Foo, Foo]; + x[3..4]; +} + +fn main() { + let _ = task::try(proc() foo()); + unsafe { assert!(DTOR_COUNT == 2); } +} diff --git a/src/test/run-pass/slice-fail-2.rs b/src/test/run-pass/slice-fail-2.rs new file mode 100644 index 00000000000..cbe65fcd83d --- /dev/null +++ b/src/test/run-pass/slice-fail-2.rs @@ -0,0 +1,35 @@ +// Copyright 2014 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. + +// Test that is a slicing expr[..] fails, the correct cleanups happen. + +use std::task; + +struct Foo; + +static mut DTOR_COUNT: int = 0; + +impl Drop for Foo { + fn drop(&mut self) { unsafe { DTOR_COUNT += 1; } } +} + +fn bar() -> uint { + fail!(); +} + +fn foo() { + let x: &[_] = &[Foo, Foo]; + x[3..bar()]; +} + +fn main() { + let _ = task::try(proc() foo()); + unsafe { assert!(DTOR_COUNT == 2); } +} diff --git a/src/test/run-pass/slice.rs b/src/test/run-pass/slice.rs index 1aa40f0d492..39feb075add 100644 --- a/src/test/run-pass/slice.rs +++ b/src/test/run-pass/slice.rs @@ -67,4 +67,4 @@ fn main() { unsafe { assert!(COUNT == 8); } -} \ No newline at end of file +}