Repository navigation
"assigning... prohibited due to outstanding loan" could be clearer #2969
Description
Activity
Reproduced as of b60a0be
According to my experiments with the current rustc, the statement "if you were to change it to a mutable loan, it's okay" is false, and therefore changing the error message in the manner described would be a mistake.
That is, from what I can tell, rustc treats this:
fn foo01() { // local vector, mutable borrow let x = [1, 2, 4]; let v : &mut int = &mut x[2]; x[2] = 6; // error: assigning to mutable vec content prohibited due to outstanding loan fail_unless!( *v == 6 ); }
the same way that it treats this:
fn foo11() { // owned vector, mutable borrow let x = ~[1, 2, 4]; let v : &mut int = &mut x[2]; x[2] = 6; // error: assigning to mutable vec content prohibited due to outstanding loan fail_unless!( *v == 6 ); }
and that is very different from how it treats this:
fn foo21() { // heap-mutable vector, mutable borrow let x = @mut [1, 2, 4]; let v : &mut int = &mut x[2]; x[2] = 6; fail_unless!( *v == 6 ); }
For the case of the owned vector, the error message makes perfect sense, regardless of whether the loan is mutable or immutable. (And I'm pretty sure we have intentionally given stack-local allocation a semantics matching that of owned allocations.)
The only other scenario that I can imagine this bug is trying to describe, is when we have a heap-mutable vector and an immutable-borrow, like this:
fn foo20() { // heap-mutable vector, immutable borrow let x = @mut [1, 2, 4]; let v : &int = &x[2]; // error: illegal borrow unless pure: creating immutable alias to mutable vec content x[2] = 6; // note: impure due to assigning to mutable vec content fail_unless!( *v == 6 ); }
But rustc emits different error messages (shown above) for these two cases.
So, I am closing this bug as it is not-a-bug, AFAICT. Feel free to reopen if I have misunderstood the issue or incorrectly translated the example to the current syntax.
- added a commit that references this issue
on Jun 4, 2024 - added 2 commits that reference this issue
on Aug 21, 2026
gives me
I think the error message should emphasize that it is an immutable loan. So it's clear that if you were to change it to a mutable loan, it's okay.