@@ -5,6 +5,7 @@ extern crate rustc_driver;
55extern crate rustc_hir;
66extern crate rustc_interface;
77extern crate rustc_session;
8+ extern crate rustc_errors;
89
910use std:: convert:: TryFrom ;
1011use std:: env;
@@ -13,7 +14,8 @@ use std::str::FromStr;
1314use hex:: FromHexError ;
1415use log:: debug;
1516
16- use rustc_session:: CtfeBacktrace ;
17+ use rustc_session:: { CtfeBacktrace , config:: ErrorOutputType } ;
18+ use rustc_errors:: emitter:: { HumanReadableErrorType , ColorConfig } ;
1719use rustc_driver:: Compilation ;
1820use rustc_hir:: def_id:: LOCAL_CRATE ;
1921use rustc_middle:: ty:: TyCtxt ;
@@ -32,7 +34,12 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
3234
3335 queries. global_ctxt ( ) . unwrap ( ) . peek_mut ( ) . enter ( |tcx| {
3436 init_late_loggers ( tcx) ;
35- let ( entry_def_id, _) = tcx. entry_fn ( LOCAL_CRATE ) . expect ( "no main function found!" ) ;
37+ let ( entry_def_id, _) = if let Some ( ( entry_def, x) ) = tcx. entry_fn ( LOCAL_CRATE ) {
38+ ( entry_def, x)
39+ } else {
40+ let output_ty = ErrorOutputType :: HumanReadable ( HumanReadableErrorType :: Default ( ColorConfig :: Auto ) ) ;
41+ rustc_session:: early_error ( output_ty, "miri can only run programs that have a main function" ) ;
42+ } ;
3643 let mut config = self . miri_config . clone ( ) ;
3744
3845 // Add filename to `miri` arguments.
0 commit comments