Skip to content

Commit

Permalink
Make function bodies with &! arguments unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Mar 10, 2024
1 parent 9bd88ef commit 9c5081f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 9c5081f

Please sign in to comment.