Skip to content

Lint against calling .clone() on an otherwise copyable value. #27266

Closed

Description

@eddyb

Certain types could start out as having contents that move and then switch to only copyable field, or could just be missing #[deriving(Copy)] initially.

If Copy is implemented after that type has been used in a large codebase (there's a few cases in rustc itself), there will likely be many .clone() calls around, and finding which ones belong to the type could be tedious.

A lint would ease this work, by suggesting the replacement of an unnecessary x.clone() call with a dereference (if x is a reference to the type being cloned - could use the autoderef count here) or nothing at all (since using a Copy lvalue as an rvalue will just copy it).

Activity

  1. added
    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
    on Jul 24, 2015
  2. nagisa commented on Jul 24, 2015

    @nagisa
    Member

    Is it really necessary? Doesn’t sound like a footgun type of an issue.

  3. Gankra commented on Jul 24, 2015

    @Gankra
    Contributor

    I agree with @nagisa, especially if your code is generated (macros, syntax extensions, etc...).

  4. eddyb commented on Jul 24, 2015

    @eddyb
    ContributorAuthor

    I don't know how else to clean up the compiler code. In a cargo crate I'd just use clippy.

  5. Gankra commented on Jul 24, 2015

    @Gankra
    Contributor

    @eddyb ...is it a serious problem?

  6. steveklabnik commented on Feb 11, 2016

    @steveklabnik
    Contributor

    Since new lints have a big impact on users of rustc, the policy is that they should go through the RFC process like other user-facing changes. As such, I'm going to give this one a close, but if anyone comes across this ticket and wants this lint, consider adding it to clippy and/or writing up an RFC. Thanks!

  7. eddyb commented on Feb 11, 2016

    @eddyb
    ContributorAuthor

    @steveklabnik That's fine, I'm hoping #31123 will let us use clippy on rustc fairly easy.

  8. Manishearth commented on Apr 25, 2016

    @Manishearth
    Member
  9. strega-nil commented on Apr 26, 2016

    @strega-nil
    Contributor

    This seems really useful in normal rust, like with <&T>::clone

  10. Manishearth commented on Apr 27, 2016

    @Manishearth
    Member

    The current policy is no new lints in Rust unless it's really special.

  11. strega-nil commented on Apr 27, 2016

    @strega-nil
    Contributor

    Merp :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions