1
Fork 0

reverse binding order in matches ...

... to allow the subbinding of copyable fields in bindings after `@`

Fixes #69971
This commit is contained in:
Vishnunarayan K I 2020-11-02 00:05:55 +05:30
parent 0d33ab7af4
commit c93d25b6af
21 changed files with 654 additions and 722 deletions

View file

@ -131,7 +131,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
PatKind::Binding { name, mutability, mode, var, ty, ref subpattern, is_primary: _ } => {
candidate.bindings.push(Binding {
// issue #69971: the binding order should be right to left if there are more
// bindings after `@` to please the borrow checker
// Ex
// struct NonCopyStruct {
// copy_field: u32,
// }
//
// fn foo1(x: NonCopyStruct) {
// let y @ NonCopyStruct { copy_field: z } = x;
// // the above should turn into
// let z = x.copy_field;
// let y = x;
// }
candidate.bindings.insert(0, Binding {
name,
mutability,
span: match_pair.pattern.span,