2018-10-23 02:01:45 -05:00
|
|
|
#![warn(clippy::redundant_clone)]
|
|
|
|
|
|
|
|
use std::ffi::OsString;
|
2018-12-09 16:26:16 -06:00
|
|
|
use std::path::Path;
|
2018-10-23 02:01:45 -05:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let _ = ["lorem", "ipsum"].join(" ").to_string();
|
|
|
|
|
|
|
|
let s = String::from("foo");
|
|
|
|
let _ = s.clone();
|
|
|
|
|
|
|
|
let s = String::from("foo");
|
|
|
|
let _ = s.to_string();
|
|
|
|
|
|
|
|
let s = String::from("foo");
|
|
|
|
let _ = s.to_owned();
|
|
|
|
|
|
|
|
let _ = Path::new("/a/b/").join("c").to_owned();
|
|
|
|
|
|
|
|
let _ = Path::new("/a/b/").join("c").to_path_buf();
|
|
|
|
|
|
|
|
let _ = OsString::new().to_owned();
|
|
|
|
|
|
|
|
let _ = OsString::new().to_os_string();
|
2018-10-25 07:08:32 -05:00
|
|
|
|
|
|
|
// Check that lint level works
|
2018-12-09 16:26:16 -06:00
|
|
|
#[allow(clippy::redundant_clone)]
|
|
|
|
let _ = String::new().to_string();
|
2018-12-09 05:19:21 -06:00
|
|
|
|
|
|
|
let tup = (String::from("foo"),);
|
|
|
|
let _ = tup.0.clone();
|
|
|
|
|
|
|
|
let tup_ref = &(String::from("foo"),);
|
|
|
|
let _s = tup_ref.0.clone(); // this `.clone()` cannot be removed
|
2018-10-23 02:01:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
struct Alpha;
|
2018-12-09 04:18:44 -06:00
|
|
|
fn with_branch(a: Alpha, b: bool) -> (Alpha, Alpha) {
|
|
|
|
if b {
|
2018-10-23 02:01:45 -05:00
|
|
|
(a.clone(), a.clone())
|
|
|
|
} else {
|
|
|
|
(Alpha, a)
|
|
|
|
}
|
|
|
|
}
|
2018-12-09 05:19:21 -06:00
|
|
|
|
|
|
|
struct TypeWithDrop {
|
|
|
|
x: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for TypeWithDrop {
|
|
|
|
fn drop(&mut self) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn cannot_move_from_type_with_drop() -> String {
|
2018-12-10 18:41:59 -06:00
|
|
|
let s = TypeWithDrop { x: String::new() };
|
2018-12-09 05:19:21 -06:00
|
|
|
s.x.clone() // removing this `clone()` summons E0509
|
|
|
|
}
|