Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assigning_clones should respect MSRV #12502

Closed
taiki-e opened this issue Mar 18, 2024 · 2 comments · Fixed by #12511
Closed

assigning_clones should respect MSRV #12502

taiki-e opened this issue Mar 18, 2024 · 2 comments · Fixed by #12511
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@taiki-e
Copy link
Member

taiki-e commented Mar 18, 2024

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

@taiki-e taiki-e added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 18, 2024
@humannum14916
Copy link
Contributor

@rustbot claim

@apoelstra
Copy link

Looks like this bug made it into 1.78.0 stable :(.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants