@@ -5,6 +5,7 @@ extern crate rustc_driver;
5
5
extern crate rustc_hir;
6
6
extern crate rustc_interface;
7
7
extern crate rustc_session;
8
+ extern crate rustc_errors;
8
9
9
10
use std:: convert:: TryFrom ;
10
11
use std:: env;
@@ -13,7 +14,8 @@ use std::str::FromStr;
13
14
use hex:: FromHexError ;
14
15
use log:: debug;
15
16
16
- use rustc_session:: CtfeBacktrace ;
17
+ use rustc_session:: { CtfeBacktrace , config:: ErrorOutputType } ;
18
+ use rustc_errors:: emitter:: { HumanReadableErrorType , ColorConfig } ;
17
19
use rustc_driver:: Compilation ;
18
20
use rustc_hir:: def_id:: LOCAL_CRATE ;
19
21
use rustc_middle:: ty:: TyCtxt ;
@@ -32,7 +34,12 @@ impl rustc_driver::Callbacks for MiriCompilerCalls {
32
34
33
35
queries. global_ctxt ( ) . unwrap ( ) . peek_mut ( ) . enter ( |tcx| {
34
36
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
+ } ;
36
43
let mut config = self . miri_config . clone ( ) ;
37
44
38
45
// Add filename to `miri` arguments.
0 commit comments