RS.CLIPPY.STR_TO_STRING

Using `to_string()` on a `&str`, which should be `to_owned()`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: str_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 &str.

Why restrict this?

The to_string method is also used on other types to convert them to a string. When called on a &str it turns the &str into the owned variant String, which can be more specifically expressed with .to_owned().

Example

let _ = "str".to_string();

Use instead:

let _ = "str".to_owned();