Skip to content

assigning_clones should respect MSRV #12502

Closed
@taiki-e

Description

@taiki-e

Summary

clone_into has been stabilized in 1.63, but this lint also suggests using it for code with MSRV less than 1.63.

Mentioning @Kobzol, who implemented this lint in #12077.

Lint Name

assigning_clones

Reproducer

I tried this code:

#![warn(clippy::assigning_clones)]
#![allow(dead_code, unused_assignments)]

#[clippy::msrv = "1.62"]
fn f(mut a: String, b: &str) -> String {
    a = b.to_owned();
    a
}

I saw this happen:

warning: assigning the result of `ToOwned::to_owned()` may be inefficient
 --> src/lib.rs:6:5
  |
6 |     a = b.to_owned();
  |     ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `b.clone_into(&mut a)`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::assigning_clones)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^

However suggested code is not compatible with MSRV:

#![warn(clippy::assigning_clones)]
#![allow(dead_code, unused_assignments)]

#[clippy::msrv = "1.62"]
fn f(mut a: String, b: &str) -> String {
    b.clone_into(&mut a);
    a
}
warning: current MSRV (Minimum Supported Rust Version) is `1.62.0` but this item is stable since `1.63.0`
 --> src/lib.rs:6:7
  |
6 |     b.clone_into(&mut a);
  |       ^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#incompatible_msrv
  = note: `#[warn(clippy::incompatible_msrv)]` on by default

I expected to see this happen: no warning

playground

Version

rustc 1.79.0-nightly (eb45c8444 2024-03-17)
binary: rustc
commit-hash: eb45c844407968ea54df0d9870ebce9e3235b706
commit-date: 2024-03-17
host: aarch64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions