1 // Copyright 2014 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 // Test how overloaded deref interacts with borrows when only
12 // Deref and not DerefMut is implemented.
20 impl<T> Deref<T> for Rc<T> {
21 fn deref<'a>(&'a self) -> &'a T {
22 unsafe { &*self.value }
26 fn deref_imm(x: Rc<int>) {
30 fn deref_mut1(x: Rc<int>) {
31 let _i = &mut *x; //~ ERROR cannot borrow
34 fn deref_mut2(mut x: Rc<int>) {
35 let _i = &mut *x; //~ ERROR cannot borrow
38 fn deref_extend<'a>(x: &'a Rc<int>) -> &'a int {
42 fn deref_extend_mut1<'a>(x: &'a Rc<int>) -> &'a mut int {
43 &mut **x //~ ERROR cannot borrow
46 fn deref_extend_mut2<'a>(x: &'a mut Rc<int>) -> &'a mut int {
47 &mut **x //~ ERROR cannot borrow
50 fn assign1<'a>(x: Rc<int>) {
51 *x = 3; //~ ERROR cannot assign
54 fn assign2<'a>(x: &'a Rc<int>) {
55 **x = 3; //~ ERROR cannot assign
58 fn assign3<'a>(x: &'a mut Rc<int>) {
59 **x = 3; //~ ERROR cannot assign