Skip to content

Commit

Permalink
add regression test for unsound Flatten/FlatMap specialization
Browse files Browse the repository at this point in the history
  • Loading branch information
the8472 committed Jan 4, 2025
1 parent 3d871b3 commit 1ed0ea4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"];
Expand Down

0 comments on commit 1ed0ea4

Please sign in to comment.