about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2017-08-29 16:51:26 +0200
committerRalf Jung <post@ralfj.de>2017-08-29 16:51:26 +0200
commite6a874b0bf35b7f5fadfc63f18be45ecc30579e7 (patch)
treee7a8992d0982a981e229c32def70312f1b855e68
parent33bfb64e6d7a94db6db024a6069b7d4a7e116603 (diff)
downloadrust-e6a874b0bf35b7f5fadfc63f18be45ecc30579e7.tar.gz
rust-e6a874b0bf35b7f5fadfc63f18be45ecc30579e7.zip
test new From instances for Rc
-rw-r--r--tests/run-pass/rc.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/run-pass/rc.rs b/tests/run-pass/rc.rs
index c6de3675abe..0bf70750311 100644
--- a/tests/run-pass/rc.rs
+++ b/tests/run-pass/rc.rs
@@ -1,11 +1,11 @@
 use std::cell::RefCell;
 use std::rc::Rc;
 
-fn rc_refcell() -> i32 {
+fn rc_refcell() {
     let r = Rc::new(RefCell::new(42));
     *r.borrow_mut() += 10;
     let x = *r.borrow();
-    x
+    assert_eq!(x, 52);
 }
 
 fn rc_raw() {
@@ -17,7 +17,23 @@ fn rc_raw() {
     assert!(Rc::try_unwrap(r2).is_ok());
 }
 
+// Make sure this Rc doesn't fall apart when touched
+fn check_unique_rc<T: ?Sized>(mut r: Rc<T>) {
+    let r2 = r.clone();
+    assert!(Rc::get_mut(&mut r).is_none());
+    drop(r2);
+    assert!(Rc::get_mut(&mut r).is_some());
+}
+
+fn rc_from() {
+    check_unique_rc::<[_]>(Rc::from(&[1,2,3] as &[_]));
+    check_unique_rc::<[_]>(Rc::from(vec![1,2,3]));
+    check_unique_rc::<[_]>(Rc::from(Box::new([1,2,3]) as Box<[_]>));
+    check_unique_rc::<str>(Rc::from("Hello, World!"));
+}
+
 fn main() {
     rc_refcell();
     rc_raw();
+    rc_from();
 }