@@ -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
@@ -161,11 +162,10 @@ fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
161162 {
162163 Ok ( abi) => abi,
163164 Err ( err) => {
164- // Emit the error directly rather than using `delayed_bug`, because codegen
165- // may never process this instance (e.g., unreachable code or `-Zno-codegen`),
166- // which would leave the error unreported and trigger an ICE.
167- let ty:: layout:: FnAbiError :: Layout ( layout_err) = err;
168- tcx. dcx ( ) . emit_err ( ( * layout_err) . into_diagnostic ( ) ) ;
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 } ) ;
169169 return ;
170170 }
171171 } ;
0 commit comments