rust-lang / rust-lang/rust-clippy

`RefCell<u32>` -> `Cell<u32>`

Open
#7,490 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

Suggest using Cell<T> instead of RefCell<T>, T=u32,i32,f32 ...

Categories (optional)

clippy::perf

What is the advantage of the recommended code over the original code

  • RefCell will calculate borrow at runtime, so RefCell has more overhead over Cell
  • RefCell may panic at runtime
Drawbacks

Maybe some problems in generic type.

Example
struct S(RefCell<u32>);

Could be written as:

struct S(Cell<u32>);

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 with the proposed RefCell to Cell transformation and the clippy::perf category. Determine which concrete types and generic cases are safe to cover; done means the accepted scope is specified and the corresponding lint behavior is tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
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.