From 7010fed10e822a1f3b2f433456a830aae9f202a4 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 16 Nov 2024 18:53:53 +0000 Subject: [PATCH] demo borrowed panic --- src/test.rs | 11 +++++++++++ src/test/demo.rs | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) 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, -- 2.30.2