rust/tests/ui/issues/issue-16774.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

46 lines
773 B
Rust
Raw Normal View History

// run-pass
#![feature(box_patterns)]
2014-11-02 23:58:00 +00:00
use std::ops::{Deref, DerefMut};
struct X(Box<isize>);
2014-11-02 23:58:00 +00:00
static mut DESTRUCTOR_RAN: bool = false;
impl Drop for X {
fn drop(&mut self) {
unsafe {
assert!(!DESTRUCTOR_RAN);
DESTRUCTOR_RAN = true;
}
}
}
2015-01-01 19:53:20 +00:00
impl Deref for X {
type Target = isize;
2015-01-01 19:53:20 +00:00
fn deref(&self) -> &isize {
2014-11-02 23:58:00 +00:00
let &X(box ref x) = self;
x
}
}
2015-01-01 19:53:20 +00:00
impl DerefMut for X {
fn deref_mut(&mut self) -> &mut isize {
2015-01-08 00:26:00 +00:00
let &mut X(box ref mut x) = self;
2014-11-02 23:58:00 +00:00
x
}
}
fn main() {
{
let mut test = X(Box::new(5));
2014-11-02 23:58:00 +00:00
{
let mut change = || { *test = 10 };
2014-11-02 23:58:00 +00:00
change();
}
assert_eq!(*test, 10);
}
assert!(unsafe { DESTRUCTOR_RAN });
}