Skip to content

std::mem::replace doesn't work on Sid #4

@roblabla

Description

@roblabla

Because Sid is an opaque type, it is impossible to std::mem::replace it. Example test:

    /// Ensures that std::mem::replace works properly with Sid
    #[test]
    fn mem_replace() {
        let mut sid1 = crate::Sid::well_known_sid(winapi::um::winnt::WinWorldSid).unwrap();
        let mut sid2 = crate::Sid::well_known_sid(winapi::um::winnt::WinNtAuthoritySid).unwrap();
        assert_eq!(sid1.id_authority(), &[0, 0, 0, 0, 0, 1]);
        assert_eq!(sid2.id_authority(), &[0, 0, 0, 0, 0, 5]);

        std::mem::swap(&mut *sid1, &mut *sid2);

        assert_eq!(sid1.id_authority(), &[0, 0, 0, 0, 0, 5]);
        assert_eq!(sid2.id_authority(), &[0, 0, 0, 0, 0, 1]);
    }

Fixing this is, erm, complicated. I suppose the ideal solution would be to make Sid an unsized type ([u8]) instead of an opaque type. This would cause mem::replace to become a compile time error, I believe, but would turn pointers to Sid into fat pointers.

EDIT: I think what we'd need is rust-lang/rust#43467. If Sid was an Opaque Type, it'd be !Sized, and thus mem::replace wouldn't work, but a reference to it would still be only a single pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions