1 // run-pass
2 // ignore-windows
3 // ignore-emscripten no threads support
4 
5 use std::cell::Cell;
6 use std::fmt;
7 use std::thread;
8 
9 struct Foo(Cell<isize>);
10 
11 impl fmt::Debug for Foo {
fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result12     fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
13         let Foo(ref f) = *self;
14         assert_eq!(f.get(), 0);
15         f.set(1);
16         Ok(())
17     }
18 }
19 
main()20 pub fn main() {
21     thread::spawn(move || {
22         let mut f = Foo(Cell::new(0));
23         println!("{:?}", f);
24         let Foo(ref mut f) = f;
25         assert_eq!(f.get(), 1);
26     })
27     .join()
28     .ok()
29     .unwrap();
30 }
31