add check for uninhabited types along side never
(cherry picked from commit 2a2da782d3)
This commit is contained in:
parent
e17ea4bf4e
commit
3f4f07f0b9
2 changed files with 30 additions and 1 deletions
|
|
@ -839,6 +839,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
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
|
||||
|
|
@ -849,7 +868,7 @@ 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() {
|
||||
if !ty.is_never() && output_is_inhabited {
|
||||
lints.push((target_bb, ty, term.source_info.span));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
#![deny(unreachable_code)]
|
||||
//@ run-pass
|
||||
|
||||
use std::convert::Infallible;
|
||||
|
||||
pub fn foo(f: impl FnOnce() -> Infallible) -> Infallible {
|
||||
f()
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue