@@ -143,10 +143,13 @@ struct DropData<'tcx> {
143
143
144
144
/// Whether this is a value Drop or a StorageDead.
145
145
kind : DropKind ,
146
+
147
+ /// The cached blocks for unwinds.
148
+ cached_block : CachedBlock ,
146
149
}
147
150
148
151
#[ derive( Debug , Default , Clone , Copy ) ]
149
- pub ( crate ) struct CachedBlock {
152
+ struct CachedBlock {
150
153
/// The cached block for the cleanups-on-diverge path. This block
151
154
/// contains code to run the current drop and all the preceding
152
155
/// drops (i.e., those having lower index in Drop’s Scope drop
@@ -164,8 +167,8 @@ pub(crate) struct CachedBlock {
164
167
165
168
#[ derive( Debug ) ]
166
169
pub ( crate ) enum DropKind {
167
- Value { cached_block : CachedBlock } ,
168
- Storage { cached_block : CachedBlock } ,
170
+ Value ,
171
+ Storage ,
169
172
}
170
173
171
174
#[ derive( Clone , Debug ) ]
@@ -208,8 +211,8 @@ impl CachedBlock {
208
211
impl DropKind {
209
212
fn may_panic ( & self ) -> bool {
210
213
match * self {
211
- DropKind :: Value { .. } => true ,
212
- DropKind :: Storage { .. } => false
214
+ DropKind :: Value => true ,
215
+ DropKind :: Storage => false
213
216
}
214
217
}
215
218
}
@@ -240,11 +243,7 @@ impl<'tcx> Scope<'tcx> {
240
243
241
244
if !ignore_unwinds && !this_scope_only {
242
245
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 ( ) ;
248
247
}
249
248
}
250
249
}
@@ -642,18 +641,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
642
641
place : & Place < ' tcx > ,
643
642
place_ty : Ty < ' tcx > ,
644
643
) {
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 ) ;
657
646
}
658
647
659
648
// Scheduling drops
@@ -673,8 +662,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
673
662
) {
674
663
let needs_drop = self . hir . needs_drop ( place_ty) ;
675
664
match drop_kind {
676
- DropKind :: Value { .. } => if !needs_drop { return } ,
677
- DropKind :: Storage { .. } => {
665
+ DropKind :: Value => if !needs_drop { return } ,
666
+ DropKind :: Storage => {
678
667
match * place {
679
668
Place :: Base ( PlaceBase :: Local ( index) ) => if index. index ( ) <= self . arg_count {
680
669
span_bug ! (
@@ -740,7 +729,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
740
729
// cache of outer scpoe stays intact.
741
730
scope. invalidate_cache ( !needs_drop, self . is_generator , this_scope) ;
742
731
if this_scope {
743
- if let DropKind :: Value { .. } = drop_kind {
732
+ if let DropKind :: Value = drop_kind {
744
733
scope. needs_cleanup = true ;
745
734
}
746
735
@@ -752,7 +741,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
752
741
scope. drops . push ( DropData {
753
742
span : scope_end,
754
743
location : place. clone ( ) ,
755
- kind : drop_kind
744
+ kind : drop_kind,
745
+ cached_block : CachedBlock :: default ( ) ,
756
746
} ) ;
757
747
return ;
758
748
}
@@ -984,7 +974,7 @@ fn build_scope_drops<'tcx>(
984
974
let drop_data = & scope. drops [ drop_idx] ;
985
975
let source_info = scope. source_info ( drop_data. span ) ;
986
976
match drop_data. kind {
987
- DropKind :: Value { .. } => {
977
+ DropKind :: Value => {
988
978
let unwind_to = get_unwind_to ( scope, is_generator, drop_idx, generator_drop)
989
979
. unwrap_or ( last_unwind_to) ;
990
980
@@ -996,7 +986,7 @@ fn build_scope_drops<'tcx>(
996
986
} ) ;
997
987
block = next;
998
988
}
999
- DropKind :: Storage { .. } => {
989
+ DropKind :: Storage => {
1000
990
// Drop the storage for both value and storage drops.
1001
991
// Only temps and vars need their storage dead.
1002
992
match drop_data. location {
@@ -1022,14 +1012,14 @@ fn get_unwind_to<'tcx>(
1022
1012
) -> Option < BasicBlock > {
1023
1013
for drop_idx in ( 0 ..unwind_from) . rev ( ) {
1024
1014
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 ( || {
1028
1018
span_bug ! ( drop_data. span, "cached block not present for {:?}" , drop_data)
1029
1019
} ) ) ;
1030
1020
}
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 ( || {
1033
1023
span_bug ! ( drop_data. span, "cached block not present for {:?}" , drop_data)
1034
1024
} ) ) ;
1035
1025
}
@@ -1084,7 +1074,7 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1084
1074
// match the behavior of clang, but on inspection eddyb says
1085
1075
// this is not what clang does.
1086
1076
match drop_data. kind {
1087
- DropKind :: Storage { ref mut cached_block } if is_generator => {
1077
+ DropKind :: Storage if is_generator => {
1088
1078
// Only temps and vars need their storage dead.
1089
1079
match drop_data. location {
1090
1080
Place :: Base ( PlaceBase :: Local ( index) ) => {
@@ -1105,11 +1095,11 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1105
1095
}
1106
1096
_ => unreachable ! ( ) ,
1107
1097
} ;
1108
- * cached_block. ref_mut ( generator_drop) = Some ( target) ;
1098
+ * drop_data . cached_block . ref_mut ( generator_drop) = Some ( target) ;
1109
1099
}
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) ;
1113
1103
target = if let Some ( cached_block) = * cached_block {
1114
1104
storage_deads. clear ( ) ;
1115
1105
target_built_by_us = false ;
0 commit comments