rust-lang / rust-lang/rust-clippy

`needless_pass_by_value`: Wrongly emit on Rc values

Open
#13,155 5 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.