Skip to content
Open
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
38 changes: 17 additions & 21 deletions compiler/rustc_mir_build/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -838,26 +838,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
self.parent_module,
self.infcx.typing_env(self.param_env),
);

// check if the function's return type is inhabited
// this was added here because of this regression
// https://github.com/rust-lang/rust/issues/149571
let output_is_inhabited =
if matches!(self.tcx.def_kind(self.def_id), DefKind::Fn | DefKind::AssocFn) {
self.tcx
.fn_sig(self.def_id)
.instantiate_identity()
.skip_binder()
.output()
.is_inhabited_from(
self.tcx,
self.parent_module,
self.infcx.typing_env(self.param_env),
)
} else {
true
};

if !ty_is_inhabited {
// Unreachable code warnings are already emitted during type checking.
// However, during type checking, full type information is being
Expand All @@ -868,7 +848,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// uninhabited types (e.g. empty enums). The check above is used so
// that we do not emit the same warning twice if the uninhabited type
// is indeed `!`.
if !ty.is_never() && output_is_inhabited {
if !ty.is_never()
&& matches!(self.tcx.def_kind(self.def_id), DefKind::Fn | DefKind::AssocFn)
// check if the function's return type is inhabited
// this was added here because of this regression
// https://github.com/rust-lang/rust/issues/149571
&& self
.tcx
.fn_sig(self.def_id)
.instantiate_identity()
.skip_binder()
.output()
.is_inhabited_from(
self.tcx,
self.parent_module,
self.infcx.typing_env(self.param_env),
)
{
lints.push((target_bb, ty, term.source_info.span));
}

Expand Down
Loading