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

Use the `cloned` method instead of manually cloning each iterator value #7906

Closed
jdm opened this issue Oct 7, 2015 · 11 comments
Closed

Use the `cloned` method instead of manually cloning each iterator value #7906

jdm opened this issue Oct 7, 2015 · 11 comments

Comments

@jdm
Copy link
Member

@jdm jdm commented Oct 7, 2015

In reftest.rs, there's a servo_args.iter().map(|x| x.clone()).collect() which could be written as servo_args.iter().cloned().collect() instead.

@frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Oct 7, 2015

Ideally, this is something clippy would catch (opened an issue upstream)

@Ms2ger
Copy link
Contributor

@Ms2ger Ms2ger commented Oct 7, 2015

servo_args.to_owned() might work too.

@craftytrickster
Copy link
Contributor

@craftytrickster craftytrickster commented Oct 9, 2015

I am interested in learning Rust and would like to start contributing to servo in the near future. You already wrote out the required solution here, so I really wouldn't be doing anything, but it in case it helps, I can open up a pull request for the change.

@frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Oct 9, 2015

Go for it @craftytrickster! Let us know if you need any help 💁

@pierrechevalier83
Copy link
Contributor

@pierrechevalier83 pierrechevalier83 commented Oct 9, 2015

Oops! I got this one wrong...
#7946
I saw the other ticket (367 from rust-clippy) that was tagged E-medium and thought it was about replacing the instances of this pattern...
Turns out I fixed this one instead by mistake...
Sorry guys (especially craftytrickster). I promise I'll move away from the E-easy ones now.

@pierrechevalier83
Copy link
Contributor

@pierrechevalier83 pierrechevalier83 commented Oct 9, 2015

feel free to reject my PR (if it's possible at this point) so that craftytrickster can give it a go

@pierrechevalier83
Copy link
Contributor

@pierrechevalier83 pierrechevalier83 commented Oct 9, 2015

Small recap of the situation: jdm rejected my PR and I deleted the branch... Go for it craftytrickster! This issue is yours :)

@craftytrickster
Copy link
Contributor

@craftytrickster craftytrickster commented Oct 9, 2015

I had heard that the Rust community was very nice, looks like the rumors were true.

Ultimately, my pull request was just the same as pierre's, thanks for giving me the chance to do it. I thought I found a few more instances, but they were cargo dependencies and not part of the actual project.

@craftytrickster
Copy link
Contributor

@craftytrickster craftytrickster commented Oct 9, 2015

I've noticed several uses of the method .unwrap() in the code, such as in one of the changed files

.cloned()).unwrap();

I was under the impression that it was dangerous, since a missing value can crash the program. Is there a reason why it is in use?

bors-servo pushed a commit that referenced this issue Oct 10, 2015
Making map+clone more succinct with cloned

#7906

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7949)
<!-- Reviewable:end -->
@jdm
Copy link
Member Author

@jdm jdm commented Oct 10, 2015

Sometimes it's used because the author of the code knows that there will always be a value (for example, they checked is_some() earlier). Other times it's incorrect, like you said :)

bors-servo pushed a commit that referenced this issue Oct 10, 2015
Making map+clone more succinct with cloned

#7906

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7949)
<!-- Reviewable:end -->
@jdm
Copy link
Member Author

@jdm jdm commented Nov 17, 2015

Fixed by #7949.

@jdm jdm closed this Nov 17, 2015
jrmuizel pushed a commit to jrmuizel/gecko-cinnabar that referenced this issue Jun 12, 2017
… craftytrickster:map-clone-to-cloned); r=nox

servo/servo#7906

Source-Repo: https://github.com/servo/servo
Source-Revision: 04266f237a807ed3abbb678cbda0f5a8439171c7
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Sep 30, 2019
… craftytrickster:map-clone-to-cloned); r=nox

servo/servo#7906

Source-Repo: https://github.com/servo/servo
Source-Revision: 04266f237a807ed3abbb678cbda0f5a8439171c7

UltraBlame original commit: 5eaaffda24495aefe547f0fea1edec3bef09f34c
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 1, 2019
… craftytrickster:map-clone-to-cloned); r=nox

servo/servo#7906

Source-Repo: https://github.com/servo/servo
Source-Revision: 04266f237a807ed3abbb678cbda0f5a8439171c7

UltraBlame original commit: 5eaaffda24495aefe547f0fea1edec3bef09f34c
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 1, 2019
… craftytrickster:map-clone-to-cloned); r=nox

servo/servo#7906

Source-Repo: https://github.com/servo/servo
Source-Revision: 04266f237a807ed3abbb678cbda0f5a8439171c7

UltraBlame original commit: 5eaaffda24495aefe547f0fea1edec3bef09f34c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.