Rust-clippy: lint against String.repeat(1)

Created on 10 Aug 2018  Â·  11Comments  Â·  Source: rust-lang/rust-clippy

rust let x = String::from("hello world").repeat(1);
or
rust let x = String::from("hello"); let y = x.repeat(1);
does just clone the String.

L-lint good-first-issue hacktoberfest

Most helpful comment

I'll pick this up!

All 11 comments

I'll pick this up!

Great! If you have any questions, feel free to ask here or open a WIP PR. We're happy to help!

Awesome, thanks!

Here's an initial stab at it: https://github.com/rust-lang-nursery/rust-clippy/pull/3060

@einashaddad Are you still interested in taking care of this lint? I'm looking for an issue or two to pick up, I'd be willing to help out here if you're no longer available.

I think the PR #3060 was nearly finished, except of some review comments, that need to be addressed. You could go from there.

Ok, will do. Thanks!

Hey y'all - sorry for the late reply, I've been traveling. I can address
the comments in a week when I'm back from vacation!

On Tue, Apr 23, 2019, 12:29 AM Harrison notifications@github.com wrote:

Ok, will do. Thanks!

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rust-lang/rust-clippy/issues/3028#issuecomment-485450294,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAUBWSKYX5WL7ZLAXZFKU7LPRXKW5ANCNFSM4FPDI4OQ
.

Hi! If nobody is interested in this, could I try this?

Yes, take a look at #3060, which is nearly finished

@flip1995 Thank you for your infomation.

And I am sorry for the question immediately, why is String.repeat(1) bad?
I couldn't understand the hidden intention behind the repeat(1) call in this comment well.

Oh String.repeat(1) is the same as String.clone(). See the documentation:

Creates a new String by repeating a string n times.

with n=1 this is the same as cloning the string. If that is really the intention behind this, clone should be used.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Manishearth picture Manishearth  Â·  20Comments

Manishearth picture Manishearth  Â·  20Comments

kevincox picture kevincox  Â·  17Comments

davemilter picture davemilter  Â·  18Comments

malbarbo picture malbarbo  Â·  26Comments