Skip to content

Commit d8f7910

Browse files
committed
Ensure input errors can be catched by user of rustc_driver
1 parent 2fabbf6 commit d8f7910

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest};
3535
use rustc_session::getopts;
3636
use rustc_session::lint::{Lint, LintId};
3737
use rustc_session::{config, DiagnosticOutput, Session};
38-
use rustc_session::{early_error, early_warn};
38+
use rustc_session::{early_error, early_error_no_abort, early_warn};
3939
use rustc_span::source_map::{FileLoader, FileName};
4040
use rustc_span::symbol::sym;
4141

@@ -233,7 +233,8 @@ fn run_compiler(
233233
if let Some(err) = input_err {
234234
// Immediately stop compilation if there was an issue reading
235235
// the input (for example if the input stream is not UTF-8).
236-
early_error(config.opts.error_format, &err.to_string());
236+
early_error_no_abort(config.opts.error_format, &err.to_string());
237+
return Err(ErrorReported);
237238
}
238239

239240
config.input = input;

compiler/rustc_session/src/session.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ pub enum IncrCompSession {
16371637
InvalidBecauseOfErrors { session_directory: PathBuf },
16381638
}
16391639

1640-
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
1640+
pub fn early_error_no_abort(output: config::ErrorOutputType, msg: &str) {
16411641
let emitter: Box<dyn Emitter + sync::Send> = match output {
16421642
config::ErrorOutputType::HumanReadable(kind) => {
16431643
let (short, color_config) = kind.unzip();
@@ -1649,6 +1649,10 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
16491649
};
16501650
let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
16511651
handler.struct_fatal(msg).emit();
1652+
}
1653+
1654+
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
1655+
early_error_no_abort(output, msg);
16521656
rustc_errors::FatalError.raise();
16531657
}
16541658

0 commit comments

Comments
 (0)