Skip to content

Commit 59e97f4

Browse files
committed
Move vec-slice-drop test
1 parent 5b15751 commit 59e97f4

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

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+
}

0 commit comments

Comments
 (0)