We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5b15751 commit 59e97f4Copy full SHA for 59e97f4
core/tests/slice.rs
@@ -1980,3 +1980,32 @@ fn test_is_sorted() {
1980
assert!(!["c", "bb", "aaa"].is_sorted());
1981
assert!(["c", "bb", "aaa"].is_sorted_by_key(|s| s.len()));
1982
}
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