summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs')
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs b/tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs
new file mode 100644
index 000000000..a85335438
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/mut_ref_struct_mem.rs
@@ -0,0 +1,43 @@
+// edition:2021
+// run-pass
+
+// Test that we can mutate a place through a mut-borrow
+// that is captured by the closure
+
+// More specifically we test that the if the mutable reference isn't root variable of a capture
+// but rather accessed while accessing the precise capture.
+
+fn mut_tuple() {
+ let mut t = (10, 10);
+
+ let t1 = (&mut t, 10);
+
+ let mut c = || {
+ // Mutable because (*t.0) is mutable
+ t1.0.0 += 10;
+ };
+
+ c();
+}
+
+fn mut_tuple_nested() {
+ let mut t = (10, 10);
+
+ let t1 = (&mut t, 10);
+
+ let mut c = || {
+ let mut c = || {
+ // Mutable because (*t.0) is mutable
+ t1.0.0 += 10;
+ };
+
+ c();
+ };
+
+ c();
+}
+
+fn main() {
+ mut_tuple();
+ mut_tuple_nested();
+}