Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit ptr_arg warning about unused function arguments #13728

Open
orlp opened this issue Nov 25, 2024 · 1 comment
Open

Don't emit ptr_arg warning about unused function arguments #13728

orlp opened this issue Nov 25, 2024 · 1 comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@orlp
Copy link

orlp commented Nov 25, 2024

Summary

If a function argument is unused there is no way to know whether or not its signature is appropriate. It's better to not bother people with lints based entirely on the assumption of one usage when in reality it might have another usage if implemented.

Lint Name

clippy::ptr_arg

Reproducer

I tried this code:

fn bar(_x: &mut Vec<u32>) {
    todo!()
}

I saw this happen:

warning: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
 --> src/lib.rs:8:16
  |
8 |     fn bar(_x: &mut Vec<u32>) {
  |                ^^^^^^^^^^^^^ help: change this to: `&mut [u32]`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
  = note: `#[warn(clippy::ptr_arg)]` on by default

I expected to see this happen:

No warning, there is no way to know if a slice would be sufficient once the function body is expanded to use the argument.

Version

rustc 1.84.0-nightly (a0d98ff0e 2024-10-31)
binary: rustc
commit-hash: a0d98ff0e5b6e1f2c63fd26f68484792621b235c
commit-date: 2024-10-31
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.1

Additional Labels

No response

@orlp orlp added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 25, 2024
@Centri3
Copy link
Member

Centri3 commented Nov 25, 2024

Similar to #13489, I think not linting on both unused and _ prefixed arguments is reasonable.

@Centri3 Centri3 added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-positive Issue: The lint was triggered on code it shouldn't have and removed C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants