Skip to content

Borrow checker gives E0499 in loops with mutable borrows, but it is misleading #99824

Closed
@TheButlah

Description

@TheButlah

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6a4dbffaa1c7bfe6e167b40eacaca921
The current output is:

error[E0499]: cannot borrow `decoder` as mutable more than once at a time
  --> src/main.rs:15:29
   |
15 |     while let Some(frame) = decoder.read_next_frame().unwrap() {
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^ `decoder` was mutably borrowed here in the previous iteration of the loop

It looks like the error is pointing to the wrong spot in the code and is quite misleading.
Ideally the output should mention that decoder is still mutably borrowed because it holds a reference to frame between loops. Or something, im not actually sure :P

I have confirmed that this occurs in both the latest stable (1.62.1) and nightly (1.64.0-nightly 4d6d601c8 2022-07-26)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions