rust/src/test/ui/logging-only-prints-once.rs

29 lines
578 B
Rust
Raw Normal View History

// run-pass
// ignore-windows
// ignore-emscripten no threads support
2019-04-30 08:27:53 +00:00
// exec-env:RUSTC_LOG=debug
2013-12-31 23:46:27 +00:00
use std::cell::Cell;
use std::fmt;
2015-02-17 23:24:34 +00:00
use std::thread;
struct Foo(Cell<isize>);
2015-01-28 13:34:18 +00:00
impl fmt::Debug for Foo {
fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
let Foo(ref f) = *self;
assert_eq!(f.get(), 0);
2013-12-31 23:46:27 +00:00
f.set(1);
2014-01-30 19:56:51 +00:00
Ok(())
}
}
pub fn main() {
2015-02-17 23:24:34 +00:00
thread::spawn(move|| {
2013-12-31 23:46:27 +00:00
let mut f = Foo(Cell::new(0));
println!("{:?}", f);
let Foo(ref mut f) = f;
assert_eq!(f.get(), 1);
}).join().ok().unwrap();
}