rust-lang / rust-lang/rust-clippy
Regression in `ptr_arg`
Open
Nobody has claimed this yet.
C-bug
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
Clippy had displayed ptr_arg warnings before Rust version 1.60
➜ expr git:(master) ✗ cargo +1.59 clippy
Checking expr v0.1.0 (/home/maksim/dev/my/expr)
warning: writing `&String` instead of `&str` involves a new object where a slice will do
--> src/lib.rs:1:15
|
1 | pub fn foo(_: &String) {}
| ^^^^^^^ help: change this to: `&str`
|
= note: `#[warn(clippy::ptr_arg)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
--> src/lib.rs:2:15
|
2 | pub fn bar(_: &Vec<u8>) {}
| ^^^^^^^^ help: change this to: `&[u8]`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
warning: `expr` (lib) generated 2 warnings
Finished dev [unoptimized + debuginfo] target(s) in 0.14s
➜ expr git:(master) ✗ cargo +1.60 clippy
Checking expr v0.1.0 (/home/maksim/dev/my/expr)
Finished dev [unoptimized + debuginfo] target(s) in 0.14s
Reproducer
I tried this code:
fn foo(_: &String) {}
fn bar(_: &Vec<u8>) {}
I expected to see this happen:
warning: writing `&String` instead of `&str` involves a new object where a slice will do
--> src/lib.rs:1:15
|
1 | pub fn foo(_: &String) {}
| ^^^^^^^ help: change this to: `&str`
|
= note: `#[warn(clippy::ptr_arg)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
--> src/lib.rs:2:15
|
2 | pub fn bar(_: &Vec<u8>) {}
| ^^^^^^^^ help: change this to: `&[u8]`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
Instead, this happened:
No warning
Version
Working:
rustc 1.59.0 (9d1b2106e 2022-02-23)
binary: rustc
commit-hash: 9d1b2106e23b1abd32fce1f17267604a5102f57a
commit-date: 2022-02-23
host: x86_64-unknown-linux-gnu
release: 1.59.0
LLVM version: 13.0.0
Not working:
rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the src/lib.rs reproducer and compare cargo +1.59 clippy with cargo +1.60 clippy, then trace the ptr_arg lint entry point. Add regression coverage for both &String and &Vec, and verify that the expected warnings return without breaking the existing lint tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100