rust-lang / rust-lang/rust-clippy

rc-buffer doesn't recognize Rc<String> in some cases

Open
#8,059 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

rc-buffer doesn't recognize Rc<Buffer> when used in function body.

If a local function variable has Rc<String> type, the lint should trigger, but it does not.

Lint Name

rc-buffer

Reproducer

I tried this code:

use std::collections::BTreeMap;
use std::rc::Rc;

fn main() {
    let mut bt = BTreeMap::<Rc<String>, u64>::new();
    let key: Rc<String> = Rc::from("foo".to_string());
    bt.insert(key, 12);
    println!("{:?}", bt.get(&"foo".to_string()));
}

I expected to see this happen:
clippy displays rc-buffer lint for lines 4 and 5 and suggests to use Rc<str> instead of Rc<String>.

Instead, this happened:
clippy returns no lint messages.

Version
rustc 1.59.0-nightly (48a5999fc 2021-12-01)
binary: rustc
commit-hash: 48a5999fceeea84a8971634355287faa349909d4
commit-date: 2021-12-01
host: x86_64-pc-windows-msvc
release: 1.59.0-nightly
LLVM version: 13.0.0

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 reproducing the provided Rust example and then locate the rc-buffer lint implementation. Confirm that Rc local variables in function bodies are diagnosed and that the lint suggests Rc; add or update coverage for this reproducer.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.