Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion compiler/rustc_mir_build/src/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/borrowck/borrowck-move-error-with-note.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0507]: cannot move out of `f.0` which is behind a shared reference
error[E0507]: cannot move out of `f.1` which is behind a shared reference
--> $DIR/borrowck-move-error-with-note.rs:11:11
|
LL | match *f {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as im
--> $DIR/borrowck-slice-pattern-element-loan-slice.rs:25:23
|
LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
| ------------- immutable borrow occurs here
| ------------- immutable borrow occurs here
...
LL | if let [_, _, ref mut from_begin2, ..] = *s {
| ^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL | nop(&[from_begin2, from_end1, from_end3, from_end4]);
| --------- immutable borrow later used here
| --------- immutable borrow later used here

error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-slice-pattern-element-loan-slice.rs:28:26
|
LL | if let [.., _, ref from_end4, ref from_end3, _, ref from_end1] = *s {
| ------------- immutable borrow occurs here
| ------------- immutable borrow occurs here
...
LL | if let [_, _, _, ref mut from_begin3, ..] = *s {
| ^^^^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL | nop(&[from_begin3, from_end1, from_end3, from_end4]);
| --------- immutable borrow later used here
| --------- immutable borrow later used here

error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-slice-pattern-element-loan-slice.rs:33:21
Expand All @@ -75,12 +75,12 @@ error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as im
--> $DIR/borrowck-slice-pattern-element-loan-slice.rs:39:21
|
LL | if let [ref from_begin0, ref from_begin1, _, ref from_begin3, _, ..] = *s {
| --------------- immutable borrow occurs here
| --------------- immutable borrow occurs here
...
LL | if let [.., ref mut from_end4, _, _, _] = *s {
| ^^^^^^^^^^^^^^^^^ mutable borrow occurs here
LL | nop(&[from_begin0, from_begin1, from_begin3, from_end4]);
| ----------- immutable borrow later used here
| ----------- immutable borrow later used here

error[E0502]: cannot borrow `s[..]` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-slice-pattern-element-loan-slice.rs:47:20
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-12567.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
| -- data moved here
LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| --- ...and here
| --- ...and here
|
= note: move occurs because these variables have types that don't implement the `Copy` trait

Expand All @@ -22,7 +22,7 @@ LL | (&[], &[hd, ..]) | (&[hd, ..], &[])
| -- data moved here
LL | => println!("one empty"),
LL | (&[hd1, ..], &[hd2, ..])
| --- ...and here
| --- ...and here
|
= note: move occurs because these variables have types that don't implement the `Copy` trait

Expand Down
24 changes: 12 additions & 12 deletions src/test/ui/nll/move-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,6 @@ LL | B::U(D(s)) => (),
| data moved here
| move occurs because `s` has type `String`, which does not implement the `Copy` trait

error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> $DIR/move-errors.rs:92:11
|
LL | match x {
| ^ cannot move out of here
...
LL | (D(s), &t) => (),
| -
| |
| data moved here
| move occurs because `s` has type `String`, which does not implement the `Copy` trait

error[E0507]: cannot move out of `*x.1` which is behind a shared reference
--> $DIR/move-errors.rs:92:11
|
Expand All @@ -121,6 +109,18 @@ LL | (D(s), &t) => (),
| data moved here
| move occurs because `t` has type `String`, which does not implement the `Copy` trait

error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> $DIR/move-errors.rs:92:11
|
LL | match x {
| ^ cannot move out of here
...
LL | (D(s), &t) => (),
| -
| |
| data moved here
| move occurs because `s` has type `String`, which does not implement the `Copy` trait

error[E0509]: cannot move out of type `F`, which implements the `Drop` trait
--> $DIR/move-errors.rs:102:11
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ fn main() {
let x = Some(X { x: () });
match x {
Some(ref _y @ _z) => {} //~ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
None => panic!(),
}

let x = Some(X { x: () });
match x {
Some(_z @ ref _y) => {}
//~^ ERROR borrow of moved value
//~| ERROR borrow of moved value
None => panic!(),
}

let mut x = Some(X { x: () });
match x {
Some(ref mut _y @ _z) => {} //~ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
None => panic!(),
}

let mut x = Some(X { x: () });
match x {
Some(_z @ ref mut _y) => {}
//~^ ERROR borrow of moved value
//~| ERROR borrow of moved value
None => panic!(),
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | Some(ref _y @ _z) => {}
| value borrowed, by `_y`, here

error: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:20:14
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:21:14
|
LL | Some(_z @ ref _y) => {}
| --^^^------
Expand All @@ -27,7 +27,7 @@ LL | Some(ref mut _y @ _z) => {}
| value borrowed, by `_y`, here

error: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:34:14
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:14
|
LL | Some(_z @ ref mut _y) => {}
| --^^^----------
Expand All @@ -37,34 +37,34 @@ LL | Some(_z @ ref mut _y) => {}
| move occurs because `_z` has type `X` which does not implement the `Copy` trait

error[E0382]: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:20:19
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:14:14
|
LL | Some(_z @ ref _y) => {}
| -----^^^^^^
| | |
| | value borrowed here after move
| value moved here
LL | Some(ref _y @ _z) => {}
| ^^^^^^^^^--
| | |
| | value moved here
| value borrowed here after move
|
= note: move occurs because value has type `X`, which does not implement the `Copy` trait
help: borrow this field in the pattern to avoid moving `x.0`
|
LL | Some(ref _z @ ref _y) => {}
| ^^^
LL | Some(ref _y @ ref _z) => {}
| ^^^

error[E0382]: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:34:19
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:28:14
|
LL | Some(_z @ ref mut _y) => {}
| -----^^^^^^^^^^
| | |
| | value borrowed here after move
| value moved here
LL | Some(ref mut _y @ _z) => {}
| ^^^^^^^^^^^^^--
| | |
| | value moved here
| value borrowed here after move
|
= note: move occurs because value has type `X`, which does not implement the `Copy` trait
help: borrow this field in the pattern to avoid moving `x.0`
|
LL | Some(ref _z @ ref mut _y) => {}
| ^^^
LL | Some(ref mut _y @ ref _z) => {}
| ^^^

error: aborting due to 6 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() {}
struct A(Box<u8>);

fn f(a @ A(u): A) -> Box<u8> {
//~^ ERROR use of moved value
//~^ ERROR use of partially moved value
drop(a);
u
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
error[E0382]: use of moved value
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:9:12
error[E0382]: use of partially moved value
--> $DIR/bind-by-move-no-subbindings-fun-param.rs:9:6
|
LL | fn f(a @ A(u): A) -> Box<u8> {
| ------^-
| ^^^^^^-^
| | |
| | value used here after move
| value moved here
| move occurs because value has type `A`, which does not implement the `Copy` trait
| | value partially moved here
| value used here after partial move
|
= note: partial move occurs because value has type `Box<u8>`, which does not implement the `Copy` trait

error: aborting due to previous error

Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/pattern/bindings-after-at/borrowck-move-and-move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ fn main() {

let a @ b = U; //~ ERROR use of moved value

let a @ (b, c) = (U, U); //~ ERROR use of moved value
let a @ (b, c) = (U, U); //~ ERROR use of partially moved value

let a @ (b, c) = (u(), u()); //~ ERROR use of moved value
let a @ (b, c) = (u(), u()); //~ ERROR use of partially moved value

match Ok(U) {
a @ Ok(b) | a @ Err(b) => {} //~ ERROR use of moved value
//~^ ERROR use of moved value
a @ Ok(b) | a @ Err(b) => {} //~ ERROR use of partially moved value
//~^ ERROR use of partially moved value
}

fn fun(a @ b: U) {} //~ ERROR use of moved value

match [u(), u(), u(), u()] {
xs @ [a, .., b] => {} //~ ERROR use of moved value
xs @ [a, .., b] => {} //~ ERROR use of partially moved value
}

match [u(), u(), u(), u()] {
xs @ [_, ys @ .., _] => {} //~ ERROR use of moved value
xs @ [_, ys @ .., _] => {} //~ ERROR use of partially moved value
}
}
Loading