2015-02-20 06:33:11 +00: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 12:13:27 +00:00
|
|
|
Mutex::new(&x)
|
2017-12-14 01:27:23 +00:00
|
|
|
};
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-02-20 06:33:11 +00:00
|
|
|
|
|
|
|
let _dangling = *lock.lock().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn rwlock() {
|
|
|
|
let lock = {
|
|
|
|
let x = 1;
|
2017-11-20 12:13:27 +00:00
|
|
|
RwLock::new(&x)
|
2017-12-14 01:27:23 +00:00
|
|
|
};
|
|
|
|
//~^^ ERROR `x` does not live long enough
|
2015-02-20 06:33:11 +00:00
|
|
|
let _dangling = *lock.read().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn channel() {
|
|
|
|
let (_tx, rx) = {
|
|
|
|
let x = 1;
|
|
|
|
let (tx, rx) = mpsc::channel();
|
2017-11-20 12:13:27 +00:00
|
|
|
let _ = tx.send(&x);
|
2015-02-20 06:33:11 +00:00
|
|
|
(tx, rx)
|
2017-12-14 01:27:23 +00:00
|
|
|
};
|
|
|
|
//~^^^ ERROR `x` does not live long enough
|
2015-02-20 06:33:11 +00:00
|
|
|
|
|
|
|
let _dangling = rx.recv();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|