about summary refs log tree commit diff
path: root/src/test/run-pass/func-arg-ref-pattern.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/run-pass/func-arg-ref-pattern.rs')
-rw-r--r--src/test/run-pass/func-arg-ref-pattern.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/run-pass/func-arg-ref-pattern.rs b/src/test/run-pass/func-arg-ref-pattern.rs
new file mode 100644
index 00000000000..84c2b3acf35
--- /dev/null
+++ b/src/test/run-pass/func-arg-ref-pattern.rs
@@ -0,0 +1,24 @@
+// exec-env:RUST_POISON_ON_FREE=1
+
+// Test argument patterns where we create refs to the inside of `~`
+// boxes. Make sure that we don't free the box as we match the
+// pattern.
+
+fn getaddr(~ref x: ~uint) -> *uint {
+    let addr: *uint = &*x;
+    addr
+}
+
+fn checkval(~ref x: ~uint) -> uint {
+    *x
+}
+
+fn main() {
+    let obj = ~1;
+    let objptr: *uint = &*obj;
+    let xptr = getaddr(obj);
+    assert_eq!(objptr, xptr);
+
+    let obj = ~22;
+    assert_eq!(checkval(obj), 22);
+}