|
12 | 12 | //! initialization and can otherwise silence errors, if |
13 | 13 | //! move analysis runs after promotion on broken MIR. |
14 | 14 |
|
| 15 | +use rustc::hir::def_id::DefId; |
15 | 16 | use rustc::mir::*; |
16 | 17 | use rustc::mir::visit::{PlaceContext, MutatingUseContext, MutVisitor, Visitor}; |
17 | 18 | use rustc::mir::traversal::ReversePostorder; |
@@ -151,7 +152,8 @@ struct Promoter<'a, 'tcx: 'a> { |
151 | 152 |
|
152 | 153 | /// If true, all nested temps are also kept in the |
153 | 154 | /// source MIR, not moved to the promoted MIR. |
154 | | - keep_original: bool |
| 155 | + keep_original: bool, |
| 156 | + def_id: DefId |
155 | 157 | } |
156 | 158 |
|
157 | 159 | impl<'a, 'tcx> Promoter<'a, 'tcx> { |
@@ -287,14 +289,19 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { |
287 | 289 | } |
288 | 290 |
|
289 | 291 | fn promote_candidate(mut self, candidate: Candidate) { |
| 292 | + use rustc::mir::Static; |
290 | 293 | let mut operand = { |
| 294 | + let def_id = self.def_id.clone(); |
291 | 295 | let promoted = &mut self.promoted; |
292 | 296 | let promoted_id = Promoted::new(self.source.promoted.len()); |
293 | 297 | let mut promoted_place = |ty, span| { |
294 | 298 | promoted.span = span; |
295 | 299 | promoted.local_decls[RETURN_PLACE] = |
296 | 300 | LocalDecl::new_return_place(ty, span); |
297 | | - Place::Base(PlaceBase::Promoted(box (promoted_id, ty))) |
| 301 | + Place::Base(PlaceBase::Static( |
| 302 | + Box::new(Static { def_id: def_id, ty, promoted: Some(promoted_id) }) |
| 303 | + ) |
| 304 | + ) |
298 | 305 | }; |
299 | 306 | let (blocks, local_decls) = self.source.basic_blocks_and_local_decls_mut(); |
300 | 307 | match candidate { |
@@ -367,7 +374,8 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { |
367 | 374 | pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, |
368 | 375 | tcx: TyCtxt<'a, 'tcx, 'tcx>, |
369 | 376 | mut temps: IndexVec<Local, TempState>, |
370 | | - candidates: Vec<Candidate>) { |
| 377 | + candidates: Vec<Candidate>, |
| 378 | + def_id: DefId) { |
371 | 379 | // Visit candidates in reverse, in case they're nested. |
372 | 380 | debug!("promote_candidates({:?})", candidates); |
373 | 381 |
|
@@ -412,7 +420,8 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>, |
412 | 420 | tcx, |
413 | 421 | source: mir, |
414 | 422 | temps: &mut temps, |
415 | | - keep_original: false |
| 423 | + keep_original: false, |
| 424 | + def_id |
416 | 425 | }; |
417 | 426 | promoter.promote_candidate(candidate); |
418 | 427 | } |
|
0 commit comments