about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-10-09 18:16:27 +0200
committerRalf Jung <post@ralfj.de>2018-10-13 09:09:02 +0200
commita05914e2dcf196c226a9a93c6609e57970be7e23 (patch)
treee274b7f6efceb3343e38f168a79a7653843741d8
parent5b75ec0a91f548a5a37afc050474ce47f3e74a40 (diff)
check return type even for uninhabited case
-rw-r--r--src/librustc_mir/interpret/terminator.rs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs
index 0ff18b0dd0b..d8ec014b852 100644
--- a/src/librustc_mir/interpret/terminator.rs
+++ b/src/librustc_mir/interpret/terminator.rs
@@ -375,18 +375,19 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
                         return err!(FunctionArgCountMismatch);
                     }
                     // Don't forget to check the return type!
+                    let callee_ret = self.eval_place(&mir::Place::Local(mir::RETURN_PLACE))?;
                     if let Some(caller_ret) = dest {
-                        let callee_ret = self.eval_place(&mir::Place::Local(mir::RETURN_PLACE))?;
                         if !Self::check_argument_compat(caller_ret.layout, callee_ret.layout) {
                             return err!(FunctionRetMismatch(
                                 caller_ret.layout.ty, callee_ret.layout.ty
                             ));
                         }
                     } else {
-                        // FIXME: The caller thinks this function cannot return. How do
-                        // we verify that the callee agrees?
-                        // On the plus side, the the callee ever writes to its return place,
-                        // that will be detected as UB (because we set that to NULL above).
+                        if !callee_ret.layout.abi.is_uninhabited() {
+                            return err!(FunctionRetMismatch(
+                                self.tcx.types.never, callee_ret.layout.ty
+                            ));
+                        }
                     }
                     Ok(())
                 })();