]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-16774.rs
point at private fields in struct literal
[rust.git] / src / test / ui / issues / issue-16774.rs
1 // run-pass
2 #![feature(box_syntax)]
3 #![feature(box_patterns)]
4
5 use std::ops::{Deref, DerefMut};
6
7 struct X(Box<isize>);
8
9 static mut DESTRUCTOR_RAN: bool = false;
10
11 impl Drop for X {
12     fn drop(&mut self) {
13         unsafe {
14             assert!(!DESTRUCTOR_RAN);
15             DESTRUCTOR_RAN = true;
16         }
17     }
18 }
19
20 impl Deref for X {
21     type Target = isize;
22
23     fn deref(&self) -> &isize {
24         let &X(box ref x) = self;
25         x
26     }
27 }
28
29 impl DerefMut for X {
30     fn deref_mut(&mut self) -> &mut isize {
31         let &mut X(box ref mut x) = self;
32         x
33     }
34 }
35
36 fn main() {
37     {
38         let mut test = X(box 5);
39         {
40             let mut change = || { *test = 10 };
41             change();
42         }
43         assert_eq!(*test, 10);
44     }
45     assert!(unsafe { DESTRUCTOR_RAN });
46 }