@@ -28,6 +28,7 @@ use std::mem;
2828use std:: u32;
2929use syntax:: abi:: Abi ;
3030use syntax:: ast;
31+ use syntax:: attr:: { self , UnwindAttr } ;
3132use syntax:: symbol:: keywords;
3233use syntax_pos:: Span ;
3334use transform:: MirSource ;
@@ -355,10 +356,9 @@ macro_rules! unpack {
355356}
356357
357358fn should_abort_on_panic < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
358- fn_id : ast :: NodeId ,
359+ fn_def_id : DefId ,
359360 abi : Abi )
360361 -> bool {
361-
362362 // Not callable from C, so we can safely unwind through these
363363 if abi == Abi :: Rust || abi == Abi :: RustCall { return false ; }
364364
@@ -370,9 +370,17 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
370370
371371 // This is a special case: some functions have a C abi but are meant to
372372 // unwind anyway. Don't stop them.
373- if tcx. has_attr ( tcx. hir . local_def_id ( fn_id) , "unwind" ) { return false ; }
373+ let attrs = & tcx. get_attrs ( fn_def_id) ;
374+ match attr:: find_unwind_attr ( Some ( tcx. sess . diagnostic ( ) ) , attrs) {
375+ None => {
376+ // FIXME(rust-lang/rust#48251) -- Had to disable
377+ // abort-on-panic for backwards compatibility reasons.
378+ false
379+ }
374380
375- return true ;
381+ Some ( UnwindAttr :: Allowed ) => false ,
382+ Some ( UnwindAttr :: Aborts ) => true ,
383+ }
376384}
377385
378386///////////////////////////////////////////////////////////////////////////
@@ -399,13 +407,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
399407 safety,
400408 return_ty) ;
401409
410+ let fn_def_id = tcx. hir . local_def_id ( fn_id) ;
402411 let call_site_scope = region:: Scope :: CallSite ( body. value . hir_id . local_id ) ;
403412 let arg_scope = region:: Scope :: Arguments ( body. value . hir_id . local_id ) ;
404413 let mut block = START_BLOCK ;
405414 let source_info = builder. source_info ( span) ;
406415 let call_site_s = ( call_site_scope, source_info) ;
407416 unpack ! ( block = builder. in_scope( call_site_s, LintLevel :: Inherited , block, |builder| {
408- if should_abort_on_panic( tcx, fn_id , abi) {
417+ if should_abort_on_panic( tcx, fn_def_id , abi) {
409418 builder. schedule_abort( ) ;
410419 }
411420
0 commit comments