rust-lang/rust-clippy

Lint for .clone().into_boxed_str()

Open

#15 951 ouverte le 25 oct. 2025

Voir sur GitHub
 (4 commentaires) (0 réactions) (1 assigné)Rust (1 391 forks)batch import
A-lintgood first issue

Métriques du dépôt

Stars
 (10 406 stars)
Métriques de merge PR
 (Merge moyen 16j 6h) (79 PRs mergées en 30 j)

Description

What it does

Suggest turning s.clone().into_boxed_str() into Box::from(s.as_str()).

Possibly could be grouped together with other inefficient string conversions.

Advantage

Removes a call to __rust_realloc

Drawbacks

No response

Example

fn foo(s: &String) -> Box<str> {
    s.clone().into_boxed_str()
}

Could be written as:

fn foo(s: &String) -> Box<str> {
    Box::from(s.as_str())
}

Comparison with existing lints

redundant_clone generally doesn't consider the semantics of the

Additional Context

A GitHub search shows this unoptimal pattern is actually used fairly often.

Guide contributeur