diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2016-05-10 21:26:34 +0300 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2016-05-10 21:26:34 +0300 |
| commit | e5a91b7ba1a22e34c7d09105e7a115e696ffcd0f (patch) | |
| tree | 2d96a4defdd7731c7ef230d16662456d8ca61ecc /src/librustc_mir/transform | |
| parent | d6588097d4d65e567fb234c042e61ad8ce4d41e6 (diff) | |
| download | rust-e5a91b7ba1a22e34c7d09105e7a115e696ffcd0f.tar.gz rust-e5a91b7ba1a22e34c7d09105e7a115e696ffcd0f.zip | |
mir: don't attempt to promote Unpromotable constant temps.
Diffstat (limited to 'src/librustc_mir/transform')
| -rw-r--r-- | src/librustc_mir/transform/qualify_consts.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 90823528973..e7693d2691b 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -65,13 +65,18 @@ bitflags! { // pointer comparisons, ptr-to-int casts, etc. const NOT_CONST = 1 << 6, + // Refers to temporaries which cannot be promoted as + // promote_consts decided they weren't simple enough. + const NOT_PROMOTABLE = 1 << 7, + // Borrows of temporaries can be promoted only // if they have none of the above qualifications. - const UNPROMOTABLE = !0, + const NEVER_PROMOTE = !0, // Const items can only have MUTABLE_INTERIOR - // without producing an error. - const CONST_ERROR = !Qualif::MUTABLE_INTERIOR.bits + // and NOT_PROMOTABLE without producing an error. + const CONST_ERROR = !Qualif::MUTABLE_INTERIOR.bits & + !Qualif::NOT_PROMOTABLE.bits } } @@ -502,6 +507,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> { self.add(Qualif::NOT_CONST); } Lvalue::Temp(index) => { + if !self.temp_promotion_state[index as usize].is_promotable() { + self.add(Qualif::NOT_PROMOTABLE); + } + if let Some(qualif) = self.temp_qualif[index as usize] { self.add(qualif); } else { @@ -687,8 +696,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> { // We might have a candidate for promotion. let candidate = Candidate::Ref(self.location); if self.mode == Mode::Fn || self.mode == Mode::ConstFn { - if !self.qualif.intersects(Qualif::UNPROMOTABLE) { - self.promotion_candidates.push(candidate); + if !self.qualif.intersects(Qualif::NEVER_PROMOTE) { + // We can only promote direct borrows of temps. + if let Lvalue::Temp(_) = *lvalue { + self.promotion_candidates.push(candidate); + } } } } @@ -780,7 +792,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx> { this.visit_operand(arg); if is_shuffle && i == 2 && this.mode == Mode::Fn { let candidate = Candidate::ShuffleIndices(bb); - if !this.qualif.intersects(Qualif::UNPROMOTABLE) { + if !this.qualif.intersects(Qualif::NEVER_PROMOTE) { this.promotion_candidates.push(candidate); } else { span_err!(this.tcx.sess, this.span, E0526, |
