Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ae37d1c

Browse files
the8472cuviper
authored andcommittedJan 17, 2025
add regression test for unsound Flatten/FlatMap specialization
(cherry picked from commit 1ed0ea4)
1 parent 8a7dc21 commit ae37d1c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎library/alloc/tests/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,20 @@ fn test_collect_after_iterator_clone() {
13371337
assert_eq!(v, [1, 1, 1, 1, 1]);
13381338
assert!(v.len() <= v.capacity());
13391339
}
1340+
1341+
// regression test for #135103, similar to the one above Flatten/FlatMap had an unsound InPlaceIterable
1342+
// implementation.
1343+
#[test]
1344+
fn test_flatten_clone() {
1345+
const S: String = String::new();
1346+
1347+
let v = vec![[S, "Hello World!".into()], [S, S]];
1348+
let mut i = v.into_iter().flatten();
1349+
let _ = i.next();
1350+
let result: Vec<String> = i.clone().collect();
1351+
assert_eq!(result, ["Hello World!", "", ""]);
1352+
}
1353+
13401354
#[test]
13411355
fn test_cow_from() {
13421356
let borrowed: &[_] = &["borrowed", "(slice)"];

0 commit comments

Comments
 (0)
Failed to load comments.