RS.CLIPPY.STRING_TO_STRING

Using `to_string()` on a `String`, which should be `clone()`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: string_to_string. Copyright ©2025 The Rust Team. All rights reserved.

What it does

This lint checks for .to_string() method calls on values of type String.

Why restrict this?

The to_string method is also used on other types to convert them to a string. When called on a String it only clones the String, which can be more specifically expressed with .clone().

Example

let msg = String::from("Hello World");
let _ = msg.to_string();

Use instead:

let msg = String::from("Hello World");
let _ = msg.clone();