Skip to content

Commit 275eed7

Browse files
committed
Move vec-slice-drop test
1 parent 8904921 commit 275eed7

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

library/core/tests/slice.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,3 +1980,32 @@ fn test_is_sorted() {
19801980
assert!(!["c", "bb", "aaa"].is_sorted());
19811981
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
19821982
}
1983+
1984+
#[test]
1985+
fn test_slice_run_destructors() {
1986+
use core::cell::Cell;
1987+
1988+
// Make sure that destructors get run on slice literals
1989+
struct Foo<'a> {
1990+
x: &'a Cell<isize>,
1991+
}
1992+
1993+
impl<'a> Drop for Foo<'a> {
1994+
fn drop(&mut self) {
1995+
self.x.set(self.x.get() + 1);
1996+
}
1997+
}
1998+
1999+
fn foo(x: &Cell<isize>) -> Foo<'_> {
2000+
Foo { x }
2001+
}
2002+
2003+
let x = &Cell::new(0);
2004+
2005+
{
2006+
let l = &[foo(x)];
2007+
assert_eq!(l[0].x.get(), 0);
2008+
}
2009+
2010+
assert_eq!(x.get(), 1);
2011+
}

src/test/ui/array-slice-vec/vec-slice-drop.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)