mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-23 02:27:39 +03:00
28 lines
722 B
Rust
28 lines
722 B
Rust
//@ check-pass
|
|
#![allow(incomplete_features)]
|
|
#![feature(move_expr)]
|
|
|
|
use std::sync::Arc;
|
|
|
|
fn main() {
|
|
let x = Arc::new(String::from("hello"));
|
|
assert_eq!(Arc::strong_count(&x), 1);
|
|
|
|
let outer = || {
|
|
assert_eq!(Arc::strong_count(&x), 1);
|
|
let inner = || move(x.clone());
|
|
assert_eq!(Arc::strong_count(&x), 2);
|
|
let y = inner();
|
|
assert_eq!(&*y, "hello");
|
|
assert_eq!(Arc::strong_count(&x), 2);
|
|
drop(y);
|
|
assert_eq!(Arc::strong_count(&x), 1);
|
|
};
|
|
|
|
assert_eq!(Arc::strong_count(&x), 1);
|
|
// `outer` captures `x` by reference, and `inner` takes ownership of a clone.
|
|
println!("{x}");
|
|
outer();
|
|
assert_eq!(Arc::strong_count(&x), 1);
|
|
}
|