diff options
| author | bors <bors@rust-lang.org> | 2023-09-28 04:26:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-28 04:26:40 +0000 |
| commit | aeaa5c30e5c9041264a2e8314b68ad84c2dc3169 (patch) | |
| tree | b8f3ed58834bfaca53d7fa4086c2a011d1059aca /library/alloc/tests | |
| parent | 2ba4eb2d49e774b5fbc2a06258ac7b0f60b92b7e (diff) | |
| parent | 27e10e2b5e2a589196c3d72f5da58f480ad14374 (diff) | |
Auto merge of #111278 - EFanZh:implement-from-array-refs-for-vec, r=dtolnay
Implement `From<{&,&mut} [T; N]>` for `Vec<T>` where `T: Clone`
Currently, if `T` implements `Clone`, we can create a `Vec<T>` from an `&[T]` or an `&mut [T]`, can we also support creating a `Vec<T>` from an `&[T; N]` or an `&mut [T; N]`? Also, do I need to add `#[inline]` to the implementation?
ACP: rust-lang/libs-team#220. [Accepted]
Closes #100880.
Diffstat (limited to 'library/alloc/tests')
| -rw-r--r-- | library/alloc/tests/vec.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 9cb27899f10..d44dcfbf673 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -2562,3 +2562,13 @@ fn test_box_zero_allocator() { // Ensure all ZSTs have been freed. assert!(alloc.state.borrow().0.is_empty()); } + +#[test] +fn test_vec_from_array_ref() { + assert_eq!(Vec::from(&[1, 2, 3]), vec![1, 2, 3]); +} + +#[test] +fn test_vec_from_array_mut_ref() { + assert_eq!(Vec::from(&mut [1, 2, 3]), vec![1, 2, 3]); +} |
