]> git.lizzy.rs Git - rust.git/blob - src/test/ui/span/send-is-not-static-std-sync-2.rs
Auto merge of #46739 - arielb1:simple-loops, r=nikomatsakis
[rust.git] / src / test / ui / span / send-is-not-static-std-sync-2.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // basic tests to see that certain "obvious" errors are caught by
12 // these types no longer requiring `'static` (RFC 458)
13
14 #![allow(dead_code)]
15
16 use std::sync::{Mutex, RwLock, mpsc};
17
18 fn mutex() {
19     let lock = {
20         let x = 1;
21         Mutex::new(&x)
22     };
23     //~^^ ERROR `x` does not live long enough
24
25     let _dangling = *lock.lock().unwrap();
26 }
27
28 fn rwlock() {
29     let lock = {
30         let x = 1;
31         RwLock::new(&x)
32     };
33     //~^^ ERROR `x` does not live long enough
34     let _dangling = *lock.read().unwrap();
35 }
36
37 fn channel() {
38     let (_tx, rx) = {
39         let x = 1;
40         let (tx, rx) = mpsc::channel();
41         let _ = tx.send(&x);
42         (tx, rx)
43     };
44     //~^^^ ERROR `x` does not live long enough
45
46     let _dangling = rx.recv();
47 }
48
49 fn main() {}