Module remove_unneeded_drops

Module remove_unneeded_drops 

Source
Expand description

This pass replaces a drop of a type that does not need dropping, with a goto.

When the MIR is built, we check needs_drop before emitting a Drop for a place. This pass is useful because (unlike MIR building) it runs after type checking, so it can make use of TypingMode::PostAnalysis to provide more precise type information, especially about opaque types.

When we’re optimizing, we also remove calls to drop_in_place<T> when T isn’t needs_drop, as those are essentially equivalent to Drop terminators. While the compiler doesn’t insert them automatically, preferring the built-in instead, they’re common in generic code (such as Vec::truncate) so removing them from things like inlined Vec<u8> is helpful.

Structs§

RemoveUnneededDrops 🔒