Skip to content

Commit c8620a3

Browse files
committed
Nicer error when implementation limits are exceeded
Fixes rust-lang#1370
1 parent e526880 commit c8620a3

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/base.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use rustc_middle::ty::layout::FnAbiOf;
77
use rustc_middle::ty::print::with_no_trimmed_paths;
88

99
use cranelift_codegen::ir::UserFuncName;
10+
use cranelift_codegen::CodegenError;
11+
use cranelift_module::ModuleError;
1012

1113
use crate::constant::ConstantCx;
1214
use crate::debuginfo::FunctionDebugContext;
@@ -172,7 +174,26 @@ pub(crate) fn compile_fn(
172174
// Define function
173175
cx.profiler.generic_activity("define function").run(|| {
174176
context.want_disasm = cx.should_write_ir;
175-
module.define_function(codegened_func.func_id, context).unwrap();
177+
match module.define_function(codegened_func.func_id, context) {
178+
Ok(()) => {}
179+
Err(ModuleError::Compilation(CodegenError::ImplLimitExceeded)) => {
180+
// FIXME pass the error to the main thread and do a span_fatal instead
181+
rustc_session::early_error(
182+
rustc_session::config::ErrorOutputType::HumanReadable(
183+
rustc_errors::emitter::HumanReadableErrorType::Default(
184+
rustc_errors::emitter::ColorConfig::Auto,
185+
),
186+
),
187+
format!(
188+
"backend implementation limit exceeded while compiling {name}",
189+
name = codegened_func.symbol_name
190+
),
191+
);
192+
}
193+
Err(err) => {
194+
panic!("Error while defining {name}: {err:?}", name = codegened_func.symbol_name);
195+
}
196+
}
176197
});
177198

178199
if cx.should_write_ir {

0 commit comments

Comments
 (0)