Skip to content

Prefer .cloned() over .map(|x| x.clone()) #427

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

Merged
merged 2 commits into from
Nov 4, 2015
Merged

Prefer .cloned() over .map(|x| x.clone()) #427

merged 2 commits into from
Nov 4, 2015

Conversation

wartmanm
Copy link

Implicit cloning by dereferencing Copy types is included as well. It seems to be almost as common, at least in the code I've written.

I feel like I'm misusing if_let_chain!(), I hope not too badly...

@llogiq
Copy link
Contributor

llogiq commented Oct 31, 2015

Looks good, just one potential problem: The deref_only part may lead to false positives if the Deref contains an implicit type conversion (e.g. syntax::ptr::P<T> derefs to T, whereas .clone() will create another P<T>.

Solving this will require checking for auto-adjustments, I think.

@wartmanm
Copy link
Author

You're right, I completely overlooked that. I figured the walk_ptrs_ty_depth check would avoid it, but it didn't work if you derefed a &P<T> twice.

@llogiq
Copy link
Contributor

llogiq commented Nov 3, 2015

Do you need help with the check? I think we should have something similar in eta_reduction.rs.

@wartmanm
Copy link
Author

wartmanm commented Nov 4, 2015

Sorry, it's been done for a little while, but I force-pushed the change, which wasn't very helpful of me. I moved the check in eta_reduction.rs into util.rs, I hope that's okay.

@Manishearth
Copy link
Member

Force push is fine with us

@llogiq
Copy link
Contributor

llogiq commented Nov 4, 2015

Yes, I just overlooked it. I'll merge.

llogiq added a commit that referenced this pull request Nov 4, 2015
Prefer `.cloned()` over `.map(|x| x.clone())`
@llogiq llogiq merged commit 364bdc5 into rust-lang:master Nov 4, 2015
Manishearth added a commit that referenced this pull request Oct 2, 2018
This removes the code added in #427
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants