Skip to content

Make function bodies with &! arguments unreachable #112372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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