@@ -4,6 +4,7 @@ mod comments;
4
4
mod pass_mode;
5
5
mod returning;
6
6
7
+ use cranelift_module:: ModuleError ;
7
8
use rustc_middle:: middle:: codegen_fn_attrs:: CodegenFnAttrFlags ;
8
9
use rustc_middle:: ty:: layout:: FnAbiOf ;
9
10
use rustc_target:: abi:: call:: { Conv , FnAbi } ;
@@ -69,7 +70,17 @@ pub(crate) fn import_function<'tcx>(
69
70
) -> FuncId {
70
71
let name = tcx. symbol_name ( inst) . name ;
71
72
let sig = get_function_sig ( tcx, module. isa ( ) . triple ( ) , inst) ;
72
- module. declare_function ( name, Linkage :: Import , & sig) . unwrap ( )
73
+ match module. declare_function ( name, Linkage :: Import , & sig) {
74
+ Ok ( func_id) => func_id,
75
+ Err ( ModuleError :: IncompatibleDeclaration ( _) ) => tcx. sess . fatal ( & format ! (
76
+ "attempt to declare `{name}` as function, but it was already declared as static"
77
+ ) ) ,
78
+ Err ( ModuleError :: IncompatibleSignature ( _, prev_sig, new_sig) ) => tcx. sess . fatal ( & format ! (
79
+ "attempt to declare `{name}` with signature {new_sig:?}, \
80
+ but it was already declared with signature {prev_sig:?}"
81
+ ) ) ,
82
+ Err ( err) => Err :: < _ , _ > ( err) . unwrap ( ) ,
83
+ }
73
84
}
74
85
75
86
impl < ' tcx > FunctionCx < ' _ , ' _ , ' tcx > {
0 commit comments