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 for Rc<T> {
23 fn deref(&self) -> &T {
24 unsafe { &*self.value }
34 fn get(&self) -> (isize, isize) {
38 fn set(&mut self, x: isize, y: isize) {
43 fn x_ref(&self) -> &isize {
47 fn y_mut(&mut self) -> &mut isize {
52 fn deref_imm_field(x: Rc<Point>) {
56 fn deref_mut_field1(x: Rc<Point>) {
57 let _i = &mut x.y; //~ ERROR cannot borrow
60 fn deref_mut_field2(mut x: Rc<Point>) {
61 let _i = &mut x.y; //~ ERROR cannot borrow
64 fn deref_extend_field(x: &Rc<Point>) -> &isize {
68 fn deref_extend_mut_field1(x: &Rc<Point>) -> &mut isize {
69 &mut x.y //~ ERROR cannot borrow
72 fn deref_extend_mut_field2(x: &mut Rc<Point>) -> &mut isize {
73 &mut x.y //~ ERROR cannot borrow
76 fn assign_field1<'a>(x: Rc<Point>) {
77 x.y = 3; //~ ERROR cannot assign
80 fn assign_field2<'a>(x: &'a Rc<Point>) {
81 x.y = 3; //~ ERROR cannot assign
84 fn assign_field3<'a>(x: &'a mut Rc<Point>) {
85 x.y = 3; //~ ERROR cannot assign
88 fn deref_imm_method(x: Rc<Point>) {
92 fn deref_mut_method1(x: Rc<Point>) {
93 x.set(0, 0); //~ ERROR cannot borrow
96 fn deref_mut_method2(mut x: Rc<Point>) {
97 x.set(0, 0); //~ ERROR cannot borrow
100 fn deref_extend_method(x: &Rc<Point>) -> &isize {
104 fn deref_extend_mut_method1(x: &Rc<Point>) -> &mut isize {
105 x.y_mut() //~ ERROR cannot borrow
108 fn deref_extend_mut_method2(x: &mut Rc<Point>) -> &mut isize {
109 x.y_mut() //~ ERROR cannot borrow
112 fn assign_method1<'a>(x: Rc<Point>) {
113 *x.y_mut() = 3; //~ ERROR cannot borrow
116 fn assign_method2<'a>(x: &'a Rc<Point>) {
117 *x.y_mut() = 3; //~ ERROR cannot borrow
120 fn assign_method3<'a>(x: &'a mut Rc<Point>) {
121 *x.y_mut() = 3; //~ ERROR cannot borrow