Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint against String.repeat(1) #3028

Closed
matthiaskrgr opened this issue Aug 10, 2018 · 11 comments · Fixed by #5773
Closed

lint against String.repeat(1) #3028

matthiaskrgr opened this issue Aug 10, 2018 · 11 comments · Fixed by #5773
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@matthiaskrgr
Copy link
Member

    let x = String::from("hello world").repeat(1);

or

    let x = String::from("hello");
    let y = x.repeat(1);

does just clone the String.

@matthiaskrgr matthiaskrgr changed the title identity_op: lint against String.repeat(1) lint against String.repeat(1) Aug 10, 2018
@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Aug 10, 2018
@einashaddad
Copy link

I'll pick this up!

@flip1995
Copy link
Member

flip1995 commented Aug 16, 2018

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

@einashaddad
Copy link

einashaddad commented Aug 17, 2018

Awesome, thanks!

Here's an initial stab at it: #3060

@HarrisonMc555
Copy link
Contributor

@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.

@flip1995
Copy link
Member

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

@HarrisonMc555
Copy link
Contributor

Ok, will do. Thanks!

@einashaddad
Copy link

einashaddad commented Apr 23, 2019 via email

@giraffate
Copy link
Contributor

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

@flip1995
Copy link
Member

flip1995 commented Jul 3, 2020

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

@giraffate
Copy link
Contributor

@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.

@flip1995
Copy link
Member

flip1995 commented Jul 3, 2020

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.

bors added a commit that referenced this issue Jul 14, 2020
Add a lint for `.repeat(1)`

changelog: New lint `repeat_once`

fix #3028.
@bors bors closed this as completed in 5307cb5 Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants