@@ -94,7 +94,7 @@ use std::collections::hash_map::Entry;
94
94
use std:: mem;
95
95
96
96
#[ derive( Debug ) ]
97
- struct Scope < ' tcx > {
97
+ struct Scope {
98
98
/// The source scope this scope was created in.
99
99
source_scope : SourceScope ,
100
100
@@ -121,7 +121,7 @@ struct Scope<'tcx> {
121
121
/// out empty but grows as variables are declared during the
122
122
/// building process. This is a stack, so we always drop from the
123
123
/// end of the vector (top of the stack) first.
124
- drops : Vec < DropData < ' tcx > > ,
124
+ drops : Vec < DropData > ,
125
125
126
126
/// The cache for drop chain on “normal” exit into a particular BasicBlock.
127
127
cached_exits : FxHashMap < ( BasicBlock , region:: Scope ) , BasicBlock > ,
@@ -135,18 +135,18 @@ struct Scope<'tcx> {
135
135
136
136
#[ derive( Debug , Default ) ]
137
137
pub struct Scopes < ' tcx > {
138
- scopes : Vec < Scope < ' tcx > > ,
138
+ scopes : Vec < Scope > ,
139
139
/// The current set of breakable scopes. See module comment for more details.
140
140
breakable_scopes : Vec < BreakableScope < ' tcx > > ,
141
141
}
142
142
143
143
#[ derive( Debug ) ]
144
- struct DropData < ' tcx > {
144
+ struct DropData {
145
145
/// span where drop obligation was incurred (typically where place was declared)
146
146
span : Span ,
147
147
148
- /// place to drop
149
- location : Place < ' tcx > ,
148
+ /// local to drop
149
+ local : Local ,
150
150
151
151
/// Whether this is a value Drop or a StorageDead.
152
152
kind : DropKind ,
@@ -223,7 +223,7 @@ impl CachedBlock {
223
223
}
224
224
}
225
225
226
- impl < ' tcx > Scope < ' tcx > {
226
+ impl Scope {
227
227
/// Invalidates all the cached blocks in the scope.
228
228
///
229
229
/// Should always be run for all inner scopes when a drop is pushed into some scope enclosing a
@@ -285,7 +285,7 @@ impl<'tcx> Scopes<'tcx> {
285
285
fn pop_scope (
286
286
& mut self ,
287
287
region_scope : ( region:: Scope , SourceInfo ) ,
288
- ) -> ( Scope < ' tcx > , Option < BasicBlock > ) {
288
+ ) -> ( Scope , Option < BasicBlock > ) {
289
289
let scope = self . scopes . pop ( ) . unwrap ( ) ;
290
290
assert_eq ! ( scope. region_scope, region_scope. 0 ) ;
291
291
let unwind_to = self . scopes . last ( )
@@ -343,11 +343,11 @@ impl<'tcx> Scopes<'tcx> {
343
343
scope_count
344
344
}
345
345
346
- fn iter_mut ( & mut self ) -> impl DoubleEndedIterator < Item =& mut Scope < ' tcx > > + ' _ {
346
+ fn iter_mut ( & mut self ) -> impl DoubleEndedIterator < Item =& mut Scope > + ' _ {
347
347
self . scopes . iter_mut ( ) . rev ( )
348
348
}
349
349
350
- fn top_scopes ( & mut self , count : usize ) -> impl DoubleEndedIterator < Item =& mut Scope < ' tcx > > + ' _ {
350
+ fn top_scopes ( & mut self , count : usize ) -> impl DoubleEndedIterator < Item =& mut Scope > + ' _ {
351
351
let len = self . len ( ) ;
352
352
self . scopes [ len - count..] . iter_mut ( )
353
353
}
@@ -717,11 +717,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
717
717
& mut self ,
718
718
span : Span ,
719
719
region_scope : region:: Scope ,
720
- place : & Place < ' tcx > ,
720
+ local : Local ,
721
721
place_ty : Ty < ' tcx > ,
722
722
) {
723
- self . schedule_drop ( span, region_scope, place , place_ty, DropKind :: Storage ) ;
724
- self . schedule_drop ( span, region_scope, place , place_ty, DropKind :: Value ) ;
723
+ self . schedule_drop ( span, region_scope, local , place_ty, DropKind :: Storage ) ;
724
+ self . schedule_drop ( span, region_scope, local , place_ty, DropKind :: Value ) ;
725
725
}
726
726
727
727
/// Indicates that `place` should be dropped on exit from
@@ -733,25 +733,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
733
733
& mut self ,
734
734
span : Span ,
735
735
region_scope : region:: Scope ,
736
- place : & Place < ' tcx > ,
736
+ local : Local ,
737
737
place_ty : Ty < ' tcx > ,
738
738
drop_kind : DropKind ,
739
739
) {
740
740
let needs_drop = self . hir . needs_drop ( place_ty) ;
741
741
match drop_kind {
742
742
DropKind :: Value => if !needs_drop { return } ,
743
743
DropKind :: Storage => {
744
- match * place {
745
- Place :: Base ( PlaceBase :: Local ( index) ) => if index. index ( ) <= self . arg_count {
746
- span_bug ! (
747
- span, "`schedule_drop` called with index {} and arg_count {}" ,
748
- index. index( ) ,
749
- self . arg_count,
750
- )
751
- } ,
752
- _ => span_bug ! (
753
- span, "`schedule_drop` called with non-`Local` place {:?}" , place
754
- ) ,
744
+ if local. index ( ) <= self . arg_count {
745
+ span_bug ! (
746
+ span, "`schedule_drop` called with local {:?} and arg_count {}" ,
747
+ local,
748
+ self . arg_count,
749
+ )
755
750
}
756
751
}
757
752
}
@@ -817,14 +812,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
817
812
818
813
scope. drops . push ( DropData {
819
814
span : scope_end,
820
- location : place . clone ( ) ,
815
+ local ,
821
816
kind : drop_kind,
822
817
cached_block : CachedBlock :: default ( ) ,
823
818
} ) ;
824
819
return ;
825
820
}
826
821
}
827
- span_bug ! ( span, "region scope {:?} not in scope to drop {:?}" , region_scope, place ) ;
822
+ span_bug ! ( span, "region scope {:?} not in scope to drop {:?}" , region_scope, local ) ;
828
823
}
829
824
830
825
// Other
@@ -867,29 +862,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
867
862
bug ! ( "Drop scheduled on top of condition variable" )
868
863
}
869
864
DropKind :: Storage => {
870
- // Drop the storage for both value and storage drops.
871
- // Only temps and vars need their storage dead.
872
- match top_drop_data. location {
873
- Place :: Base ( PlaceBase :: Local ( index) ) => {
874
- let source_info = top_scope. source_info ( top_drop_data. span ) ;
875
- assert_eq ! ( index, cond_temp, "Drop scheduled on top of condition" ) ;
876
- self . cfg . push (
877
- true_block,
878
- Statement {
879
- source_info,
880
- kind : StatementKind :: StorageDead ( index)
881
- } ,
882
- ) ;
883
- self . cfg . push (
884
- false_block,
885
- Statement {
886
- source_info,
887
- kind : StatementKind :: StorageDead ( index)
888
- } ,
889
- ) ;
890
- }
891
- _ => unreachable ! ( ) ,
892
- }
865
+ let source_info = top_scope. source_info ( top_drop_data. span ) ;
866
+ let local = top_drop_data. local ;
867
+ assert_eq ! ( local, cond_temp, "Drop scheduled on top of condition" ) ;
868
+ self . cfg . push (
869
+ true_block,
870
+ Statement {
871
+ source_info,
872
+ kind : StatementKind :: StorageDead ( local)
873
+ } ,
874
+ ) ;
875
+ self . cfg . push (
876
+ false_block,
877
+ Statement {
878
+ source_info,
879
+ kind : StatementKind :: StorageDead ( local)
880
+ } ,
881
+ ) ;
893
882
}
894
883
}
895
884
@@ -1020,7 +1009,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1020
1009
fn build_scope_drops < ' tcx > (
1021
1010
cfg : & mut CFG < ' tcx > ,
1022
1011
is_generator : bool ,
1023
- scope : & Scope < ' tcx > ,
1012
+ scope : & Scope ,
1024
1013
mut block : BasicBlock ,
1025
1014
last_unwind_to : BasicBlock ,
1026
1015
arg_count : usize ,
@@ -1050,39 +1039,35 @@ fn build_scope_drops<'tcx>(
1050
1039
for drop_idx in ( 0 ..scope. drops . len ( ) ) . rev ( ) {
1051
1040
let drop_data = & scope. drops [ drop_idx] ;
1052
1041
let source_info = scope. source_info ( drop_data. span ) ;
1042
+ let local = drop_data. local ;
1053
1043
match drop_data. kind {
1054
1044
DropKind :: Value => {
1055
1045
let unwind_to = get_unwind_to ( scope, is_generator, drop_idx, generator_drop)
1056
1046
. unwrap_or ( last_unwind_to) ;
1057
1047
1058
1048
let next = cfg. start_new_block ( ) ;
1059
1049
cfg. terminate ( block, source_info, TerminatorKind :: Drop {
1060
- location : drop_data . location . clone ( ) ,
1050
+ location : local . into ( ) ,
1061
1051
target : next,
1062
1052
unwind : Some ( unwind_to)
1063
1053
} ) ;
1064
1054
block = next;
1065
1055
}
1066
1056
DropKind :: Storage => {
1067
- // Drop the storage for both value and storage drops.
1068
1057
// Only temps and vars need their storage dead.
1069
- match drop_data. location {
1070
- Place :: Base ( PlaceBase :: Local ( index) ) if index. index ( ) > arg_count => {
1071
- cfg. push ( block, Statement {
1072
- source_info,
1073
- kind : StatementKind :: StorageDead ( index)
1074
- } ) ;
1075
- }
1076
- _ => unreachable ! ( ) ,
1077
- }
1058
+ assert ! ( local. index( ) > arg_count) ;
1059
+ cfg. push ( block, Statement {
1060
+ source_info,
1061
+ kind : StatementKind :: StorageDead ( local)
1062
+ } ) ;
1078
1063
}
1079
1064
}
1080
1065
}
1081
1066
block. unit ( )
1082
1067
}
1083
1068
1084
- fn get_unwind_to < ' tcx > (
1085
- scope : & Scope < ' tcx > ,
1069
+ fn get_unwind_to (
1070
+ scope : & Scope ,
1086
1071
is_generator : bool ,
1087
1072
unwind_from : usize ,
1088
1073
generator_drop : bool ,
@@ -1108,7 +1093,7 @@ fn get_unwind_to<'tcx>(
1108
1093
1109
1094
fn build_diverge_scope < ' tcx > ( cfg : & mut CFG < ' tcx > ,
1110
1095
span : Span ,
1111
- scope : & mut Scope < ' tcx > ,
1096
+ scope : & mut Scope ,
1112
1097
mut target : BasicBlock ,
1113
1098
generator_drop : bool ,
1114
1099
is_generator : bool )
@@ -1152,26 +1137,20 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1152
1137
// this is not what clang does.
1153
1138
match drop_data. kind {
1154
1139
DropKind :: Storage if is_generator => {
1155
- // Only temps and vars need their storage dead.
1156
- match drop_data. location {
1157
- Place :: Base ( PlaceBase :: Local ( index) ) => {
1158
- storage_deads. push ( Statement {
1159
- source_info : source_info ( drop_data. span ) ,
1160
- kind : StatementKind :: StorageDead ( index)
1161
- } ) ;
1162
- if !target_built_by_us {
1163
- // We cannot add statements to an existing block, so we create a new
1164
- // block for our StorageDead statements.
1165
- let block = cfg. start_new_cleanup_block ( ) ;
1166
- let source_info = SourceInfo { span : DUMMY_SP , scope : source_scope } ;
1167
- cfg. terminate ( block, source_info,
1168
- TerminatorKind :: Goto { target : target } ) ;
1169
- target = block;
1170
- target_built_by_us = true ;
1171
- }
1172
- }
1173
- _ => unreachable ! ( ) ,
1174
- } ;
1140
+ storage_deads. push ( Statement {
1141
+ source_info : source_info ( drop_data. span ) ,
1142
+ kind : StatementKind :: StorageDead ( drop_data. local )
1143
+ } ) ;
1144
+ if !target_built_by_us {
1145
+ // We cannot add statements to an existing block, so we create a new
1146
+ // block for our StorageDead statements.
1147
+ let block = cfg. start_new_cleanup_block ( ) ;
1148
+ let source_info = SourceInfo { span : DUMMY_SP , scope : source_scope } ;
1149
+ cfg. terminate ( block, source_info,
1150
+ TerminatorKind :: Goto { target : target } ) ;
1151
+ target = block;
1152
+ target_built_by_us = true ;
1153
+ }
1175
1154
* drop_data. cached_block . ref_mut ( generator_drop) = Some ( target) ;
1176
1155
}
1177
1156
DropKind :: Storage => { }
@@ -1184,12 +1163,15 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1184
1163
} else {
1185
1164
push_storage_deads ( cfg, target, & mut storage_deads) ;
1186
1165
let block = cfg. start_new_cleanup_block ( ) ;
1187
- cfg. terminate ( block, source_info ( drop_data. span ) ,
1188
- TerminatorKind :: Drop {
1189
- location : drop_data. location . clone ( ) ,
1190
- target,
1191
- unwind : None
1192
- } ) ;
1166
+ cfg. terminate (
1167
+ block,
1168
+ source_info ( drop_data. span ) ,
1169
+ TerminatorKind :: Drop {
1170
+ location : drop_data. local . into ( ) ,
1171
+ target,
1172
+ unwind : None
1173
+ } ,
1174
+ ) ;
1193
1175
* cached_block = Some ( block) ;
1194
1176
target_built_by_us = true ;
1195
1177
block
0 commit comments