]> git.lizzy.rs Git - rust.git/blob - tests/ui/binding/func-arg-ref-pattern.rs
Auto merge of #101138 - Rejyr:diagnostic-migration-rustc-lint-pt2, r=davidtwco
[rust.git] / tests / ui / binding / func-arg-ref-pattern.rs
1 // run-pass
2
3 // Test argument patterns where we create refs to the inside of
4 // boxes. Make sure that we don't free the box as we match the
5 // pattern.
6
7 #![feature(box_patterns)]
8
9 fn getaddr(box ref x: Box<usize>) -> *const usize {
10     let addr: *const usize = &*x;
11     addr
12 }
13
14 fn checkval(box ref x: Box<usize>) -> usize {
15     *x
16 }
17
18 pub fn main() {
19     let obj: Box<_> = Box::new(1);
20     let objptr: *const usize = &*obj;
21     let xptr = getaddr(obj);
22     assert_eq!(objptr, xptr);
23
24     let obj = Box::new(22);
25     assert_eq!(checkval(obj), 22);
26 }