Ways to leak Unmovable type

I'm currently playing with with "Unmovable" type taken from this github issue comment (credit @Kimundi). I've ported it to work with modern Rust versions: playground link.

I am trying to think of ways to leak it. So far I've found only one: locking the type in an async block and leaking that block (playground link).

Does anyone know of any other way to leak this Unmovable type?

Well, trivially, you could leak it before it is locked using Box::leak().

ManuallyDrop ala this playground.

Nice! I'm surprised it never crossed my mind to leak it before locking

oh wow. no heap needed at all. nice!

FWIW, this ManuallyDrop escape hatch is precisely what prevented this "idiom" into leading to a function-backed implementation of stack pinning (so close though).

1 Like

Also, you can just exit without running destuctors. Or have your thread killed, perhaps implicitly. The latter is probably something like what is happening with your async block.

2 Likes