2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2021-12-03 09:32:51 -06:00
|
|
|
// needs-unwind
|
2017-10-22 22:01:00 -05:00
|
|
|
|
2020-10-04 15:24:14 -05:00
|
|
|
#![feature(generators, generator_trait)]
|
2023-09-18 10:18:51 -05:00
|
|
|
#![feature(if_let_guard)]
|
2021-01-21 21:35:05 -06:00
|
|
|
|
2019-12-29 18:23:42 -06:00
|
|
|
#![allow(unused_assignments)]
|
|
|
|
#![allow(unused_variables)]
|
2016-05-29 14:01:06 -05:00
|
|
|
|
|
|
|
use std::cell::{Cell, RefCell};
|
2019-07-03 05:35:02 -05:00
|
|
|
use std::mem::ManuallyDrop;
|
2017-10-17 07:20:22 -05:00
|
|
|
use std::ops::Generator;
|
2016-05-29 14:01:06 -05:00
|
|
|
use std::panic;
|
2018-10-04 13:49:38 -05:00
|
|
|
use std::pin::Pin;
|
2016-05-29 14:01:06 -05:00
|
|
|
|
|
|
|
struct InjectedFailure;
|
2016-05-16 18:26:18 -05:00
|
|
|
|
|
|
|
struct Allocator {
|
|
|
|
data: RefCell<Vec<bool>>,
|
2016-05-29 14:01:06 -05:00
|
|
|
failing_op: usize,
|
|
|
|
cur_ops: Cell<usize>,
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
|
|
|
|
2016-05-29 14:01:06 -05:00
|
|
|
impl panic::UnwindSafe for Allocator {}
|
|
|
|
impl panic::RefUnwindSafe for Allocator {}
|
|
|
|
|
2016-05-16 18:26:18 -05:00
|
|
|
impl Drop for Allocator {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
let data = self.data.borrow();
|
|
|
|
if data.iter().any(|d| *d) {
|
2021-01-21 21:35:05 -06:00
|
|
|
panic!("missing free: {:?}", data);
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Allocator {
|
2021-01-21 21:35:05 -06:00
|
|
|
fn new(failing_op: usize) -> Self {
|
2016-05-29 14:01:06 -05:00
|
|
|
Allocator {
|
|
|
|
failing_op: failing_op,
|
|
|
|
cur_ops: Cell::new(0),
|
2021-01-21 21:35:05 -06:00
|
|
|
data: RefCell::new(vec![])
|
2016-05-29 14:01:06 -05:00
|
|
|
}
|
|
|
|
}
|
2019-05-11 05:16:26 -05:00
|
|
|
fn alloc(&self) -> Ptr<'_> {
|
2016-05-29 14:01:06 -05:00
|
|
|
self.cur_ops.set(self.cur_ops.get() + 1);
|
|
|
|
|
|
|
|
if self.cur_ops.get() == self.failing_op {
|
2021-02-01 17:40:17 -06:00
|
|
|
panic::panic_any(InjectedFailure);
|
2016-05-29 14:01:06 -05:00
|
|
|
}
|
|
|
|
|
2016-05-16 18:26:18 -05:00
|
|
|
let mut data = self.data.borrow_mut();
|
|
|
|
let addr = data.len();
|
|
|
|
data.push(true);
|
|
|
|
Ptr(addr, self)
|
|
|
|
}
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME(#47949) Any use of this indicates a bug in rustc: we should never
|
|
|
|
// be leaking values in the cases here.
|
|
|
|
//
|
|
|
|
// Creates a `Ptr<'_>` and checks that the allocated value is leaked if the
|
|
|
|
// `failing_op` is in the list of exception.
|
|
|
|
fn alloc_leaked(&self, exceptions: Vec<usize>) -> Ptr<'_> {
|
|
|
|
let ptr = self.alloc();
|
|
|
|
|
|
|
|
if exceptions.iter().any(|operation| *operation == self.failing_op) {
|
|
|
|
let mut data = self.data.borrow_mut();
|
|
|
|
data[ptr.0] = false;
|
|
|
|
}
|
|
|
|
ptr
|
|
|
|
}
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Ptr<'a>(usize, &'a Allocator);
|
|
|
|
impl<'a> Drop for Ptr<'a> {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
match self.1.data.borrow_mut()[self.0] {
|
2021-01-21 21:35:05 -06:00
|
|
|
false => {
|
|
|
|
panic!("double free at index {:?}", self.0)
|
|
|
|
}
|
|
|
|
ref mut d => *d = false
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
2016-05-29 14:01:06 -05:00
|
|
|
|
2021-01-21 21:35:05 -06:00
|
|
|
self.1.cur_ops.set(self.1.cur_ops.get()+1);
|
2016-05-29 14:01:06 -05:00
|
|
|
|
|
|
|
if self.1.cur_ops.get() == self.1.failing_op {
|
2021-02-01 17:40:17 -06:00
|
|
|
panic::panic_any(InjectedFailure);
|
2016-05-29 14:01:06 -05:00
|
|
|
}
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn dynamic_init(a: &Allocator, c: bool) {
|
|
|
|
let _x;
|
|
|
|
if c {
|
|
|
|
_x = Some(a.alloc());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-29 14:01:06 -05:00
|
|
|
fn dynamic_drop(a: &Allocator, c: bool) {
|
2016-05-16 18:26:18 -05:00
|
|
|
let x = a.alloc();
|
|
|
|
if c {
|
|
|
|
Some(x)
|
|
|
|
} else {
|
|
|
|
None
|
2016-05-29 14:01:06 -05:00
|
|
|
};
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|
|
|
|
|
2022-07-25 15:36:03 -05:00
|
|
|
struct TwoPtrs<'a>(Ptr<'a>, #[allow(unused_tuple_struct_fields)] Ptr<'a>);
|
2017-05-15 07:22:59 -05:00
|
|
|
fn struct_dynamic_drop(a: &Allocator, c0: bool, c1: bool, c: bool) {
|
|
|
|
for i in 0..2 {
|
|
|
|
let x;
|
|
|
|
let y;
|
|
|
|
if (c0 && i == 0) || (c1 && i == 1) {
|
|
|
|
x = (a.alloc(), a.alloc(), a.alloc());
|
|
|
|
y = TwoPtrs(a.alloc(), a.alloc());
|
|
|
|
if c {
|
|
|
|
drop(x.1);
|
|
|
|
drop(y.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-27 10:34:07 -05:00
|
|
|
fn field_assignment(a: &Allocator, c0: bool) {
|
|
|
|
let mut x = (TwoPtrs(a.alloc(), a.alloc()), a.alloc());
|
|
|
|
|
|
|
|
x.1 = a.alloc();
|
|
|
|
x.1 = a.alloc();
|
|
|
|
|
|
|
|
let f = (x.0).0;
|
|
|
|
if c0 {
|
|
|
|
(x.0).0 = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 18:26:18 -05:00
|
|
|
fn assignment2(a: &Allocator, c0: bool, c1: bool) {
|
|
|
|
let mut _v = a.alloc();
|
|
|
|
let mut _w = a.alloc();
|
|
|
|
if c0 {
|
|
|
|
drop(_v);
|
|
|
|
}
|
|
|
|
_v = _w;
|
|
|
|
if c1 {
|
|
|
|
_w = a.alloc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn assignment1(a: &Allocator, c0: bool) {
|
|
|
|
let mut _v = a.alloc();
|
|
|
|
let mut _w = a.alloc();
|
|
|
|
if c0 {
|
|
|
|
drop(_v);
|
|
|
|
}
|
|
|
|
_v = _w;
|
|
|
|
}
|
|
|
|
|
2016-09-08 12:12:53 -05:00
|
|
|
union Boxy<T> {
|
2019-07-03 05:35:02 -05:00
|
|
|
a: ManuallyDrop<T>,
|
|
|
|
b: ManuallyDrop<T>,
|
2016-09-08 12:12:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn union1(a: &Allocator) {
|
|
|
|
unsafe {
|
2019-07-03 05:35:02 -05:00
|
|
|
let mut u = Boxy { a: ManuallyDrop::new(a.alloc()) };
|
|
|
|
*u.b = a.alloc(); // drops first alloc
|
|
|
|
drop(ManuallyDrop::into_inner(u.a));
|
2016-09-08 12:12:53 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:02:52 -05:00
|
|
|
fn array_simple(a: &Allocator) {
|
|
|
|
let _x = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
|
|
|
}
|
|
|
|
|
|
|
|
fn vec_simple(a: &Allocator) {
|
|
|
|
let _x = vec![a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
|
|
|
}
|
|
|
|
|
2017-10-17 07:20:22 -05:00
|
|
|
fn generator(a: &Allocator, run_count: usize) {
|
|
|
|
assert!(run_count < 4);
|
|
|
|
|
|
|
|
let mut gen = || {
|
2021-01-21 21:35:05 -06:00
|
|
|
(a.alloc(),
|
|
|
|
yield a.alloc(),
|
|
|
|
a.alloc(),
|
|
|
|
yield a.alloc()
|
|
|
|
);
|
2017-10-17 07:20:22 -05:00
|
|
|
};
|
|
|
|
for _ in 0..run_count {
|
2020-01-25 13:03:10 -06:00
|
|
|
Pin::new(&mut gen).resume(());
|
2017-10-17 07:20:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 13:37:18 -05:00
|
|
|
fn mixed_drop_and_nondrop(a: &Allocator) {
|
|
|
|
// check that destructor panics handle drop
|
|
|
|
// and non-drop blocks in the same scope correctly.
|
|
|
|
//
|
|
|
|
// Surprisingly enough, this used to not work.
|
|
|
|
let (x, y, z);
|
|
|
|
x = a.alloc();
|
|
|
|
y = 5;
|
|
|
|
z = a.alloc();
|
|
|
|
}
|
|
|
|
|
2017-08-09 14:23:27 -05:00
|
|
|
#[allow(unreachable_code)]
|
|
|
|
fn vec_unreachable(a: &Allocator) {
|
|
|
|
let _x = vec![a.alloc(), a.alloc(), a.alloc(), return];
|
|
|
|
}
|
|
|
|
|
2017-11-28 06:48:23 -06:00
|
|
|
fn slice_pattern_first(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_x, ..] = [a.alloc(), a.alloc(), a.alloc()];
|
2017-11-28 06:48:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn slice_pattern_middle(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _x, _] = [a.alloc(), a.alloc(), a.alloc()];
|
2017-11-28 06:48:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn slice_pattern_two(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_x, _, _y, _] = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
2017-11-28 06:48:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn slice_pattern_last(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[.., _y] = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
2017-11-28 06:48:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn slice_pattern_one_of(a: &Allocator, i: usize) {
|
|
|
|
let array = [a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
|
|
|
let _x = match i {
|
2021-01-21 21:35:05 -06:00
|
|
|
0 => { let [a, ..] = array; a }
|
|
|
|
1 => { let [_, a, ..] = array; a }
|
|
|
|
2 => { let [_, _, a, _] = array; a }
|
|
|
|
3 => { let [_, _, _, a] = array; a }
|
2017-11-28 06:48:23 -06:00
|
|
|
_ => panic!("unmatched"),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-01-31 14:34:13 -06:00
|
|
|
fn subslice_pattern_from_end(a: &Allocator, arg: bool) {
|
|
|
|
let a = [a.alloc(), a.alloc(), a.alloc()];
|
|
|
|
if arg {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[.., _x, _] = a;
|
2018-01-31 14:34:13 -06:00
|
|
|
} else {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _y @ ..] = a;
|
2018-01-31 14:34:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn subslice_pattern_from_end_with_drop(a: &Allocator, arg: bool, arg2: bool) {
|
|
|
|
let a = [a.alloc(), a.alloc(), a.alloc(), a.alloc(), a.alloc()];
|
|
|
|
if arg2 {
|
|
|
|
drop(a);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if arg {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[.., _x, _] = a;
|
2018-01-31 14:34:13 -06:00
|
|
|
} else {
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _y @ ..] = a;
|
2018-01-31 14:34:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn slice_pattern_reassign(a: &Allocator) {
|
|
|
|
let mut ar = [a.alloc(), a.alloc()];
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _x] = ar;
|
2018-01-31 14:34:13 -06:00
|
|
|
ar = [a.alloc(), a.alloc()];
|
2021-01-21 21:35:05 -06:00
|
|
|
let[.., _y] = ar;
|
2018-01-31 14:34:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn subslice_pattern_reassign(a: &Allocator) {
|
|
|
|
let mut ar = [a.alloc(), a.alloc(), a.alloc()];
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _, _x] = ar;
|
2018-01-31 14:34:13 -06:00
|
|
|
ar = [a.alloc(), a.alloc(), a.alloc()];
|
2021-01-21 21:35:05 -06:00
|
|
|
let[_, _y @ ..] = ar;
|
2018-01-31 14:34:13 -06:00
|
|
|
}
|
|
|
|
|
2019-11-22 17:15:11 -06:00
|
|
|
fn index_field_mixed_ends(a: &Allocator) {
|
|
|
|
let ar = [(a.alloc(), a.alloc()), (a.alloc(), a.alloc())];
|
2021-01-21 21:35:05 -06:00
|
|
|
let[(_x, _), ..] = ar;
|
|
|
|
let[(_, _y), _] = ar;
|
|
|
|
let[_, (_, _w)] = ar;
|
|
|
|
let[.., (_z, _)] = ar;
|
2019-11-22 17:15:11 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn subslice_mixed_min_lengths(a: &Allocator, c: i32) {
|
|
|
|
let ar = [(a.alloc(), a.alloc()), (a.alloc(), a.alloc())];
|
|
|
|
match c {
|
2021-01-21 21:35:05 -06:00
|
|
|
0 => { let[_x, ..] = ar; }
|
|
|
|
1 => { let[_x, _, ..] = ar; }
|
|
|
|
2 => { let[_x, _] = ar; }
|
|
|
|
3 => { let[(_x, _), _, ..] = ar; }
|
|
|
|
4 => { let[.., (_x, _)] = ar; }
|
|
|
|
5 => { let[.., (_x, _), _] = ar; }
|
|
|
|
6 => { let [_y @ ..] = ar; }
|
|
|
|
_ => { let [_y @ .., _] = ar; }
|
2019-11-22 17:15:11 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-07 14:17:03 -06:00
|
|
|
fn bindings_after_at_dynamic_init_move(a: &Allocator, c: bool) {
|
|
|
|
let foo = if c { Some(a.alloc()) } else { None };
|
|
|
|
let _x;
|
|
|
|
|
|
|
|
if let bar @ Some(_) = foo {
|
|
|
|
_x = bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bindings_after_at_dynamic_init_ref(a: &Allocator, c: bool) {
|
|
|
|
let foo = if c { Some(a.alloc()) } else { None };
|
|
|
|
let _x;
|
|
|
|
|
|
|
|
if let bar @ Some(_baz) = &foo {
|
|
|
|
_x = bar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bindings_after_at_dynamic_drop_move(a: &Allocator, c: bool) {
|
|
|
|
let foo = if c { Some(a.alloc()) } else { None };
|
|
|
|
|
|
|
|
if let bar @ Some(_) = foo {
|
|
|
|
bar
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bindings_after_at_dynamic_drop_ref(a: &Allocator, c: bool) {
|
|
|
|
let foo = if c { Some(a.alloc()) } else { None };
|
|
|
|
|
|
|
|
if let bar @ Some(_baz) = &foo {
|
|
|
|
bar
|
|
|
|
} else {
|
|
|
|
&None
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-18 19:47:01 -06:00
|
|
|
fn move_ref_pattern(a: &Allocator) {
|
|
|
|
let mut tup = (a.alloc(), a.alloc(), a.alloc(), a.alloc());
|
|
|
|
let (ref _a, ref mut _b, _c, mut _d) = tup;
|
|
|
|
}
|
|
|
|
|
2023-09-18 10:18:51 -05:00
|
|
|
fn if_let_guard(a: &Allocator, c: bool, d: i32) {
|
|
|
|
let foo = if c { Some(a.alloc()) } else { None };
|
|
|
|
|
|
|
|
match d == 0 {
|
|
|
|
false if let Some(a) = foo => { let b = a; }
|
|
|
|
true if let true = { drop(foo.unwrap_or_else(|| a.alloc())); d == 1 } => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-11 05:16:26 -05:00
|
|
|
fn panic_after_return(a: &Allocator) -> Ptr<'_> {
|
2021-01-21 21:35:05 -06:00
|
|
|
// Panic in the drop of `p` or `q` can leak
|
|
|
|
let exceptions = vec![8, 9];
|
2019-05-11 05:16:26 -05:00
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
|
|
|
{
|
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME (#47949) We leak values when we panic in a destructor after
|
|
|
|
// evaluating an expression with `rustc_mir::build::Builder::into`.
|
|
|
|
a.alloc_leaked(exceptions)
|
2019-05-11 05:16:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn panic_after_return_expr(a: &Allocator) -> Ptr<'_> {
|
2021-01-21 21:35:05 -06:00
|
|
|
// Panic in the drop of `p` or `q` can leak
|
|
|
|
let exceptions = vec![8, 9];
|
2019-05-11 05:16:26 -05:00
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
|
|
|
{
|
|
|
|
a.alloc();
|
|
|
|
let q = a.alloc();
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME (#47949)
|
|
|
|
return a.alloc_leaked(exceptions);
|
2019-05-11 05:16:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn panic_after_init(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
// Panic in the drop of `r` can leak
|
|
|
|
let exceptions = vec![8];
|
2019-05-11 05:16:26 -05:00
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
|
|
|
let q = {
|
|
|
|
a.alloc();
|
|
|
|
let r = a.alloc();
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME (#47949)
|
|
|
|
a.alloc_leaked(exceptions)
|
2019-05-11 05:16:26 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn panic_after_init_temp(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
// Panic in the drop of `r` can leak
|
|
|
|
let exceptions = vec![8];
|
2019-05-11 05:16:26 -05:00
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
|
|
|
{
|
|
|
|
a.alloc();
|
|
|
|
let r = a.alloc();
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME (#47949)
|
|
|
|
a.alloc_leaked(exceptions)
|
2019-05-11 05:16:26 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn panic_after_init_by_loop(a: &Allocator) {
|
2021-01-21 21:35:05 -06:00
|
|
|
// Panic in the drop of `r` can leak
|
|
|
|
let exceptions = vec![8];
|
2019-05-11 05:16:26 -05:00
|
|
|
a.alloc();
|
|
|
|
let p = a.alloc();
|
|
|
|
let q = loop {
|
|
|
|
a.alloc();
|
|
|
|
let r = a.alloc();
|
2021-01-21 21:35:05 -06:00
|
|
|
// FIXME (#47949)
|
|
|
|
break a.alloc_leaked(exceptions);
|
2019-05-11 05:16:26 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-21 21:35:05 -06:00
|
|
|
fn run_test<F>(mut f: F)
|
|
|
|
where F: FnMut(&Allocator)
|
2016-05-29 14:01:06 -05:00
|
|
|
{
|
2021-01-21 21:35:05 -06:00
|
|
|
let first_alloc = Allocator::new(usize::MAX);
|
2016-05-29 14:01:06 -05:00
|
|
|
f(&first_alloc);
|
|
|
|
|
2021-01-21 21:35:05 -06:00
|
|
|
for failing_op in 1..first_alloc.cur_ops.get()+1 {
|
|
|
|
let alloc = Allocator::new(failing_op);
|
2016-05-29 14:01:06 -05:00
|
|
|
let alloc = &alloc;
|
|
|
|
let f = panic::AssertUnwindSafe(&mut f);
|
|
|
|
let result = panic::catch_unwind(move || {
|
|
|
|
f.0(alloc);
|
|
|
|
});
|
|
|
|
match result {
|
2021-01-21 21:35:05 -06:00
|
|
|
Ok(..) => panic!("test executed {} ops but now {}",
|
|
|
|
first_alloc.cur_ops.get(), alloc.cur_ops.get()),
|
2016-05-29 14:01:06 -05:00
|
|
|
Err(e) => {
|
|
|
|
if e.downcast_ref::<InjectedFailure>().is_none() {
|
|
|
|
panic::resume_unwind(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 18:26:18 -05:00
|
|
|
|
2021-01-21 21:35:05 -06:00
|
|
|
fn run_test_nopanic<F>(mut f: F)
|
|
|
|
where F: FnMut(&Allocator)
|
2016-09-08 12:12:53 -05:00
|
|
|
{
|
2021-01-21 21:35:05 -06:00
|
|
|
let first_alloc = Allocator::new(usize::MAX);
|
2016-09-08 12:12:53 -05:00
|
|
|
f(&first_alloc);
|
|
|
|
}
|
|
|
|
|
2016-05-16 18:26:18 -05:00
|
|
|
fn main() {
|
2021-01-21 21:35:05 -06:00
|
|
|
run_test(|a| dynamic_init(a, false));
|
|
|
|
run_test(|a| dynamic_init(a, true));
|
|
|
|
run_test(|a| dynamic_drop(a, false));
|
|
|
|
run_test(|a| dynamic_drop(a, true));
|
|
|
|
|
|
|
|
run_test(|a| assignment2(a, false, false));
|
|
|
|
run_test(|a| assignment2(a, false, true));
|
|
|
|
run_test(|a| assignment2(a, true, false));
|
|
|
|
run_test(|a| assignment2(a, true, true));
|
|
|
|
|
|
|
|
run_test(|a| assignment1(a, false));
|
|
|
|
run_test(|a| assignment1(a, true));
|
|
|
|
|
|
|
|
run_test(|a| array_simple(a));
|
|
|
|
run_test(|a| vec_simple(a));
|
|
|
|
run_test(|a| vec_unreachable(a));
|
|
|
|
|
|
|
|
run_test(|a| struct_dynamic_drop(a, false, false, false));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, false, false, true));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, false, true, false));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, false, true, true));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, true, false, false));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, true, false, true));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, true, true, false));
|
|
|
|
run_test(|a| struct_dynamic_drop(a, true, true, true));
|
|
|
|
|
|
|
|
run_test(|a| field_assignment(a, false));
|
|
|
|
run_test(|a| field_assignment(a, true));
|
|
|
|
|
|
|
|
run_test(|a| generator(a, 0));
|
|
|
|
run_test(|a| generator(a, 1));
|
|
|
|
run_test(|a| generator(a, 2));
|
|
|
|
run_test(|a| generator(a, 3));
|
|
|
|
|
|
|
|
run_test(|a| mixed_drop_and_nondrop(a));
|
|
|
|
|
|
|
|
run_test(|a| slice_pattern_first(a));
|
|
|
|
run_test(|a| slice_pattern_middle(a));
|
|
|
|
run_test(|a| slice_pattern_two(a));
|
|
|
|
run_test(|a| slice_pattern_last(a));
|
|
|
|
run_test(|a| slice_pattern_one_of(a, 0));
|
|
|
|
run_test(|a| slice_pattern_one_of(a, 1));
|
|
|
|
run_test(|a| slice_pattern_one_of(a, 2));
|
|
|
|
run_test(|a| slice_pattern_one_of(a, 3));
|
|
|
|
|
|
|
|
run_test(|a| subslice_pattern_from_end(a, true));
|
|
|
|
run_test(|a| subslice_pattern_from_end(a, false));
|
|
|
|
run_test(|a| subslice_pattern_from_end_with_drop(a, true, true));
|
|
|
|
run_test(|a| subslice_pattern_from_end_with_drop(a, true, false));
|
|
|
|
run_test(|a| subslice_pattern_from_end_with_drop(a, false, true));
|
|
|
|
run_test(|a| subslice_pattern_from_end_with_drop(a, false, false));
|
|
|
|
run_test(|a| slice_pattern_reassign(a));
|
|
|
|
run_test(|a| subslice_pattern_reassign(a));
|
|
|
|
|
|
|
|
run_test(|a| index_field_mixed_ends(a));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 0));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 1));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 2));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 3));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 4));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 5));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 6));
|
|
|
|
run_test(|a| subslice_mixed_min_lengths(a, 7));
|
|
|
|
|
|
|
|
run_test(|a| move_ref_pattern(a));
|
|
|
|
|
2023-09-18 10:18:51 -05:00
|
|
|
run_test(|a| if_let_guard(a, true, 0));
|
|
|
|
run_test(|a| if_let_guard(a, true, 1));
|
|
|
|
run_test(|a| if_let_guard(a, true, 2));
|
|
|
|
run_test(|a| if_let_guard(a, false, 0));
|
|
|
|
run_test(|a| if_let_guard(a, false, 1));
|
|
|
|
run_test(|a| if_let_guard(a, false, 2));
|
|
|
|
|
2021-01-21 21:35:05 -06:00
|
|
|
run_test(|a| {
|
2019-05-11 05:16:26 -05:00
|
|
|
panic_after_return(a);
|
|
|
|
});
|
2021-01-21 21:35:05 -06:00
|
|
|
run_test(|a| {
|
2019-05-11 05:16:26 -05:00
|
|
|
panic_after_return_expr(a);
|
|
|
|
});
|
2021-01-21 21:35:05 -06:00
|
|
|
run_test(|a| panic_after_init(a));
|
|
|
|
run_test(|a| panic_after_init_temp(a));
|
|
|
|
run_test(|a| panic_after_init_by_loop(a));
|
|
|
|
|
|
|
|
run_test(|a| bindings_after_at_dynamic_init_move(a, true));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_init_move(a, false));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_init_ref(a, true));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_init_ref(a, false));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_drop_move(a, true));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_drop_move(a, false));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_drop_ref(a, true));
|
|
|
|
run_test(|a| bindings_after_at_dynamic_drop_ref(a, false));
|
|
|
|
|
|
|
|
run_test_nopanic(|a| union1(a));
|
2016-05-16 18:26:18 -05:00
|
|
|
}
|