forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#78638 - vn-ki:bindigs-after-at-issue-69971, r…
…=oli-obk reverse binding order in matches to allow the subbinding of copyable fields in bindings after @ Fixes rust-lang#69971 ### TODO - [x] Regression tests r? `@oli-obk`
- Loading branch information
Showing
22 changed files
with
568 additions
and
595 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// run-pass | ||
|
||
// Test copy | ||
|
||
#![feature(bindings_after_at)] | ||
|
||
struct A { a: i32, b: i32 } | ||
struct B { a: i32, b: C } | ||
struct D { a: i32, d: C } | ||
#[derive(Copy,Clone)] | ||
struct C { c: i32 } | ||
|
||
pub fn main() { | ||
match (A {a: 10, b: 20}) { | ||
x@A {a, b: 20} => { assert!(x.a == 10); assert!(a == 10); } | ||
A {b: _b, ..} => { panic!(); } | ||
} | ||
|
||
let mut x@B {b, ..} = B {a: 10, b: C {c: 20}}; | ||
assert_eq!(x.a, 10); | ||
x.b.c = 30; | ||
assert_eq!(b.c, 20); | ||
let mut y@D {d, ..} = D {a: 10, d: C {c: 20}}; | ||
assert_eq!(y.a, 10); | ||
y.d.c = 30; | ||
assert_eq!(d.c, 20); | ||
|
||
let some_b = Some(B { a: 10, b: C { c: 20 } }); | ||
|
||
// in irrefutable pattern | ||
if let Some(x @ B { b, .. }) = some_b { | ||
assert_eq!(x.b.c, 20); | ||
assert_eq!(b.c, 20); | ||
} else { | ||
unreachable!(); | ||
} | ||
|
||
let some_b = Some(B { a: 10, b: C { c: 20 } }); | ||
|
||
if let Some(x @ B { b: mut b @ C { c }, .. }) = some_b { | ||
assert_eq!(x.b.c, 20); | ||
assert_eq!(b.c, 20); | ||
b.c = 30; | ||
assert_eq!(b.c, 30); | ||
assert_eq!(c, 20); | ||
} else { | ||
unreachable!(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 7 additions & 6 deletions
13
src/test/ui/pattern/bindings-after-at/bind-by-move-no-subbindings-fun-param.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.