Use better spans for cannot-move errors

This commit is contained in:
Matthew Jasper 2018-07-22 21:38:31 +01:00
parent 71637c2937
commit b32caef1ad
5 changed files with 210 additions and 28 deletions

View file

@ -2,25 +2,37 @@ error[E0507]: cannot move out of borrowed content
--> $DIR/issue-20801.rs:36:22
|
LL | let a = unsafe { *mut_ref() };
| ^^^^^^^^^^ cannot move out of borrowed content
| ^^^^^^^^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*mut_ref()`
error[E0507]: cannot move out of borrowed content
--> $DIR/issue-20801.rs:39:22
|
LL | let b = unsafe { *imm_ref() };
| ^^^^^^^^^^ cannot move out of borrowed content
| ^^^^^^^^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*imm_ref()`
error[E0507]: cannot move out of borrowed content
--> $DIR/issue-20801.rs:42:22
|
LL | let c = unsafe { *mut_ptr() };
| ^^^^^^^^^^ cannot move out of borrowed content
| ^^^^^^^^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*mut_ptr()`
error[E0507]: cannot move out of borrowed content
--> $DIR/issue-20801.rs:45:22
|
LL | let d = unsafe { *const_ptr() };
| ^^^^^^^^^^^^ cannot move out of borrowed content
| ^^^^^^^^^^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*const_ptr()`
error: aborting due to 4 previous errors

View file

@ -0,0 +1,85 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:15:15
|
LL | let x = { *r }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:16:22
|
LL | let y = unsafe { *r }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:17:26
|
LL | let z = loop { break *r; }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:21:15
|
LL | let x = { arr[0] }; //~ ERROR
| ^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&arr[0]`
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:22:22
|
LL | let y = unsafe { arr[0] }; //~ ERROR
| ^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&arr[0]`
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:23:26
|
LL | let z = loop { break arr[0]; }; //~ ERROR
| ^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&arr[0]`
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:27:38
|
LL | let x = { let mut u = 0; u += 1; *r }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:28:45
|
LL | let y = unsafe { let mut u = 0; u += 1; *r }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:29:49
|
LL | let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; //~ ERROR
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error: aborting due to 9 previous errors
Some errors occurred: E0507, E0508.
For more information about an error, try `rustc --explain E0507`.

View file

@ -0,0 +1,32 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that the we point to the inner expression when moving out to initialize
// a variable, and that we don't give a useless suggestion such as &{ *r }.
pub fn deref(r: &String) {
let x = { *r }; //~ ERROR
let y = unsafe { *r }; //~ ERROR
let z = loop { break *r; }; //~ ERROR
}
pub fn index(arr: [String; 2]) {
let x = { arr[0] }; //~ ERROR
let y = unsafe { arr[0] }; //~ ERROR
let z = loop { break arr[0]; }; //~ ERROR
}
pub fn additional_statement_cases(r: &String) {
let x = { let mut u = 0; u += 1; *r }; //~ ERROR
let y = unsafe { let mut u = 0; u += 1; *r }; //~ ERROR
let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; //~ ERROR
}
fn main() {}

View file

@ -0,0 +1,58 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:15:15
|
LL | let x = { *r }; //~ ERROR
| ^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:16:22
|
LL | let y = unsafe { *r }; //~ ERROR
| ^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:17:26
|
LL | let z = loop { break *r; }; //~ ERROR
| ^^ cannot move out of borrowed content
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:21:15
|
LL | let x = { arr[0] }; //~ ERROR
| ^^^^^^ cannot move out of here
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:22:22
|
LL | let y = unsafe { arr[0] }; //~ ERROR
| ^^^^^^ cannot move out of here
error[E0508]: cannot move out of type `[std::string::String; 2]`, a non-copy array
--> $DIR/cannot-move-block-spans.rs:23:26
|
LL | let z = loop { break arr[0]; }; //~ ERROR
| ^^^^^^ cannot move out of here
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:27:38
|
LL | let x = { let mut u = 0; u += 1; *r }; //~ ERROR
| ^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:28:45
|
LL | let y = unsafe { let mut u = 0; u += 1; *r }; //~ ERROR
| ^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> $DIR/cannot-move-block-spans.rs:29:49
|
LL | let z = loop { let mut u = 0; u += 1; break *r; u += 2; }; //~ ERROR
| ^^ cannot move out of borrowed content
error: aborting due to 9 previous errors
Some errors occurred: E0507, E0508.
For more information about an error, try `rustc --explain E0507`.