You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you need to own a value out of an array, you need to clone it. However clippy complains that the clone is redundant:
fnmain(){let a:[String;1] = [String::from("foo")];let b:String = a[0].clone();}// warning: redundant clone// --> src/main.rs:3:25// |// 3 | let b: String = a[0].clone();// | ^^^^^^^^ help: remove this// |// = note: `#[warn(clippy::redundant_clone)]` on by default// note: this value is dropped without further use// --> src/main.rs:3:21// |// 3 | let b: String = a[0].clone();// | ^^^^// = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
If I remove the clone, I get this compiler error:
fnmain(){let a:[String;1] = [String::from("foo")];let b:String = a[0];}// error[E0508]: cannot move out of type `[std::string::String; 1]`, a non-copy array// --> src/lib.rs:3:21// |// 3 | let b: String = a[0];// | ^^^^// | |// | cannot move out of here// | move occurs because `a[_]` has type `std::string::String`, which does not implement the `Copy` trait// | help: consider borrowing here: `&a[0]`//// error: aborting due to previous error//// For more information about this error, try `rustc --explain E0508`.
Activity
flip1995 commentedon Apr 2, 2020
cc @sinkuu
Fixes rust-lang#5405: redundant clone false positive with arrays
Fixes rust-lang#5405: redundant clone false positive with arrays
Auto merge of #5453 - rabisg0:fix/redundant_clone, r=phansch
submodules: update clippy from af5940b to 6651c1b