From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../borrowck-borrow-overloaded-auto-deref-mut.rs | 142 --------------------- 1 file changed, 142 deletions(-) delete mode 100644 src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs (limited to 'src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs') diff --git a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs b/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs deleted file mode 100644 index 76a1d12ea..000000000 --- a/src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.rs +++ /dev/null @@ -1,142 +0,0 @@ -// Test how overloaded deref interacts with borrows when DerefMut -// is implemented. - -use std::ops::{Deref, DerefMut}; - -struct Own { - value: *mut T -} - -impl Deref for Own { - type Target = T; - - fn deref(&self) -> &T { - unsafe { &*self.value } - } -} - -impl DerefMut for Own { - fn deref_mut(&mut self) -> &mut T { - unsafe { &mut *self.value } - } -} - -struct Point { - x: isize, - y: isize -} - -impl Point { - fn get(&self) -> (isize, isize) { - (self.x, self.y) - } - - fn set(&mut self, x: isize, y: isize) { - self.x = x; - self.y = y; - } - - fn x_ref(&self) -> &isize { - &self.x - } - - fn y_mut(&mut self) -> &mut isize { - &mut self.y - } -} - -fn deref_imm_field(x: Own) { - let __isize = &x.y; -} - -fn deref_mut_field1(x: Own) { - let __isize = &mut x.y; //~ ERROR cannot borrow -} - -fn deref_mut_field2(mut x: Own) { - let __isize = &mut x.y; -} - -fn deref_extend_field(x: &Own) -> &isize { - &x.y -} - -fn deref_extend_mut_field1(x: &Own) -> &mut isize { - &mut x.y //~ ERROR cannot borrow -} - -fn deref_extend_mut_field2(x: &mut Own) -> &mut isize { - &mut x.y -} - -fn deref_extend_mut_field3(x: &mut Own) { - // Hmm, this is unfortunate, because with box it would work, - // but it's presently the expected outcome. See `deref_extend_mut_field4` - // for the workaround. - - let _x = &mut x.x; - let _y = &mut x.y; //~ ERROR cannot borrow - use_mut(_x); -} -fn deref_extend_mut_field4<'a>(x: &'a mut Own) { - let p = &mut **x; - let _x = &mut p.x; - let _y = &mut p.y; -} - -fn assign_field1<'a>(x: Own) { - x.y = 3; //~ ERROR cannot borrow -} - -fn assign_field2<'a>(x: &'a Own) { - x.y = 3; //~ ERROR cannot borrow -} - -fn assign_field3<'a>(x: &'a mut Own) { - x.y = 3; -} - -fn assign_field4<'a>(x: &'a mut Own) { - let _p: &mut Point = &mut **x; - x.y = 3; //~ ERROR cannot borrow - use_mut(_p); -} -fn deref_imm_method(x: Own) { - let __isize = x.get(); -} - -fn deref_mut_method1(x: Own) { - x.set(0, 0); //~ ERROR cannot borrow -} - -fn deref_mut_method2(mut x: Own) { - x.set(0, 0); -} - -fn deref_extend_method(x: &Own) -> &isize { - x.x_ref() -} - -fn deref_extend_mut_method1(x: &Own) -> &mut isize { - x.y_mut() //~ ERROR cannot borrow -} - -fn deref_extend_mut_method2(x: &mut Own) -> &mut isize { - x.y_mut() -} - -fn assign_method1<'a>(x: Own) { - *x.y_mut() = 3; //~ ERROR cannot borrow -} - -fn assign_method2<'a>(x: &'a Own) { - *x.y_mut() = 3; //~ ERROR cannot borrow -} - -fn assign_method3<'a>(x: &'a mut Own) { - *x.y_mut() = 3; -} - -pub fn main() {} - -fn use_mut(_: &mut T) {} -- cgit v1.2.3