Open
Description
The following code:
#![warn(noop_method_call)]
struct Board;
fn do_part1(boards: &Vec<Board>) {
let boards = boards.clone();
boards[0] = Board;
}
produces the following error:
error[E0596]: cannot borrow `*boards` as mutable, as it is behind a `&` reference
--> src/lib.rs:7:5
|
6 | let boards = boards.clone();
| ------ help: consider changing this to be a mutable reference: `&mut Vec<Board>`
7 | boards[0] = Board;
| ^^^^^^ `boards` is a `&` reference, so the data it refers to cannot be borrowed as mutable
For more information about this error, try `rustc --explain E0596`.
If we comment out boards[0] = Board;
, then the noop_method_call
lint will fire as expected. However, when that line is present, the lint never gets a chance to run, since the mutable borrow error occurs during MIR borrowchecking. Displaying the lint would help the user to resolve the problem, since the root cause is the fact that the .clone()
call produces a &Vec<Board>
, not a Vec<Board>
.
Originally identified in #91532