@@ -13,19 +13,19 @@ use super::{parse_by_kind, PResult, ParseCtxt};
1313impl < ' tcx , ' body > ParseCtxt < ' tcx , ' body > {
1414 pub fn parse_statement ( & self , expr_id : ExprId ) -> PResult < StatementKind < ' tcx > > {
1515 parse_by_kind ! ( self , expr_id, _, "statement" ,
16- @call( " mir_storage_live" , args) => {
16+ @call( mir_storage_live, args) => {
1717 Ok ( StatementKind :: StorageLive ( self . parse_local( args[ 0 ] ) ?) )
1818 } ,
19- @call( " mir_storage_dead" , args) => {
19+ @call( mir_storage_dead, args) => {
2020 Ok ( StatementKind :: StorageDead ( self . parse_local( args[ 0 ] ) ?) )
2121 } ,
22- @call( " mir_deinit" , args) => {
22+ @call( mir_deinit, args) => {
2323 Ok ( StatementKind :: Deinit ( Box :: new( self . parse_place( args[ 0 ] ) ?) ) )
2424 } ,
25- @call( " mir_retag" , args) => {
25+ @call( mir_retag, args) => {
2626 Ok ( StatementKind :: Retag ( RetagKind :: Default , Box :: new( self . parse_place( args[ 0 ] ) ?) ) )
2727 } ,
28- @call( " mir_set_discriminant" , args) => {
28+ @call( mir_set_discriminant, args) => {
2929 let place = self . parse_place( args[ 0 ] ) ?;
3030 let var = self . parse_integer_literal( args[ 1 ] ) ? as u32 ;
3131 Ok ( StatementKind :: SetDiscriminant {
@@ -43,24 +43,30 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
4343
4444 pub fn parse_terminator ( & self , expr_id : ExprId ) -> PResult < TerminatorKind < ' tcx > > {
4545 parse_by_kind ! ( self , expr_id, expr, "terminator" ,
46- @call( " mir_return" , _args) => {
46+ @call( mir_return, _args) => {
4747 Ok ( TerminatorKind :: Return )
4848 } ,
49- @call( " mir_goto" , args) => {
49+ @call( mir_goto, args) => {
5050 Ok ( TerminatorKind :: Goto { target: self . parse_block( args[ 0 ] ) ? } )
5151 } ,
52- @call( " mir_unreachable" , _args) => {
52+ @call( mir_unreachable, _args) => {
5353 Ok ( TerminatorKind :: Unreachable )
5454 } ,
55- @call( "mir_drop" , args) => {
55+ @call( mir_unwind_resume, _args) => {
56+ Ok ( TerminatorKind :: UnwindResume )
57+ } ,
58+ @call( mir_unwind_terminate, args) => {
59+ Ok ( TerminatorKind :: UnwindTerminate ( self . parse_unwind_terminate_reason( args[ 0 ] ) ?) )
60+ } ,
61+ @call( mir_drop, args) => {
5662 Ok ( TerminatorKind :: Drop {
5763 place: self . parse_place( args[ 0 ] ) ?,
5864 target: self . parse_block( args[ 1 ] ) ?,
59- unwind: UnwindAction :: Continue ,
65+ unwind: self . parse_unwind_action ( args [ 2 ] ) ? ,
6066 replace: false ,
6167 } )
6268 } ,
63- @call( " mir_call" , args) => {
69+ @call( mir_call, args) => {
6470 self . parse_call( args)
6571 } ,
6672 ExprKind :: Match { scrutinee, arms, .. } => {
@@ -70,6 +76,34 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
7076 )
7177 }
7278
79+ fn parse_unwind_terminate_reason ( & self , expr_id : ExprId ) -> PResult < UnwindTerminateReason > {
80+ parse_by_kind ! ( self , expr_id, _, "unwind terminate reason" ,
81+ @variant( mir_unwind_terminate_reason, Abi ) => {
82+ Ok ( UnwindTerminateReason :: Abi )
83+ } ,
84+ @variant( mir_unwind_terminate_reason, InCleanup ) => {
85+ Ok ( UnwindTerminateReason :: InCleanup )
86+ } ,
87+ )
88+ }
89+
90+ fn parse_unwind_action ( & self , expr_id : ExprId ) -> PResult < UnwindAction > {
91+ parse_by_kind ! ( self , expr_id, _, "unwind action" ,
92+ @call( mir_unwind_continue, _args) => {
93+ Ok ( UnwindAction :: Continue )
94+ } ,
95+ @call( mir_unwind_unreachable, _args) => {
96+ Ok ( UnwindAction :: Unreachable )
97+ } ,
98+ @call( mir_unwind_terminate, args) => {
99+ Ok ( UnwindAction :: Terminate ( self . parse_unwind_terminate_reason( args[ 0 ] ) ?) )
100+ } ,
101+ @call( mir_unwind_cleanup, args) => {
102+ Ok ( UnwindAction :: Cleanup ( self . parse_block( args[ 0 ] ) ?) )
103+ } ,
104+ )
105+ }
106+
73107 fn parse_match ( & self , arms : & [ ArmId ] , span : Span ) -> PResult < SwitchTargets > {
74108 let Some ( ( otherwise, rest) ) = arms. split_last ( ) else {
75109 return Err ( ParseError {
@@ -113,6 +147,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
113147 ) ;
114148 let destination = self . parse_place ( destination) ?;
115149 let target = self . parse_block ( args[ 1 ] ) ?;
150+ let unwind = self . parse_unwind_action ( args[ 2 ] ) ?;
116151
117152 parse_by_kind ! ( self , call, _, "function call" ,
118153 ExprKind :: Call { fun, args, from_hir_call, fn_span, .. } => {
@@ -126,7 +161,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
126161 args,
127162 destination,
128163 target: Some ( target) ,
129- unwind: UnwindAction :: Continue ,
164+ unwind,
130165 call_source: if * from_hir_call { CallSource :: Normal } else {
131166 CallSource :: OverloadedOperator
132167 } ,
@@ -138,25 +173,25 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
138173
139174 fn parse_rvalue ( & self , expr_id : ExprId ) -> PResult < Rvalue < ' tcx > > {
140175 parse_by_kind ! ( self , expr_id, expr, "rvalue" ,
141- @call( " mir_discriminant" , args) => self . parse_place( args[ 0 ] ) . map( Rvalue :: Discriminant ) ,
142- @call( " mir_cast_transmute" , args) => {
176+ @call( mir_discriminant, args) => self . parse_place( args[ 0 ] ) . map( Rvalue :: Discriminant ) ,
177+ @call( mir_cast_transmute, args) => {
143178 let source = self . parse_operand( args[ 0 ] ) ?;
144179 Ok ( Rvalue :: Cast ( CastKind :: Transmute , source, expr. ty) )
145180 } ,
146- @call( " mir_checked" , args) => {
181+ @call( mir_checked, args) => {
147182 parse_by_kind!( self , args[ 0 ] , _, "binary op" ,
148183 ExprKind :: Binary { op, lhs, rhs } => Ok ( Rvalue :: CheckedBinaryOp (
149184 * op, Box :: new( ( self . parse_operand( * lhs) ?, self . parse_operand( * rhs) ?) )
150185 ) ) ,
151186 )
152187 } ,
153- @call( " mir_offset" , args) => {
188+ @call( mir_offset, args) => {
154189 let ptr = self . parse_operand( args[ 0 ] ) ?;
155190 let offset = self . parse_operand( args[ 1 ] ) ?;
156191 Ok ( Rvalue :: BinaryOp ( BinOp :: Offset , Box :: new( ( ptr, offset) ) ) )
157192 } ,
158- @call( " mir_len" , args) => Ok ( Rvalue :: Len ( self . parse_place( args[ 0 ] ) ?) ) ,
159- @call( " mir_copy_for_deref" , args) => Ok ( Rvalue :: CopyForDeref ( self . parse_place( args[ 0 ] ) ?) ) ,
193+ @call( mir_len, args) => Ok ( Rvalue :: Len ( self . parse_place( args[ 0 ] ) ?) ) ,
194+ @call( mir_copy_for_deref, args) => Ok ( Rvalue :: CopyForDeref ( self . parse_place( args[ 0 ] ) ?) ) ,
160195 ExprKind :: Borrow { borrow_kind, arg } => Ok (
161196 Rvalue :: Ref ( self . tcx. lifetimes. re_erased, * borrow_kind, self . parse_place( * arg) ?)
162197 ) ,
@@ -206,9 +241,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
206241
207242 pub fn parse_operand ( & self , expr_id : ExprId ) -> PResult < Operand < ' tcx > > {
208243 parse_by_kind ! ( self , expr_id, expr, "operand" ,
209- @call( " mir_move" , args) => self . parse_place( args[ 0 ] ) . map( Operand :: Move ) ,
210- @call( " mir_static" , args) => self . parse_static( args[ 0 ] ) ,
211- @call( " mir_static_mut" , args) => self . parse_static( args[ 0 ] ) ,
244+ @call( mir_move, args) => self . parse_place( args[ 0 ] ) . map( Operand :: Move ) ,
245+ @call( mir_static, args) => self . parse_static( args[ 0 ] ) ,
246+ @call( mir_static_mut, args) => self . parse_static( args[ 0 ] ) ,
212247 ExprKind :: Literal { .. }
213248 | ExprKind :: NamedConst { .. }
214249 | ExprKind :: NonHirLiteral { .. }
@@ -229,23 +264,23 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
229264
230265 fn parse_place_inner ( & self , expr_id : ExprId ) -> PResult < ( Place < ' tcx > , PlaceTy < ' tcx > ) > {
231266 let ( parent, proj) = parse_by_kind ! ( self , expr_id, expr, "place" ,
232- @call( " mir_field" , args) => {
267+ @call( mir_field, args) => {
233268 let ( parent, ty) = self . parse_place_inner( args[ 0 ] ) ?;
234269 let field = FieldIdx :: from_u32( self . parse_integer_literal( args[ 1 ] ) ? as u32 ) ;
235270 let field_ty = ty. field_ty( self . tcx, field) ;
236271 let proj = PlaceElem :: Field ( field, field_ty) ;
237272 let place = parent. project_deeper( & [ proj] , self . tcx) ;
238273 return Ok ( ( place, PlaceTy :: from_ty( field_ty) ) ) ;
239274 } ,
240- @call( " mir_variant" , args) => {
275+ @call( mir_variant, args) => {
241276 ( args[ 0 ] , PlaceElem :: Downcast (
242277 None ,
243278 VariantIdx :: from_u32( self . parse_integer_literal( args[ 1 ] ) ? as u32 )
244279 ) )
245280 } ,
246281 ExprKind :: Deref { arg } => {
247282 parse_by_kind!( self , * arg, _, "does not matter" ,
248- @call( " mir_make_place" , args) => return self . parse_place_inner( args[ 0 ] ) ,
283+ @call( mir_make_place, args) => return self . parse_place_inner( args[ 0 ] ) ,
249284 _ => ( * arg, PlaceElem :: Deref ) ,
250285 )
251286 } ,
0 commit comments