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

Removed DeepClone #12706

Merged
merged 1 commit into from
Mar 9, 2014
Merged

Removed DeepClone #12706

merged 1 commit into from
Mar 9, 2014

Conversation

pongad
Copy link
Contributor

@pongad pongad commented Mar 5, 2014

Fixes #12698

@alexcrichton
Copy link
Member

Can you reference the issue number in the commit message as well? It's helpful with rollups (not that we need one right now), and also with later historical digging.

@thestinger
Copy link
Contributor

I don't agree with removing this, as stated on the issue.

@bill-myers
Copy link
Contributor

Indeed, it seems useful.

Assume you have a simulation whose state is a bunch of interlinked objects, implemented with Rc<RefCell<T>> or @RefCell<T>: then you need DeepClone to make a copy of the state of the simulation.

At most, I think it could be moved to a loadable syntax extension, since indeed there should not be any use cases in core libraries.

That might be an interesting idea to explore as it would allow to add more specialized functionality that would meet resistance in the core libraries, such as support for deep cloning cyclic graphs using an HashMap.

@pongad
Copy link
Contributor Author

pongad commented Mar 5, 2014

A big part of me agrees with @brson that it shouldn't be in stdlib because there is no consumer for it. I also see everyone's point that it should have a use case somewhere. Should it be placed in some lib outside of libstd? It seems weird to have libdeepclone though!

@liigo
Copy link
Contributor

liigo commented Mar 5, 2014

Libextra?
2014年3月6日 上午3:27于 "Michael Darakananda" notifications@github.com写道:

A big part of me agrees with @brson https://github.com/brson that it
shouldn't be in stdlib because there is no consumer for it. I also see
everyone's point that it should have a use case somewhere. Should it be
placed in some lib outside of libstd? It seems weird to have libdeepclone
though!


Reply to this email directly or view it on GitHubhttps://github.com//pull/12706#issuecomment-36782718
.

@thestinger
Copy link
Contributor

It needs to be in libstd if it's going to exist because it's implemented by types in libstd.

@pongad
Copy link
Contributor Author

pongad commented Mar 5, 2014

You are right of course. I will leave the PR here for the time being while we try to reach a consensus.

@alexcrichton
Copy link
Member

We have reached a consensus that this trait does not belong in libstd. If this trait should exist it belongs in a separate library.

@pongad, with an expansion of the commit message, I will r+

@thestinger
Copy link
Contributor

It can't be implemented in another library, because there's no way to implement it on libstd types due to their fields being private. There would also be no way to derive the implementations.

@alexcrichton
Copy link
Member

That is incorrect.

impl<T: DeepClone> DeepClone for Rc<T> {
    fn deep_clone(&self) -> Rc<T> {
        Rc::new(self.borrow().deep_clone())
    }
}

@thestinger
Copy link
Contributor

Rc<T> isn't the only type where this trait is relevant. I don't really mind removing the current incarnation though because it's not going to work for Gc<T>. So, +1 for removing it but I do think we should consider adding something like this back in the future.

@huonw
Copy link
Member

huonw commented Mar 7, 2014

(Friendly reminder that the commit message needs updating still. :) )

@pongad
Copy link
Contributor Author

pongad commented Mar 8, 2014

Updated.

@flaper87
Copy link
Contributor

flaper87 commented Mar 8, 2014

@pongad The patch needs rebase.

@pongad
Copy link
Contributor Author

pongad commented Mar 8, 2014

Rebased. Unfortunately I have an errand to run and cannot make check it just yet. If Travis or bors fails, I'll fix when I get back this evening.

@pongad
Copy link
Contributor Author

pongad commented Mar 9, 2014

@brson I took a glance at Bors queue just now and apparently this PR is still in discussing state. Did bors not see the r+?

bors added a commit that referenced this pull request Mar 9, 2014
@bors bors closed this Mar 9, 2014
@bors bors merged commit 438893b into rust-lang:master Mar 9, 2014
@pongad pongad deleted the issue_12698 branch March 9, 2014 05:02
chris-morgan added a commit to chris-morgan/rust-http that referenced this pull request Mar 10, 2014
Rust update: `DeepClone` was removed (rust-lang/rust#12706)
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 25, 2022
…r=DorianListens

fix: Extract Function misses locals used in closures

This change fixes rust-lang#12705.

In `FunctionBody::analyze`, we need to search any `ClosureExpr`s we encounter
for any `NameRef`s, to ensure they aren't missed.
flip1995 pushed a commit to flip1995/rust that referenced this pull request May 17, 2024
…s, r=dswij

less aggressive needless_borrows_for_generic_args

Current implementation looks for significant drops, that can change the behavior, but that's not enough - value might not have a `Drop` itself but one of its children might have it.

A good example is passing a reference to `PathBuf` to `std::fs::File::open`. There's no benefits to pass `PathBuf` by value, but since `clippy` can't see `Drop` on `Vec` several layers down it complains forcing pass by value and making it impossible to use the same name later.

New implementation only looks at copy values or values created in place     so existing variable will never be moved but things that take a string reference created and value is created inplace `&"".to_owned()` will make it to suggest to use `"".to_owned()` still.

Fixes rust-lang/rust-clippy#12454

changelog: [`needless_borrows_for_generic_args`]: avoid moving variables
dingxiangfei2009 pushed a commit to dingxiangfei2009/rust that referenced this pull request Jul 28, 2024
This commit fixes a bug introduced in rust-lang#12706, where the behavior of the
lint has been changed, to avoid suggestions that introduce a move. The
motivation in the commit message is quite poor (if the detection for
significant drops is not sufficient because it's not transitive, the
proper fix would be to make it transitive). However, rust-lang#12454, the linked
issue, provides a good reason for the change — if the value being
borrowed is bound to a variable, then moving it will only introduce
friction into future refactorings.

Thus rust-lang#12706 changes the logic so that the lint triggers if the value
being borrowed is Copy, or is the result of a function call, simplifying
the logic to the point where analysing "is this the only use of this
value" isn't necessary.

However, said PR also introduces an undocumented carveout, where
referents that themselves are mutable references are treated as Copy,
to catch some cases that we do want to lint against. However, that is
not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the
referent_used_exactly_once logic and runs that check for referents that
are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the
point that while removing the &mut outright won't work, the extra
indirection is still undesirable, and perhaps instead we should suggest
reborrowing: &mut *x. That, however, is left as possible future work.

Fixes rust-lang#12856
dingxiangfei2009 pushed a commit to dingxiangfei2009/rust that referenced this pull request Jul 28, 2024
… r=xFrednet

needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in rust-lang#12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, rust-lang#12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus rust-lang#12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes rust-lang#12856

changelog: none
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 26, 2024
… r=xFrednet

needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in rust-lang#12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, rust-lang#12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus rust-lang#12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes rust-lang#12856

changelog: none
Jarcho pushed a commit to Jarcho/rust that referenced this pull request Aug 26, 2024
… r=xFrednet

needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in rust-lang#12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, rust-lang#12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus rust-lang#12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes rust-lang#12856

changelog: none
MabezDev pushed a commit to esp-rs/rust that referenced this pull request Sep 3, 2024
… r=xFrednet

needless_borrows_for_generic_args: Fix for &mut

This commit fixes a bug introduced in rust-lang#12706, where the behavior of the lint has been changed, to avoid suggestions that introduce a move. The motivation in the commit message is quite poor (if the detection for significant drops is not sufficient because it's not transitive, the proper fix would be to make it transitive). However, rust-lang#12454, the linked issue, provides a good reason for the change — if the value being borrowed is bound to a variable, then moving it will only introduce friction into future refactorings.

Thus rust-lang#12706 changes the logic so that the lint triggers if the value being borrowed is Copy, or is the result of a function call, simplifying the logic to the point where analysing "is this the only use of this value" isn't necessary.

However, said PR also introduces an undocumented carveout, where referents that themselves are mutable references are treated as Copy, to catch some cases that we do want to lint against. However, that is not sound — it's possible to consume a mutable reference by moving it.

To avoid emitting false suggestions, this PR reintroduces the referent_used_exactly_once logic and runs that check for referents that are themselves mutable references.

Thinking about the code shape of &mut x, where x: &mut T, raises the point that while removing the &mut outright won't work, the extra indirection is still undesirable, and perhaps instead we should suggest reborrowing: &mut *x. That, however, is left as possible future work.

Fixes rust-lang#12856

changelog: none
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.

Remove DeepClone
9 participants