You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnf(x:&mut[u8]) -> u8{
x[0] = 5;1}fng(y:&mut[u8],v:u8){
y[1] = v;}fnmain(){letmut a:[u8;3] = [1,2,3];// This works:let b = f(&mut a);g(&mut a, b);// But this doesn't:// g(&mut a, f(&mut a));println!("{:?}", a);}
if the g(&mut a, f(&mut a)); line is uncommented the compiler gives the following error:
cannot borrow `a` as mutable more than once at a time
--> lifetimes.rs:12:22
|
12 | g(&mut a, f(&mut a));
| - ^ - first borrow ends here
| | |
| | second mutable borrow occurs here
| first mutable borrow occurs here
It seems very odd to me that that line doesn't compile, but if I move the result of the call to f into a temporary variable it does.
Unless I am missing something the borrow in the call to f ends before the call to g starts, so this shouldn't be multiple mutable borrows at the same time.
The text was updated successfully, but these errors were encountered:
Current behavior is to evaluate the borrows from left to right. If it would be resolved (it's not resolved yet), it falls under the umbrella of rust-lang/rfcs/issues/811
Consider the following example:
if the
g(&mut a, f(&mut a));
line is uncommented the compiler gives the following error:It seems very odd to me that that line doesn't compile, but if I move the result of the call to f into a temporary variable it does.
Unless I am missing something the borrow in the call to f ends before the call to g starts, so this shouldn't be multiple mutable borrows at the same time.
The text was updated successfully, but these errors were encountered: