Do not create move paths that do not need dropping.
This commit is contained in:
parent
f038882fc0
commit
c9c0c0cbca
5 changed files with 64 additions and 60 deletions
|
@ -54,7 +54,10 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops {
|
|||
|
||||
let def_id = body.source.def_id();
|
||||
let param_env = tcx.param_env_reveal_all_normalized(def_id);
|
||||
let move_data = MoveData::gather_moves(&body, tcx, param_env, |_| true);
|
||||
// For types that do not need dropping, the behaviour is trivial. So we only need to track
|
||||
// init/uninit for types that do need dropping.
|
||||
let move_data =
|
||||
MoveData::gather_moves(&body, tcx, param_env, |ty| ty.needs_drop(tcx, param_env));
|
||||
let elaborate_patch = {
|
||||
let env = MoveDataParamEnv { move_data, param_env };
|
||||
|
||||
|
@ -338,6 +341,18 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> {
|
|||
continue;
|
||||
};
|
||||
|
||||
// This place does not need dropping. It is not have an associated move-path, so the
|
||||
// match below will conservatively keep an unconditional drop. As that drop is useless,
|
||||
// just remove it here and now.
|
||||
if !place
|
||||
.ty(&self.body.local_decls, self.tcx)
|
||||
.ty
|
||||
.needs_drop(self.tcx, self.env.param_env)
|
||||
{
|
||||
self.patch.patch_terminator(bb, TerminatorKind::Goto { target });
|
||||
continue;
|
||||
}
|
||||
|
||||
let path = self.move_data().rev_lookup.find(place.as_ref());
|
||||
match path {
|
||||
LookupResult::Exact(path) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue