Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI to unit test for those using Cell/RefCell/UnsafeCell #76454

Merged
merged 14 commits into from
Sep 28, 2020
29 changes: 29 additions & 0 deletions library/core/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
poliorcetics marked this conversation as resolved.
Show resolved Hide resolved

// 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);
}
31 changes: 0 additions & 31 deletions src/test/ui/array-slice-vec/vec-slice-drop.rs

This file was deleted.