about summary refs log tree commit diff
path: root/src/liballoc/sync
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-08-06 17:19:05 +0000
committerbors <bors@rust-lang.org>2019-08-06 17:19:05 +0000
commit6a91782b72fca586b15ba68364bc7baab837af86 (patch)
treec2d7defbb6eeffcdbd391b6e22331ba8885198fe /src/liballoc/sync
parent188ab5c976a5696ac710b7ba78849ef5dcf0235a (diff)
parent32324d22c33dda31eadf49c5f27d6e6ff38a3ef1 (diff)
Auto merge of #61515 - shepmaster:boxed-slice-to-array, r=cramertj
Add implementations for converting boxed slices into boxed arrays

This mirrors the implementations of reference slices into arrays.

# Discussion

- [x] Should we use const generics? ([probably not](https://github.com/rust-lang/rust/pull/61515#issuecomment-498690649))
- [ ] [What's the safety rationale here](https://github.com/rust-lang/rust/pull/61515#discussion_r290296613)?
- [ ] [Should the errors return the original object](https://github.com/rust-lang/rust/pull/61515#discussion_r290336592)?

# Remaining

- [ ] Implement `Error`
- [ ] Create a tracking issue
Diffstat (limited to 'src/liballoc/sync')
-rw-r--r--src/liballoc/sync/tests.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/liballoc/sync/tests.rs b/src/liballoc/sync/tests.rs
index 2e0c62f50c1..9220f5e0333 100644
--- a/src/liballoc/sync/tests.rs
+++ b/src/liballoc/sync/tests.rs
@@ -9,7 +9,7 @@ use std::option::Option::{self, None, Some};
 use std::sync::atomic::{self, Ordering::{Acquire, SeqCst}};
 use std::thread;
 use std::sync::Mutex;
-use std::convert::From;
+use std::convert::{From, TryInto};
 
 use crate::vec::Vec;
 
@@ -478,3 +478,15 @@ fn test_downcast() {
     assert!(r2str.is_ok());
     assert_eq!(r2str.unwrap(), Arc::new("abc"));
 }
+
+#[test]
+fn test_array_from_slice() {
+    let v = vec![1, 2, 3];
+    let r: Arc<[u32]> = Arc::from(v);
+
+    let a: Result<Arc<[u32; 3]>, _> = r.clone().try_into();
+    assert!(a.is_ok());
+
+    let a: Result<Arc<[u32; 2]>, _> = r.clone().try_into();
+    assert!(a.is_err());
+}