@@ -94,7 +94,7 @@ use std::collections::hash_map::Entry;
9494use std:: mem;
9595
9696#[ derive( Debug ) ]
97- struct Scope < ' tcx > {
97+ struct Scope {
9898 /// The source scope this scope was created in.
9999 source_scope : SourceScope ,
100100
@@ -121,7 +121,7 @@ struct Scope<'tcx> {
121121 /// out empty but grows as variables are declared during the
122122 /// building process. This is a stack, so we always drop from the
123123 /// end of the vector (top of the stack) first.
124- drops : Vec < DropData < ' tcx > > ,
124+ drops : Vec < DropData > ,
125125
126126 /// The cache for drop chain on “normal” exit into a particular BasicBlock.
127127 cached_exits : FxHashMap < ( BasicBlock , region:: Scope ) , BasicBlock > ,
@@ -135,18 +135,18 @@ struct Scope<'tcx> {
135135
136136#[ derive( Debug , Default ) ]
137137pub struct Scopes < ' tcx > {
138- scopes : Vec < Scope < ' tcx > > ,
138+ scopes : Vec < Scope > ,
139139 /// The current set of breakable scopes. See module comment for more details.
140140 breakable_scopes : Vec < BreakableScope < ' tcx > > ,
141141}
142142
143143#[ derive( Debug ) ]
144- struct DropData < ' tcx > {
144+ struct DropData {
145145 /// span where drop obligation was incurred (typically where place was declared)
146146 span : Span ,
147147
148- /// place to drop
149- location : Place < ' tcx > ,
148+ /// local to drop
149+ local : Local ,
150150
151151 /// Whether this is a value Drop or a StorageDead.
152152 kind : DropKind ,
@@ -223,7 +223,7 @@ impl CachedBlock {
223223 }
224224}
225225
226- impl < ' tcx > Scope < ' tcx > {
226+ impl Scope {
227227 /// Invalidates all the cached blocks in the scope.
228228 ///
229229 /// 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> {
285285 fn pop_scope (
286286 & mut self ,
287287 region_scope : ( region:: Scope , SourceInfo ) ,
288- ) -> ( Scope < ' tcx > , Option < BasicBlock > ) {
288+ ) -> ( Scope , Option < BasicBlock > ) {
289289 let scope = self . scopes . pop ( ) . unwrap ( ) ;
290290 assert_eq ! ( scope. region_scope, region_scope. 0 ) ;
291291 let unwind_to = self . scopes . last ( )
@@ -343,11 +343,11 @@ impl<'tcx> Scopes<'tcx> {
343343 scope_count
344344 }
345345
346- fn iter_mut ( & mut self ) -> impl DoubleEndedIterator < Item =& mut Scope < ' tcx > > + ' _ {
346+ fn iter_mut ( & mut self ) -> impl DoubleEndedIterator < Item =& mut Scope > + ' _ {
347347 self . scopes . iter_mut ( ) . rev ( )
348348 }
349349
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 > + ' _ {
351351 let len = self . len ( ) ;
352352 self . scopes [ len - count..] . iter_mut ( )
353353 }
@@ -717,11 +717,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
717717 & mut self ,
718718 span : Span ,
719719 region_scope : region:: Scope ,
720- place : & Place < ' tcx > ,
720+ local : Local ,
721721 place_ty : Ty < ' tcx > ,
722722 ) {
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 ) ;
725725 }
726726
727727 /// Indicates that `place` should be dropped on exit from
@@ -733,25 +733,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
733733 & mut self ,
734734 span : Span ,
735735 region_scope : region:: Scope ,
736- place : & Place < ' tcx > ,
736+ local : Local ,
737737 place_ty : Ty < ' tcx > ,
738738 drop_kind : DropKind ,
739739 ) {
740740 let needs_drop = self . hir . needs_drop ( place_ty) ;
741741 match drop_kind {
742742 DropKind :: Value => if !needs_drop { return } ,
743743 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+ )
755750 }
756751 }
757752 }
@@ -817,14 +812,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
817812
818813 scope. drops . push ( DropData {
819814 span : scope_end,
820- location : place . clone ( ) ,
815+ local ,
821816 kind : drop_kind,
822817 cached_block : CachedBlock :: default ( ) ,
823818 } ) ;
824819 return ;
825820 }
826821 }
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 ) ;
828823 }
829824
830825 // Other
@@ -867,29 +862,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
867862 bug ! ( "Drop scheduled on top of condition variable" )
868863 }
869864 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+ ) ;
893882 }
894883 }
895884
@@ -1020,7 +1009,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
10201009fn build_scope_drops < ' tcx > (
10211010 cfg : & mut CFG < ' tcx > ,
10221011 is_generator : bool ,
1023- scope : & Scope < ' tcx > ,
1012+ scope : & Scope ,
10241013 mut block : BasicBlock ,
10251014 last_unwind_to : BasicBlock ,
10261015 arg_count : usize ,
@@ -1050,39 +1039,35 @@ fn build_scope_drops<'tcx>(
10501039 for drop_idx in ( 0 ..scope. drops . len ( ) ) . rev ( ) {
10511040 let drop_data = & scope. drops [ drop_idx] ;
10521041 let source_info = scope. source_info ( drop_data. span ) ;
1042+ let local = drop_data. local ;
10531043 match drop_data. kind {
10541044 DropKind :: Value => {
10551045 let unwind_to = get_unwind_to ( scope, is_generator, drop_idx, generator_drop)
10561046 . unwrap_or ( last_unwind_to) ;
10571047
10581048 let next = cfg. start_new_block ( ) ;
10591049 cfg. terminate ( block, source_info, TerminatorKind :: Drop {
1060- location : drop_data . location . clone ( ) ,
1050+ location : local . into ( ) ,
10611051 target : next,
10621052 unwind : Some ( unwind_to)
10631053 } ) ;
10641054 block = next;
10651055 }
10661056 DropKind :: Storage => {
1067- // Drop the storage for both value and storage drops.
10681057 // 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+ } ) ;
10781063 }
10791064 }
10801065 }
10811066 block. unit ( )
10821067}
10831068
1084- fn get_unwind_to < ' tcx > (
1085- scope : & Scope < ' tcx > ,
1069+ fn get_unwind_to (
1070+ scope : & Scope ,
10861071 is_generator : bool ,
10871072 unwind_from : usize ,
10881073 generator_drop : bool ,
@@ -1108,7 +1093,7 @@ fn get_unwind_to<'tcx>(
11081093
11091094fn build_diverge_scope < ' tcx > ( cfg : & mut CFG < ' tcx > ,
11101095 span : Span ,
1111- scope : & mut Scope < ' tcx > ,
1096+ scope : & mut Scope ,
11121097 mut target : BasicBlock ,
11131098 generator_drop : bool ,
11141099 is_generator : bool )
@@ -1152,26 +1137,20 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
11521137 // this is not what clang does.
11531138 match drop_data. kind {
11541139 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+ }
11751154 * drop_data. cached_block . ref_mut ( generator_drop) = Some ( target) ;
11761155 }
11771156 DropKind :: Storage => { }
@@ -1184,12 +1163,15 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
11841163 } else {
11851164 push_storage_deads ( cfg, target, & mut storage_deads) ;
11861165 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+ ) ;
11931175 * cached_block = Some ( block) ;
11941176 target_built_by_us = true ;
11951177 block
0 commit comments