about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-06-20 15:48:00 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2023-06-20 15:48:00 +0000
commitc8620a3cbf740613e0e10941e51887f1ef983992 (patch)
treefee035a8e9a783ca00fbfbddf977922bbc369624 /src
parente5268804a204c5b3b4094ddf5dd1e5632c4f84c7 (diff)
downloadrust-c8620a3cbf740613e0e10941e51887f1ef983992.tar.gz
rust-c8620a3cbf740613e0e10941e51887f1ef983992.zip
Nicer error when implementation limits are exceeded
Fixes #1370
Diffstat (limited to 'src')
-rw-r--r--src/base.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/base.rs b/src/base.rs
index 5abb4644e1b..1c98964024a 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -7,6 +7,8 @@ use rustc_middle::ty::layout::FnAbiOf;
 use rustc_middle::ty::print::with_no_trimmed_paths;
 
 use cranelift_codegen::ir::UserFuncName;
+use cranelift_codegen::CodegenError;
+use cranelift_module::ModuleError;
 
 use crate::constant::ConstantCx;
 use crate::debuginfo::FunctionDebugContext;
@@ -172,7 +174,26 @@ pub(crate) fn compile_fn(
     // Define function
     cx.profiler.generic_activity("define function").run(|| {
         context.want_disasm = cx.should_write_ir;
-        module.define_function(codegened_func.func_id, context).unwrap();
+        match module.define_function(codegened_func.func_id, context) {
+            Ok(()) => {}
+            Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => {
+                // FIXME pass the error to the main thread and do a span_fatal instead
+                rustc_session::early_error(
+                    rustc_session::config::ErrorOutputType::HumanReadable(
+                        rustc_errors::emitter::HumanReadableErrorType::Default(
+                            rustc_errors::emitter::ColorConfig::Auto,
+                        ),
+                    ),
+                    format!(
+                        "backend implementation limit exceeded while compiling {name}",
+                        name = codegened_func.symbol_name
+                    ),
+                );
+            }
+            Err(err) => {
+                panic!("Error while defining {name}: {err:?}", name = codegened_func.symbol_name);
+            }
+        }
     });
 
     if cx.should_write_ir {