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.
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.
11 // basic tests to see that certain "obvious" errors are caught by
12 // these types no longer requiring `'static` (RFC 458)
16 use std::sync::{Mutex, RwLock, mpsc};
21 let lock = Mutex::new(&x);
22 *lock.lock().unwrap() = &*y;
23 drop(y); //~ ERROR cannot move out
26 *lock.lock().unwrap() = &z;
28 //~^^ ERROR `z` does not live long enough
29 lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z` => needs explicit use)
35 let lock = RwLock::new(&x);
36 *lock.write().unwrap() = &*y;
37 drop(y); //~ ERROR cannot move out
40 *lock.write().unwrap() = &z;
42 //~^^ ERROR `z` does not live long enough
43 lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z` => needs explicit use)
49 let (tx, rx) = mpsc::channel();
53 drop(y); //~ ERROR cannot move out
58 //~^^ ERROR `z` does not live long enough
59 // (channels lack #[may_dangle], thus their dtors are implicit uses of `z`)
64 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } }
65 impl<T> Fake for T { }