False positive for `clippy::needless_borrows_for_generic_args`?

I have an example on the playground: Rust Playground

When I run Clippy on it, I get:

warning: the borrowed expression implements the required traits

with this suggestion:

10 |     process(&mut data);
   |             ^^^^^^^^^ help: change this to: `data`

However, data is a built-in array and removing &mut would copy it instead of making the intended mutation to the original data. I would say that's not a good suggestion.

So is this a false positive?
Or am I doing something wrong?

If it is a false positive, I can create an issue, but I wanted to check here first if I'm understanding it correctly.

And a follow-up question: Is there a way to change my function signature to somehow disallow unintentionally calling it with a copy of an array (but at the same time still allow the chunks_mut() use case I mentioned in the playground example)?

I agree that this is a false positive since applying the given suggestion changes the meaning of the program.

One way would be requiring the iterator items to be mutable references whose pointed value then implements AsMut<[i32]>. Rust Playground

Thanks for confirming this! I've created an issue: False positive for `clippy::needless_borrows_for_generic_args` · Issue #16538 · rust-lang/rust-clippy · GitHub.

Thanks also for the improved trait bounds, those work great for the examples I've given!

However, there's one situation that ideally also should be disallowed (but isn't):

let mut s0 = [10, 20, 30];
let mut s1 = [40, 50, 60];
process(&mut [s0, s1]);

I have added this: Rust Playground.

Do you have an idea how this could be disallowed as well?

If not, it's not a big deal, I guess I could live with this small papercut.

I don't think this can be disallowed. From the point of view of process this is no different than passing the &mut data from your original example.

I think there could be room for a lint that catches passing mutable borrows of temporaries to functions (ie. semantics similar to C++). It feels like a footgun and is rarely what's intended.