ptr_arg
should not warn about &mut Vec<T> for underscore prefixed parameters
#13489
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
Summary
Clippy only warns about parameters of type
&mut Vec<T>
being replaceable by&mut [T]
if none of theVec
APIs are used.For example, you can't use
&mut [T]
instead if you want topush
into theVec
.A leading
_
indicates intentionally unused parameters. The compiler should essentially assume (for the purpose of warnings) that the parameter is being used, but in a way that it cannot see. This is usually done fortodo!
s,#[cfg]
stuff or api requirements.If there's a usage that we cannot see, than we should not assume anything about that usage. So we should not assume that it isn't e.g. a
push
into theVec
.Therefore, the warning about
&mut Vec<T>
should not be emitted for such parameters.Lint Name
clippy::ptr_arg
Reproducer
I tried this code:
I saw this happen:
I expected to see this happen:
No diagnostic.
Version
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
Additional Labels
No response
The text was updated successfully, but these errors were encountered: