diff options
| author | The 8472 <git@infinite-source.de> | 2025-01-04 19:44:49 +0100 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2025-01-16 17:50:04 -0800 |
| commit | ae37d1c9b6891c77254f9bd0de205d28e893efd5 (patch) | |
| tree | 3c82d484749b8ae6ad77689c698a3379a3667351 | |
| parent | 8a7dc215b02e6b4c2dd890e750dceadeaf077f7d (diff) | |
| download | rust-ae37d1c9b6891c77254f9bd0de205d28e893efd5.tar.gz rust-ae37d1c9b6891c77254f9bd0de205d28e893efd5.zip | |
add regression test for unsound Flatten/FlatMap specialization
(cherry picked from commit 1ed0ea459dc5456ebcedb798cc88671014cf0f68)
| -rw-r--r-- | library/alloc/tests/vec.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 474ea7fe56b..2e654d3d1ff 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -1337,6 +1337,20 @@ fn test_collect_after_iterator_clone() { assert_eq!(v, [1, 1, 1, 1, 1]); assert!(v.len() <= v.capacity()); } + +// regression test for #135103, similar to the one above Flatten/FlatMap had an unsound InPlaceIterable +// implementation. +#[test] +fn test_flatten_clone() { + const S: String = String::new(); + + let v = vec![[S, "Hello World!".into()], [S, S]]; + let mut i = v.into_iter().flatten(); + let _ = i.next(); + let result: Vec<String> = i.clone().collect(); + assert_eq!(result, ["Hello World!", "", ""]); +} + #[test] fn test_cow_from() { let borrowed: &[_] = &["borrowed", "(slice)"]; |
