};
let msg = &format!(
"cannot borrow `{}` as {} because it is also borrowed as {}",
- name, primary, also,
+ name, also, primary,
);
let mut err = sess.struct_span_err(pat.span, msg);
err.span_label(binding_span, &format!("{} borrow occurs here", primary));
drop(a);
drop(b);
- let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
- let ref a @ box ref mut b = Box::new(NC); // FIXME: This should not compile.
+ let ref a @ box ref mut b = Box::new(NC);
+ //~^ ERROR cannot borrow `a` 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
*b = NC;
let ref a @ box ref mut b = Box::new(NC);
- //~^ ERROR cannot borrow `_` 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 `_` 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 `_` 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 `_` as immutable because it is also borrowed as mutable
*a = Box::new(NC);
drop(b);
}
| | by-move pattern here
| by-ref pattern here
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-at-and-box.rs:32:9
+ |
+LL | let ref a @ box ref mut b = Box::new(NC);
+ | -----^^^^^^^---------
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-at-and-box.rs:34:9
+ |
+LL | let ref a @ box ref mut b = Box::new(NC);
+ | -----^^^^^^^---------
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-at-and-box.rs:37:9
+ |
+LL | let ref a @ box ref mut b = Box::new(NC);
+ | -----^^^^^^^---------
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-at-and-box.rs:43:9
+ |
+LL | let ref mut a @ box ref b = Box::new(NC);
+ | ---------^^^^^^^-----
+ | | |
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
error[E0382]: use of moved value
--> $DIR/borrowck-pat-at-and-box.rs:11:18
|
| value moved here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-at-and-box.rs:35:21
+ --> $DIR/borrowck-pat-at-and-box.rs:37:21
|
LL | let ref a @ box ref mut b = Box::new(NC);
| ------------^^^^^^^^^
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
- --> $DIR/borrowck-pat-at-and-box.rs:40:25
+ --> $DIR/borrowck-pat-at-and-box.rs:43:25
|
LL | let ref mut a @ box ref b = Box::new(NC);
| ----------------^^^^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
-LL |
+...
LL | *a = Box::new(NC);
| -- mutable borrow later used here
-error: aborting due to 7 previous errors
+error: aborting due to 11 previous errors
Some errors have detailed explanations: E0007, E0009, E0382, E0502.
For more information about an error, try `rustc --explain E0007`.
fn main() {
match &mut Some(1) {
ref mut z @ &mut Some(ref a) => {
- //~^ ERROR cannot borrow `_` as immutable because it is also borrowed as mutable
+ //~^ ERROR cannot borrow `z` 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);
}
struct U;
- let ref a @ ref mut b = U; // FIXME: This should not compile.
- let ref mut a @ ref b = U; // FIXME: This should not compile.
- let ref a @ (ref mut b, ref mut c) = (U, U); // FIXME: This should not compile.
- let ref mut a @ (ref b, ref c) = (U, U); // FIXME: This should not compile.
+ let ref a @ ref mut b = U;
+ //~^ ERROR cannot borrow `a` 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
+ let ref a @ (ref mut b, ref mut c) = (U, U);
+ //~^ ERROR cannot borrow `a` 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
- // FIXME: Seems like we have a soundness hole here.
let ref mut a @ ref b = U;
- *a = U; // We are mutating...
- drop(b); // ..but at the same time we are holding a live shared borrow.
- // FIXME: Inverted; seems like the same issue exists here as well.
+ //~^ ERROR cannot borrow `a` 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
*b = U;
drop(a);
match Ok(U) {
ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
- *a = Err(U); // FIXME: ^ should not compile.
+ //~^ 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
+ *a = Err(U);
drop(b);
}
}
match Ok(U) {
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
- //~^ ERROR cannot borrow `_` 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 `a` 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);
match Ok(U) {
ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
- //~^ ERROR cannot assign to `*b`, as it is immutable for the pattern guard
+ //~^ 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 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 assign to `*a`, as it is immutable for the pattern guard
+ //~^ 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 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 move out of `b` in pattern guard
+ //~^ 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 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 move out of `a` in pattern guard
+ //~^ 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 move out of `a` in pattern guard
_ => {}
}
let ref a @ (ref mut b, ref mut c) = (U, U);
- *b = U; // FIXME: ^ should not compile.
+ //~^ ERROR cannot borrow `a` 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 `_` 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 `_` 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);
- *b = U; //~^ ERROR cannot borrow `_` as mutable because it is also borrowed as immutable
+ //~^ ERROR cannot borrow `a` 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); // FIXME: This should not compile.
+ let ref mut a @ (ref b, ref c) = (U, U);
+ //~^ ERROR cannot borrow `a` as immutable because it is also borrowed as mutable
}
|
= note: `#[warn(incomplete_features)]` on by default
+error: cannot borrow `z` 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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:22:9
+ |
+LL | let ref a @ ref mut b = U;
+ | -----^^^---------
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:24:9
+ |
+LL | let ref mut a @ ref b = U;
+ | ---------^^^-----
+ | | |
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:26: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:28:9
+ |
+LL | let ref mut a @ (ref b, ref c) = (U, U);
+ | ---------^^^^-----^^-----^
+ | | | |
+ | | | immutable borrow occurs here
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:31:9
+ |
+LL | let ref mut a @ ref b = U;
+ | ---------^^^-----
+ | | |
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:35:9
+ |
+LL | let ref a @ ref mut b = U;
+ | -----^^^---------
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:9
+ |
+LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
+ | ---------^^^^^^-----^
+ | | |
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:41:33
+ |
+LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) => {
+ | ---------^^^^^^^-----^
+ | | |
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:9
+ |
+LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
+ | -----^^^^^^---------^
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:33
+ |
+LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
+ | -----^^^^^^^---------^
+ | | |
+ | | mutable borrow occurs here
+ | immutable borrow occurs here
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:89: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94: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
+
+error: cannot borrow `a` as mutable because it is also borrowed as immutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101: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
+
+error: cannot borrow `a` as immutable because it is also borrowed as mutable
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:106:9
+ |
+LL | let ref mut a @ (ref b, ref c) = (U, U);
+ | ---------^^^^-----^^-----^
+ | | | |
+ | | | immutable borrow occurs here
+ | | immutable borrow occurs here
+ | mutable borrow occurs here
+
error[E0502]: cannot borrow `_` as immutable because it is also borrowed as mutable
--> $DIR/borrowck-pat-ref-mut-and-ref.rs:11:31
|
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
-LL |
+...
LL | **z = None;
| ---------- mutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:43:20
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:20
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| -----------^^^^^^^^^-
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:43:45
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:50:45
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) => {
| ------------^^^^^^^^^-
| - immutable borrow later used here
error[E0594]: cannot assign to `*b`, as it is immutable for the pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:52:61
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:61:61
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { *b = U; false } => {}
| ^^^^^^ cannot assign
= note: variables bound in patterns are immutable until the end of the pattern guard
error[E0594]: cannot assign to `*a`, as it is immutable for the pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:57:61
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:68:61
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { *a = Err(U); false } => {}
| ^^^^^^^^^^^ cannot assign
= note: variables bound in patterns are immutable until the end of the pattern guard
error[E0507]: cannot move out of `b` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:62:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:75:66
|
LL | ref a @ Ok(ref mut b) | ref a @ Err(ref mut b) if { drop(b); false } => {}
| ^ move occurs because `b` has type `&mut main::U`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0507]: cannot move out of `a` in pattern guard
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:67:66
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:66
|
LL | ref mut a @ Ok(ref b) | ref mut a @ Err(ref b) if { drop(a); false } => {}
| ^ move occurs because `a` has type `&mut std::result::Result<main::U, main::U>`, which does not implement the `Copy` trait
= note: variables bound in patterns cannot be moved from until after the end of the pattern guard
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:76:18
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94:18
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| ---------^^^^^^^^^------------
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:76:29
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:94:29
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| --------------------^^^^^^^^^-
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:18
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101:18
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| ---------^^^^^^^^^------------
| - immutable borrow later used here
error[E0502]: cannot borrow `_` as mutable because it is also borrowed as immutable
- --> $DIR/borrowck-pat-ref-mut-and-ref.rs:82:29
+ --> $DIR/borrowck-pat-ref-mut-and-ref.rs:101:29
|
LL | let ref a @ (ref mut b, ref mut c) = (U, U);
| --------------------^^^^^^^^^-
LL | drop(a);
| - immutable borrow later used here
-error: aborting due to 11 previous errors
+error: aborting due to 34 previous errors
Some errors have detailed explanations: E0502, E0507, E0594.
For more information about an error, try `rustc --explain E0502`.
struct U;
let ref mut a @ ref mut b = U;
- //~^ ERROR cannot borrow `_` as mutable more than once at a time
+ //~^ ERROR cannot borrow `a` 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; // FIXME: This should not compile.
+ let ref mut a @ ref mut b = U;
+ //~^ ERROR cannot borrow `a` as mutable more than once at a time
drop(b);
- let ref mut a @ ref mut b = U; // FIXME: This should not compile.
+ let ref mut a @ ref mut b = U;
+ //~^ ERROR cannot borrow `a` as mutable more than once at a time
let ref mut a @ ref mut b = U;
- //~^ ERROR cannot borrow `_` as mutable more than once at a time
+ //~^ ERROR cannot borrow `a` 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; // FIXME: This should not compile.
+ let ref mut a @ ref mut b = U;
+ //~^ ERROR cannot borrow `a` as mutable more than once at a time
*b = U;
- let ref mut a @ (ref mut b, [ref mut c, ref mut d]) = (U, [U, U]);
- // FIXME: This should not compile.
+ let ref mut a @ (
+ //~^ ERROR cannot borrow `a` as mutable more than once at a time
+ ref mut b,
+ [
+ ref mut c,
+ ref mut d,
+ ref e,
+ ]
+ ) = (U, [U, U, U]);
let a @ (ref mut b, ref mut c) = (U, U);
//~^ ERROR cannot bind by-move with sub-bindings
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
- // FIXME: This should not compile.
+ //~^ ERROR cannot borrow `a` as mutable more than once at a time
+ //~| ERROR cannot borrow `a` 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
*b = U;
- // FIXME: This should not compile.
}
}
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
- //~^ ERROR cannot borrow `_` as mutable more than once at a time
+ //~^ 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 `_` as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
*a = Err(U);
}
match Ok(U) {
ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
- //~^ ERROR cannot borrow `_` as mutable more than once at a time
+ //~^ 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 `_` as mutable more than once at a time
//~| ERROR cannot borrow `_` as mutable more than once at a time
drop(a);
}
|
= note: `#[warn(incomplete_features)]` on by default
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:9:9
+ |
+LL | let ref mut a @ ref mut b = U;
+ | ---------^^^---------
+ | | |
+ | | another mutable borrow occurs here
+ | first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:13:9
+ |
+LL | let ref mut a @ ref mut b = U;
+ | ---------^^^---------
+ | | |
+ | | another mutable borrow occurs here
+ | first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:16:9
+ |
+LL | let ref mut a @ ref mut b = U;
+ | ---------^^^---------
+ | | |
+ | | another mutable borrow occurs here
+ | first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:19:9
+ |
+LL | let ref mut a @ ref mut b = U;
+ | ---------^^^---------
+ | | |
+ | | another mutable borrow occurs here
+ | first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:23:9
+ |
+LL | let ref mut a @ ref mut b = U;
+ | ---------^^^---------
+ | | |
+ | | another mutable borrow occurs here
+ | first mutable borrow occurs here
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:27:9
+ |
+LL | let ref mut a @ (
+ | ^--------
+ | |
+ | _________first mutable borrow occurs here
+ | |
+LL | |
+LL | | ref mut b,
+ | | --------- another mutable borrow occurs here
+LL | | [
+LL | | ref mut c,
+ | | --------- another mutable borrow occurs here
+LL | | ref mut d,
+ | | --------- another mutable borrow occurs here
+LL | | ref e,
+ | | ----- also borrowed as immutable here
+LL | | ]
+LL | | ) = (U, [U, U, U]);
+ | |_____^
+
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:25:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:37:9
|
LL | let a @ (ref mut b, ref mut c) = (U, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:29:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:41:9
|
LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
| ^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:33:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:45:9
|
LL | let a @ &mut ref mut b = &mut U;
| ^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
error[E0007]: cannot bind by-move with sub-bindings
- --> $DIR/borrowck-pat-ref-mut-twice.rs:36:9
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:48:9
|
LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ binds an already bound by-move value by moving it
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:53: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:53: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:59: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:59: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78: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
+
+error: cannot borrow `a` as mutable more than once at a time
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78: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
+
error[E0499]: cannot borrow `_` as mutable more than once at a time
--> $DIR/borrowck-pat-ref-mut-twice.rs:9:21
|
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
-LL |
+...
LL | drop(a);
| - first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:16:21
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:19:21
|
LL | let ref mut a @ ref mut b = U;
| ------------^^^^^^^^^
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
-LL |
+...
LL | *a = U;
| ------ first borrow later used here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:25:25
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:37:25
|
LL | let a @ (ref mut b, ref mut c) = (U, U);
| ----------------^^^^^^^^^- ------ move occurs because value has type `(main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:29:21
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:41:21
|
LL | let a @ (b, [c, d]) = &mut val; // Same as ^--
| ------------^-- -------- move occurs because value has type `&mut (main::U, [main::U; 2])`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:33:18
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:45:18
|
LL | let a @ &mut ref mut b = &mut U;
| ---------^^^^^^^^^ ------ move occurs because value has type `&mut main::U`, which does not implement the `Copy` trait
| value moved here
error[E0382]: borrow of moved value
- --> $DIR/borrowck-pat-ref-mut-twice.rs:36:30
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:48:30
|
LL | let a @ &mut (ref mut b, ref mut c) = &mut (U, U);
| ---------------------^^^^^^^^^- ----------- move occurs because value has type `&mut (main::U, main::U)`, which does not implement the `Copy` trait
| value moved here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:52:24
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66:24
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------------^^^^^^^^^-
| ----------- first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:52:53
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:66:53
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ----------------^^^^^^^^^-
| ----------- first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:62:24
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78:24
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ---------------^^^^^^^^^-
| - first borrow later used here
error[E0499]: cannot borrow `_` as mutable more than once at a time
- --> $DIR/borrowck-pat-ref-mut-twice.rs:62:53
+ --> $DIR/borrowck-pat-ref-mut-twice.rs:78:53
|
LL | ref mut a @ Ok(ref mut b) | ref mut a @ Err(ref mut b) => {
| ----------------^^^^^^^^^-
LL | drop(a);
| - first borrow later used here
-error: aborting due to 14 previous errors
+error: aborting due to 28 previous errors
Some errors have detailed explanations: E0007, E0382, E0499.
For more information about an error, try `rustc --explain E0007`.