rust-lang / rust-lang/rust

E0499 message under-specifying regarding the nature of borrow conflict

Open
#154,319 2 comments 0 reactions 1 assignee View on GitHub

@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?

https://github.com/rust-lang/rust/issues/154275

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.