Skip to content

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

Open

Description

@SSheldon

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.

Activity

  1. SSheldon commented on Jan 17, 2015

    @SSheldon
    OwnerAuthor

    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.

  2. SSheldon commented on Jan 31, 2015

    @SSheldon
    OwnerAuthor

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

  3. SSheldon commented on Feb 11, 2015

    @SSheldon
    OwnerAuthor

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

  4. changed the title [-]mem::swap doesn't work with NSObjects[/-] [+]mem::swap doesn't work with Objects[/+] on Mar 23, 2015
  5. SSheldon commented on Apr 22, 2017

    @SSheldon
    OwnerAuthor

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

  6. SSheldon commented on Dec 6, 2017

    @SSheldon
    OwnerAuthor

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

  7. nox commented on Dec 11, 2017

    @nox

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

  8. added a commit that references this issue on Oct 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions