Skip to content

Commit 9124eca

Browse files
committed
make the check calls fewer times
1 parent 6e7dd2c commit 9124eca

File tree

1 file changed

+20
-20
lines changed
  • compiler/rustc_mir_build/src/builder

1 file changed

+20
-20
lines changed

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -838,26 +838,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
838838
self.parent_module,
839839
self.infcx.typing_env(self.param_env),
840840
);
841-
842-
// check if the function's return type is inhabited
843-
// this was added here because of this regression
844-
// https://github.com/rust-lang/rust/issues/149571
845-
let output_is_inhabited =
846-
if matches!(self.tcx.def_kind(self.def_id), DefKind::Fn | DefKind::AssocFn) {
847-
self.tcx
848-
.fn_sig(self.def_id)
849-
.instantiate_identity()
850-
.skip_binder()
851-
.output()
852-
.is_inhabited_from(
853-
self.tcx,
854-
self.parent_module,
855-
self.infcx.typing_env(self.param_env),
856-
)
857-
} else {
858-
true
859-
};
860-
861841
if !ty_is_inhabited {
862842
// Unreachable code warnings are already emitted during type checking.
863843
// However, during type checking, full type information is being
@@ -868,6 +848,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
868848
// uninhabited types (e.g. empty enums). The check above is used so
869849
// that we do not emit the same warning twice if the uninhabited type
870850
// is indeed `!`.
851+
852+
// check if the function's return type is inhabited
853+
// this was added here because of this regression
854+
// https://github.com/rust-lang/rust/issues/149571
855+
let output_is_inhabited =
856+
if matches!(self.tcx.def_kind(self.def_id), DefKind::Fn | DefKind::AssocFn) {
857+
self.tcx
858+
.fn_sig(self.def_id)
859+
.instantiate_identity()
860+
.skip_binder()
861+
.output()
862+
.is_inhabited_from(
863+
self.tcx,
864+
self.parent_module,
865+
self.infcx.typing_env(self.param_env),
866+
)
867+
} else {
868+
true
869+
};
870+
871871
if !ty.is_never() && output_is_inhabited {
872872
lints.push((target_bb, ty, term.source_info.span));
873873
}

0 commit comments

Comments
 (0)