@@ -28,6 +28,7 @@ use std::mem;
28
28
use std:: u32;
29
29
use syntax:: abi:: Abi ;
30
30
use syntax:: ast;
31
+ use syntax:: attr:: { self , UnwindAttr } ;
31
32
use syntax:: symbol:: keywords;
32
33
use syntax_pos:: Span ;
33
34
use transform:: MirSource ;
@@ -355,10 +356,9 @@ macro_rules! unpack {
355
356
}
356
357
357
358
fn should_abort_on_panic < ' a , ' gcx , ' tcx > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
358
- fn_id : ast :: NodeId ,
359
+ fn_def_id : DefId ,
359
360
abi : Abi )
360
361
-> bool {
361
-
362
362
// Not callable from C, so we can safely unwind through these
363
363
if abi == Abi :: Rust || abi == Abi :: RustCall { return false ; }
364
364
@@ -370,9 +370,17 @@ fn should_abort_on_panic<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
370
370
371
371
// This is a special case: some functions have a C abi but are meant to
372
372
// 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
+ }
374
380
375
- return true ;
381
+ Some ( UnwindAttr :: Allowed ) => false ,
382
+ Some ( UnwindAttr :: Aborts ) => true ,
383
+ }
376
384
}
377
385
378
386
///////////////////////////////////////////////////////////////////////////
@@ -399,13 +407,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
399
407
safety,
400
408
return_ty) ;
401
409
410
+ let fn_def_id = tcx. hir . local_def_id ( fn_id) ;
402
411
let call_site_scope = region:: Scope :: CallSite ( body. value . hir_id . local_id ) ;
403
412
let arg_scope = region:: Scope :: Arguments ( body. value . hir_id . local_id ) ;
404
413
let mut block = START_BLOCK ;
405
414
let source_info = builder. source_info ( span) ;
406
415
let call_site_s = ( call_site_scope, source_info) ;
407
416
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) {
409
418
builder. schedule_abort( ) ;
410
419
}
411
420
0 commit comments