]>
Commit | Line | Data |
---|---|---|
c34b1796 AL |
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; | |
ff7c6d11 | 21 | Mutex::new(&x) |
c34b1796 | 22 | }; |
ff7c6d11 | 23 | //~^^ ERROR `x` does not live long enough |
c34b1796 AL |
24 | |
25 | let _dangling = *lock.lock().unwrap(); | |
26 | } | |
27 | ||
28 | fn rwlock() { | |
29 | let lock = { | |
30 | let x = 1; | |
ff7c6d11 | 31 | RwLock::new(&x) |
c34b1796 | 32 | }; |
ff7c6d11 | 33 | //~^^ ERROR `x` does not live long enough |
c34b1796 AL |
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(); | |
ff7c6d11 | 41 | let _ = tx.send(&x); |
c34b1796 AL |
42 | (tx, rx) |
43 | }; | |
ff7c6d11 | 44 | //~^^^ ERROR `x` does not live long enough |
c34b1796 AL |
45 | |
46 | let _dangling = rx.recv(); | |
47 | } | |
48 | ||
49 | fn main() {} |