about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-02-24 02:11:38 -0500
committerGitHub <noreply@github.com>2025-02-24 02:11:38 -0500
commit8e98f4020cb4b175a84c27dd25c19addfb5dae85 (patch)
treeed7c02d462bb6254a22980823248bafe52f75b49 /src
parentbd633547848e269c16fbd9496e226580819e0108 (diff)
parent63a3ab4fae27ffc6af807598a5634546f9c05a9f (diff)
downloadrust-8e98f4020cb4b175a84c27dd25c19addfb5dae85.tar.gz
rust-8e98f4020cb4b175a84c27dd25c19addfb5dae85.zip
Rollup merge of #137505 - tgross35:builtins-cannot-call-error, r=compiler-errors
Add a span to `CompilerBuiltinsCannotCall`

Currently, this error emit a diagnostic with no context like:

    error: `compiler_builtins` cannot call functions through upstream monomorphizations; encountered invalid call from `<math::libm::support::hex_float::Hexf<i32> as core::fmt::LowerHex>::fmt` to `core::fmt::num::<impl core::fmt::LowerHex for i32>::fmt`

With this change, it at least usually points to the problematic function:

    error: `compiler_builtins` cannot call functions through upstream monomorphizations; encountered invalid call from `<math::libm::support::hex_float::Hexf<i32> as core::fmt::LowerHex>::fmt` to `core::fmt::num::<impl core::fmt::LowerHex for i32>::fmt`
       --> src/../libm/src/math/support/hex_float.rs:270:5
        |
    270 |     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
Diffstat (limited to 'src')
-rw-r--r--src/abi/mod.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index 756a2226753..e8076ce77ab 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -402,9 +402,13 @@ pub(crate) fn codegen_terminator_call<'tcx>(
 
         if is_call_from_compiler_builtins_to_upstream_monomorphization(fx.tcx, instance) {
             if target.is_some() {
-                let caller = with_no_trimmed_paths!(fx.tcx.def_path_str(fx.instance.def_id()));
-                let callee = with_no_trimmed_paths!(fx.tcx.def_path_str(def_id));
-                fx.tcx.dcx().emit_err(CompilerBuiltinsCannotCall { caller, callee });
+                let caller_def = fx.instance.def_id();
+                let e = CompilerBuiltinsCannotCall {
+                    span: fx.tcx.def_span(caller_def),
+                    caller: with_no_trimmed_paths!(fx.tcx.def_path_str(caller_def)),
+                    callee: with_no_trimmed_paths!(fx.tcx.def_path_str(def_id)),
+                };
+                fx.tcx.dcx().emit_err(e);
             } else {
                 fx.bcx.ins().trap(TrapCode::user(2).unwrap());
                 return;