From: Ian Jackson Date: Sat, 16 Nov 2024 18:53:53 +0000 (+0000) Subject: demo borrowed panic X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=7010fed10e822a1f3b2f433456a830aae9f202a4;p=manually-boxed demo borrowed panic --- diff --git a/src/test.rs b/src/test.rs index 7b17430..e1b133a 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,6 +1,7 @@ use super::*; use fmt::Write as _; +use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind}; mod demo; use demo::{List, HeadAndTail}; @@ -45,6 +46,16 @@ fn demo() { l.check_consistency(); assert_eq!(l.head_and_tail_mut(), H::Both(&mut s("one"), &mut s("ho"))); + catch_unwind(AssertUnwindSafe(|| { + l.temporarily_prepend(s("t"), |l| { + l.check_consistency(); + assert_eq!(l.front(), Some(&s("t"))); + panic!("yikes"); + }); + })).unwrap_err(); + l.check_consistency(); + assert_eq!(l.head_and_tail_mut(), H::Both(&mut s("one"), &mut s("ho"))); + write!(l.front_mut().unwrap(), "!").unwrap(); assert_eq!(l.pop_front(), Some(s("one!"))); l.check_consistency(); assert_eq!(l.front(), Some(&s("hi"))); l.check_consistency(); diff --git a/src/test/demo.rs b/src/test/demo.rs index da3304d..4054b5f 100644 --- a/src/test/demo.rs +++ b/src/test/demo.rs @@ -120,8 +120,6 @@ impl List { data: T, then: impl FnOnce(&Self) -> R, ) -> R { - use std::panic::{AssertUnwindSafe, catch_unwind, resume_unwind}; - let mut tmp_node = Node { data, next: None,