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
I recently had a case where a function needed an argument prepared by another function. Both functions take the same &mut (they both update a cache reachable through that reference). However, I had to pull the argument preparation call out of the argument list to avoid a cannot borrow ... as mutable more than once at a time error. Here is a minimal test case:
fn g(x: &mut int) -> int {
*x
}
fn f(x: &mut int, y: int) {
*x += y;
}
fn main() {
let mut a = 1;
// This works:
let tmp = g(&mut a);
f(&mut a, tmp);
// This is essentially the same, but fails the borrow check
f(&mut a, g(&mut a));
}
Maybe I'm overlooking something here, but I think the second call should work too, as the ref borrowed by g() is returned before it is borrowed by f().
The text was updated successfully, but these errors were encountered:
Rename run_lints -> lints_enabled
Just a quick rename of a utilities function. `run_lints` kinda suggested that the lints were run by this function. But the only thing this function does is to check if the lints are enabled in the context of the `hir_id`
changelog: none
I recently had a case where a function needed an argument prepared by another function. Both functions take the same
&mut
(they both update a cache reachable through that reference). However, I had to pull the argument preparation call out of the argument list to avoid acannot borrow ... as mutable more than once at a time
error. Here is a minimal test case:Maybe I'm overlooking something here, but I think the second call should work too, as the ref borrowed by
g()
is returned before it is borrowed byf()
.The text was updated successfully, but these errors were encountered: