Skip to content

Commit 9c5081f

Browse files
committed
Make function bodies with &! arguments unreachable
1 parent 9bd88ef commit 9c5081f

File tree

1 file changed

+13
-0
lines changed
  • compiler/rustc_codegen_ssa/src/mir

1 file changed

+13
-0
lines changed

compiler/rustc_codegen_ssa/src/mir/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,19 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
209209
caller_location: None,
210210
};
211211

212+
if mir.args_iter().any(|arg| {
213+
// Find the monomorphized type of our argument
214+
let arg_decl = &mir.local_decls[arg];
215+
let arg_ty = fx.monomorphize(arg_decl.ty);
216+
217+
// And check if it is a reference to an uninhabited type
218+
let ty = arg_ty.peel_refs();
219+
start_bx.layout_of(ty).abi.is_uninhabited()
220+
}) {
221+
start_bx.unreachable();
222+
return;
223+
}
224+
212225
// It may seem like we should iterate over `required_consts` to ensure they all successfully
213226
// evaluate; however, the `MirUsedCollector` already did that during the collection phase of
214227
// monomorphization so we don't have to do it again.

0 commit comments

Comments
 (0)