Skip to content

Commit a05914e

Browse files
committed
check return type even for uninhabited case
1 parent 5b75ec0 commit a05914e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/librustc_mir/interpret/terminator.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
375375
return err!(FunctionArgCountMismatch);
376376
}
377377
// Don't forget to check the return type!
378+
let callee_ret = self.eval_place(&mir::Place::Local(mir::RETURN_PLACE))?;
378379
if let Some(caller_ret) = dest {
379-
let callee_ret = self.eval_place(&mir::Place::Local(mir::RETURN_PLACE))?;
380380
if !Self::check_argument_compat(caller_ret.layout, callee_ret.layout) {
381381
return err!(FunctionRetMismatch(
382382
caller_ret.layout.ty, callee_ret.layout.ty
383383
));
384384
}
385385
} else {
386-
// FIXME: The caller thinks this function cannot return. How do
387-
// we verify that the callee agrees?
388-
// On the plus side, the the callee ever writes to its return place,
389-
// that will be detected as UB (because we set that to NULL above).
386+
if !callee_ret.layout.abi.is_uninhabited() {
387+
return err!(FunctionRetMismatch(
388+
self.tcx.types.never, callee_ret.layout.ty
389+
));
390+
}
390391
}
391392
Ok(())
392393
})();

0 commit comments

Comments
 (0)