Move vec-slice-drop test

This commit is contained in:
Alexis Bourget 2020-09-10 15:35:29 +02:00
parent 8904921c1d
commit 275eed7eb1
2 changed files with 29 additions and 31 deletions

View File

@ -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);
}

View File

@ -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);
}