rust-lang / rust-lang/rust-clippy

The "rc_buffer" lint is probably wrong for inner Vec types which implement Clone or Copy

Open
#6,359 3 comments 0 reactions 0 assignees View on GitHub

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

I previously landed a clarification that this lint is not always correct, depending on the use-case: https://github.com/rust-lang/rust-clippy/pull/6090

Today I discovered that Rc::make_mut() and Arc::make_mut() exist for Rc<T: Clone> and Arc<T: Clone> respectively.

The rc_buffer lint says that you can only get a mutable reference if there are no mutable references or else panic, which is not true due to these functions. Copy-on-write is perfectly reasonable for types which are Clone. See also https://github.com/http-rs/tide/pull/747.

I'm willing to make a change to only have this lint apply when T is not Clone if someone can point me in the direction of how to do that. It looks like there are 4 lint sites, two of which are for slices. The lint should also be updated to mention make_mut, which could be done either in the same PR or separately.

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

Start by locating the four rc_buffer lint sites mentioned in the issue, including the two handling slices, and inspect how they determine whether the inner type is Clone. Check the existing lint tests and documentation around rc_buffer. Done means the lint no longer recommends the change for Clone types and its message explains Rc::make_mut() and Arc::make_mut().

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.