rust-lang / rust-lang/rust-clippy

Suggest trait implementations for references/boxes

Open
#2,258 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint E-medium L-guidelines T-middle
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Sort of an awkward way to word this, but it'll make a bit more sense with an explanation.

Right now, there are implementations for &T + T, T + &T, and T += &T for integer types. There should be some nice list of traits where there should be suggestions to add implementations for references as well.

Just off the top of my head:

  • Add, etc. should have Add<&U> for T and Add<U> for &T if Add<U> for T is available.
  • AddAssign, etc. should have AddAssign<&U> for T if AddAssign<U> for T is available.
  • Sum, etc. should have Sum for &T if Sum for T is available.

There may be a way to detect a list of traits where an impl for T should suggest an impl for &T, &mut T, and Box<T> as well, like Hasher and Debug. I'm not sure how we could suggest which traits work for this, but I figured I'd add it to the discussion.

These "convenience" impls are nice to have and there are a lot of cases where these are added to the standard library when they are forgotten. It'd be nice if we could suggest them via clippy.

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

No source file, test, or entry point is named. Start by reviewing the existing reference implementations for Add, AddAssign, and Sum, then compare the possible Hasher and Debug cases mentioned in the issue. Done would require a decided, maintainable rule for which reference, mutable-reference, and Box implementations Clippy should suggest.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.