|
| 1 | +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +use std::any::Any; |
| 12 | +use std::sync::{Arc, Weak}; |
| 13 | + |
| 14 | +#[test] |
| 15 | +fn uninhabited() { |
| 16 | + enum Void {} |
| 17 | + let mut a = Weak::<Void>::new(); |
| 18 | + a = a.clone(); |
| 19 | + assert!(a.upgrade().is_none()); |
| 20 | + |
| 21 | + let mut a: Weak<Any> = a; // Unsizing |
| 22 | + a = a.clone(); |
| 23 | + assert!(a.upgrade().is_none()); |
| 24 | +} |
| 25 | + |
| 26 | +#[test] |
| 27 | +fn slice() { |
| 28 | + let a: Arc<[u32; 3]> = Arc::new([3, 2, 1]); |
| 29 | + let a: Arc<[u32]> = a; // Unsizing |
| 30 | + let b: Arc<[u32]> = Arc::from(&[3, 2, 1][..]); // Conversion |
| 31 | + assert_eq!(a, b); |
| 32 | + |
| 33 | + // Exercise is_dangling() with a DST |
| 34 | + let mut a = Arc::downgrade(&a); |
| 35 | + a = a.clone(); |
| 36 | + assert!(a.upgrade().is_some()); |
| 37 | +} |
| 38 | + |
| 39 | +#[test] |
| 40 | +fn trait_object() { |
| 41 | + let a: Arc<u32> = Arc::new(4); |
| 42 | + let a: Arc<Any> = a; // Unsizing |
| 43 | + |
| 44 | + // Exercise is_dangling() with a DST |
| 45 | + let mut a = Arc::downgrade(&a); |
| 46 | + a = a.clone(); |
| 47 | + assert!(a.upgrade().is_some()); |
| 48 | + |
| 49 | + let mut b = Weak::<u32>::new(); |
| 50 | + b = b.clone(); |
| 51 | + assert!(b.upgrade().is_none()); |
| 52 | + let mut b: Weak<Any> = b; // Unsizing |
| 53 | + b = b.clone(); |
| 54 | + assert!(b.upgrade().is_none()); |
| 55 | +} |
0 commit comments