@@ -143,10 +143,13 @@ struct DropData<'tcx> {
143143
144144 /// Whether this is a value Drop or a StorageDead.
145145 kind : DropKind ,
146+
147+ /// The cached blocks for unwinds.
148+ cached_block : CachedBlock ,
146149}
147150
148151#[ derive( Debug , Default , Clone , Copy ) ]
149- pub ( crate ) struct CachedBlock {
152+ struct CachedBlock {
150153 /// The cached block for the cleanups-on-diverge path. This block
151154 /// contains code to run the current drop and all the preceding
152155 /// drops (i.e., those having lower index in Drop’s Scope drop
@@ -164,8 +167,8 @@ pub(crate) struct CachedBlock {
164167
165168#[ derive( Debug ) ]
166169pub ( crate ) enum DropKind {
167- Value { cached_block : CachedBlock } ,
168- Storage { cached_block : CachedBlock } ,
170+ Value ,
171+ Storage ,
169172}
170173
171174#[ derive( Clone , Debug ) ]
@@ -208,8 +211,8 @@ impl CachedBlock {
208211impl DropKind {
209212 fn may_panic ( & self ) -> bool {
210213 match * self {
211- DropKind :: Value { .. } => true ,
212- DropKind :: Storage { .. } => false
214+ DropKind :: Value => true ,
215+ DropKind :: Storage => false
213216 }
214217 }
215218}
@@ -240,11 +243,7 @@ impl<'tcx> Scope<'tcx> {
240243
241244 if !ignore_unwinds && !this_scope_only {
242245 for drop_data in & mut self . drops {
243- let cached_block = match drop_data. kind {
244- DropKind :: Storage { ref mut cached_block } => cached_block,
245- DropKind :: Value { ref mut cached_block } => cached_block,
246- } ;
247- cached_block. invalidate ( ) ;
246+ drop_data. cached_block . invalidate ( ) ;
248247 }
249248 }
250249 }
@@ -642,18 +641,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
642641 place : & Place < ' tcx > ,
643642 place_ty : Ty < ' tcx > ,
644643 ) {
645- self . schedule_drop (
646- span, region_scope, place, place_ty,
647- DropKind :: Storage {
648- cached_block : CachedBlock :: default ( ) ,
649- } ,
650- ) ;
651- self . schedule_drop (
652- span, region_scope, place, place_ty,
653- DropKind :: Value {
654- cached_block : CachedBlock :: default ( ) ,
655- } ,
656- ) ;
644+ self . schedule_drop ( span, region_scope, place, place_ty, DropKind :: Storage ) ;
645+ self . schedule_drop ( span, region_scope, place, place_ty, DropKind :: Value ) ;
657646 }
658647
659648 // Scheduling drops
@@ -673,8 +662,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
673662 ) {
674663 let needs_drop = self . hir . needs_drop ( place_ty) ;
675664 match drop_kind {
676- DropKind :: Value { .. } => if !needs_drop { return } ,
677- DropKind :: Storage { .. } => {
665+ DropKind :: Value => if !needs_drop { return } ,
666+ DropKind :: Storage => {
678667 match * place {
679668 Place :: Base ( PlaceBase :: Local ( index) ) => if index. index ( ) <= self . arg_count {
680669 span_bug ! (
@@ -740,7 +729,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
740729 // cache of outer scpoe stays intact.
741730 scope. invalidate_cache ( !needs_drop, self . is_generator , this_scope) ;
742731 if this_scope {
743- if let DropKind :: Value { .. } = drop_kind {
732+ if let DropKind :: Value = drop_kind {
744733 scope. needs_cleanup = true ;
745734 }
746735
@@ -752,7 +741,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
752741 scope. drops . push ( DropData {
753742 span : scope_end,
754743 location : place. clone ( ) ,
755- kind : drop_kind
744+ kind : drop_kind,
745+ cached_block : CachedBlock :: default ( ) ,
756746 } ) ;
757747 return ;
758748 }
@@ -984,7 +974,7 @@ fn build_scope_drops<'tcx>(
984974 let drop_data = & scope. drops [ drop_idx] ;
985975 let source_info = scope. source_info ( drop_data. span ) ;
986976 match drop_data. kind {
987- DropKind :: Value { .. } => {
977+ DropKind :: Value => {
988978 let unwind_to = get_unwind_to ( scope, is_generator, drop_idx, generator_drop)
989979 . unwrap_or ( last_unwind_to) ;
990980
@@ -996,7 +986,7 @@ fn build_scope_drops<'tcx>(
996986 } ) ;
997987 block = next;
998988 }
999- DropKind :: Storage { .. } => {
989+ DropKind :: Storage => {
1000990 // Drop the storage for both value and storage drops.
1001991 // Only temps and vars need their storage dead.
1002992 match drop_data. location {
@@ -1022,14 +1012,14 @@ fn get_unwind_to<'tcx>(
10221012) -> Option < BasicBlock > {
10231013 for drop_idx in ( 0 ..unwind_from) . rev ( ) {
10241014 let drop_data = & scope. drops [ drop_idx] ;
1025- match drop_data. kind {
1026- DropKind :: Storage { cached_block } if is_generator => {
1027- return Some ( cached_block. get ( generator_drop) . unwrap_or_else ( || {
1015+ match ( is_generator , & drop_data. kind ) {
1016+ ( true , DropKind :: Storage ) => {
1017+ return Some ( drop_data . cached_block . get ( generator_drop) . unwrap_or_else ( || {
10281018 span_bug ! ( drop_data. span, "cached block not present for {:?}" , drop_data)
10291019 } ) ) ;
10301020 }
1031- DropKind :: Value { cached_block } if !is_generator => {
1032- return Some ( cached_block. get ( generator_drop) . unwrap_or_else ( || {
1021+ ( false , DropKind :: Value ) => {
1022+ return Some ( drop_data . cached_block . get ( generator_drop) . unwrap_or_else ( || {
10331023 span_bug ! ( drop_data. span, "cached block not present for {:?}" , drop_data)
10341024 } ) ) ;
10351025 }
@@ -1084,7 +1074,7 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
10841074 // match the behavior of clang, but on inspection eddyb says
10851075 // this is not what clang does.
10861076 match drop_data. kind {
1087- DropKind :: Storage { ref mut cached_block } if is_generator => {
1077+ DropKind :: Storage if is_generator => {
10881078 // Only temps and vars need their storage dead.
10891079 match drop_data. location {
10901080 Place :: Base ( PlaceBase :: Local ( index) ) => {
@@ -1105,11 +1095,11 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
11051095 }
11061096 _ => unreachable ! ( ) ,
11071097 } ;
1108- * cached_block. ref_mut ( generator_drop) = Some ( target) ;
1098+ * drop_data . cached_block . ref_mut ( generator_drop) = Some ( target) ;
11091099 }
1110- DropKind :: Storage { .. } => { }
1111- DropKind :: Value { ref mut cached_block } => {
1112- let cached_block = cached_block. ref_mut ( generator_drop) ;
1100+ DropKind :: Storage => { }
1101+ DropKind :: Value => {
1102+ let cached_block = drop_data . cached_block . ref_mut ( generator_drop) ;
11131103 target = if let Some ( cached_block) = * cached_block {
11141104 storage_deads. clear ( ) ;
11151105 target_built_by_us = false ;
0 commit comments