Skip to content

Commit 958c585

Browse files
committed
Only codegen a trap for functions with uninhabited arguments
Fixes #847
1 parent 8bf5cd3 commit 958c585

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/base.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ pub fn trans_fn<'clif, 'tcx, B: Backend + 'static>(
5454
source_info_set: indexmap::IndexSet::new(),
5555
};
5656

57-
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
58-
codegen_fn_content(&mut fx);
57+
if fx.mir.args_iter().any(|arg| fx.layout_of(fx.monomorphize(&fx.mir.local_decls[arg].ty)).abi.is_uninhabited()) {
58+
let entry_block = fx.bcx.create_ebb();
59+
fx.bcx.append_ebb_params_for_function_params(entry_block);
60+
fx.bcx.switch_to_block(entry_block);
61+
crate::trap::trap_unreachable(&mut fx, "function has uninhabited argument");
62+
} else {
63+
crate::abi::codegen_fn_prelude(&mut fx, start_ebb);
64+
codegen_fn_content(&mut fx);
65+
}
5966

6067
// Recover all necessary data from fx, before accessing func will prevent future access to it.
6168
let instance = fx.instance;

0 commit comments

Comments
 (0)