From 1f6f917f73a4372f098e9b19560b5945be145dc3 Mon Sep 17 00:00:00 2001 From: Giacomo Stevanato Date: Thu, 29 Oct 2020 11:48:56 +0100 Subject: [PATCH] Added test for issue #78498 --- library/alloc/tests/string.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/library/alloc/tests/string.rs b/library/alloc/tests/string.rs index a6e41b21b61..b28694186b6 100644 --- a/library/alloc/tests/string.rs +++ b/library/alloc/tests/string.rs @@ -1,6 +1,7 @@ use std::borrow::Cow; use std::collections::TryReserveError::*; use std::ops::Bound::*; +use std::panic; pub trait IntoCow<'a, B: ?Sized> where @@ -378,6 +379,20 @@ fn test_retain() { s.retain(|_| false); assert_eq!(s, ""); + + let mut s = String::from("0รจ0"); + let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| { + let mut count = 0; + s.retain(|_| { + count += 1; + match count { + 1 => false, + 2 => true, + _ => panic!(), + } + }); + })); + assert!(std::str::from_utf8(s.as_bytes()).is_ok()); } #[test]