Skip to content

Suggest trait implementations for references/boxes #2258

@clarfonthey

Description

@clarfonthey

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.L-guidelinesLint: Related to the Rust API GuidelinesT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions