diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index e615f8a4846..2bc79e5080f 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -105,13 +105,20 @@ pub fn abort_on_err(result: Result, sess: &Session) -> T { pub trait Callbacks { /// Called before creating the compiler instance fn config(&mut self, _config: &mut interface::Config) {} - /// Called after parsing and returns true to continue execution - fn after_parsing(&mut self, _compiler: &interface::Compiler) -> bool { - true + /// Called after parsing. Return value instructs the compiler whether to + /// continue the compilation afterwards (defaults to `Compilation::Continue`) + fn after_parsing(&mut self, _compiler: &interface::Compiler) -> Compilation { + Compilation::Continue } - /// Called after analysis and returns true to continue execution - fn after_analysis(&mut self, _compiler: &interface::Compiler) -> bool { - true + /// Called after expansion. Return value instructs the compiler whether to + /// continue the compilation afterwards (defaults to `Compilation::Continue`) + fn after_expansion(&mut self, _compiler: &interface::Compiler) -> Compilation { + Compilation::Continue + } + /// Called after analysis. Return value instructs the compiler whether to + /// continue the compilation afterwards (defaults to `Compilation::Continue`) + fn after_analysis(&mut self, _compiler: &interface::Compiler) -> Compilation { + Compilation::Continue } } @@ -294,7 +301,7 @@ pub fn run_compiler( } } - if !callbacks.after_parsing(compiler) { + if callbacks.after_parsing(compiler) == Compilation::Stop { return sess.compile_status(); } @@ -312,6 +319,11 @@ pub fn run_compiler( return sess.compile_status(); } + compiler.expansion()?; + if callbacks.after_expansion(compiler) == Compilation::Stop { + return sess.compile_status(); + } + compiler.prepare_outputs()?; if sess.opts.output_types.contains_key(&OutputType::DepInfo) @@ -355,7 +367,7 @@ pub fn run_compiler( compiler.global_ctxt()?.peek_mut().enter(|tcx| tcx.analysis(LOCAL_CRATE))?; - if !callbacks.after_analysis(compiler) { + if callbacks.after_analysis(compiler) == Compilation::Stop { return sess.compile_status(); }