diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 3e9f7b51cb1c5..310228838e0ad 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -1501,13 +1501,6 @@ impl<'tcx> BasicBlockData<'tcx> { self.terminator.as_mut().expect("invalid terminator state") } - pub fn is_unreachable(&self) -> bool { - match self.terminator().kind { - TerminatorKind::Unreachable => true, - _ => false, - } - } - pub fn retain_statements(&mut self, mut f: F) where F: FnMut(&mut Statement<'_>) -> bool, diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index caff75a36cd5e..2cf61d7b3f529 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -1311,7 +1311,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { ) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> { use SavedLocalEligibility::*; let tcx = self.tcx; - let recompute_memory_index = |offsets: &Vec| -> Vec { + let recompute_memory_index = |offsets: &[Size]| -> Vec { debug!("recompute_memory_index({:?})", offsets); let mut inverse_index = (0..offsets.len() as u32).collect::>(); inverse_index.sort_unstable_by_key(|i| offsets[*i as usize]); @@ -1349,19 +1349,14 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { // get included in each variant that requested them in // GeneratorLayout. debug!("prefix = {:#?}", prefix); - let (outer_fields, promoted_offsets, promoted_memory_index) = match prefix.fields { - FieldPlacement::Arbitrary { offsets, memory_index } => { - let (offsets_a, offsets_b) = - offsets.split_at(discr_index + 1); - let (memory_index_a, memory_index_b) = - memory_index.split_at(discr_index + 1); - let outer_fields = FieldPlacement::Arbitrary { - offsets: offsets_a.to_vec(), - memory_index: recompute_memory_index(&memory_index_a.to_vec()) - }; - (outer_fields, - offsets_b.to_vec(), - recompute_memory_index(&memory_index_b.to_vec())) + let (outer_fields, promoted_offsets) = match prefix.fields { + FieldPlacement::Arbitrary { mut offsets, .. } => { + let offsets_b = offsets.split_off(discr_index + 1); + let offsets_a = offsets; + + let memory_index = recompute_memory_index(&offsets_a); + let outer_fields = FieldPlacement::Arbitrary { offsets: offsets_a, memory_index }; + (outer_fields, offsets_b) } _ => bug!(), }; @@ -1391,8 +1386,8 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { StructKind::Prefixed(prefix_size, prefix_align.abi))?; variant.variants = Variants::Single { index }; - let (offsets, memory_index) = match variant.fields { - FieldPlacement::Arbitrary { offsets, memory_index } => (offsets, memory_index), + let offsets = match variant.fields { + FieldPlacement::Arbitrary { offsets, .. } => offsets, _ => bug!(), }; @@ -1400,32 +1395,21 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { // the order they are mentioned by our GeneratorLayout. let mut next_variant_field = 0; let mut combined_offsets = Vec::new(); - let mut combined_memory_index = Vec::new(); for local in variant_fields.iter() { match assignments[*local] { Unassigned => bug!(), Assigned(_) => { combined_offsets.push(offsets[next_variant_field]); - // Shift memory indices by the number of promoted - // fields, which all come first. We may not use all - // promoted fields in our variant but that's okay; we'll - // renumber them below. - combined_memory_index.push( - promoted_memory_index.len() as u32 + - memory_index[next_variant_field]); next_variant_field += 1; } Ineligible(field_idx) => { let field_idx = field_idx.unwrap() as usize; combined_offsets.push(promoted_offsets[field_idx]); - combined_memory_index.push(promoted_memory_index[field_idx]); } } } - variant.fields = FieldPlacement::Arbitrary { - offsets: combined_offsets, - memory_index: recompute_memory_index(&combined_memory_index), - }; + let memory_index = recompute_memory_index(&combined_offsets); + variant.fields = FieldPlacement::Arbitrary { offsets: combined_offsets, memory_index }; size = size.max(variant.size); align = align.max(variant.align); diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 9dc9f8fdf72a9..e3c3506454601 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -660,9 +660,10 @@ impl<'body, 'tcx: 'body, 's> StorageConflictVisitor<'body, 'tcx, 's> { flow_state: &FlowAtLocation<'tcx, MaybeStorageLive<'body, 'tcx>>, loc: Location) { // Ignore unreachable blocks. - if self.body.basic_blocks()[loc.block].is_unreachable() { - return; - } + match self.body.basic_blocks()[loc.block].terminator().kind { + TerminatorKind::Unreachable => return, + _ => (), + }; let mut eligible_storage_live = flow_state.as_dense().clone(); eligible_storage_live.intersect(&self.stored_locals);