When I write this:
fn add1(vc: &mut Vec<usize>) {
func1(vc, vc[0]);
}
fn func1(vc: &mut Vec<usize>, val: usize) {}
Clippy tells me that "writing &mut Vec
instead of &mut [_]
involves a new object where a slice will do".
However if I switch it to this:
fn add1(vc: &mut Vec<usize>) {
func1(vc, vc[0]);
}
fn func1(vc: &mut [usize], val: usize) {}
I get "cannot borrow *vc
as immutable because it is also borrowed as mutable [E0502]".
This makes sense, but why then did it work before?
Also, why is Clippy giving me incorrect warnings?