@@ -105,9 +105,14 @@ pub enum MirLowerError {
105105/// A token to ensuring that each drop scope is popped at most once, thanks to the compiler that checks moves.
106106struct DropScopeToken ;
107107impl DropScopeToken {
108- fn pop_and_drop ( self , ctx : & mut MirLowerCtx < ' _ > , current : BasicBlockId ) -> BasicBlockId {
108+ fn pop_and_drop (
109+ self ,
110+ ctx : & mut MirLowerCtx < ' _ > ,
111+ current : BasicBlockId ,
112+ span : MirSpan ,
113+ ) -> BasicBlockId {
109114 std:: mem:: forget ( self ) ;
110- ctx. pop_drop_scope_internal ( current)
115+ ctx. pop_drop_scope_internal ( current, span )
111116 }
112117
113118 /// It is useful when we want a drop scope is syntaxically closed, but we don't want to execute any drop
@@ -582,7 +587,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
582587 self . lower_loop ( current, place, * label, expr_id. into ( ) , |this, begin| {
583588 let scope = this. push_drop_scope ( ) ;
584589 if let Some ( ( _, mut current) ) = this. lower_expr_as_place ( begin, * body, true ) ? {
585- current = scope. pop_and_drop ( this, current) ;
590+ current = scope. pop_and_drop ( this, current, body . into ( ) ) ;
586591 this. set_goto ( current, begin, expr_id. into ( ) ) ;
587592 } else {
588593 scope. pop_assume_dropped ( this) ;
@@ -720,7 +725,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
720725 . ok_or ( MirLowerError :: ContinueWithoutLoop ) ?,
721726 } ;
722727 let begin = loop_data. begin ;
723- current = self . drop_until_scope ( loop_data. drop_scope_index , current) ;
728+ current =
729+ self . drop_until_scope ( loop_data. drop_scope_index , current, expr_id. into ( ) ) ;
724730 self . set_goto ( current, begin, expr_id. into ( ) ) ;
725731 Ok ( None )
726732 }
@@ -759,7 +765,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
759765 self . current_loop_blocks . as_ref ( ) . unwrap ( ) . drop_scope_index ,
760766 ) ,
761767 } ;
762- current = self . drop_until_scope ( drop_scope, current) ;
768+ current = self . drop_until_scope ( drop_scope, current, expr_id . into ( ) ) ;
763769 self . set_goto ( current, end, expr_id. into ( ) ) ;
764770 Ok ( None )
765771 }
@@ -773,7 +779,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
773779 return Ok ( None ) ;
774780 }
775781 }
776- current = self . drop_until_scope ( 0 , current) ;
782+ current = self . drop_until_scope ( 0 , current, expr_id . into ( ) ) ;
777783 self . set_terminator ( current, TerminatorKind :: Return , expr_id. into ( ) ) ;
778784 Ok ( None )
779785 }
@@ -1782,7 +1788,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
17821788 return Ok ( None ) ;
17831789 } ;
17841790 self . push_fake_read ( c, p, expr. into ( ) ) ;
1785- current = scope2. pop_and_drop ( self , c) ;
1791+ current = scope2. pop_and_drop ( self , c, expr . into ( ) ) ;
17861792 }
17871793 }
17881794 }
@@ -1793,7 +1799,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
17931799 } ;
17941800 current = c;
17951801 }
1796- current = scope. pop_and_drop ( self , current) ;
1802+ current = scope. pop_and_drop ( self , current, span ) ;
17971803 Ok ( Some ( current) )
17981804 }
17991805
@@ -1873,9 +1879,14 @@ impl<'ctx> MirLowerCtx<'ctx> {
18731879 }
18741880 }
18751881
1876- fn drop_until_scope ( & mut self , scope_index : usize , mut current : BasicBlockId ) -> BasicBlockId {
1882+ fn drop_until_scope (
1883+ & mut self ,
1884+ scope_index : usize ,
1885+ mut current : BasicBlockId ,
1886+ span : MirSpan ,
1887+ ) -> BasicBlockId {
18771888 for scope in self . drop_scopes [ scope_index..] . to_vec ( ) . iter ( ) . rev ( ) {
1878- self . emit_drop_and_storage_dead_for_scope ( scope, & mut current) ;
1889+ self . emit_drop_and_storage_dead_for_scope ( scope, & mut current, span ) ;
18791890 }
18801891 current
18811892 }
@@ -1891,17 +1902,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
18911902 }
18921903
18931904 /// Don't call directly
1894- fn pop_drop_scope_internal ( & mut self , mut current : BasicBlockId ) -> BasicBlockId {
1905+ fn pop_drop_scope_internal (
1906+ & mut self ,
1907+ mut current : BasicBlockId ,
1908+ span : MirSpan ,
1909+ ) -> BasicBlockId {
18951910 let scope = self . drop_scopes . pop ( ) . unwrap ( ) ;
1896- self . emit_drop_and_storage_dead_for_scope ( & scope, & mut current) ;
1911+ self . emit_drop_and_storage_dead_for_scope ( & scope, & mut current, span ) ;
18971912 current
18981913 }
18991914
19001915 fn pop_drop_scope_assert_finished (
19011916 & mut self ,
19021917 mut current : BasicBlockId ,
1918+ span : MirSpan ,
19031919 ) -> Result < BasicBlockId > {
1904- current = self . pop_drop_scope_internal ( current) ;
1920+ current = self . pop_drop_scope_internal ( current, span ) ;
19051921 if !self . drop_scopes . is_empty ( ) {
19061922 implementation_error ! ( "Mismatched count between drop scope push and pops" ) ;
19071923 }
@@ -1912,20 +1928,18 @@ impl<'ctx> MirLowerCtx<'ctx> {
19121928 & mut self ,
19131929 scope : & DropScope ,
19141930 current : & mut Idx < BasicBlock > ,
1931+ span : MirSpan ,
19151932 ) {
19161933 for & l in scope. locals . iter ( ) . rev ( ) {
19171934 if !self . result . locals [ l] . ty . clone ( ) . is_copy ( self . db , self . owner ) {
19181935 let prev = std:: mem:: replace ( current, self . new_basic_block ( ) ) ;
19191936 self . set_terminator (
19201937 prev,
19211938 TerminatorKind :: Drop { place : l. into ( ) , target : * current, unwind : None } ,
1922- MirSpan :: Unknown ,
1939+ span ,
19231940 ) ;
19241941 }
1925- self . push_statement (
1926- * current,
1927- StatementKind :: StorageDead ( l) . with_span ( MirSpan :: Unknown ) ,
1928- ) ;
1942+ self . push_statement ( * current, StatementKind :: StorageDead ( l) . with_span ( span) ) ;
19291943 }
19301944 }
19311945}
@@ -2002,7 +2016,7 @@ pub fn mir_body_for_closure_query(
20022016 |_| true ,
20032017 ) ?;
20042018 if let Some ( current) = ctx. lower_expr_to_place ( * root, return_slot ( ) . into ( ) , current) ? {
2005- let current = ctx. pop_drop_scope_assert_finished ( current) ?;
2019+ let current = ctx. pop_drop_scope_assert_finished ( current, root . into ( ) ) ?;
20062020 ctx. set_terminator ( current, TerminatorKind :: Return , ( * root) . into ( ) ) ;
20072021 }
20082022 let mut upvar_map: FxHashMap < LocalId , Vec < ( & CapturedItem , usize ) > > = FxHashMap :: default ( ) ;
@@ -2146,7 +2160,7 @@ pub fn lower_to_mir(
21462160 ctx. lower_params_and_bindings ( [ ] . into_iter ( ) , binding_picker) ?
21472161 } ;
21482162 if let Some ( current) = ctx. lower_expr_to_place ( root_expr, return_slot ( ) . into ( ) , current) ? {
2149- let current = ctx. pop_drop_scope_assert_finished ( current) ?;
2163+ let current = ctx. pop_drop_scope_assert_finished ( current, root_expr . into ( ) ) ?;
21502164 ctx. set_terminator ( current, TerminatorKind :: Return , root_expr. into ( ) ) ;
21512165 }
21522166 Ok ( ctx. result )
0 commit comments