about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexis Bourget <alexis.bourget@gmail.com>2020-09-10 15:35:29 +0200
committerAlexis Bourget <alexis.bourget@gmail.com>2020-09-21 21:50:27 +0200
commit275eed7eb1d45e8173b932e2abfdae2201d2cf62 (patch)
tree65fe353e023778761c01c1cf46f8e34eec54f0fd
parent8904921c1d6b3636f4352f9dd6d4875132b89998 (diff)
downloadrust-275eed7eb1d45e8173b932e2abfdae2201d2cf62.tar.gz
rust-275eed7eb1d45e8173b932e2abfdae2201d2cf62.zip
Move vec-slice-drop test
-rw-r--r--library/core/tests/slice.rs29
-rw-r--r--src/test/ui/array-slice-vec/vec-slice-drop.rs31
2 files changed, 29 insertions, 31 deletions
diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs
index 9556d43f9d7..d66d17c1c85 100644
--- a/library/core/tests/slice.rs
+++ b/library/core/tests/slice.rs
@@ -1980,3 +1980,32 @@ fn test_is_sorted() {
     assert!(!["c", "bb", "aaa"].is_sorted());
     assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
 }
+
+#[test]
+fn test_slice_run_destructors() {
+    use core::cell::Cell;
+
+    // Make sure that destructors get run on slice literals
+    struct Foo<'a> {
+        x: &'a Cell<isize>,
+    }
+
+    impl<'a> Drop for Foo<'a> {
+        fn drop(&mut self) {
+            self.x.set(self.x.get() + 1);
+        }
+    }
+
+    fn foo(x: &Cell<isize>) -> Foo<'_> {
+        Foo { x }
+    }
+
+    let x = &Cell::new(0);
+
+    {
+        let l = &[foo(x)];
+        assert_eq!(l[0].x.get(), 0);
+    }
+
+    assert_eq!(x.get(), 1);
+}
diff --git a/src/test/ui/array-slice-vec/vec-slice-drop.rs b/src/test/ui/array-slice-vec/vec-slice-drop.rs
deleted file mode 100644
index 3a9ea86af34..00000000000
--- a/src/test/ui/array-slice-vec/vec-slice-drop.rs
+++ /dev/null
@@ -1,31 +0,0 @@
-// run-pass
-
-#![allow(non_camel_case_types)]
-
-use std::cell::Cell;
-
-// Make sure that destructors get run on slice literals
-struct foo<'a> {
-    x: &'a Cell<isize>,
-}
-
-impl<'a> Drop for foo<'a> {
-    fn drop(&mut self) {
-        self.x.set(self.x.get() + 1);
-    }
-}
-
-fn foo(x: &Cell<isize>) -> foo {
-    foo {
-        x: x
-    }
-}
-
-pub fn main() {
-    let x = &Cell::new(0);
-    {
-        let l = &[foo(x)];
-        assert_eq!(l[0].x.get(), 0);
-    }
-    assert_eq!(x.get(), 1);
-}