summaryrefslogtreecommitdiffstats
path: root/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.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/issue-55492-borrowck-migrate-scans-parents.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/issue-55492-borrowck-migrate-scans-parents.rs')
-rw-r--r--tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs
new file mode 100644
index 000000000..b3cce1b3a
--- /dev/null
+++ b/tests/ui/borrowck/issue-55492-borrowck-migrate-scans-parents.rs
@@ -0,0 +1,55 @@
+// rust-lang/rust#55492: errors detected during MIR-borrowck's
+// analysis of a closure body may only be caught when AST-borrowck
+// looks at some parent.
+
+// transcribed from borrowck-closures-unique.rs
+mod borrowck_closures_unique {
+ pub fn e(x: &'static mut isize) {
+ static mut Y: isize = 3;
+ let mut c1 = |y: &'static mut isize| x = y;
+ //~^ ERROR is not declared as mutable
+ unsafe { c1(&mut Y); }
+ }
+}
+
+mod borrowck_closures_unique_grandparent {
+ pub fn ee(x: &'static mut isize) {
+ static mut Z: isize = 3;
+ let mut c1 = |z: &'static mut isize| {
+ let mut c2 = |y: &'static mut isize| x = y;
+ //~^ ERROR is not declared as mutable
+ c2(z);
+ };
+ unsafe { c1(&mut Z); }
+ }
+}
+
+// adapted from mutability_errors.rs
+mod mutability_errors {
+ pub fn capture_assign_whole(x: (i32,)) {
+ || { x = (1,); };
+ //~^ ERROR is not declared as mutable
+ }
+ pub fn capture_assign_part(x: (i32,)) {
+ || { x.0 = 1; };
+ //~^ ERROR is not declared as mutable
+ }
+ pub fn capture_reborrow_whole(x: (i32,)) {
+ || { &mut x; };
+ //~^ ERROR is not declared as mutable
+ }
+ pub fn capture_reborrow_part(x: (i32,)) {
+ || { &mut x.0; };
+ //~^ ERROR is not declared as mutable
+ }
+}
+
+fn main() {
+ static mut X: isize = 2;
+ unsafe { borrowck_closures_unique::e(&mut X); }
+
+ mutability_errors::capture_assign_whole((1000,));
+ mutability_errors::capture_assign_part((2000,));
+ mutability_errors::capture_reborrow_whole((3000,));
+ mutability_errors::capture_reborrow_part((4000,));
+}