summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/borrowck-access-permissions.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/borrowck/borrowck-access-permissions.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/borrowck/borrowck-access-permissions.rs')
-rw-r--r--tests/ui/borrowck/borrowck-access-permissions.rs50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/borrowck/borrowck-access-permissions.rs b/tests/ui/borrowck/borrowck-access-permissions.rs
new file mode 100644
index 000000000..469ad508b
--- /dev/null
+++ b/tests/ui/borrowck/borrowck-access-permissions.rs
@@ -0,0 +1,50 @@
+static static_x : i32 = 1;
+static mut static_x_mut : i32 = 1;
+
+fn main() {
+ let x = 1;
+ let mut x_mut = 1;
+
+ { // borrow of local
+ let _y1 = &mut x; //~ ERROR [E0596]
+ let _y2 = &mut x_mut; // No error
+ }
+
+ { // borrow of static
+ let _y1 = &mut static_x; //~ ERROR [E0596]
+ unsafe { let _y2 = &mut static_x_mut; } // No error
+ }
+
+ { // borrow of deref to box
+ let box_x = Box::new(1);
+ let mut box_x_mut = Box::new(1);
+
+ let _y1 = &mut *box_x; //~ ERROR [E0596]
+ let _y2 = &mut *box_x_mut; // No error
+ }
+
+ { // borrow of deref to reference
+ let ref_x = &x;
+ let ref_x_mut = &mut x_mut;
+
+ let _y1 = &mut *ref_x; //~ ERROR [E0596]
+ let _y2 = &mut *ref_x_mut; // No error
+ }
+
+ { // borrow of deref to pointer
+ let ptr_x : *const _ = &x;
+ let ptr_mut_x : *mut _ = &mut x_mut;
+
+ unsafe {
+ let _y1 = &mut *ptr_x; //~ ERROR [E0596]
+ let _y2 = &mut *ptr_mut_x; // No error
+ }
+ }
+
+ { // borrowing mutably through an immutable reference
+ struct Foo<'a> { f: &'a mut i32, g: &'a i32 };
+ let mut foo = Foo { f: &mut x_mut, g: &x };
+ let foo_ref = &foo;
+ let _y = &mut *foo_ref.f; //~ ERROR [E0596]
+ }
+}