From 9c5081f4818c2b0bcb55810949726107ea1650d1 Mon Sep 17 00:00:00 2001 From: Ben Kimock Date: Tue, 6 Jun 2023 21:25:42 -0400 Subject: [PATCH] Make function bodies with &! arguments unreachable --- compiler/rustc_codegen_ssa/src/mir/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/compiler/rustc_codegen_ssa/src/mir/mod.rs b/compiler/rustc_codegen_ssa/src/mir/mod.rs index a6fcf1fd38c1f..73a7db5097c22 100644 --- a/compiler/rustc_codegen_ssa/src/mir/mod.rs +++ b/compiler/rustc_codegen_ssa/src/mir/mod.rs @@ -209,6 +209,19 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( caller_location: None, }; + if mir.args_iter().any(|arg| { + // Find the monomorphized type of our argument + let arg_decl = &mir.local_decls[arg]; + let arg_ty = fx.monomorphize(arg_decl.ty); + + // And check if it is a reference to an uninhabited type + let ty = arg_ty.peel_refs(); + start_bx.layout_of(ty).abi.is_uninhabited() + }) { + start_bx.unreachable(); + return; + } + // It may seem like we should iterate over `required_consts` to ensure they all successfully // evaluate; however, the `MirUsedCollector` already did that during the collection phase of // monomorphization so we don't have to do it again.