update tests for migrate mode by default

This commit is contained in:
Matthew Jasper 2019-04-22 08:40:08 +01:00
parent aa6fb6caf9
commit 8eef102270
1356 changed files with 5926 additions and 21932 deletions

View File

@ -4,10 +4,10 @@
// compile-flags: -Z query-dep-graph
#![feature(rustc_attrs)]
#![cfg_attr(rpass1, feature(nll))]
#![cfg_attr(rpass1, feature(abi_unadjusted))]
fn main() {
let mut v = vec![1];
v.push(v[0]);
//[cfail2]~^ ERROR cannot borrow
}
extern "unadjusted" fn foo() {}
//[cfail2]~^ ERROR: unadjusted ABI is an implementation detail and perma-unstable

View File

@ -60,9 +60,11 @@ fn main() {
// goto -> bb16;
// }
// bb12: {
// StorageLive(_8);
// _8 = _2;
// switchInt(move _8) -> [false: bb6, otherwise: bb11];
// _8 = &shallow _1;
// StorageLive(_9);
// _9 = _2;
// FakeRead(ForMatchGuard, _8);
// switchInt(move _9) -> [false: bb6, otherwise: bb11];
// }
// bb13: {
// _3 = const 1i32;
@ -77,7 +79,7 @@ fn main() {
// goto -> bb16;
// }
// bb16: {
// StorageDead(_8);
// StorageDead(_9);
// _0 = ();
// StorageDead(_2);
// StorageDead(_1);

View File

@ -1,6 +1,6 @@
// error-pattern:panic 1
// revisions: ast mir
// revisions: migrate mir
//[mir]compile-flags: -Z borrowck=mir
fn main() {

View File

@ -1,6 +1,3 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(asm)]
#![allow(dead_code)]

View File

@ -1,6 +1,3 @@
// revisions ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(asm)]
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

View File

@ -2,9 +2,6 @@
#![allow(dead_code)]
// Test taken from #45641 (https://github.com/rust-lang/rust/issues/45641)
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
static mut Y: u32 = 0;
unsafe fn should_ok() {

View File

@ -1,6 +1,4 @@
// run-pass
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
// Test file taken from issue 45129 (https://github.com/rust-lang/rust/issues/45129)

View File

@ -1,5 +1,4 @@
// run-pass
// compile-flags: -Z borrowck=mir -Z two-phase-borrows
// This is the "goto example" for why we want two phase borrows.

View File

@ -1,8 +1,4 @@
// run-pass
// revisions: lxl nll
//[lxl]compile-flags: -Z borrowck=mir -Z two-phase-borrows
#![cfg_attr(nll, feature(nll))]
fn main() {
let mut a = 0;

View File

@ -1,8 +1,6 @@
// run-pass
#![allow(unused_assignments)]
#![allow(unused_variables)]
// revisions:lexical nll
#![cfg_attr(nll, feature(nll))]
// ignore-wasm32-bare compiled with panic=abort by default

View File

@ -2,9 +2,6 @@
#![allow(dead_code)]
#![allow(dead_code)]
// revisions:lexical nll
#![cfg_attr(nll, feature(nll))]
#![feature(generators)]
fn bar<'a>() {

View File

@ -1,8 +1,5 @@
// run-pass
// revisions: normal nll
//[nll] compile-flags:-Zborrowck=mir
#![feature(fn_traits,
step_trait,
unboxed_closures,

View File

@ -2,9 +2,9 @@
// This test is bogus (i.e., should be compile-fail) during the period
// where #54986 is implemented and #54987 is *not* implemented. For
// now: just ignore it under nll
// now: just ignore it
//
// ignore-compare-mode-nll
// ignore-test
// This test is checking that the write to `c.0` (which has been moved out of)
// won't overwrite the state in `c2`.

View File

@ -2,9 +2,9 @@
// This test is bogus (i.e., should be compile-fail) during the period
// where #54986 is implemented and #54987 is *not* implemented. For
// now: just ignore it under nll
// now: just ignore it
//
// ignore-compare-mode-nll
// ignore-test
// These are variants of issue-26996.rs. In all cases we are writing
// into a record field that has been moved out of, and ensuring that

View File

@ -4,9 +4,9 @@
// This test is bogus (i.e., should be compile-fail) during the period
// where #54986 is implemented and #54987 is *not* implemented. For
// now: just ignore it under nll
// now: just ignore it
//
// ignore-compare-mode-nll
// ignore-test
// This test is checking that the space allocated for `x.1` does not
// overlap with `y`. (The reason why such a thing happened at one

View File

@ -1,12 +1,13 @@
error[E0597]: `arena` does not live long enough
--> $DIR/dropck-tarena-cycle-checked.rs:116:8
--> $DIR/dropck-tarena-cycle-checked.rs:116:7
|
LL | f(&arena);
| ^^^^^ borrowed value does not live long enough
| ^^^^^^ borrowed value does not live long enough
LL | }
| - `arena` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created
| -
| |
| `arena` dropped here while still borrowed
| borrow might be used here, when `arena` is dropped and runs the `Drop` code for type `arena::TypedArena`
error: aborting due to previous error

View File

@ -1,12 +1,13 @@
error[E0597]: `arena` does not live long enough
--> $DIR/dropck-tarena-unsound-drop.rs:41:8
--> $DIR/dropck-tarena-unsound-drop.rs:41:7
|
LL | f(&arena);
| ^^^^^ borrowed value does not live long enough
| ^^^^^^ borrowed value does not live long enough
LL | }
| - `arena` dropped here while still borrowed
|
= note: values in a scope are dropped in the opposite order they are created
| -
| |
| `arena` dropped here while still borrowed
| borrow might be used here, when `arena` is dropped and runs the `Drop` code for type `arena::TypedArena`
error: aborting due to previous error

View File

@ -1,31 +0,0 @@
error[E0501]: cannot borrow `*a` as mutable because previous closure requires unique access
--> $DIR/E0501.rs:18:23
|
LL | let bar = || {
| -- closure construction occurs here
LL | inside_closure(a)
| - previous borrow occurs due to use of `a` in closure
LL | };
LL | outside_closure_1(a);
| ^ borrow occurs here
...
LL | }
| - borrow from closure ends here
error[E0501]: cannot borrow `*a` as immutable because previous closure requires unique access
--> $DIR/E0501.rs:21:23
|
LL | let bar = || {
| -- closure construction occurs here
LL | inside_closure(a)
| - previous borrow occurs due to use of `a` in closure
...
LL | outside_closure_2(a);
| ^ borrow occurs here
...
LL | }
| - borrow from closure ends here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0501`.

View File

@ -1,31 +0,0 @@
error[E0501]: cannot borrow `*a` as mutable because previous closure requires unique access
--> $DIR/E0501.rs:18:23
|
LL | let bar = || {
| -- closure construction occurs here
LL | inside_closure(a)
| - first borrow occurs due to use of `a` in closure
LL | };
LL | outside_closure_1(a);
| ^ second borrow occurs here
...
LL | drop(bar);
| --- first borrow later used here
error[E0501]: cannot borrow `*a` as immutable because previous closure requires unique access
--> $DIR/E0501.rs:21:23
|
LL | let bar = || {
| -- closure construction occurs here
LL | inside_closure(a)
| - first borrow occurs due to use of `a` in closure
...
LL | outside_closure_2(a);
| ^ second borrow occurs here
...
LL | drop(bar);
| --- first borrow later used here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0501`.

View File

@ -1,7 +1,3 @@
// ignore-tidy-linelength
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
fn inside_closure(x: &mut i32) {
}
@ -15,11 +11,11 @@ fn foo(a: &mut i32) {
let bar = || {
inside_closure(a)
};
outside_closure_1(a); //[ast]~ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
//[mir]~^ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
outside_closure_1(a);
//~^ ERROR cannot borrow `*a` as mutable because previous closure requires unique access
outside_closure_2(a); //[ast]~ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
//[mir]~^ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
outside_closure_2(a);
//~^ ERROR cannot borrow `*a` as immutable because previous closure requires unique access
drop(bar);
}

View File

@ -1,5 +1,5 @@
error[E0501]: cannot borrow `*a` as mutable because previous closure requires unique access
--> $DIR/E0501.rs:18:23
--> $DIR/E0501.rs:14:23
|
LL | let bar = || {
| -- closure construction occurs here
@ -13,7 +13,7 @@ LL | drop(bar);
| --- first borrow later used here
error[E0501]: cannot borrow `*a` as immutable because previous closure requires unique access
--> $DIR/E0501.rs:21:23
--> $DIR/E0501.rs:17:23
|
LL | let bar = || {
| -- closure construction occurs here

View File

@ -1,14 +0,0 @@
error[E0506]: cannot assign to `fancy_num` because it is borrowed
--> $DIR/E0506.rs:11:5
|
LL | let fancy_ref = &fancy_num;
| ---------- borrow of `fancy_num` occurs here
LL | fancy_num = FancyNum { num: 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `fancy_num` occurs here
...
LL | println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
| ------------- borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0506`.

View File

@ -1,11 +0,0 @@
error[E0506]: cannot assign to `fancy_num` because it is borrowed
--> $DIR/E0506.rs:11:5
|
LL | let fancy_ref = &fancy_num;
| --------- borrow of `fancy_num` occurs here
LL | fancy_num = FancyNum { num: 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `fancy_num` occurs here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0506`.

View File

@ -1,6 +1,3 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
struct FancyNum {
num: u8,
}
@ -8,8 +5,7 @@ struct FancyNum {
fn main() {
let mut fancy_num = FancyNum { num: 5 };
let fancy_ref = &fancy_num;
fancy_num = FancyNum { num: 6 }; //[ast]~ ERROR E0506
//[mir]~^ ERROR [E0506]
fancy_num = FancyNum { num: 6 }; //~ ERROR [E0506]
println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
}

View File

@ -1,11 +1,11 @@
error[E0506]: cannot assign to `fancy_num` because it is borrowed
--> $DIR/E0506.rs:11:5
--> $DIR/E0506.rs:8:5
|
LL | let fancy_ref = &fancy_num;
| ---------- borrow of `fancy_num` occurs here
LL | fancy_num = FancyNum { num: 6 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `fancy_num` occurs here
...
LL |
LL | println!("Num: {}, Ref: {}", fancy_num.num, fancy_ref.num);
| ------------- borrow later used here

View File

@ -1,12 +0,0 @@
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
--> $DIR/E0508-fail.rs:8:18
|
LL | let _value = array[0];
| ^^^^^^^^
| |
| cannot move out of here
| help: consider borrowing here: `&array[0]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0508`.

View File

@ -1,12 +0,0 @@
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
--> $DIR/E0508-fail.rs:8:18
|
LL | let _value = array[0];
| ^^^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&array[0]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0508`.

View File

@ -1,12 +0,0 @@
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
--> $DIR/E0508-fail.rs:8:18
|
LL | let _value = array[0];
| ^^^^^^^^
| |
| cannot move out of here
| help: consider borrowing here: `&array[0]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0508`.

View File

@ -1,10 +1,6 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
struct NonCopy;
fn main() {
let array = [NonCopy; 1];
let _value = array[0]; //[ast]~ ERROR [E0508]
//[mir]~^ ERROR [E0508]
let _value = array[0]; //~ ERROR [E0508]
}

View File

@ -1,5 +1,5 @@
error[E0508]: cannot move out of type `[NonCopy; 1]`, a non-copy array
--> $DIR/E0508.rs:5:18
--> $DIR/E0508-fail.rs:5:18
|
LL | let _value = array[0];
| ^^^^^^^^

View File

@ -5,7 +5,7 @@ LL | let _value = array[0];
| ^^^^^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&array[0]`
| help: consider borrowing here: `&array[0]`
error: aborting due to previous error

View File

@ -1,8 +0,0 @@
error[E0594]: cannot assign to immutable static item
--> $DIR/E0594.rs:7:5
|
LL | NUM = 20;
| ^^^^^^^^
error: aborting due to previous error

View File

@ -1,8 +0,0 @@
error[E0594]: cannot assign to immutable static item `NUM`
--> $DIR/E0594.rs:7:5
|
LL | NUM = 20;
| ^^^^^^^^ cannot assign
error: aborting due to previous error

View File

@ -1,9 +1,5 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
static NUM: i32 = 18;
fn main() {
NUM = 20; //[ast]~ ERROR E0594
//[mir]~^ ERROR cannot assign to immutable static item `NUM`
NUM = 20; //~ ERROR cannot assign to immutable static item `NUM`
}

View File

@ -1,5 +1,5 @@
error[E0594]: cannot assign to immutable static item `NUM`
--> $DIR/E0594.rs:7:5
--> $DIR/E0594.rs:4:5
|
LL | NUM = 20;
| ^^^^^^^^ cannot assign

View File

@ -1,11 +0,0 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/E0596.rs:6:13
|
LL | let x = 1;
| - help: consider changing this to be mutable: `mut x`
LL | let y = &mut x;
| ^^^^^^ cannot borrow as mutable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View File

@ -1,11 +0,0 @@
error[E0596]: cannot borrow immutable local variable `x` as mutable
--> $DIR/E0596.rs:6:18
|
LL | let x = 1;
| - help: make this binding mutable: `mut x`
LL | let y = &mut x;
| ^ cannot borrow mutably
error: aborting due to previous error
For more information about this error, try `rustc --explain E0596`.

View File

@ -1,8 +1,4 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
fn main() {
let x = 1;
let y = &mut x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let y = &mut x; //~ ERROR [E0596]
}

View File

@ -1,5 +1,5 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/E0596.rs:6:13
--> $DIR/E0596.rs:3:13
|
LL | let x = 1;
| - help: consider changing this to be mutable: `mut x`

View File

@ -1,18 +0,0 @@
error[E0507]: cannot move out of borrowed content
--> $DIR/access-mode-in-closures.rs:8:15
|
LL | match *s { S(v) => v }
| ^^ - data moved here
| |
| cannot move out of borrowed content
| help: consider removing the `*`: `s`
|
note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not implement the `Copy` trait
--> $DIR/access-mode-in-closures.rs:8:22
|
LL | match *s { S(v) => v }
| ^
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.

View File

@ -2,9 +2,16 @@ error[E0507]: cannot move out of borrowed content
--> $DIR/access-mode-in-closures.rs:8:15
|
LL | match *s { S(v) => v }
| ^^ - hint: to prevent move, use `ref v` or `ref mut v`
| ^^ - data moved here
| |
| cannot move out of borrowed content
| help: consider removing the `*`: `s`
|
note: move occurs because `v` has type `std::vec::Vec<isize>`, which does not implement the `Copy` trait
--> $DIR/access-mode-in-closures.rs:8:22
|
LL | match *s { S(v) => v }
| ^
error: aborting due to previous error

View File

@ -1,14 +0,0 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/asm-out-assign-imm.rs:24:34
|
LL | let x: isize;
| - help: make this binding mutable: `mut x`
LL | x = 1;
| ----- first assignment to `x`
...
LL | asm!("mov $1, $0" : "=r"(x) : "r"(5));
| ^ cannot assign twice to immutable variable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0384`.

View File

@ -1,6 +1,8 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/asm-out-assign-imm.rs:24:34
|
LL | let x: isize;
| - help: make this binding mutable: `mut x`
LL | x = 1;
| ----- first assignment to `x`
...

View File

@ -1,9 +0,0 @@
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/asm-out-read-uninit.rs:25:43
|
LL | asm!("mov $1, $0" : "=r"(x) : "r"(x));
| ^ use of possibly uninitialized `x`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0381`.

View File

@ -8,9 +8,6 @@
// ignore-mips
// ignore-mips64
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(asm)]
fn foo(x: isize) { println!("{}", x); }
@ -23,8 +20,7 @@ pub fn main() {
let x: isize;
unsafe {
asm!("mov $1, $0" : "=r"(x) : "r"(x));
//[ast]~^ ERROR use of possibly uninitialized variable: `x`
//[mir]~^^ ERROR use of possibly uninitialized variable: `x`
//~^ ERROR use of possibly uninitialized variable: `x`
}
foo(x);
}

View File

@ -1,5 +1,5 @@
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/asm-out-read-uninit.rs:25:43
--> $DIR/asm-out-read-uninit.rs:22:43
|
LL | asm!("mov $1, $0" : "=r"(x) : "r"(x));
| ^ use of possibly uninitialized `x`

View File

@ -1,15 +0,0 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/assign-imm-local-twice.rs:11:5
|
LL | let v: isize;
| - help: make this binding mutable: `mut v`
...
LL | v = 1;
| ----- first assignment to `v`
...
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0384`.

View File

@ -1,12 +0,0 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/assign-imm-local-twice.rs:11:5
|
LL | v = 1;
| ----- first assignment to `v`
...
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0384`.

View File

@ -1,17 +1,11 @@
// revisions: ast mir
//[mir]compile-flags: -Zborrowck=mir
fn test() {
let v: isize;
//[mir]~^ HELP make this binding mutable
//[mir]~| SUGGESTION mut v
v = 1; //[ast]~ NOTE first assignment
//[mir]~^ NOTE first assignment
//~^ HELP make this binding mutable
//~| SUGGESTION mut v
v = 1; //~ NOTE first assignment
println!("v={}", v);
v = 2; //[ast]~ ERROR cannot assign twice to immutable variable
//[mir]~^ ERROR cannot assign twice to immutable variable `v`
//[ast]~| NOTE cannot assign twice to immutable
//[mir]~| NOTE cannot assign twice to immutable
v = 2; //~ ERROR cannot assign twice to immutable variable
//~| NOTE cannot assign twice to immutable
println!("v={}", v);
}

View File

@ -1,12 +1,12 @@
error[E0384]: cannot assign twice to immutable variable `v`
--> $DIR/assign-imm-local-twice.rs:11:5
--> $DIR/assign-imm-local-twice.rs:7:5
|
LL | let v: isize;
| - help: make this binding mutable: `mut v`
...
LL | v = 1;
| ----- first assignment to `v`
...
LL | println!("v={}", v);
LL | v = 2;
| ^^^^^ cannot assign twice to immutable variable

View File

@ -1,13 +0,0 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/associated-types-outlives.rs:22:14
|
LL | 's: loop { y = denormalise(&x); break }
| -- borrow of `x` occurs here
LL | drop(x);
| ^ move out of `x` occurs here
LL | return f(y);
| - borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0505`.

View File

@ -2,9 +2,11 @@ error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/associated-types-outlives.rs:22:14
|
LL | 's: loop { y = denormalise(&x); break }
| - borrow of `x` occurs here
| -- borrow of `x` occurs here
LL | drop(x);
| ^ move out of `x` occurs here
LL | return f(y);
| - borrow later used here
error: aborting due to previous error

View File

@ -1,22 +0,0 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/augmented-assignments.rs:16:5
|
LL | x
| - borrow of `x` occurs here
...
LL | x;
| ^ move out of `x` occurs here
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
--> $DIR/augmented-assignments.rs:21:5
|
LL | let y = Int(2);
| - help: consider changing this to be mutable: `mut y`
...
LL | y
| ^ cannot borrow as mutable
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0505, E0596.
For more information about an error, try `rustc --explain E0505`.

View File

@ -10,16 +10,18 @@ impl AddAssign for Int {
fn main() {
let mut x = Int(1);
x //~ error: use of moved value: `x`
//~^ value used here after move
x
//~^ NOTE borrow of `x` occurs here
+=
x; //~ value moved here
x;
//~^ ERROR cannot move out of `x` because it is borrowed
//~| move out of `x` occurs here
let y = Int(2);
//~^ HELP make this binding mutable
//~^ HELP consider changing this to be mutable
//~| SUGGESTION mut y
y //~ error: cannot borrow immutable local variable `y` as mutable
//~| cannot borrow
y //~ ERROR cannot borrow `y` as mutable, as it is not declared as mutable
//~| cannot borrow as mutable
+=
Int(1);
}

View File

@ -1,24 +1,22 @@
error[E0596]: cannot borrow immutable local variable `y` as mutable
--> $DIR/augmented-assignments.rs:21:5
|
LL | let y = Int(2);
| - help: make this binding mutable: `mut y`
...
LL | y
| ^ cannot borrow mutably
error[E0382]: use of moved value: `x`
--> $DIR/augmented-assignments.rs:13:5
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/augmented-assignments.rs:16:5
|
LL | x
| ^ value used here after move
| - borrow of `x` occurs here
...
LL | x;
| - value moved here
| ^ move out of `x` occurs here
error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable
--> $DIR/augmented-assignments.rs:23:5
|
= note: move occurs because `x` has type `Int`, which does not implement the `Copy` trait
LL | let y = Int(2);
| - help: consider changing this to be mutable: `mut y`
...
LL | y
| ^ cannot borrow as mutable
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0382, E0596.
For more information about an error, try `rustc --explain E0382`.
Some errors have detailed explanations: E0505, E0596.
For more information about an error, try `rustc --explain E0505`.

View File

@ -1,11 +0,0 @@
error[E0008]: cannot bind by-move into a pattern guard
--> $DIR/bind-by-move-no-guards.rs:8:14
|
LL | Some(z) if z.recv().unwrap() => { panic!() },
| ^ moves value into pattern guard
|
= help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0008`.

View File

@ -3,6 +3,8 @@ error[E0008]: cannot bind by-move into a pattern guard
|
LL | Some(z) if z.recv().unwrap() => { panic!() },
| ^ moves value into pattern guard
|
= help: add #![feature(bind_by_move_pattern_guards)] to the crate attributes to enable
error: aborting due to previous error

View File

@ -1,253 +0,0 @@
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:7:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs + rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:8:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs + rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:13:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs - rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:14:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs - rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:19:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs * rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:20:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs * rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:25:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs / rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:26:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs / rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:31:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs % rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:32:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs % rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:37:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs & rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:38:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs & rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:43:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs | rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:44:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs | rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:49:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs ^ rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:50:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs ^ rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:55:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs << rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:56:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs << rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:61:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs >> rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:62:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs >> rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
error: aborting due to 20 previous errors
For more information about this error, try `rustc --explain E0382`.

View File

@ -1,212 +1,252 @@
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:7:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs + rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:8:10
|
LL | fn add<A: Add<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs + rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:13:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs - rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:14:10
|
LL | fn sub<A: Sub<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs - rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:19:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs * rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:20:10
|
LL | fn mul<A: Mul<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs * rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:25:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs / rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:26:10
|
LL | fn div<A: Div<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs / rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:31:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs % rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:32:10
|
LL | fn rem<A: Rem<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs % rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:37:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs & rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:38:10
|
LL | fn bitand<A: BitAnd<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs & rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:43:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs | rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:44:10
|
LL | fn bitor<A: BitOr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs | rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:49:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs ^ rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:50:10
|
LL | fn bitxor<A: BitXor<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs ^ rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:55:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs << rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:56:10
|
LL | fn shl<A: Shl<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs << rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `lhs`
--> $DIR/binop-consume-args.rs:61:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs >> rhs;
| --- value moved here
LL | drop(lhs);
| ^^^ value used here after move
|
= note: move occurs because `lhs` has type `A`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `rhs`
--> $DIR/binop-consume-args.rs:62:10
|
LL | fn shr<A: Shr<B, Output=()>, B>(lhs: A, rhs: B) {
| - --- move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | lhs >> rhs;
| --- value moved here
LL | drop(lhs);
LL | drop(rhs);
| ^^^ value used here after move
|
= note: move occurs because `rhs` has type `B`, which does not implement the `Copy` trait
error: aborting due to 20 previous errors

View File

@ -1,95 +0,0 @@
error[E0382]: use of moved value: `x`
--> $DIR/binop-move-semantics.rs:8:5
|
LL | fn double_move<T: Add<Output=()>>(x: T) {
| - - move occurs because `x` has type `T`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | x
| - value moved here
LL | +
LL | x;
| ^ value used here after move
error[E0382]: borrow of moved value: `x`
--> $DIR/binop-move-semantics.rs:14:5
|
LL | fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
| - - move occurs because `x` has type `T`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | x
| - value moved here
LL | +
LL | x.clone();
| ^ value borrowed here after move
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/binop-move-semantics.rs:21:5
|
LL | let m = &x;
| -- borrow of `x` occurs here
...
LL | x
| ^ move out of `x` occurs here
...
LL | use_mut(n); use_imm(m);
| - borrow later used here
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/binop-move-semantics.rs:23:5
|
LL | let n = &mut y;
| ------ borrow of `y` occurs here
...
LL | y;
| ^ move out of `y` occurs here
LL | use_mut(n); use_imm(m);
| - borrow later used here
error[E0507]: cannot move out of borrowed content
--> $DIR/binop-move-semantics.rs:30:5
|
LL | *m
| ^^ cannot move out of borrowed content
error[E0507]: cannot move out of borrowed content
--> $DIR/binop-move-semantics.rs:32:5
|
LL | *n;
| ^^ cannot move out of borrowed content
error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/binop-move-semantics.rs:54:5
|
LL | &mut f
| ------
| |
| _____mutable borrow occurs here
| |
LL | | +
LL | | &f;
| | ^-
| |_____||
| |mutable borrow later used here
| immutable borrow occurs here
error[E0502]: cannot borrow `f` as mutable because it is also borrowed as immutable
--> $DIR/binop-move-semantics.rs:62:5
|
LL | &f
| --
| |
| _____immutable borrow occurs here
| |
LL | | +
LL | | &mut f;
| | ^^^^^-
| |_____|____|
| | immutable borrow later used here
| mutable borrow occurs here
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0382, E0502, E0505, E0507.
For more information about an error, try `rustc --explain E0382`.

View File

@ -11,7 +11,7 @@ fn double_move<T: Add<Output=()>>(x: T) {
fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
x
+
x.clone(); //~ ERROR: use of moved value
x.clone(); //~ ERROR: borrow of moved value
}
fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {

View File

@ -1,42 +1,51 @@
error[E0382]: use of moved value: `x`
--> $DIR/binop-move-semantics.rs:8:5
|
LL | fn double_move<T: Add<Output=()>>(x: T) {
| - - move occurs because `x` has type `T`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | x
| - value moved here
LL | +
LL | x;
| ^ value used here after move
|
= note: move occurs because `x` has type `T`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x`
error[E0382]: borrow of moved value: `x`
--> $DIR/binop-move-semantics.rs:14:5
|
LL | fn move_then_borrow<T: Add<Output=()> + Clone>(x: T) {
| - - move occurs because `x` has type `T`, which does not implement the `Copy` trait
| |
| consider adding a `Copy` constraint to this type argument
LL | x
| - value moved here
LL | +
LL | x.clone();
| ^ value used here after move
|
= note: move occurs because `x` has type `T`, which does not implement the `Copy` trait
| ^ value borrowed here after move
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/binop-move-semantics.rs:21:5
|
LL | let m = &x;
| - borrow of `x` occurs here
| -- borrow of `x` occurs here
...
LL | x
| ^ move out of `x` occurs here
...
LL | use_mut(n); use_imm(m);
| - borrow later used here
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/binop-move-semantics.rs:23:5
|
LL | let n = &mut y;
| - borrow of `y` occurs here
| ------ borrow of `y` occurs here
...
LL | y;
| ^ move out of `y` occurs here
LL | use_mut(n); use_imm(m);
| - borrow later used here
error[E0507]: cannot move out of borrowed content
--> $DIR/binop-move-semantics.rs:30:5
@ -51,28 +60,34 @@ LL | *n;
| ^^ cannot move out of borrowed content
error[E0502]: cannot borrow `f` as immutable because it is also borrowed as mutable
--> $DIR/binop-move-semantics.rs:54:6
--> $DIR/binop-move-semantics.rs:54:5
|
LL | &mut f
| - mutable borrow occurs here
LL | +
LL | &f;
| ^
| |
| immutable borrow occurs here
| mutable borrow ends here
LL | &mut f
| ------
| |
| _____mutable borrow occurs here
| |
LL | | +
LL | | &f;
| | ^-
| |_____||
| |mutable borrow later used here
| immutable borrow occurs here
error[E0502]: cannot borrow `f` as mutable because it is also borrowed as immutable
--> $DIR/binop-move-semantics.rs:62:10
--> $DIR/binop-move-semantics.rs:62:5
|
LL | &f
| - immutable borrow occurs here
LL | +
LL | &mut f;
| ^
| |
| mutable borrow occurs here
| immutable borrow ends here
LL | &f
| --
| |
| _____immutable borrow occurs here
| |
LL | | +
LL | | &mut f;
| | ^^^^^-
| |_____|____|
| | immutable borrow later used here
| mutable borrow occurs here
error: aborting due to 8 previous errors

View File

@ -1,15 +0,0 @@
error[E0381]: assign to part of possibly uninitialized variable: `x`
--> $DIR/assign_mutable_fields.rs:9:5
|
LL | x.0 = 1;
| ^^^^^^^ use of possibly uninitialized `x`
error[E0381]: assign to part of possibly uninitialized variable: `x`
--> $DIR/assign_mutable_fields.rs:17:5
|
LL | x.0 = 1;
| ^^^^^^^ use of possibly uninitialized `x`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0381`.

View File

@ -1,22 +1,22 @@
// Currently, we permit you to assign to individual fields of a mut
// var, but we do not permit you to use the complete var afterwards.
// Currently, we do permit you to assign to individual fields of an
// uninitialized var.
// We hope to fix this at some point.
//
// FIXME(#54987)
fn assign_both_fields_and_use() {
let mut x: (u32, u32);
x.0 = 1;
x.0 = 1; //~ ERROR
x.1 = 22;
drop(x.0); //~ ERROR
drop(x.1); //~ ERROR
drop(x.0);
drop(x.1);
}
fn assign_both_fields_the_use_var() {
let mut x: (u32, u32);
x.0 = 1;
x.0 = 1; //~ ERROR
x.1 = 22;
drop(x); //~ ERROR
drop(x);
}
fn main() { }

View File

@ -1,21 +1,15 @@
error[E0381]: use of possibly uninitialized variable: `x.0`
--> $DIR/assign_mutable_fields.rs:11:10
error[E0381]: assign to part of possibly uninitialized variable: `x`
--> $DIR/assign_mutable_fields.rs:9:5
|
LL | drop(x.0);
| ^^^ use of possibly uninitialized `x.0`
LL | x.0 = 1;
| ^^^^^^^ use of possibly uninitialized `x`
error[E0381]: use of possibly uninitialized variable: `x.1`
--> $DIR/assign_mutable_fields.rs:12:10
error[E0381]: assign to part of possibly uninitialized variable: `x`
--> $DIR/assign_mutable_fields.rs:17:5
|
LL | drop(x.1);
| ^^^ use of possibly uninitialized `x.1`
LL | x.0 = 1;
| ^^^^^^^ use of possibly uninitialized `x`
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/assign_mutable_fields.rs:19:10
|
LL | drop(x);
| ^ use of possibly uninitialized `x`
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0381`.

View File

@ -1,75 +0,0 @@
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:15:27
|
LL | let _f = to_fn(|| x = 42);
| ^^^^^^ cannot assign
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:15:24
|
LL | let _f = to_fn(|| x = 42);
| ^^^^^^^^^
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:18:31
|
LL | let _g = to_fn(|| set(&mut y));
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:18:24
|
LL | let _g = to_fn(|| set(&mut y));
| ^^^^^^^^^^^^^^
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:21:55
|
LL | let _h = to_fn_mut(|| { set(&mut z); to_fn(|| z = 42); });
| ^^^^^^ cannot assign
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:21:52
|
LL | let _h = to_fn_mut(|| { set(&mut z); to_fn(|| z = 42); });
| ^^^^^^^^^
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:27:32
|
LL | let _f = to_fn(move || x = 42);
| ^^^^^^ cannot assign
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:27:24
|
LL | let _f = to_fn(move || x = 42);
| ^^^^^^^^^^^^^^
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:30:36
|
LL | let _g = to_fn(move || set(&mut y));
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:30:24
|
LL | let _g = to_fn(move || set(&mut y));
| ^^^^^^^^^^^^^^^^^^^
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:33:65
|
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
| ^^^^^^ cannot assign
|
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:33:57
|
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
| ^^^^^^^^^^^^^^
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0596`.

View File

@ -1,72 +1,70 @@
error[E0387]: cannot assign to data in a captured outer variable in an `Fn` closure
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:15:27
|
LL | let _f = to_fn(|| x = 42);
| ^^^^^^
| ^^^^^^ cannot assign
|
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:15:24
|
LL | let _f = to_fn(|| x = 42);
| ^^^^^^^^^
error[E0387]: cannot borrow data mutably in a captured outer variable in an `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:18:36
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:18:31
|
LL | let _g = to_fn(|| set(&mut y));
| ^
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:18:24
|
LL | let _g = to_fn(|| set(&mut y));
| ^^^^^^^^^^^^^^
error[E0387]: cannot assign to data in a captured outer variable in an `Fn` closure
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:21:55
|
LL | let _h = to_fn_mut(|| { set(&mut z); to_fn(|| z = 42); });
| ^^^^^^
| ^^^^^^ cannot assign
|
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:21:52
|
LL | let _h = to_fn_mut(|| { set(&mut z); to_fn(|| z = 42); });
| ^^^^^^^^^
error[E0594]: cannot assign to captured outer variable in an `Fn` closure
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:27:32
|
LL | let _f = to_fn(move || x = 42);
| ^^^^^^
| ^^^^^^ cannot assign
|
= note: `Fn` closures cannot capture their enclosing environment for modifications
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:27:24
|
LL | let _f = to_fn(move || x = 42);
| ^^^^^^^^^^^^^^
error[E0596]: cannot borrow captured outer variable in an `Fn` closure as mutable
--> $DIR/borrow-immutable-upvar-mutation.rs:30:41
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:30:36
|
LL | let _g = to_fn(move || set(&mut y));
| ^
| ^^^^^^ cannot borrow as mutable
|
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:30:24
|
LL | let _g = to_fn(move || set(&mut y));
| ^^^^^^^^^^^^^^^^^^^
error[E0594]: cannot assign to captured outer variable in an `Fn` closure
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
--> $DIR/borrow-immutable-upvar-mutation.rs:33:65
|
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
| ^^^^^^
| ^^^^^^ cannot assign
|
= note: `Fn` closures cannot capture their enclosing environment for modifications
help: consider changing this closure to take self by mutable reference
help: consider changing this to accept closures that implement `FnMut`
--> $DIR/borrow-immutable-upvar-mutation.rs:33:57
|
LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); });
@ -74,5 +72,4 @@ LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); })
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0387, E0596.
For more information about an error, try `rustc --explain E0387`.
For more information about this error, try `rustc --explain E0596`.

View File

@ -1,65 +0,0 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:12:13
|
LL | let r = &x.0;
| ---- borrow of `x.0` occurs here
LL | let y = x;
| ^ move out of `x` occurs here
LL |
LL | r.use_ref();
| - borrow later used here
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:18:13
|
LL | let a = &x.0;
| ---- immutable borrow occurs here
LL | let b = &mut x.0;
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - immutable borrow later used here
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:23:13
|
LL | let a = &mut x.0;
| -------- first mutable borrow occurs here
LL | let b = &mut x.0;
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_ref();
| - first borrow later used here
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:28:13
|
LL | let r = &x.0;
| ---- borrow of `x.0` occurs here
LL | let y = x;
| ^ move out of `x` occurs here
LL | r.use_ref();
| - borrow later used here
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:33:13
|
LL | let a = &x.0;
| ---- immutable borrow occurs here
LL | let b = &mut x.0;
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - immutable borrow later used here
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:38:13
|
LL | let a = &mut x.0;
| -------- first mutable borrow occurs here
LL | let b = &mut x.0;
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_mut();
| - first borrow later used here
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0499, E0502, E0505.
For more information about an error, try `rustc --explain E0499`.

View File

@ -1,62 +1,63 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:12:9
--> $DIR/borrow-tuple-fields.rs:12:13
|
LL | let r = &x.0;
| --- borrow of `x.0` occurs here
| ---- borrow of `x.0` occurs here
LL | let y = x;
| ^ move out of `x` occurs here
| ^ move out of `x` occurs here
LL |
LL | r.use_ref();
| - borrow later used here
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:18:18
--> $DIR/borrow-tuple-fields.rs:18:13
|
LL | let a = &x.0;
| --- immutable borrow occurs here
| ---- immutable borrow occurs here
LL | let b = &mut x.0;
| ^^^ mutable borrow occurs here
...
LL | }
| - immutable borrow ends here
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - immutable borrow later used here
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:23:18
--> $DIR/borrow-tuple-fields.rs:23:13
|
LL | let a = &mut x.0;
| --- first mutable borrow occurs here
| -------- first mutable borrow occurs here
LL | let b = &mut x.0;
| ^^^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_ref();
| - first borrow later used here
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/borrow-tuple-fields.rs:28:9
--> $DIR/borrow-tuple-fields.rs:28:13
|
LL | let r = &x.0;
| --- borrow of `x.0` occurs here
| ---- borrow of `x.0` occurs here
LL | let y = x;
| ^ move out of `x` occurs here
| ^ move out of `x` occurs here
LL | r.use_ref();
| - borrow later used here
error[E0502]: cannot borrow `x.0` as mutable because it is also borrowed as immutable
--> $DIR/borrow-tuple-fields.rs:33:18
--> $DIR/borrow-tuple-fields.rs:33:13
|
LL | let a = &x.0;
| --- immutable borrow occurs here
| ---- immutable borrow occurs here
LL | let b = &mut x.0;
| ^^^ mutable borrow occurs here
...
LL | }
| - immutable borrow ends here
| ^^^^^^^^ mutable borrow occurs here
LL | a.use_ref();
| - immutable borrow later used here
error[E0499]: cannot borrow `x.0` as mutable more than once at a time
--> $DIR/borrow-tuple-fields.rs:38:18
--> $DIR/borrow-tuple-fields.rs:38:13
|
LL | let a = &mut x.0;
| --- first mutable borrow occurs here
| -------- first mutable borrow occurs here
LL | let b = &mut x.0;
| ^^^ second mutable borrow occurs here
| ^^^^^^^^ second mutable borrow occurs here
LL | a.use_mut();
LL | }
| - first borrow ends here
| - first borrow later used here
error: aborting due to 6 previous errors

View File

@ -1,53 +0,0 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:12:19
|
LL | let x = 1;
| - help: consider changing this to be mutable: `mut x`
...
LL | let _y1 = &mut x;
| ^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable static item `static_x` as mutable
--> $DIR/borrowck-access-permissions.rs:18:19
|
LL | let _y1 = &mut static_x;
| ^^^^^^^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `*box_x` as mutable, as `box_x` is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:27:19
|
LL | let box_x = Box::new(1);
| ----- help: consider changing this to be mutable: `mut box_x`
...
LL | let _y1 = &mut *box_x;
| ^^^^^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:36:19
|
LL | let ref_x = &x;
| -- help: consider changing this to be a mutable reference: `&mut x`
...
LL | let _y1 = &mut *ref_x;
| ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrowck-access-permissions.rs:46:23
|
LL | let ptr_x : *const _ = &x;
| -- help: consider changing this to be a mutable pointer: `&mut x`
...
LL | let _y1 = &mut *ptr_x;
| ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:56:18
|
LL | let foo_ref = &foo;
| ---- help: consider changing this to be a mutable reference: `&mut foo`
LL | let _y = &mut *foo_ref.f;
| ^^^^^^^^^^^^^^^ `foo_ref` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0596`.

View File

@ -1,46 +0,0 @@
error[E0596]: cannot borrow immutable local variable `x` as mutable
--> $DIR/borrowck-access-permissions.rs:12:24
|
LL | let x = 1;
| - help: make this binding mutable: `mut x`
...
LL | let _y1 = &mut x;
| ^ cannot borrow mutably
error[E0596]: cannot borrow immutable static item as mutable
--> $DIR/borrowck-access-permissions.rs:18:24
|
LL | let _y1 = &mut static_x;
| ^^^^^^^^
error[E0596]: cannot borrow immutable `Box` content `*box_x` as mutable
--> $DIR/borrowck-access-permissions.rs:27:24
|
LL | let box_x = Box::new(1);
| ----- help: make this binding mutable: `mut box_x`
...
LL | let _y1 = &mut *box_x;
| ^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable borrowed content `*ref_x` as mutable
--> $DIR/borrowck-access-permissions.rs:36:24
|
LL | let _y1 = &mut *ref_x;
| ^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable dereference of raw pointer `*ptr_x` as mutable
--> $DIR/borrowck-access-permissions.rs:46:28
|
LL | let _y1 = &mut *ptr_x;
| ^^^^^^ cannot borrow as mutable
error[E0389]: cannot borrow data mutably in a `&` reference
--> $DIR/borrowck-access-permissions.rs:56:23
|
LL | let _y = &mut *foo_ref.f;
| ^^^^^^^^^^ assignment into an immutable reference
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0389, E0596.
For more information about an error, try `rustc --explain E0389`.

View File

@ -1,6 +1,3 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
static static_x : i32 = 1;
static mut static_x_mut : i32 = 1;
@ -9,14 +6,12 @@ fn main() {
let mut x_mut = 1;
{ // borrow of local
let _y1 = &mut x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let _y1 = &mut x; //~ ERROR [E0596]
let _y2 = &mut x_mut; // No error
}
{ // borrow of static
let _y1 = &mut static_x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let _y1 = &mut static_x; //~ ERROR [E0596]
unsafe { let _y2 = &mut static_x_mut; } // No error
}
@ -24,8 +19,7 @@ fn main() {
let box_x = Box::new(1);
let mut box_x_mut = Box::new(1);
let _y1 = &mut *box_x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let _y1 = &mut *box_x; //~ ERROR [E0596]
let _y2 = &mut *box_x_mut; // No error
}
@ -33,8 +27,7 @@ fn main() {
let ref_x = &x;
let ref_x_mut = &mut x_mut;
let _y1 = &mut *ref_x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let _y1 = &mut *ref_x; //~ ERROR [E0596]
let _y2 = &mut *ref_x_mut; // No error
}
@ -43,8 +36,7 @@ fn main() {
let ptr_mut_x : *mut _ = &mut x_mut;
unsafe {
let _y1 = &mut *ptr_x; //[ast]~ ERROR [E0596]
//[mir]~^ ERROR [E0596]
let _y1 = &mut *ptr_x; //~ ERROR [E0596]
let _y2 = &mut *ptr_mut_x; // No error
}
}
@ -53,8 +45,6 @@ fn main() {
struct Foo<'a> { f: &'a mut i32, g: &'a i32 };
let mut foo = Foo { f: &mut x_mut, g: &x };
let foo_ref = &foo;
let _y = &mut *foo_ref.f; //[ast]~ ERROR [E0389]
//[mir]~^ ERROR [E0596]
// FIXME: Wrong error in MIR
let _y = &mut *foo_ref.f; //~ ERROR [E0596]
}
}

View File

@ -1,5 +1,5 @@
error[E0596]: cannot borrow `x` as mutable, as it is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:12:19
--> $DIR/borrowck-access-permissions.rs:9:19
|
LL | let x = 1;
| - help: consider changing this to be mutable: `mut x`
@ -8,13 +8,13 @@ LL | let _y1 = &mut x;
| ^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable static item `static_x` as mutable
--> $DIR/borrowck-access-permissions.rs:18:19
--> $DIR/borrowck-access-permissions.rs:14:19
|
LL | let _y1 = &mut static_x;
| ^^^^^^^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `*box_x` as mutable, as `box_x` is not declared as mutable
--> $DIR/borrowck-access-permissions.rs:27:19
--> $DIR/borrowck-access-permissions.rs:22:19
|
LL | let box_x = Box::new(1);
| ----- help: consider changing this to be mutable: `mut box_x`
@ -23,7 +23,7 @@ LL | let _y1 = &mut *box_x;
| ^^^^^^^^^^^ cannot borrow as mutable
error[E0596]: cannot borrow `*ref_x` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:36:19
--> $DIR/borrowck-access-permissions.rs:30:19
|
LL | let ref_x = &x;
| -- help: consider changing this to be a mutable reference: `&mut x`
@ -32,7 +32,7 @@ LL | let _y1 = &mut *ref_x;
| ^^^^^^^^^^^ `ref_x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` pointer
--> $DIR/borrowck-access-permissions.rs:46:23
--> $DIR/borrowck-access-permissions.rs:39:23
|
LL | let ptr_x : *const _ = &x;
| -- help: consider changing this to be a mutable pointer: `&mut x`
@ -41,7 +41,7 @@ LL | let _y1 = &mut *ptr_x;
| ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
error[E0596]: cannot borrow `*foo_ref.f` as mutable, as it is behind a `&` reference
--> $DIR/borrowck-access-permissions.rs:56:18
--> $DIR/borrowck-access-permissions.rs:48:18
|
LL | let foo_ref = &foo;
| ---- help: consider changing this to be a mutable reference: `&mut foo`

View File

@ -1,9 +0,0 @@
error[E0381]: borrow of possibly uninitialized variable: `i`
--> $DIR/borrowck-and-init.rs:5:20
|
LL | println!("{}", i);
| ^ use of possibly uninitialized `i`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0381`.

View File

@ -2,5 +2,5 @@ fn main() {
let i: isize;
println!("{}", false && { i = 5; true });
println!("{}", i); //~ ERROR use of possibly uninitialized variable: `i`
println!("{}", i); //~ ERROR borrow of possibly uninitialized variable: `i`
}

View File

@ -1,4 +1,4 @@
error[E0381]: use of possibly uninitialized variable: `i`
error[E0381]: borrow of possibly uninitialized variable: `i`
--> $DIR/borrowck-and-init.rs:5:20
|
LL | println!("{}", i);

View File

@ -1,15 +0,0 @@
error[E0499]: cannot borrow `y.0` as mutable more than once at a time
--> $DIR/borrowck-anon-fields-struct.rs:29:11
|
LL | Y(ref mut a, _) => a
| --------- first mutable borrow occurs here
...
LL | Y(ref mut b, _) => b
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0499`.

View File

@ -7,8 +7,8 @@ LL | Y(ref mut a, _) => a
LL | Y(ref mut b, _) => b
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to previous error

View File

@ -1,15 +0,0 @@
error[E0499]: cannot borrow `y.0` as mutable more than once at a time
--> $DIR/borrowck-anon-fields-tuple.rs:27:10
|
LL | (ref mut a, _) => a
| --------- first mutable borrow occurs here
...
LL | (ref mut b, _) => b
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to previous error
For more information about this error, try `rustc --explain E0499`.

View File

@ -7,8 +7,8 @@ LL | (ref mut a, _) => a
LL | (ref mut b, _) => b
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to previous error

View File

@ -1,43 +0,0 @@
warning[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:17:7
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
...
LL | Foo::Y(_, ref mut b) => b,
| ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
...
LL | *a += 1;
| ------- borrow later used here
|
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
error[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:34:7
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
...
LL | Foo::Y(ref mut b, _) => b,
| ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
...
LL | *a += 1;
| ------- borrow later used here
error[E0499]: cannot borrow `y.0` as mutable more than once at a time
--> $DIR/borrowck-anon-fields-variant.rs:34:14
|
LL | Foo::Y(ref mut a, _) => a,
| --------- first mutable borrow occurs here
...
LL | Foo::Y(ref mut b, _) => b,
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0499, E0503.
For more information about an error, try `rustc --explain E0499`.

View File

@ -1,6 +1,3 @@
// Tests that we are able to distinguish when loans borrow different
// anonymous fields of an enum variant vs the same anonymous field.
enum Foo {
X, Y(usize, usize)
}
@ -13,8 +10,14 @@ fn distinct_variant() {
Foo::X => panic!()
};
// While `a` and `b` are disjoint, borrowck doesn't know that `a` is not
// also used for the discriminant of `Foo`, which it would be if `a` was a
// reference.
let b = match y {
Foo::Y(_, ref mut b) => b,
//~^ WARNING cannot use `y`
//~| WARNING this error has been downgraded to a warning
//~| WARNING this warning will become a hard error in the future
Foo::X => panic!()
};
@ -31,7 +34,8 @@ fn same_variant() {
};
let b = match y {
Foo::Y(ref mut b, _) => b, //~ ERROR cannot borrow
Foo::Y(ref mut b, _) => b, //~ ERROR cannot use `y`
//~| ERROR cannot borrow `y.0` as mutable
Foo::X => panic!()
};

View File

@ -1,5 +1,32 @@
warning[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:17:7
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
...
LL | Foo::Y(_, ref mut b) => b,
| ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
...
LL | *a += 1;
| ------- borrow later used here
|
= warning: this error has been downgraded to a warning for backwards compatibility with previous releases
= warning: this represents potential undefined behavior in your code and this warning will become a hard error in the future
error[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:37:7
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
...
LL | Foo::Y(ref mut b, _) => b,
| ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0`
...
LL | *a += 1;
| ------- borrow later used here
error[E0499]: cannot borrow `y.0` as mutable more than once at a time
--> $DIR/borrowck-anon-fields-variant.rs:34:14
--> $DIR/borrowck-anon-fields-variant.rs:37:14
|
LL | Foo::Y(ref mut a, _) => a,
| --------- first mutable borrow occurs here
@ -7,9 +34,10 @@ LL | Foo::Y(ref mut a, _) => a,
LL | Foo::Y(ref mut b, _) => b,
| ^^^^^^^^^ second mutable borrow occurs here
...
LL | }
| - first borrow ends here
LL | *a += 1;
| ------- first borrow later used here
error: aborting due to previous error
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0499`.
Some errors have detailed explanations: E0499, E0503.
For more information about an error, try `rustc --explain E0499`.

View File

@ -1,35 +0,0 @@
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:10:5
|
LL | fn func(arg: S) {
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:15:9
|
LL | fn method(&self, arg: S) {
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:21:9
|
LL | fn default(&self, arg: S) {
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:32:17
|
LL | (|arg: S| { arg.mutate() })(s);
| --- ^^^ cannot borrow as mutable
| |
| help: consider changing this to be mutable: `mut arg`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0596`.

View File

@ -7,18 +7,18 @@ impl S {
}
fn func(arg: S) {
arg.mutate(); //~ ERROR: cannot borrow immutable argument
arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
}
impl S {
fn method(&self, arg: S) {
arg.mutate(); //~ ERROR: cannot borrow immutable argument
arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
}
}
trait T {
fn default(&self, arg: S) {
arg.mutate(); //~ ERROR: cannot borrow immutable argument
arg.mutate(); //~ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
}
}
@ -29,5 +29,6 @@ fn main() {
func(s);
s.method(s);
s.default(s);
(|arg: S| { arg.mutate() })(s); //~ ERROR: cannot borrow immutable argument
(|arg: S| { arg.mutate() })(s);
//~^ ERROR: cannot borrow `arg` as mutable, as it is not declared as mutable
}

View File

@ -1,34 +1,34 @@
error[E0596]: cannot borrow immutable argument `arg` as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:10:5
|
LL | fn func(arg: S) {
| --- help: make this binding mutable: `mut arg`
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow mutably
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable argument `arg` as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:15:9
|
LL | fn method(&self, arg: S) {
| --- help: make this binding mutable: `mut arg`
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow mutably
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable argument `arg` as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:21:9
|
LL | fn default(&self, arg: S) {
| --- help: make this binding mutable: `mut arg`
| --- help: consider changing this to be mutable: `mut arg`
LL | arg.mutate();
| ^^^ cannot borrow mutably
| ^^^ cannot borrow as mutable
error[E0596]: cannot borrow immutable argument `arg` as mutable
error[E0596]: cannot borrow `arg` as mutable, as it is not declared as mutable
--> $DIR/borrowck-argument.rs:32:17
|
LL | (|arg: S| { arg.mutate() })(s);
| --- ^^^ cannot borrow mutably
| --- ^^^ cannot borrow as mutable
| |
| help: make this binding mutable: `mut arg`
| help: consider changing this to be mutable: `mut arg`
error: aborting due to 4 previous errors

View File

@ -1,76 +0,0 @@
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:27:13
|
LL | asm!("nop" : : "r"(x));
| - value moved here
LL | }
LL | let z = x;
| ^ value used here after move
|
= note: move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait
error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/borrowck-asm.rs:35:32
|
LL | let y = &mut x;
| - borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : : "r"(x));
| ^ use of borrowed `x`
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:44:31
|
LL | let x = 3;
| - first assignment to `x`
LL | unsafe {
LL | asm!("nop" : "=r"(x));
| ^ cannot assign twice to immutable variable
error[E0506]: cannot assign to `a` because it is borrowed
--> $DIR/borrowck-asm.rs:50:31
|
LL | let b = &*a;
| -- borrow of `a` occurs here
LL | unsafe {
LL | asm!("nop" : "=r"(a));
| ^ assignment to borrowed `a` occurs here
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:60:31
|
LL | let x = 3;
| - first assignment to `x`
LL | unsafe {
LL | asm!("nop" : "+r"(x));
| ^ cannot assign twice to immutable variable
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/borrowck-asm.rs:68:32
|
LL | asm!("nop" : "=*r"(x));
| ^ use of possibly uninitialized `x`
error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/borrowck-asm.rs:77:31
|
LL | let y = &*x;
| -- borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : "+r"(x));
| ^ assignment to borrowed `x` occurs here
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:86:40
|
LL | asm!("nop" : : "r"(x), "r"(x) );
| - ^ value used here after move
| |
| value moved here
|
= note: move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
error: aborting due to 8 previous errors
Some errors have detailed explanations: E0381, E0382, E0384, E0503, E0506.
For more information about an error, try `rustc --explain E0381`.

View File

@ -1,81 +0,0 @@
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:27:17
|
LL | let x = &mut 0isize;
| - move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait
LL | unsafe {
LL | asm!("nop" : : "r"(x));
| - value moved here
LL | }
LL | let z = x;
| ^ value used here after move
error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/borrowck-asm.rs:35:32
|
LL | let y = &mut x;
| ------ borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : : "r"(x));
| ^ use of borrowed `x`
...
LL | let z = y;
| - borrow later used here
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:44:31
|
LL | let x = 3;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
LL | unsafe {
LL | asm!("nop" : "=r"(x));
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:60:31
|
LL | let x = 3;
| -
| |
| first assignment to `x`
| help: make this binding mutable: `mut x`
LL | unsafe {
LL | asm!("nop" : "+r"(x));
| ^ cannot assign twice to immutable variable
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/borrowck-asm.rs:68:32
|
LL | asm!("nop" : "=*r"(x));
| ^ use of possibly uninitialized `x`
error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/borrowck-asm.rs:77:31
|
LL | let y = &*x;
| --- borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : "+r"(x));
| ^ assignment to borrowed `x` occurs here
...
LL | let z = y;
| - borrow later used here
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:86:40
|
LL | let x = &mut 2;
| - move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait
LL | unsafe {
LL | asm!("nop" : : "r"(x), "r"(x) );
| - ^ value used here after move
| |
| value moved here
error: aborting due to 7 previous errors
Some errors have detailed explanations: E0381, E0382, E0384, E0503, E0506.
For more information about an error, try `rustc --explain E0381`.

View File

@ -6,9 +6,6 @@
// ignore-sparc
// ignore-sparc64
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
#![feature(asm)]
#[cfg(any(target_arch = "x86",
@ -24,16 +21,14 @@ mod test_cases {
unsafe {
asm!("nop" : : "r"(x));
}
let z = x; //[ast]~ ERROR use of moved value: `x`
//[mir]~^ ERROR use of moved value: `x`
let z = x; //~ ERROR use of moved value: `x`
}
fn in_is_read() {
let mut x = 3;
let y = &mut x;
unsafe {
asm!("nop" : : "r"(x)); //[ast]~ ERROR cannot use
//[mir]~^ ERROR cannot use
asm!("nop" : : "r"(x)); //~ ERROR cannot use
}
let z = y;
}
@ -41,14 +36,12 @@ mod test_cases {
fn out_is_assign() {
let x = 3;
unsafe {
asm!("nop" : "=r"(x)); //[ast]~ ERROR cannot assign twice
//[mir]~^ ERROR cannot assign twice
asm!("nop" : "=r"(x)); //~ ERROR cannot assign twice
}
let mut a = &mut 3;
let b = &*a;
unsafe {
asm!("nop" : "=r"(a)); //[ast]~ ERROR cannot assign to `a` because it is borrowed
// No MIR error, this is a shallow write.
asm!("nop" : "=r"(a)); // OK, Shallow write to `a`
}
let c = b;
let d = *a;
@ -57,16 +50,14 @@ mod test_cases {
fn rw_is_assign() {
let x = 3;
unsafe {
asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign twice
//[mir]~^ ERROR cannot assign twice
asm!("nop" : "+r"(x)); //~ ERROR cannot assign twice
}
}
fn indirect_is_not_init() {
let x: i32;
unsafe {
asm!("nop" : "=*r"(x)); //[ast]~ ERROR use of possibly uninitialized variable
//[mir]~^ ERROR use of possibly uninitialized variable
asm!("nop" : "=*r"(x)); //~ ERROR use of possibly uninitialized variable
}
}
@ -74,8 +65,7 @@ mod test_cases {
let mut x = &mut 3;
let y = &*x;
unsafe {
asm!("nop" : "+r"(x)); //[ast]~ ERROR cannot assign to `x` because it is borrowed
//[mir]~^ ERROR cannot assign to `x` because it is borrowed
asm!("nop" : "+r"(x)); //~ ERROR cannot assign to `x` because it is borrowed
}
let z = y;
}
@ -83,8 +73,7 @@ mod test_cases {
fn two_moves() {
let x = &mut 2;
unsafe {
asm!("nop" : : "r"(x), "r"(x) ); //[ast]~ ERROR use of moved value
//[mir]~^ ERROR use of moved value
asm!("nop" : : "r"(x), "r"(x) ); //~ ERROR use of moved value
}
}
}

View File

@ -1,5 +1,5 @@
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:27:17
--> $DIR/borrowck-asm.rs:24:17
|
LL | let x = &mut 0isize;
| - move occurs because `x` has type `&mut isize`, which does not implement the `Copy` trait
@ -11,19 +11,19 @@ LL | let z = x;
| ^ value used here after move
error[E0503]: cannot use `x` because it was mutably borrowed
--> $DIR/borrowck-asm.rs:35:32
--> $DIR/borrowck-asm.rs:31:32
|
LL | let y = &mut x;
| ------ borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : : "r"(x));
| ^ use of borrowed `x`
...
LL | }
LL | let z = y;
| - borrow later used here
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:44:31
--> $DIR/borrowck-asm.rs:39:31
|
LL | let x = 3;
| -
@ -35,7 +35,7 @@ LL | asm!("nop" : "=r"(x));
| ^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/borrowck-asm.rs:60:31
--> $DIR/borrowck-asm.rs:53:31
|
LL | let x = 3;
| -
@ -47,25 +47,25 @@ LL | asm!("nop" : "+r"(x));
| ^ cannot assign twice to immutable variable
error[E0381]: use of possibly uninitialized variable: `x`
--> $DIR/borrowck-asm.rs:68:32
--> $DIR/borrowck-asm.rs:60:32
|
LL | asm!("nop" : "=*r"(x));
| ^ use of possibly uninitialized `x`
error[E0506]: cannot assign to `x` because it is borrowed
--> $DIR/borrowck-asm.rs:77:31
--> $DIR/borrowck-asm.rs:68:31
|
LL | let y = &*x;
| --- borrow of `x` occurs here
LL | unsafe {
LL | asm!("nop" : "+r"(x));
| ^ assignment to borrowed `x` occurs here
...
LL | }
LL | let z = y;
| - borrow later used here
error[E0382]: use of moved value: `x`
--> $DIR/borrowck-asm.rs:86:40
--> $DIR/borrowck-asm.rs:76:40
|
LL | let x = &mut 2;
| - move occurs because `x` has type `&mut i32`, which does not implement the `Copy` trait

View File

@ -1,27 +0,0 @@
error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-assign-comp-idx.rs:12:5
|
LL | let q: &isize = &p[0];
| - immutable borrow occurs here
LL |
LL | p[0] = 5;
| ^ mutable borrow occurs here
LL |
LL | println!("{}", *q);
| -- immutable borrow later used here
error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-assign-comp-idx.rs:27:9
|
LL | borrow(
| ------ immutable borrow later used by call
LL | &p,
| -- immutable borrow occurs here
LL | || p[0] = 5);
| ^^ - second borrow occurs due to use of `p` in closure
| |
| mutable borrow occurs here
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0502`.

View File

@ -6,19 +6,20 @@ LL | let q: &isize = &p[0];
LL |
LL | p[0] = 5;
| ^ mutable borrow occurs here
...
LL | }
| - immutable borrow ends here
LL |
LL | println!("{}", *q);
| -- immutable borrow later used here
error[E0502]: cannot borrow `p` as mutable because it is also borrowed as immutable
--> $DIR/borrowck-assign-comp-idx.rs:27:9
|
LL | borrow(
| ------ immutable borrow later used by call
LL | &p,
| - immutable borrow occurs here
| -- immutable borrow occurs here
LL | || p[0] = 5);
| ^^ - - immutable borrow ends here
| | |
| | borrow occurs due to use of `p` in closure
| ^^ - second borrow occurs due to use of `p` in closure
| |
| mutable borrow occurs here
error: aborting due to 2 previous errors

View File

@ -1,28 +0,0 @@
error[E0506]: cannot assign to `p.x` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:13:5
|
LL | let q = &p;
| - borrow of `p.x` occurs here
...
LL | p.x = 5;
| ^^^^^^^ assignment to borrowed `p.x` occurs here
error[E0506]: cannot assign to `p` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:24:5
|
LL | let q = &p.y;
| --- borrow of `p` occurs here
LL | p = Point {x: 5, y: 7};
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
error[E0506]: cannot assign to `p.y` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:36:5
|
LL | let q = &p.y;
| --- borrow of `p.y` occurs here
LL | p.y = 5;
| ^^^^^^^ assignment to borrowed `p.y` occurs here
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0506`.

View File

@ -1,37 +0,0 @@
error[E0506]: cannot assign to `p.x` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:13:5
|
LL | let q = &p;
| -- borrow of `p.x` occurs here
...
LL | p.x = 5;
| ^^^^^^^ assignment to borrowed `p.x` occurs here
LL |
LL | q.x;
| --- borrow later used here
error[E0506]: cannot assign to `p` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:24:5
|
LL | let q = &p.y;
| ---- borrow of `p` occurs here
LL | p = Point {x: 5, y: 7};
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
...
LL | *q; // stretch loan
| -- borrow later used here
error[E0506]: cannot assign to `p.y` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:36:5
|
LL | let q = &p.y;
| ---- borrow of `p.y` occurs here
LL | p.y = 5;
| ^^^^^^^ assignment to borrowed `p.y` occurs here
LL |
LL | *q;
| -- borrow later used here
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0506`.

View File

@ -1,6 +1,3 @@
// revisions: ast mir
//[mir]compile-flags: -Z borrowck=mir
struct Point { x: isize, y: isize }
fn a() {
@ -10,8 +7,7 @@ fn a() {
// This assignment is illegal because the field x is not
// inherently mutable; since `p` was made immutable, `p.x` is now
// immutable. Otherwise the type of &_q.x (&isize) would be wrong.
p.x = 5; //[ast]~ ERROR cannot assign to `p.x`
//[mir]~^ ERROR cannot assign to `p.x` because it is borrowed
p.x = 5; //~ ERROR cannot assign to `p.x` because it is borrowed
q.x;
}
@ -21,8 +17,7 @@ fn c() {
let mut p = Point {x: 3, y: 4};
let q = &p.y;
p = Point {x: 5, y: 7};//[ast]~ ERROR cannot assign to `p`
//[mir]~^ ERROR cannot assign to `p` because it is borrowed
p = Point {x: 5, y: 7};//~ ERROR cannot assign to `p` because it is borrowed
p.x; // silence warning
*q; // stretch loan
}
@ -33,8 +28,7 @@ fn d() {
let mut p = Point {x: 3, y: 4};
let q = &p.y;
p.y = 5; //[ast]~ ERROR cannot assign to `p.y`
//[mir]~^ ERROR cannot assign to `p.y` because it is borrowed
p.y = 5; //~ ERROR cannot assign to `p.y` because it is borrowed
*q;
}

View File

@ -1,34 +1,32 @@
error[E0506]: cannot assign to `p.x` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:13:5
--> $DIR/borrowck-assign-comp.rs:10:5
|
LL | let q = &p;
| -- borrow of `p.x` occurs here
...
LL | p.x = 5;
| ^^^^^^^ assignment to borrowed `p.x` occurs here
LL |
LL | q.x;
| --- borrow later used here
error[E0506]: cannot assign to `p` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:24:5
--> $DIR/borrowck-assign-comp.rs:20:5
|
LL | let q = &p.y;
| ---- borrow of `p` occurs here
LL | p = Point {x: 5, y: 7};
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
...
LL | p.x; // silence warning
LL | *q; // stretch loan
| -- borrow later used here
error[E0506]: cannot assign to `p.y` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:36:5
--> $DIR/borrowck-assign-comp.rs:31:5
|
LL | let q = &p.y;
| ---- borrow of `p.y` occurs here
LL | p.y = 5;
| ^^^^^^^ assignment to borrowed `p.y` occurs here
LL |
LL | *q;
| -- borrow later used here

View File

@ -1,18 +0,0 @@
error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5
|
LL | fn a(s: &S) {
| -- help: consider changing this to be a mutable reference: `&mut S<'_>`
LL | *s.pointer += 1;
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
|
LL | fn c(s: & &mut S) {
| -------- help: consider changing this to be a mutable reference: `&mut &mut S<'_>`
LL | *s.pointer += 1;
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
error: aborting due to 2 previous errors

View File

@ -1,19 +1,18 @@
error[E0389]: cannot assign to data in a `&` reference
error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:9:5
|
LL | fn a(s: &S) {
| -- use `&mut S` here to make mutable
| -- help: consider changing this to be a mutable reference: `&mut S<'_>`
LL | *s.pointer += 1;
| ^^^^^^^^^^^^^^^ assignment into an immutable reference
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
error[E0389]: cannot assign to data in a `&` reference
error[E0594]: cannot assign to `*s.pointer` which is behind a `&` reference
--> $DIR/borrowck-assign-to-andmut-in-aliasable-loc.rs:17:5
|
LL | fn c(s: & &mut S) {
| -------- use `&mut &mut S` here to make mutable
| -------- help: consider changing this to be a mutable reference: `&mut &mut S<'_>`
LL | *s.pointer += 1;
| ^^^^^^^^^^^^^^^ assignment into an immutable reference
| ^^^^^^^^^^^^^^^ `s` is a `&` reference, so the data it refers to cannot be written
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0389`.

View File

@ -1,24 +0,0 @@
error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
--> $DIR/borrowck-assign-to-andmut-in-borrowed-loc.rs:18:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ borrow of `y` occurs here
LL | *y.pointer += 1;
| ^^^^^^^^^^^^^^^ use of borrowed `y`
LL | *z.pointer += 1;
| --------------- borrow later used here
error[E0506]: cannot assign to `*y.pointer` because it is borrowed
--> $DIR/borrowck-assign-to-andmut-in-borrowed-loc.rs:18:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ borrow of `*y.pointer` occurs here
LL | *y.pointer += 1;
| ^^^^^^^^^^^^^^^ assignment to borrowed `*y.pointer` occurs here
LL | *z.pointer += 1;
| --------------- borrow later used here
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0503, E0506.
For more information about an error, try `rustc --explain E0503`.

View File

@ -15,7 +15,9 @@ fn main() {
{
let mut y = S { pointer: &mut x };
let z = copy_borrowed_ptr(&mut y);
*y.pointer += 1; //~ ERROR cannot assign
*y.pointer += 1;
//~^ ERROR cannot use `*y.pointer`
//~| ERROR cannot assign to `*y.pointer`
*z.pointer += 1;
}
}

Some files were not shown because too many files have changed in this diff Show More