2019-11-11 04:39:52 -06:00
|
|
|
// check-pass
|
|
|
|
|
|
|
|
// Test that `ref` patterns may be used on both sides
|
|
|
|
// of an `@` pattern according to NLL borrowck.
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
struct U; // Not copy!
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
// Promotion:
|
2019-11-11 04:39:52 -06:00
|
|
|
let ref a @ ref b = U;
|
|
|
|
let _: &U = a;
|
|
|
|
let _: &U = b;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
// Prevent promotion:
|
|
|
|
fn u() -> U { U }
|
|
|
|
|
|
|
|
let ref a @ ref b = u();
|
|
|
|
let _: &U = a;
|
|
|
|
let _: &U = b;
|
|
|
|
|
|
|
|
let ref a @ (ref b, [ref c, ref d]) = (u(), [u(), u()]);
|
2019-11-11 04:39:52 -06:00
|
|
|
let _: &(U, [U; 2]) = a;
|
|
|
|
let _: &U = b;
|
|
|
|
let _: &U = c;
|
|
|
|
let _: &U = d;
|
|
|
|
|
2019-12-14 20:50:55 -06:00
|
|
|
fn f1(ref a @ (ref b, [ref c, ref mid @ .., ref d]): (U, [U; 4])) {}
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
let a @ (b, [c, d]) = &(u(), [u(), u()]);
|
2019-11-11 04:39:52 -06:00
|
|
|
let _: &(U, [U; 2]) = a;
|
|
|
|
let _: &U = b;
|
|
|
|
let _: &U = c;
|
|
|
|
let _: &U = d;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
let ref a @ &ref b = &u();
|
2019-11-11 04:39:52 -06:00
|
|
|
let _: &&U = a;
|
|
|
|
let _: &U = b;
|
|
|
|
|
2019-12-14 17:50:44 -06:00
|
|
|
match Ok(u()) {
|
2019-11-11 04:39:52 -06:00
|
|
|
ref a @ Ok(ref b) | ref a @ Err(ref b) => {
|
|
|
|
let _: &Result<U, U> = a;
|
|
|
|
let _: &U = b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|