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

Should clone take &mut self? #8768

Closed
brson opened this issue Aug 26, 2013 · 5 comments
Closed

Should clone take &mut self? #8768

brson opened this issue Aug 26, 2013 · 5 comments

Comments

@brson
Copy link
Contributor

brson commented Aug 26, 2013

There are plenty of types that need to do record keeping during clone. Don't see an issue for this.

@thestinger
Copy link
Contributor

I don't think it should, because it would become much less useful in generic functions. Most of the types needing to do record keeping are going to be doing it through a type with inherent mutability like *mut (reference counting).

@lilyball
Copy link
Contributor

If clone takes &mut self, how would you ever clone an immutable value?

@thestinger
Copy link
Contributor

Heh, I wasn't even thinking about that. We should probably just have an alternate way of cloning things when it requires mutation. Since Clone is just a normal trait in the standard library it doesn't really have to cover all use cases.

@nikomatsakis
Copy link
Contributor

What are some examples of types that need record keeping? @thestinger mentioned reference counting (i.e., ARC, RC). Are there others?

I tend to think of our type system as sometimes ruling out potential designs (i.e., mutable fields in C++) because their safety cannot be automatically verified, and I'm ok with that, so long as the set of designs is... not too large. (The option of unsafe code is there too, of course)

@thestinger
Copy link
Contributor

I think it's clear that we're not going to be able to make Clone take &mut self. If we end up with a significant number of these, we should consider making a separate trait, but we can just use a non-trait method for now.

flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 21, 2022
Fix `#[allow]` for `module_name_repetitions` & `single_component_path_imports`

Fixes rust-lang#7511
Fixes rust-lang#8768
Fixes rust-lang#9401

`single_component_path_imports` needed some changes to the lint itself, it now buffers the found single component paths to emit in the equivalent `check_item`

changelog: Fix `#[allow(clippy::module_name_repetitions)]` and `#[allow(clippy::single_component_path_imports)]`
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

No branches or pull requests

4 participants