rust-lang / rust-lang/rust-clippy
`needless_pass_by_value`: Wrongly emit on Rc values
Open
Nobody has claimed this yet.
C-bug
I-false-positive
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
It's more expensive to pass in a &Rc than just cloning it.
Lint Name
clippy::needless_pass_by_value
Reproducer
I tried this code:
#![warn(clippy::needless_pass_by_value)]
#![allow(unused)]
use std::rc::Rc;
fn foo(s: Rc<()>) {}
I saw this happen:
warning: this argument is passed by value, but not consumed in the function body
--> src/main.rs:5:11
|
5 | fn foo(s: Rc<()>) {}
| ^^^^^^ help: consider taking a reference instead: `&Rc<()>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::needless_pass_by_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Version
rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6
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
Reproduce the warning with the provided Rc<()> example, then inspect the implementation of clippy::needless_pass_by_value and its existing tests. Update the lint handling so Rc values are not incorrectly diagnosed, add coverage for the reproducer, and verify the test suite passes with the corrected diagnostic behavior.
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
- Mostly clear
- Newbie friendliness
- 45/100