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

RFC: changes to implicit copyability #9098

Closed
metajack opened this issue Sep 10, 2013 · 7 comments
Closed

RFC: changes to implicit copyability #9098

metajack opened this issue Sep 10, 2013 · 7 comments
Labels
A-type-system Area: Type system
Milestone

Comments

@metajack
Copy link
Contributor

Right now any struct that contains only implicitly copyable types is implicitly copyable and there is no way to turn this off.

We need a way to annotate that a struct should not be implicitly copyable at the very least.

I think a better solution would to make the default not to have structs be implicitly copyable unless annotated specifically that they are. That is, the default would be reversed.

This is an issue for things like Option where T is implicitly copyable. It completely changes the semantics of functions like unwrap(). Depending on the type of T, this may move or copy.

This recently caused a Servo bug where the different between unwrap() and with_mut_ref() caused an infinite loop:

sammykim/servo@7a1493a

@metajack
Copy link
Contributor Author

nominating backwards compat

@bluss
Copy link
Member

bluss commented Sep 10, 2013

Including std::util::NonCopyable as a member in your struct will "make the annotation". It's zero-sized, so it should be just fine.

@catamorphism
Copy link
Contributor

Accepted for backwards-compatible

@thestinger
Copy link
Contributor

I think the current situation is the best compromise between all the competing interests. At the moment, you can explain the copy/move semantics as follows:

Rust uses shallow copies for assignment, parameter passing and returning. If the type contains &fn, &mut or a destructor, it will move ownership and the source will no longer be usable.

Any extra complications at a language level have a very real cost in complexity.

@bluss
Copy link
Member

bluss commented Sep 26, 2013

by the way, std::util::NonCopyable's destructor does not inline (and disappear) like one would expect. This is something that should be improved so that the annotation doesn't have this unintended small cost.

@alexcrichton
Copy link
Member

We now have efficient markers introduced in #11768 for opting out of implicit copyability.

Nominating for closure, I don't think we want to modify the rules to opt-in to implicit copyability.

@pnkfelix
Copy link
Member

Note that the marking struct has been renamed to std::kinds::markers::NoPod.

Closing. (There may be other changes in the future that affect this issues, but this ticket on its own can be handled currently via the marker.)

flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 31, 2023
New lint [`filter_map_bool_then`]

Closes rust-lang#9098

changelog: New lint [`filter_map_bool_then`]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

6 participants