@@ -15,6 +15,7 @@ use build::expr::category::{Category, RvalueFunc};
1515use build:: scope:: LoopScope ;
1616use hair:: * ;
1717use rustc:: middle:: region:: CodeExtent ;
18+ use rustc:: middle:: ty;
1819use rustc:: mir:: repr:: * ;
1920use syntax:: codemap:: Span ;
2021
@@ -210,22 +211,30 @@ impl<'a,'tcx> Builder<'a,'tcx> {
210211 this. exit_scope ( expr_span, extent, block, END_BLOCK ) ;
211212 this. cfg . start_new_block ( ) . unit ( )
212213 }
213- ExprKind :: Call { fun, args } => {
214+ ExprKind :: Call { ty, fun, args } => {
215+ let diverges = match ty. sty {
216+ ty:: TyBareFn ( _, ref f) => f. sig . 0 . output . diverges ( ) ,
217+ _ => false
218+ } ;
214219 let fun = unpack ! ( block = this. as_operand( block, fun) ) ;
215220 let args: Vec < _ > =
216221 args. into_iter ( )
217222 . map ( |arg| unpack ! ( block = this. as_operand( block, arg) ) )
218223 . collect ( ) ;
224+
219225 let success = this. cfg . start_new_block ( ) ;
220- let panic = this. diverge_cleanup ( ) ;
221- let targets = CallTargets :: WithCleanup ( ( success, panic) ) ;
222- this. cfg . terminate ( block,
223- Terminator :: Call {
224- func : fun,
225- args : args,
226- destination : destination. clone ( ) ,
227- targets : targets
228- } ) ;
226+ let cleanup = this. diverge_cleanup ( ) ;
227+ let term = if diverges {
228+ Terminator :: DivergingCall { func : fun, args : args, cleanup : Some ( cleanup) }
229+ } else {
230+ Terminator :: Call {
231+ func : fun,
232+ args : args,
233+ destination : destination. clone ( ) ,
234+ targets : CallTargets :: WithCleanup ( ( success, cleanup) )
235+ }
236+ } ;
237+ this. cfg . terminate ( block, term) ;
229238 success. unit ( )
230239 }
231240
0 commit comments