Make string_to_string emit a suggestion when cloned can be used

This commit is contained in:
Guillaume Gomez 2025-03-13 11:46:02 +01:00
parent 0ffc6cf097
commit 0e4b6c8124
6 changed files with 66 additions and 49 deletions

View file

@ -1,8 +1,22 @@
#![warn(clippy::string_to_string)]
#![allow(clippy::redundant_clone)]
#![allow(clippy::redundant_clone, clippy::unnecessary_literal_unwrap)]
fn main() {
let mut message = String::from("Hello");
let mut v = message.to_string();
//~^ string_to_string
let variable1 = String::new();
let v = &variable1;
let variable2 = Some(v);
let _ = variable2.map(|x| {
println!();
x.to_string()
});
//~^^ string_to_string
// Should not lint.
let x = Some(String::new());
let _ = x.unwrap_or_else(|| v.to_string());
//~^ string_to_string
}