E0499 message under-specifying regarding the nature of borrow conflict
Open
@ozankenangungor is already working on this.
Since Mar 24, 2026.
A-diagnostics
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.2k
- PR merge metrics
- PR metrics pending
Description
Code
struct S {
a: Vec<i32>,
b: i32,
}
impl S {
fn g(&mut self, x: &i32) -> i32 {
self.b += 1;
*x + self.b
}
fn f(&mut self) -> i32 {
let x: &i32 = self.a.get_mut(0).unwrap();
self.g(x)
}
}
fn main() {}
Current output
error[E0499]: cannot borrow `*self` as mutable more than once at a time
--> src/compiler_error_message_issue2.rs:14:9
|
13 | let x: &i32 = self.a.get_mut(0).unwrap();
| ------ first mutable borrow occurs here
14 | self.g(x)
| ^^^^ - first borrow later used here
| |
| second mutable borrow occurs here
Desired output
error[E0499]: cannot borrow `*self` as mutable when a part of it is already borrowed as mutable.
--> src/compiler_error_message_issue2.rs:14:9
|
13 | let x: &i32 = self.a.get_mut(0).unwrap();
| ------ mutable partial borrow of `self` first occurs here
14 | self.g(x)
| ^^^^ - first borrow later used here
| |
| mutable borrow of `self` occurs here
Rationale and extra context
No response
Other cases
Rust Version
rustc --version --verbose
rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0
Anything else?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.