diff options
| author | bors <bors@rust-lang.org> | 2013-07-08 18:49:46 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-07-08 18:49:46 -0700 |
| commit | a48ca3290df992fde2f74ccf5b9f4e36563af8da (patch) | |
| tree | 816142177cf53d6185626aee592ef837b5e1d93a /src/test/run-pass/func-arg-ref-pattern.rs | |
| parent | 30c8aac677a754e0d4ebc16f261618f15d15a6e2 (diff) | |
| parent | 0c6d02f391aa668b2ead91e8a4ed545475ac2c90 (diff) | |
auto merge of #7262 : nikomatsakis/rust/ref-bindings-in-irrefut-patterns, r=catamorphism
Correct treatment of irrefutable patterns. The old code was wrong in many, many ways. `ref` bindings didn't work, it sometimes copied when it should have moved, the borrow checker didn't even look at such patterns at all, we weren't consistent about preventing values with destructors from being pulled apart, etc. Fixes #3224. Fixes #3225. Fixes #3255. Fixes #6225. Fixes #6386. r? @catamorphism
Diffstat (limited to 'src/test/run-pass/func-arg-ref-pattern.rs')
| -rw-r--r-- | src/test/run-pass/func-arg-ref-pattern.rs | 24 |
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); +} |
