@@ -5,6 +5,7 @@ use rustc_hir::{CRATE_HIR_ID, HirId};
55use rustc_middle:: mir:: { self , Location , traversal} ;
66use rustc_middle:: ty:: { self , Instance , InstanceKind , Ty , TyCtxt } ;
77use rustc_span:: def_id:: DefId ;
8+ use rustc_span:: source_map:: Spanned ;
89use rustc_span:: { DUMMY_SP , Span , Symbol , sym} ;
910use rustc_target:: callconv:: { FnAbi , PassMode } ;
1011
@@ -157,12 +158,16 @@ fn do_check_unsized_params<'tcx>(
157158/// - the signature requires target features that are not enabled
158159fn check_instance_abi < ' tcx > ( tcx : TyCtxt < ' tcx > , instance : Instance < ' tcx > ) {
159160 let typing_env = ty:: TypingEnv :: fully_monomorphized ( ) ;
160- let Ok ( abi) = tcx. fn_abi_of_instance ( typing_env. as_query_input ( ( instance, ty:: List :: empty ( ) ) ) )
161- else {
162- // An error will be reported during codegen if we cannot determine the ABI of this
163- // function.
164- tcx. dcx ( ) . delayed_bug ( "ABI computation failure should lead to compilation failure" ) ;
165- return ;
161+ let abi = match tcx. fn_abi_of_instance ( typing_env. as_query_input ( ( instance, ty:: List :: empty ( ) ) ) )
162+ {
163+ Ok ( abi) => abi,
164+ Err ( err) => {
165+ // Emit directly: codegen may never see this instance (dead code, `-Zno-codegen`).
166+ let ty:: layout:: FnAbiError :: Layout ( layout_err) = * err;
167+ let span = tcx. def_span ( instance. def_id ( ) ) ;
168+ tcx. dcx ( ) . emit_err ( Spanned { node : layout_err. into_diagnostic ( ) , span } ) ;
169+ return ;
170+ }
166171 } ;
167172 // Unlike the call-site check, we do also check "Rust" ABI functions here.
168173 // This should never trigger, *except* if we start making use of vector registers
0 commit comments