Rollup merge of #71587 - matthewjasper:promoted-move-errors, r=nikomatsakis

Report cannot move errors in promoted MIR

Closes #70934
This commit is contained in:
Dylan DPC 2020-05-05 01:49:32 +02:00 committed by GitHub
commit 4bde46e0e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 6 deletions

View file

@ -0,0 +1,10 @@
// Regression test for #70934
struct S;
fn foo() {
&([S][0],);
//~^ ERROR cannot move out of type `[S; 1]`
}
fn main() {}

View file

@ -0,0 +1,12 @@
error[E0508]: cannot move out of type `[S; 1]`, a non-copy array
--> $DIR/move-error-in-promoted-2.rs:6:7
|
LL | &([S][0],);
| ^^^^^^
| |
| cannot move out of here
| move occurs because value has type `S`, which does not implement the `Copy` trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0508`.

View file

@ -0,0 +1,17 @@
// Regression test for #70934
fn f() {
const C: [S2; 1] = [S2];
let _ = S1(C[0]).clone();
//~^ ERROR cannot move out of type `[S2; 1]`
}
#[derive(Clone)]
struct S1(S2);
#[derive(Clone)]
struct S2;
fn main() {
f();
}

View file

@ -0,0 +1,12 @@
error[E0508]: cannot move out of type `[S2; 1]`, a non-copy array
--> $DIR/move-error-in-promoted.rs:5:16
|
LL | let _ = S1(C[0]).clone();
| ^^^^
| |
| cannot move out of here
| move occurs because value has type `S2`, which does not implement the `Copy` trait
error: aborting due to previous error
For more information about this error, try `rustc --explain E0508`.