diff options
| author | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2019-10-23 10:30:51 -0700 |
|---|---|---|
| committer | Dylan MacKenzie <ecstaticmorse@gmail.com> | 2019-11-03 12:24:52 -0800 |
| commit | 420457e5ca9e724b045fc45f6b05dac8476a5ef4 (patch) | |
| tree | deb790e31a15710eaacac61c776ff0899040cd6e /src | |
| parent | d6431f69ad2d05e9aa2d5a316c1b4fcaf85f24aa (diff) | |
| download | rust-420457e5ca9e724b045fc45f6b05dac8476a5ef4.tar.gz rust-420457e5ca9e724b045fc45f6b05dac8476a5ef4.zip | |
Don't extend lifetime of temp in `Repeat` expressions
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 5dbb4d8d73e..353ce884656 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1065,30 +1065,23 @@ impl<'a, 'tcx> Checker<'a, 'tcx> { } else { self.valid_promotion_candidates() }; + debug!("qualify_const: promotion_candidates={:?}", promotion_candidates); for candidate in promotion_candidates { - let promoted_place = match candidate { - Candidate::Repeat(Location { block: bb, statement_index: stmt_idx }) => { - match &self.body[bb].statements[stmt_idx].kind { - StatementKind::Assign(box(_, Rvalue::Repeat(Operand::Move(place), _))) - => place, - _ => continue, - } - } + match candidate { Candidate::Ref(Location { block: bb, statement_index: stmt_idx }) => { - match &self.body[bb].statements[stmt_idx].kind { - StatementKind::Assign(box( _, Rvalue::Ref(_, _, place))) => place, - _ => continue, + if let StatementKind::Assign(box( _, Rvalue::Ref(_, _, place))) + = &self.body[bb].statements[stmt_idx].kind + { + if let PlaceBase::Local(local) = place.base { + promoted_temps.insert(local); + } } } - Candidate::Argument { .. } => continue, - }; - match promoted_place.base { - PlaceBase::Local(local) if !promoted_place.is_indirect() => { - promoted_temps.insert(local); - } - _ => {} + // Only rvalue-static promotion requires extending the lifetime of the promoted + // local. + Candidate::Argument { .. } | Candidate::Repeat(_) => {} } } |
