move_ref_pattern: change pov in diagnostics & add binding names

This commit is contained in:
Mazdak Farrokhzad 2020-02-02 17:58:15 +01:00
parent 8d4973f587
commit bd318be05d
15 changed files with 501 additions and 489 deletions

View file

@ -658,8 +658,8 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
name,
tables.node_type(pat.hir_id),
);
sess.struct_span_err(pat.span, &format!("borrow of moved value: `{}`", name))
.span_label(binding_span, "value moved here")
sess.struct_span_err(pat.span, "borrow of moved value")
.span_label(binding_span, format!("value moved into `{}` here", name))
.span_label(binding_span, occurs_because)
.span_labels(conflicts_ref, "value borrowed here after move")
.emit();
@ -675,50 +675,62 @@ fn check_borrow_conflicts_in_at_patterns(cx: &MatchVisitor<'_, '_>, pat: &Pat<'_
let mut conflicts_move = Vec::new();
let mut conflicts_mut_mut = Vec::new();
let mut conflicts_mut_ref = Vec::new();
sub.each_binding(|_, hir_id, span, _| match tables.extract_binding_mode(sess, hir_id, span) {
Some(ty::BindByReference(mut_inner)) => match (mut_outer, mut_inner) {
(Mutability::Not, Mutability::Not) => {} // Both sides are `ref`.
(Mutability::Mut, Mutability::Mut) => conflicts_mut_mut.push(span), // 2x `ref mut`.
_ => conflicts_mut_ref.push(span), // `ref` + `ref mut` in either direction.
},
Some(ty::BindByValue(_)) if is_binding_by_move(cx, hir_id, span) => {
conflicts_move.push(span) // `ref mut?` + by-move conflict.
sub.each_binding(|_, hir_id, span, name| {
match tables.extract_binding_mode(sess, hir_id, span) {
Some(ty::BindByReference(mut_inner)) => match (mut_outer, mut_inner) {
(Mutability::Not, Mutability::Not) => {} // Both sides are `ref`.
(Mutability::Mut, Mutability::Mut) => conflicts_mut_mut.push((span, name)), // 2x `ref mut`.
_ => conflicts_mut_ref.push((span, name)), // `ref` + `ref mut` in either direction.
},
Some(ty::BindByValue(_)) if is_binding_by_move(cx, hir_id, span) => {
conflicts_move.push((span, name)) // `ref mut?` + by-move conflict.
}
Some(ty::BindByValue(_)) | None => {} // `ref mut?` + by-copy is fine.
}
Some(ty::BindByValue(_)) | None => {} // `ref mut?` + by-copy is fine.
});
// Report errors if any.
if !conflicts_mut_mut.is_empty() {
// Report mutability conflicts for e.g. `ref mut x @ Some(ref mut y)`.
let msg = &format!("cannot borrow `{}` as mutable more than once at a time", name);
sess.struct_span_err(pat.span, msg)
.span_label(binding_span, "first mutable borrow occurs here")
.span_labels(conflicts_mut_mut, "another mutable borrow occurs here")
.span_labels(conflicts_mut_ref, "also borrowed as immutable here")
.span_labels(conflicts_move, "also moved here")
.emit();
let mut err = sess
.struct_span_err(pat.span, "cannot borrow value as mutable more than once at a time");
err.span_label(binding_span, format!("first mutable borrow, by `{}`, occurs here", name));
for (span, name) in conflicts_mut_mut {
err.span_label(span, format!("another mutable borrow, by `{}`, occurs here", name));
}
for (span, name) in conflicts_mut_ref {
err.span_label(span, format!("also borrowed as immutable, by `{}`, here", name));
}
for (span, name) in conflicts_move {
err.span_label(span, format!("also moved into `{}` here", name));
}
err.emit();
} else if !conflicts_mut_ref.is_empty() {
// Report mutability conflicts for e.g. `ref x @ Some(ref mut y)` or the converse.
let (primary, also) = match mut_outer {
Mutability::Mut => ("mutable", "immutable"),
Mutability::Not => ("immutable", "mutable"),
};
let msg = &format!(
"cannot borrow `{}` as {} because it is also borrowed as {}",
name, also, primary,
);
sess.struct_span_err(pat.span, msg)
.span_label(binding_span, format!("{} borrow occurs here", primary))
.span_labels(conflicts_mut_ref, format!("{} borrow occurs here", also))
.span_labels(conflicts_move, "also moved here")
.emit();
let msg =
format!("cannot borrow value as {} because it is also borrowed as {}", also, primary);
let mut err = sess.struct_span_err(pat.span, &msg);
err.span_label(binding_span, format!("{} borrow, by `{}`, occurs here", primary, name));
for (span, name) in conflicts_mut_ref {
err.span_label(span, format!("{} borrow, by `{}`, occurs here", also, name));
}
for (span, name) in conflicts_move {
err.span_label(span, format!("also moved into `{}` here", name));
}
err.emit();
} else if !conflicts_move.is_empty() {
// Report by-ref and by-move conflicts, e.g. `ref x @ y`.
let msg = &format!("cannot move out of `{}` because it is borrowed", name);
sess.struct_span_err(pat.span, msg)
.span_label(binding_span, format!("borrow of `{}` occurs here", name))
.span_labels(conflicts_move, format!("move out of `{}` occurs here", name))
.emit();
let mut err =
sess.struct_span_err(pat.span, "cannot move out of value because it is borrowed");
err.span_label(binding_span, format!("value borrowed, by `{}`, here", name));
for (span, name) in conflicts_move {
err.span_label(span, format!("value moved into `{}` here", name));
}
err.emit();
}
}

View file

@ -12,7 +12,7 @@ struct X {
fn main() {
let x = Some(X { x: () });
match x {
Some(ref _y @ _z) => {} //~ ERROR cannot move out of `_y` because it is borrowed
Some(ref _y @ _z) => {} //~ ERROR cannot move out of value because it is borrowed
None => panic!(),
}
@ -26,7 +26,7 @@ fn main() {
let mut x = Some(X { x: () });
match x {
Some(ref mut _y @ _z) => {} //~ ERROR cannot move out of `_y` because it is borrowed
Some(ref mut _y @ _z) => {} //~ ERROR cannot move out of value because it is borrowed
None => panic!(),
}

View file

@ -1,39 +1,39 @@
error: cannot move out of `_y` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:15:14
|
LL | Some(ref _y @ _z) => {}
| ------^^^--
| | |
| | move out of `_y` occurs here
| borrow of `_y` occurs here
| | value moved into `_z` here
| value borrowed, by `_y`, here
error: borrow of moved value: `_z`
error: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:21:14
|
LL | Some(_z @ ref _y) => {}
| --^^^------
| | |
| | value borrowed here after move
| value moved here
| value moved into `_z` here
| move occurs because `_z` has type `X` which does implement the `Copy` trait
error: cannot move out of `_y` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:29:14
|
LL | Some(ref mut _y @ _z) => {}
| ----------^^^--
| | |
| | move out of `_y` occurs here
| borrow of `_y` occurs here
| | value moved into `_z` here
| value borrowed, by `_y`, here
error: borrow of moved value: `_z`
error: borrow of moved value
--> $DIR/bind-by-move-neither-can-live-while-the-other-survives-1.rs:35:14
|
LL | Some(_z @ ref mut _y) => {}
| --^^^----------
| | |
| | value borrowed here after move
| value moved here
| value moved into `_z` here
| move occurs because `_z` has type `X` which does implement the `Copy` trait
error[E0382]: borrow of moved value

View file

@ -34,29 +34,29 @@ fn main() {
a @ box b => {} //~ ERROR use of moved value
}
let ref a @ box b = Box::new(NC); //~ ERROR cannot move out of `a` because it is borrowed
let ref a @ box b = Box::new(NC); //~ ERROR cannot move out of value because it is borrowed
let ref a @ box ref mut b = Box::new(nc());
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
let ref a @ box ref mut b = Box::new(NC);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
let ref a @ box ref mut b = Box::new(NC);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
*b = NC;
let ref a @ box ref mut b = Box::new(NC);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
*b = NC;
drop(a);
let ref mut a @ box ref b = Box::new(NC);
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
*a = Box::new(NC);
drop(b);
fn f5(ref mut a @ box ref b: Box<NC>) {
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
*a = Box::new(NC);
drop(b);
@ -64,7 +64,7 @@ fn main() {
match Box::new(nc()) {
ref mut a @ box ref b => {
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
*a = Box::new(NC);
drop(b);

View file

@ -1,74 +1,74 @@
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-at-and-box.rs:37:9
|
LL | let ref a @ box b = Box::new(NC);
| -----^^^^^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-at-and-box.rs:39:9
|
LL | let ref a @ box ref mut b = Box::new(nc());
| -----^^^^^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-at-and-box.rs:41:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-at-and-box.rs:43:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-at-and-box.rs:46:9
|
LL | let ref a @ box ref mut b = Box::new(NC);
| -----^^^^^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-at-and-box.rs:52:9
|
LL | let ref mut a @ box ref b = Box::new(NC);
| ---------^^^^^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-at-and-box.rs:66:9
|
LL | ref mut a @ box ref b => {
| ---------^^^^^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-at-and-box.rs:58:11
|
LL | fn f5(ref mut a @ box ref b: Box<NC>) {
| ---------^^^^^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error[E0382]: use of moved value
--> $DIR/borrowck-pat-at-and-box.rs:21:18

View file

@ -1,11 +1,11 @@
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse-promotion.rs:9:9
|
LL | let a @ ref b = U;
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `main::U` which does implement the `Copy` trait
error: aborting due to previous error

View file

@ -1,14 +1,14 @@
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:29:9
|
LL | let a @ ref b = U;
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:31:9
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U);
@ -16,30 +16,30 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U);
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `(main::U, main::U)` which does implement the `Copy` trait
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:31:14
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U);
| -----^^^---------
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `d`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:31:33
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (U, U);
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `d` here
| move occurs because `d` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:38:9
|
LL | let a @ [ref mut b, ref c] = [U, U];
@ -47,20 +47,20 @@ LL | let a @ [ref mut b, ref c] = [U, U];
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `[main::U; 2]` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:41:9
|
LL | let a @ ref b = u();
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:44:9
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u());
@ -68,30 +68,30 @@ LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u());
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `(main::U, main::U)` which does implement the `Copy` trait
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:44:14
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u());
| -----^^^---------
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `d`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:44:33
|
LL | let a @ (mut b @ ref mut c, d @ ref e) = (u(), u());
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `d` here
| move occurs because `d` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:51:9
|
LL | let a @ [ref mut b, ref c] = [u(), u()];
@ -99,20 +99,20 @@ LL | let a @ [ref mut b, ref c] = [u(), u()];
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `[main::U; 2]` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:56:9
|
LL | a @ Some(ref b) => {}
| -^^^^^^^^-----^
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<main::U>` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:61:9
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
@ -120,30 +120,30 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<(main::U, main::U)>` which does implement the `Copy` trait
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:61:19
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| -----^^^---------
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `d`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:61:38
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `d` here
| move occurs because `d` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:71:9
|
LL | mut a @ Some([ref b, ref mut c]) => {}
@ -151,20 +151,20 @@ LL | mut a @ Some([ref b, ref mut c]) => {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<[main::U; 2]>` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:77:9
|
LL | a @ Some(ref b) => {}
| -^^^^^^^^-----^
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<main::U>` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:83:9
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
@ -172,30 +172,30 @@ LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<(main::U, main::U)>` which does implement the `Copy` trait
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:83:19
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| -----^^^---------
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `d`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:83:38
|
LL | a @ Some((mut b @ ref mut c, d @ ref e)) => {}
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `d` here
| move occurs because `d` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:93:9
|
LL | mut a @ Some([ref b, ref mut c]) => {}
@ -203,20 +203,20 @@ LL | mut a @ Some([ref b, ref mut c]) => {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `std::option::Option<[main::U; 2]>` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:14:11
|
LL | fn f1(a @ ref b: U) {}
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:18:11
|
LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {}
@ -224,30 +224,30 @@ LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `(main::U, main::U)` which does implement the `Copy` trait
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:18:20
|
LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {}
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `d`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:18:31
|
LL | fn f2(mut a @ (b @ ref c, mut d @ ref e): (U, U)) {}
| -----^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `d` here
| move occurs because `d` has type `main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-by-move-and-ref-inverse.rs:25:11
|
LL | fn f3(a @ [ref mut b, ref c]: [U; 2]) {}
@ -255,7 +255,7 @@ LL | fn f3(a @ [ref mut b, ref c]: [U; 2]) {}
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `[main::U; 2]` which does implement the `Copy` trait
error[E0382]: borrow of moved value

View file

@ -12,63 +12,63 @@ fn main() {
}
fn f1(ref a @ b: U) {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
fn f2(ref a @ (ref b @ mut c, ref d @ e): (U, U)) {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR cannot move out of `b` because it is borrowed
//~| ERROR cannot move out of `d` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
fn f3(ref mut a @ [b, mut c]: [U; 2]) {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
let ref a @ b = U;
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
let ref a @ (ref b @ mut c, ref d @ e) = (U, U);
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR cannot move out of `b` because it is borrowed
//~| ERROR cannot move out of `d` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
let ref mut a @ [b, mut c] = [U, U];
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
let ref a @ b = u();
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
let ref a @ (ref b @ mut c, ref d @ e) = (u(), u());
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR cannot move out of `b` because it is borrowed
//~| ERROR cannot move out of `d` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
let ref mut a @ [b, mut c] = [u(), u()];
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
match Some(U) {
ref a @ Some(b) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some((U, U)) {
ref a @ Some((ref b @ mut c, ref d @ e)) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR cannot move out of `b` because it is borrowed
//~| ERROR cannot move out of `d` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
None => {}
}
match Some([U, U]) {
ref mut a @ Some([b, mut c]) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some(u()) {
ref a @ Some(b) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
match Some((u(), u())) {
ref a @ Some((ref b @ mut c, ref d @ e)) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR cannot move out of `b` because it is borrowed
//~| ERROR cannot move out of `d` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
//~| ERROR cannot move out of value because it is borrowed
None => {}
}
match Some([u(), u()]) {
ref mut a @ Some([b, mut c]) => {}
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
None => {}
}
}

View file

@ -1,237 +1,237 @@
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:23:9
|
LL | let ref a @ b = U;
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:25:9
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (U, U);
| -----^^^^^^^^^^^^-----^^^^^^^^^^-^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `e` here
| | value moved into `c` here
| value borrowed, by `a`, here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:25:18
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (U, U);
| -----^^^-----
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error: cannot move out of `d` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:25:33
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (U, U);
| -----^^^-
| | |
| | move out of `d` occurs here
| borrow of `d` occurs here
| | value moved into `e` here
| value borrowed, by `d`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:29:9
|
LL | let ref mut a @ [b, mut c] = [U, U];
| ---------^^^^-^^-----^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `c` here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:31:9
|
LL | let ref a @ b = u();
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:33:9
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (u(), u());
| -----^^^^^^^^^^^^-----^^^^^^^^^^-^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `e` here
| | value moved into `c` here
| value borrowed, by `a`, here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:33:18
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (u(), u());
| -----^^^-----
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error: cannot move out of `d` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:33:33
|
LL | let ref a @ (ref b @ mut c, ref d @ e) = (u(), u());
| -----^^^-
| | |
| | move out of `d` occurs here
| borrow of `d` occurs here
| | value moved into `e` here
| value borrowed, by `d`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:37:9
|
LL | let ref mut a @ [b, mut c] = [u(), u()];
| ---------^^^^-^^-----^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `c` here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:41:9
|
LL | ref a @ Some(b) => {}
| -----^^^^^^^^-^
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:46:9
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^^^^^^^^^^^^^^^-----^^^^^^^^^^-^^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `e` here
| | value moved into `c` here
| value borrowed, by `a`, here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:46:23
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^-----
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error: cannot move out of `d` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:46:38
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^-
| | |
| | move out of `d` occurs here
| borrow of `d` occurs here
| | value moved into `e` here
| value borrowed, by `d`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:53:9
|
LL | ref mut a @ Some([b, mut c]) => {}
| ---------^^^^^^^^^-^^-----^^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `c` here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:58:9
|
LL | ref a @ Some(b) => {}
| -----^^^^^^^^-^
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:63:9
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^^^^^^^^^^^^^^^-----^^^^^^^^^^-^^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `e` here
| | value moved into `c` here
| value borrowed, by `a`, here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:63:23
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^-----
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error: cannot move out of `d` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:63:38
|
LL | ref a @ Some((ref b @ mut c, ref d @ e)) => {}
| -----^^^-
| | |
| | move out of `d` occurs here
| borrow of `d` occurs here
| | value moved into `e` here
| value borrowed, by `d`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:70:9
|
LL | ref mut a @ Some([b, mut c]) => {}
| ---------^^^^^^^^^-^^-----^^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `c` here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:14:11
|
LL | fn f1(ref a @ b: U) {}
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:16:11
|
LL | fn f2(ref a @ (ref b @ mut c, ref d @ e): (U, U)) {}
| -----^^^^^^^^^^^^-----^^^^^^^^^^-^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `e` here
| | value moved into `c` here
| value borrowed, by `a`, here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:16:20
|
LL | fn f2(ref a @ (ref b @ mut c, ref d @ e): (U, U)) {}
| -----^^^-----
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error: cannot move out of `d` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:16:35
|
LL | fn f2(ref a @ (ref b @ mut c, ref d @ e): (U, U)) {}
| -----^^^-
| | |
| | move out of `d` occurs here
| borrow of `d` occurs here
| | value moved into `e` here
| value borrowed, by `d`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-by-move-and-ref.rs:20:11
|
LL | fn f3(ref mut a @ [b, mut c]: [U; 2]) {}
| ---------^^^^-^^-----^
| | | |
| | | move out of `a` occurs here
| | move out of `a` occurs here
| borrow of `a` occurs here
| | | value moved into `c` here
| | value moved into `b` here
| value borrowed, by `a`, here
error: aborting due to 25 previous errors

View file

@ -9,7 +9,7 @@ enum Option<T> {
fn main() {
match &mut Some(1) {
ref mut z @ &mut Some(ref a) => {
//~^ ERROR cannot borrow `z` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
**z = None;
println!("{}", *a);
@ -23,52 +23,52 @@ fn main() {
fn u() -> U { U }
fn f1(ref a @ ref mut b: U) {}
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
fn f2(ref mut a @ ref b: U) {}
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
fn f3(ref a @ [ref b, ref mut mid @ .., ref c]: [U; 4]) {}
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
fn f4_also_moved(ref a @ ref mut b @ c: U) {}
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~| ERROR cannot move out of `b` because it is borrowed
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot move out of value because it is borrowed
let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot borrow `b` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
let ref a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
let ref mut a @ ref b = U;
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
let ref a @ (ref mut b, ref mut c) = (U, U);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
let ref mut a @ (ref b, ref c) = (U, U);
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
let ref mut a @ ref b = u();
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
*a = u();
drop(b);
let ref a @ ref mut b = u();
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
*b = u();
drop(a);
let ref mut a @ ref b = U;
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
*a = U;
drop(b);
let ref a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
*b = U;
drop(a);
match Ok(U) {
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
*a = Err(U);
drop(b);
}
@ -76,8 +76,8 @@ fn main() {
match Ok(U) {
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
*b = U;
@ -87,52 +87,52 @@ fn main() {
match Ok(U) {
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot assign to `*b`, as it is immutable for the pattern guard
_ => {}
}
match Ok(U) {
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot assign to `*a`, as it is immutable for the pattern guard
_ => {}
}
match Ok(U) {
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot move out of `b` in pattern guard
//~| ERROR cannot move out of `b` in pattern guard
_ => {}
}
match Ok(U) {
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot borrow value as immutable because it is also borrowed as mutable
//~| ERROR cannot move out of `a` in pattern guard
//~| ERROR cannot move out of `a` in pattern guard
_ => {}
}
let ref a @ (ref mut b, ref mut c) = (U, U);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
*b = U;
*c = U;
let ref a @ (ref mut b, ref mut c) = (U, U);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
//~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
*b = U;
drop(a);
let ref a @ (ref mut b, ref mut c) = (U, U);
//~^ ERROR cannot borrow `a` as mutable because it is also borrowed as immutable
//~^ ERROR cannot borrow value as mutable because it is also borrowed as immutable
*b = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
*c = U; //~| ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
drop(a);
let ref mut a @ (ref b, ref c) = (U, U);
//~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
//~^ ERROR cannot borrow value as immutable because it is also borrowed as mutable
}

View file

@ -1,298 +1,298 @@
error: cannot borrow `z` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:9
|
LL | ref mut z @ &mut Some(ref a) => {
| ---------^^^^^^^^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `a`, occurs here
| mutable borrow, by `z`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:35:9
|
LL | let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
| ---------^^^^-----------------^
| | | |
| | | another mutable borrow occurs here
| | also borrowed as immutable here
| first mutable borrow occurs here
| | | another mutable borrow, by `c`, occurs here
| | also borrowed as immutable, by `b`, here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `b` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:35:22
|
LL | let ref mut a @ (ref b @ ref mut c) = u(); // sub-in-sub
| -----^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `c`, occurs here
| immutable borrow, by `b`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:39:9
|
LL | let ref a @ ref mut b = U;
| -----^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:9
|
LL | let ref mut a @ ref b = U;
| ---------^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:43:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| | | |
| | | mutable borrow occurs here
| | mutable borrow occurs here
| immutable borrow occurs here
| | | mutable borrow, by `c`, occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:45:9
|
LL | let ref mut a @ (ref b, ref c) = (U, U);
| ---------^^^^-----^^-----^
| | | |
| | | immutable borrow occurs here
| | immutable borrow occurs here
| mutable borrow occurs here
| | | immutable borrow, by `c`, occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:48:9
|
LL | let ref mut a @ ref b = u();
| ---------^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:53:9
|
LL | let ref a @ ref mut b = u();
| -----^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:59:9
|
LL | let ref mut a @ ref b = U;
| ---------^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:63:9
|
LL | let ref a @ ref mut b = U;
| -----^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:69:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
| ---------^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:69:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
| ---------^^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:78:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:78:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----^^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:89:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| -----^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:89:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| -----^^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:96:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ---------^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:96:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ---------^^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:103:9
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| -----^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:103:33
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| -----^^^^^^^---------^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:111:9
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ---------^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:111:33
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ---------^^^^^^^-----^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:119:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| | | |
| | | mutable borrow occurs here
| | mutable borrow occurs here
| immutable borrow occurs here
| | | mutable borrow, by `c`, occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:124:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| | | |
| | | mutable borrow occurs here
| | mutable borrow occurs here
| immutable borrow occurs here
| | | mutable borrow, by `c`, occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:131:9
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| -----^^^^---------^^---------^
| | | |
| | | mutable borrow occurs here
| | mutable borrow occurs here
| immutable borrow occurs here
| | | mutable borrow, by `c`, occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:136:9
|
LL | let ref mut a @ (ref b, ref c) = (U, U);
| ---------^^^^-----^^-----^
| | | |
| | | immutable borrow occurs here
| | immutable borrow occurs here
| mutable borrow occurs here
| | | immutable borrow, by `c`, occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:25:11
|
LL | fn f1(ref a @ ref mut b: U) {}
| -----^^^---------
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as immutable because it is also borrowed as mutable
error: cannot borrow value as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:27:11
|
LL | fn f2(ref mut a @ ref b: U) {}
| ---------^^^-----
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
| | immutable borrow, by `b`, occurs here
| mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:29:11
|
LL | fn f3(ref a @ [ref b, ref mut mid @ .., ref c]: [U; 4]) {}
| -----^^^^^^^^^^^----------------^^^^^^^^
| | |
| | mutable borrow occurs here
| immutable borrow occurs here
| | mutable borrow, by `mid`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable because it is also borrowed as immutable
error: cannot borrow value as mutable because it is also borrowed as immutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:22
|
LL | fn f4_also_moved(ref a @ ref mut b @ c: U) {}
| -----^^^-------------
| | | |
| | | also moved here
| | mutable borrow occurs here
| immutable borrow occurs here
| | | also moved into `c` here
| | mutable borrow, by `b`, occurs here
| immutable borrow, by `a`, occurs here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:30
|
LL | fn f4_also_moved(ref a @ ref mut b @ c: U) {}
| ---------^^^-
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31

View file

@ -9,12 +9,12 @@ fn main() {
fn u() -> U { U }
fn f1(ref mut a @ ref mut b: U) {}
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
fn f2(ref mut a @ ref mut b: U) {}
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
fn f3(
ref mut a @ [
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
[ref b @ .., _],
[_, ref mut mid @ ..],
..,
@ -22,29 +22,29 @@ fn main() {
] : [[U; 4]; 5]
) {}
fn f4_also_moved(ref mut a @ ref mut b @ c: U) {}
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot move out of `b` because it is borrowed
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot move out of value because it is borrowed
let ref mut a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
drop(a);
let ref mut a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
drop(b);
let ref mut a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
let ref mut a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
*a = U;
let ref mut a @ ref mut b = U;
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
*b = U;
let ref mut a @ (
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
ref mut b,
[
ref mut c,
@ -54,7 +54,7 @@ fn main() {
) = (U, [U, U, U]);
let ref mut a @ (
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
ref mut b,
[
ref mut c,
@ -80,21 +80,21 @@ fn main() {
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow value as mutable more than once at a time
}
}
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow value as mutable more than once at a time
*b = U;
}
}
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
*a = Err(U);
@ -105,8 +105,8 @@ fn main() {
}
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
//~^ ERROR cannot borrow `a` as mutable more than once at a time
//~| ERROR cannot borrow `a` as mutable more than once at a time
//~^ ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow value as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
drop(a);

View file

@ -1,93 +1,93 @@
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:28:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:32:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:35:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:38:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:42:9
|
LL | let ref mut a @ ref mut b = U;
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:46:9
|
LL | let ref mut a @ (
| ^--------
| |
| _________first mutable borrow occurs here
| _________first mutable borrow, by `a`, occurs here
| |
LL | |
LL | | ref mut b,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `b`, occurs here
LL | | [
LL | | ref mut c,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `c`, occurs here
LL | | ref mut d,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `d`, occurs here
LL | | ref e,
| | ----- also borrowed as immutable here
| | ----- also borrowed as immutable, by `e`, here
LL | | ]
LL | | ) = (U, [U, U, U]);
| |_____^
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:56:9
|
LL | let ref mut a @ (
| ^--------
| |
| _________first mutable borrow occurs here
| _________first mutable borrow, by `a`, occurs here
| |
LL | |
LL | | ref mut b,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `b`, occurs here
LL | | [
LL | | ref mut c,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `c`, occurs here
LL | | ref mut d,
| | --------- another mutable borrow occurs here
| | --------- another mutable borrow, by `d`, occurs here
LL | | ref e,
| | ----- also borrowed as immutable here
| | ----- also borrowed as immutable, by `e`, here
LL | | ]
LL | | ) = (u(), [u(), u(), u()]);
| |_________^
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-ref-mut-twice.rs:66:9
|
LL | let a @ (ref mut b, ref mut c) = (U, U);
@ -95,10 +95,10 @@ LL | let a @ (ref mut b, ref mut c) = (U, U);
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `(main::U, main::U)` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-ref-mut-twice.rs:70:9
|
LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
@ -107,20 +107,20 @@ LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
| | | | value borrowed here after move
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `&mut (main::U, [main::U; 2])` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-ref-mut-twice.rs:74:9
|
LL | let a @ &mut ref mut b = &mut U;
| -^^^^^^^^---------
| | |
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `&mut main::U` which does implement the `Copy` trait
error: borrow of moved value: `a`
error: borrow of moved value
--> $DIR/borrowck-pat-ref-mut-twice.rs:77:9
|
LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
@ -128,135 +128,135 @@ LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
| | | |
| | | value borrowed here after move
| | value borrowed here after move
| value moved here
| value moved into `a` here
| move occurs because `a` has type `&mut (main::U, main::U)` which does implement the `Copy` trait
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:82:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:82:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:88:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:88:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:95:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:95:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:107:9
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:107:37
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------^^^^^^^---------^
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:11:11
|
LL | fn f1(ref mut a @ ref mut b: U) {}
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:13:11
|
LL | fn f2(ref mut a @ ref mut b: U) {}
| ---------^^^---------
| | |
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:16:9
|
LL | ref mut a @ [
| ^--------
| |
| _________first mutable borrow occurs here
| _________first mutable borrow, by `a`, occurs here
| |
LL | |
LL | | [ref b @ .., _],
| | ---------- also borrowed as immutable here
| | ---------- also borrowed as immutable, by `b`, here
LL | | [_, ref mut mid @ ..],
| | ---------------- another mutable borrow occurs here
| | ---------------- another mutable borrow, by `mid`, occurs here
LL | | ..,
LL | | [..],
LL | | ] : [[U; 4]; 5]
| |_________^
error: cannot borrow `a` as mutable more than once at a time
error: cannot borrow value as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:24:22
|
LL | fn f4_also_moved(ref mut a @ ref mut b @ c: U) {}
| ---------^^^-------------
| | | |
| | | also moved here
| | another mutable borrow occurs here
| first mutable borrow occurs here
| | | also moved into `c` here
| | another mutable borrow, by `b`, occurs here
| first mutable borrow, by `a`, occurs here
error: cannot move out of `b` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/borrowck-pat-ref-mut-twice.rs:24:34
|
LL | fn f4_also_moved(ref mut a @ ref mut b @ c: U) {}
| ---------^^^-
| | |
| | move out of `b` occurs here
| borrow of `b` occurs here
| | value moved into `c` here
| value borrowed, by `b`, here
error[E0499]: cannot borrow `_` as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:28:21

View file

@ -25,24 +25,24 @@ fn main() {
let ref a @ b = &NotCopy; // OK
let _: &&NotCopy = a;
let ref a @ b = NotCopy; //~ ERROR cannot move out of `a` because it is borrowed
let ref a @ b = NotCopy; //~ ERROR cannot move out of value because it is borrowed
let _a: &NotCopy = a;
let _b: NotCopy = b;
let ref mut a @ b = NotCopy; //~ ERROR cannot move out of `a` because it is borrowed
let ref mut a @ b = NotCopy; //~ ERROR cannot move out of value because it is borrowed
//~^ ERROR cannot move out of `_` because it is borrowed
let _a: &NotCopy = a;
let _b: NotCopy = b;
match Ok(NotCopy) {
Ok(ref a @ b) | Err(b @ ref a) => {
//~^ ERROR cannot move out of `a` because it is borrowed
//~| ERROR borrow of moved value: `b`
//~^ ERROR cannot move out of value because it is borrowed
//~| ERROR borrow of moved value
let _a: &NotCopy = a;
let _b: NotCopy = b;
}
}
match NotCopy {
ref a @ b => {
//~^ ERROR cannot move out of `a` because it is borrowed
//~^ ERROR cannot move out of value because it is borrowed
let _a: &NotCopy = a;
let _b: NotCopy = b;
}

View file

@ -1,48 +1,48 @@
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/default-binding-modes-both-sides-independent.rs:28:9
|
LL | let ref a @ b = NotCopy;
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/default-binding-modes-both-sides-independent.rs:31:9
|
LL | let ref mut a @ b = NotCopy;
| ---------^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/default-binding-modes-both-sides-independent.rs:36:12
|
LL | Ok(ref a @ b) | Err(b @ ref a) => {
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error: borrow of moved value: `b`
error: borrow of moved value
--> $DIR/default-binding-modes-both-sides-independent.rs:36:29
|
LL | Ok(ref a @ b) | Err(b @ ref a) => {
| -^^^-----
| | |
| | value borrowed here after move
| value moved here
| value moved into `b` here
| move occurs because `b` has type `main::NotCopy` which does implement the `Copy` trait
error: cannot move out of `a` because it is borrowed
error: cannot move out of value because it is borrowed
--> $DIR/default-binding-modes-both-sides-independent.rs:44:9
|
LL | ref a @ b => {
| -----^^^-
| | |
| | move out of `a` occurs here
| borrow of `a` occurs here
| | value moved into `b` here
| value borrowed, by `a`, here
error[E0505]: cannot move out of `_` because it is borrowed
--> $DIR/default-binding-modes-both-sides-independent.rs:31:21