]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Auto merge of #68943 - ecstatic-morse:no-useless-drop-on-enum-variants, r=matthewjasper
authorbors <bors@rust-lang.org>
Sun, 1 Mar 2020 04:42:21 +0000 (04:42 +0000)
committerbors <bors@rust-lang.org>
Sun, 1 Mar 2020 04:42:21 +0000 (04:42 +0000)
commitd9051341a1c142542a3f7dab509266606c775382
tree50160e1bc8b40e2a1c89cdd68be101e1140fa242
parent2917d993023dec5111147a1552ec78b206a5a37e
parentb23d910d570b392b1740ef1bb888f04194fe82c1
Auto merge of #68943 - ecstatic-morse:no-useless-drop-on-enum-variants, r=matthewjasper

Skip `Drop` terminators for enum variants without drop glue

Split out from #68528.

When doing drop elaboration for an `enum` that may or may not be moved out of (an open drop), we check the discriminant of the `enum` to see whether the live variant has any drop flags and then check the drop flags to see whether we need to drop each field. Sometimes, however, the live
variant has no move paths and thus no drop flags. In this case, we still emit a drop terminator
for the entire enum after checking the enum discriminant. This drop shim will check the discriminant of the enum *again* and then drop the fields of the active variant. If the active variant has no drop glue, nothing will be done.

This commit skips emitting the drop terminator during drop elaboration when the "otherwise" variants, those without move paths, have no drop glue. A common example of this scenario is when an `Option` is moved from, since `Option::None` never needs drop glue. Below is a fragment the pre-codegen CFG for `Option::unwrap_or` in which we check the drop flag (`_5`) for `self` (`_1`), before and after the change.

Before:

![image](https://user-images.githubusercontent.com/29463364/74078927-52942380-49e5-11ea-8e34-4b9d6d94ef25.png)

After:

![image](https://user-images.githubusercontent.com/29463364/74078945-78b9c380-49e5-11ea-8302-b043c4a7515a.png)

This change doesn't do much on its own, but it is a prerequisite to get the perf gains from #68528.

cc @arielb1
src/librustc_mir/util/elaborate_drops.rs