summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs')
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs b/tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs
new file mode 100644
index 000000000..81f0328b9
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/capture-disjoint-field-tuple.rs
@@ -0,0 +1,21 @@
+// edition:2021
+// run-pass
+
+// Test that we can immutably borrow an element of a tuple from within a closure,
+// while having a mutable borrow to another element of the same tuple outside the closure.
+
+#![feature(rustc_attrs)]
+
+fn main() {
+ let mut t = (10, 10);
+
+ let c = || {
+ println!("{}", t.0);
+ };
+
+ // `c` only captures t.0, therefore mutating t.1 is allowed.
+ let t1 = &mut t.1;
+
+ c();
+ *t1 = 20;
+}