@@ -105,9 +105,14 @@ pub enum MirLowerError {
105
105
/// A token to ensuring that each drop scope is popped at most once, thanks to the compiler that checks moves.
106
106
struct DropScopeToken ;
107
107
impl 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 {
109
114
std:: mem:: forget ( self ) ;
110
- ctx. pop_drop_scope_internal ( current)
115
+ ctx. pop_drop_scope_internal ( current, span )
111
116
}
112
117
113
118
/// 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> {
582
587
self . lower_loop ( current, place, * label, expr_id. into ( ) , |this, begin| {
583
588
let scope = this. push_drop_scope ( ) ;
584
589
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 ( ) ) ;
586
591
this. set_goto ( current, begin, expr_id. into ( ) ) ;
587
592
} else {
588
593
scope. pop_assume_dropped ( this) ;
@@ -720,7 +725,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
720
725
. ok_or ( MirLowerError :: ContinueWithoutLoop ) ?,
721
726
} ;
722
727
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 ( ) ) ;
724
730
self . set_goto ( current, begin, expr_id. into ( ) ) ;
725
731
Ok ( None )
726
732
}
@@ -759,7 +765,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
759
765
self . current_loop_blocks . as_ref ( ) . unwrap ( ) . drop_scope_index ,
760
766
) ,
761
767
} ;
762
- current = self . drop_until_scope ( drop_scope, current) ;
768
+ current = self . drop_until_scope ( drop_scope, current, expr_id . into ( ) ) ;
763
769
self . set_goto ( current, end, expr_id. into ( ) ) ;
764
770
Ok ( None )
765
771
}
@@ -773,7 +779,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
773
779
return Ok ( None ) ;
774
780
}
775
781
}
776
- current = self . drop_until_scope ( 0 , current) ;
782
+ current = self . drop_until_scope ( 0 , current, expr_id . into ( ) ) ;
777
783
self . set_terminator ( current, TerminatorKind :: Return , expr_id. into ( ) ) ;
778
784
Ok ( None )
779
785
}
@@ -1782,7 +1788,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
1782
1788
return Ok ( None ) ;
1783
1789
} ;
1784
1790
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 ( ) ) ;
1786
1792
}
1787
1793
}
1788
1794
}
@@ -1793,7 +1799,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
1793
1799
} ;
1794
1800
current = c;
1795
1801
}
1796
- current = scope. pop_and_drop ( self , current) ;
1802
+ current = scope. pop_and_drop ( self , current, span ) ;
1797
1803
Ok ( Some ( current) )
1798
1804
}
1799
1805
@@ -1873,9 +1879,14 @@ impl<'ctx> MirLowerCtx<'ctx> {
1873
1879
}
1874
1880
}
1875
1881
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 {
1877
1888
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 ) ;
1879
1890
}
1880
1891
current
1881
1892
}
@@ -1891,17 +1902,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
1891
1902
}
1892
1903
1893
1904
/// 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 {
1895
1910
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 ) ;
1897
1912
current
1898
1913
}
1899
1914
1900
1915
fn pop_drop_scope_assert_finished (
1901
1916
& mut self ,
1902
1917
mut current : BasicBlockId ,
1918
+ span : MirSpan ,
1903
1919
) -> Result < BasicBlockId > {
1904
- current = self . pop_drop_scope_internal ( current) ;
1920
+ current = self . pop_drop_scope_internal ( current, span ) ;
1905
1921
if !self . drop_scopes . is_empty ( ) {
1906
1922
implementation_error ! ( "Mismatched count between drop scope push and pops" ) ;
1907
1923
}
@@ -1912,20 +1928,18 @@ impl<'ctx> MirLowerCtx<'ctx> {
1912
1928
& mut self ,
1913
1929
scope : & DropScope ,
1914
1930
current : & mut Idx < BasicBlock > ,
1931
+ span : MirSpan ,
1915
1932
) {
1916
1933
for & l in scope. locals . iter ( ) . rev ( ) {
1917
1934
if !self . result . locals [ l] . ty . clone ( ) . is_copy ( self . db , self . owner ) {
1918
1935
let prev = std:: mem:: replace ( current, self . new_basic_block ( ) ) ;
1919
1936
self . set_terminator (
1920
1937
prev,
1921
1938
TerminatorKind :: Drop { place : l. into ( ) , target : * current, unwind : None } ,
1922
- MirSpan :: Unknown ,
1939
+ span ,
1923
1940
) ;
1924
1941
}
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) ) ;
1929
1943
}
1930
1944
}
1931
1945
}
@@ -2002,7 +2016,7 @@ pub fn mir_body_for_closure_query(
2002
2016
|_| true ,
2003
2017
) ?;
2004
2018
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 ( ) ) ?;
2006
2020
ctx. set_terminator ( current, TerminatorKind :: Return , ( * root) . into ( ) ) ;
2007
2021
}
2008
2022
let mut upvar_map: FxHashMap < LocalId , Vec < ( & CapturedItem , usize ) > > = FxHashMap :: default ( ) ;
@@ -2146,7 +2160,7 @@ pub fn lower_to_mir(
2146
2160
ctx. lower_params_and_bindings ( [ ] . into_iter ( ) , binding_picker) ?
2147
2161
} ;
2148
2162
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 ( ) ) ?;
2150
2164
ctx. set_terminator ( current, TerminatorKind :: Return , root_expr. into ( ) ) ;
2151
2165
}
2152
2166
Ok ( ctx. result )
0 commit comments