-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Opt-in copy causes types that shouldn't be Copy to be copy #20126
Comments
I noticed this possibility too and was debating if this is a problem. It's not clear to me. Probably best to disallow it for now. |
@nikomatsakis at the very least, it's causing incorrect behaviour at runtime, since it's zeroing out types like a move, but not forbidding the use of them like a copy. |
Looks unsafe to me: struct Foo { a: &'static int }
impl Drop for Foo { fn drop(&mut self) { } }
impl Copy for Foo { }
fn main() {
static I: int = 42;
let x = Foo { a: &I };
let y = x;
println!("{}\n{}", y.a, x.a);
} Program received signal SIGSEGV, Segmentation fault. |
I agree that combining it with zeroing is unsafe. If zeroing did not occur, or we did not zero for types that were copy, there wouldn't necessarily be a problem. |
Anyhow, it's easiest to forbid it for now. We can always make it legal later if someone comes up with a persuasive use case. Idempotent destructors seem like a bit of an odd thing. |
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes rust-lang#20126.
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes #20126.
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes rust-lang#20126.
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes #20126.
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes rust-lang#20126.
Opt-in built-in traits allowed one to explicitly implement both `Drop` and `Copy` for a type. This can theoretically make some sense, but the current implementation means it is codegened totally incorrectly which can lead to memory unsafety, so this feature is disabled for now. Fixes #20126.
Basically, it's now possible to write:
and have everything work. This unfortunately means that doing something like
let a = b
with aFoo
will zero b, but not move it./cc @nikomatsakis @pcwalton
The text was updated successfully, but these errors were encountered: