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

mem::swap doesn't work with Objects #6

Open
SSheldon opened this Issue Sep 3, 2014 · 6 comments

Comments

Projects
None yet
2 participants
@SSheldon
Copy link
Owner

SSheldon commented Sep 3, 2014

For example, the following code:

let mut a: Id<NSString> = INSString::from_str("a");
let mut b: Id<NSString> = INSString::from_str("b");
println!("{} {}", a, b);

mem::swap(a.deref_mut(), b.deref_mut());
println!("{} {}", a, b);

Expected output:

a b
b a

Actual output:

a b
a b

We cannot have the expected output happen, because an NSObject's memory address cannot change after it has been constructed.

@SSheldon

This comment has been minimized.

Copy link
Owner Author

SSheldon commented Jan 17, 2015

The ideal fix for this would be to make NSObjects not Sized; then the example code wouldn't even compile. Unfortunately, it doesn't seem that there's a way to make a struct not Sized without the struct using "fat" (two-word) references, which would be incorrect for an NSObject.

@SSheldon

This comment has been minimized.

Copy link
Owner Author

SSheldon commented Jan 31, 2015

If rust-lang/rfcs#709 were accepted, this could be resolved by marking NSObjects as NotSized.

@SSheldon

This comment has been minimized.

Copy link
Owner Author

SSheldon commented Feb 11, 2015

The unsized types RFC was postponed as rust-lang/rfcs#813.

@SSheldon SSheldon changed the title mem::swap doesn't work with NSObjects mem::swap doesn't work with Objects Mar 23, 2015

@SSheldon

This comment has been minimized.

Copy link
Owner Author

SSheldon commented Apr 22, 2017

If rust-lang/rfcs#1861 is accepted, we could fix this by making Object an opaque extern type.

@SSheldon

This comment has been minimized.

Copy link
Owner Author

SSheldon commented Dec 6, 2017

The extern types RFC was accepted and implemented! Stabilization tracked in rust-lang/rust#43467.

@nox

This comment has been minimized.

Copy link

nox commented Dec 11, 2017

Getting mutable references to void types is undefined behaviour to begin with, will file an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.