2015-02-20 00:33:11 -06:00
|
|
|
// basic tests to see that certain "obvious" errors are caught by
|
|
|
|
// these types no longer requiring `'static` (RFC 458)
|
|
|
|
|
|
|
|
#![allow(dead_code)]
|
|
|
|
|
|
|
|
use std::sync::{Mutex, RwLock, mpsc};
|
|
|
|
|
|
|
|
fn mutex() {
|
|
|
|
let lock = {
|
|
|
|
let x = 1;
|
2017-11-20 06:13:27 -06:00
|
|
|
Mutex::new(&x)
|
2017-12-13 19:27:23 -06:00
|
|
|
};
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-02-20 00:33:11 -06:00
|
|
|
|
|
|
|
let _dangling = *lock.lock().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rwlock() {
|
|
|
|
let lock = {
|
|
|
|
let x = 1;
|
2017-11-20 06:13:27 -06:00
|
|
|
RwLock::new(&x)
|
2017-12-13 19:27:23 -06:00
|
|
|
};
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-02-20 00:33:11 -06:00
|
|
|
let _dangling = *lock.read().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn channel() {
|
|
|
|
let (_tx, rx) = {
|
|
|
|
let x = 1;
|
|
|
|
let (tx, rx) = mpsc::channel();
|
2017-11-20 06:13:27 -06:00
|
|
|
let _ = tx.send(&x);
|
2015-02-20 00:33:11 -06:00
|
|
|
(tx, rx)
|
2017-12-13 19:27:23 -06:00
|
|
|
};
|
|
|
|
//~^^^ ERROR `x` does not live long enough
|
2015-02-20 00:33:11 -06:00
|
|
|
|
|
|
|
let _dangling = rx.recv();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|