@@ -543,11 +543,13 @@ fn fn_abi_new_uncached<'tcx>(
543
543
instance : Option < ty:: Instance < ' tcx > > ,
544
544
) -> Result < & ' tcx FnAbi < ' tcx , Ty < ' tcx > > , & ' tcx FnAbiError < ' tcx > > {
545
545
let tcx = cx. tcx ( ) ;
546
- let ( caller_location, fn_def_id, is_virtual_call) = if let Some ( instance) = instance {
546
+ let ( caller_location, determined_fn_def_id, is_virtual_call) = if let Some ( instance) = instance
547
+ {
548
+ let is_virtual_call = matches ! ( instance. def, ty:: InstanceKind :: Virtual ( ..) ) ;
547
549
(
548
550
instance. def . requires_caller_location ( tcx) . then ( || tcx. caller_location_ty ( ) ) ,
549
- Some ( instance. def_id ( ) ) ,
550
- matches ! ( instance . def , ty :: InstanceKind :: Virtual ( .. ) ) ,
551
+ if is_virtual_call { None } else { Some ( instance. def_id ( ) ) } ,
552
+ is_virtual_call ,
551
553
)
552
554
} else {
553
555
( None , None , false )
@@ -577,7 +579,7 @@ fn fn_abi_new_uncached<'tcx>(
577
579
} ;
578
580
579
581
let is_drop_in_place =
580
- fn_def_id . is_some_and ( |def_id| tcx. is_lang_item ( def_id, LangItem :: DropInPlace ) ) ;
582
+ determined_fn_def_id . is_some_and ( |def_id| tcx. is_lang_item ( def_id, LangItem :: DropInPlace ) ) ;
581
583
582
584
let arg_of = |ty : Ty < ' tcx > , arg_idx : Option < usize > | -> Result < _ , & ' tcx FnAbiError < ' tcx > > {
583
585
let span = tracing:: debug_span!( "arg_of" ) ;
@@ -633,7 +635,12 @@ fn fn_abi_new_uncached<'tcx>(
633
635
c_variadic : sig. c_variadic ,
634
636
fixed_count : inputs. len ( ) as u32 ,
635
637
conv,
636
- can_unwind : fn_can_unwind ( cx. tcx ( ) , fn_def_id, sig. abi ) ,
638
+ can_unwind : fn_can_unwind (
639
+ tcx,
640
+ // Since `#[rustc_nounwind]` can change unwinding, we cannot infer unwinding by `fn_def_id` for a virtual call.
641
+ determined_fn_def_id,
642
+ sig. abi ,
643
+ ) ,
637
644
} ;
638
645
fn_abi_adjust_for_abi (
639
646
cx,
@@ -642,7 +649,7 @@ fn fn_abi_new_uncached<'tcx>(
642
649
// If this is a virtual call, we cannot pass the `fn_def_id`, as it might call other
643
650
// functions from vtable. Internally, `deduced_param_attrs` attempts to infer attributes by
644
651
// visit the function body.
645
- fn_def_id . filter ( |_| !is_virtual_call ) ,
652
+ determined_fn_def_id ,
646
653
) ;
647
654
debug ! ( "fn_abi_new_uncached = {:?}" , fn_abi) ;
648
655
fn_abi_sanity_check ( cx, & fn_abi, sig. abi ) ;
0 commit comments