rust/tests/ui/span/send-is-not-static-std-sync-2.rs

40 lines
772 B
Rust
Raw Normal View History

// 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
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
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);
(tx, rx)
2017-12-13 19:27:23 -06:00
};
//~^^^ ERROR `x` does not live long enough
let _dangling = rx.recv();
}
fn main() {}