Skip to content

Commit 0a5fd1d

Browse files
rjsberryDirbaio
authored andcommitted
Add test for drop behavior on array to vec conversion
1 parent fb78a9b commit 0a5fd1d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/vec.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,23 @@ mod tests {
16001600
assert_eq!(v.as_slice(), &[1, 2, 3]);
16011601
}
16021602

1603+
#[test]
1604+
fn from_array_no_drop() {
1605+
struct Drops(Option<u8>);
1606+
1607+
impl Drop for Drops {
1608+
fn drop(&mut self) {
1609+
self.0 = None;
1610+
}
1611+
}
1612+
1613+
let v: Vec<Drops, 3> = Vec::from([Drops(Some(1)), Drops(Some(2)), Drops(Some(3))]);
1614+
1615+
assert_eq!(v[0].0, Some(1));
1616+
assert_eq!(v[1].0, Some(2));
1617+
assert_eq!(v[2].0, Some(3));
1618+
}
1619+
16031620
#[test]
16041621
fn starts_with() {
16051622
let v: Vec<_, 8> = Vec::from_slice(b"ab").unwrap();

0 commit comments

Comments
 (0)