Skip to content

alloc should require T: !Drop or be unsafe #251

Open
@Pr0methean

Description

@Pr0methean

To prevent users from unwittingly allocating structs that they aren't aware need to have their Drop methods run, the alloc* and try_alloc* methods should add the type constraint T: !Drop, and have pub unsafe fn *_unchecked versions for use when the user can't meet that constraint.

It might also be useful to have a wrapper which had a Vec or LinkedList<*mut dyn Any> droppables; then, the unsafe methods would be replaced with alloc_*_droppable methods that pushed the allocated pointer onto self.droppables, and then the wrapper's impl Drop would call self.droppables.into_iter().rev().for_each(mem::drop_in_place).

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