mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-04 11:17:04 +00:00
27 lines
339 B
Rust
27 lines
339 B
Rust
//@ run-pass
|
|
|
|
use std::cell::Cell;
|
|
|
|
struct R<'a> {
|
|
b: &'a Cell<isize>,
|
|
}
|
|
|
|
impl<'a> Drop for R<'a> {
|
|
fn drop(&mut self) {
|
|
self.b.set(self.b.get() + 1);
|
|
}
|
|
}
|
|
|
|
fn r(b: &Cell<isize>) -> R<'_> {
|
|
R { b }
|
|
}
|
|
|
|
pub fn main() {
|
|
let b = &Cell::new(0);
|
|
{
|
|
let _p = Some(r(b));
|
|
}
|
|
|
|
assert_eq!(b.get(), 1);
|
|
}
|