diff options
| author | Michael Goulet <michael@errs.io> | 2022-03-09 16:11:28 -0800 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-03-27 22:25:32 -0700 |
| commit | 928388bad20572e9ffa575319bb6d3b636bcdc69 (patch) | |
| tree | 80cd8720d389e6faa6b0f23ffcf5496cb29ebb25 /compiler/rustc_session/src | |
| parent | 93313d108fb7aa209b6ed1ae64d7c05e425d69ad (diff) | |
Make fatal DiagnosticBuilder yield never
Diffstat (limited to 'compiler/rustc_session/src')
| -rw-r--r-- | compiler/rustc_session/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_session/src/session.rs | 31 |
2 files changed, 12 insertions, 20 deletions
diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index bd4e37f1ab7..14273b07ebd 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -3,6 +3,7 @@ #![feature(let_chains)] #![feature(let_else)] #![feature(min_specialization)] +#![feature(never_type)] #![feature(once_cell)] #![feature(option_get_or_insert_default)] #![recursion_limit = "256"] diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 4876e2eb851..eed0f1e09ff 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -341,7 +341,7 @@ impl Session { &self, sp: S, msg: &str, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + ) -> DiagnosticBuilder<'_, !> { self.diagnostic().struct_span_fatal(sp, msg) } pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>( @@ -349,10 +349,10 @@ impl Session { sp: S, msg: &str, code: DiagnosticId, - ) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + ) -> DiagnosticBuilder<'_, !> { self.diagnostic().struct_span_fatal_with_code(sp, msg, code) } - pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_, ErrorGuaranteed> { + pub fn struct_fatal(&self, msg: &str) -> DiagnosticBuilder<'_, !> { self.diagnostic().struct_fatal(msg) } @@ -1384,7 +1384,7 @@ pub enum IncrCompSession { InvalidBecauseOfErrors { session_directory: PathBuf }, } -pub fn early_error_no_abort(output: config::ErrorOutputType, msg: &str) -> ErrorGuaranteed { +fn early_error_handler(output: config::ErrorOutputType) -> rustc_errors::Handler { let emitter: Box<dyn Emitter + sync::Send> = match output { config::ErrorOutputType::HumanReadable(kind) => { let (short, color_config) = kind.unzip(); @@ -1394,26 +1394,17 @@ pub fn early_error_no_abort(output: config::ErrorOutputType, msg: &str) -> Error Box::new(JsonEmitter::basic(pretty, json_rendered, None, false)) } }; - let handler = rustc_errors::Handler::with_emitter(true, None, emitter); - let reported = handler.struct_fatal(msg).emit(); - reported + rustc_errors::Handler::with_emitter(true, None, emitter) +} + +pub fn early_error_no_abort(output: config::ErrorOutputType, msg: &str) -> ErrorGuaranteed { + early_error_handler(output).struct_err(msg).emit() } pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! { - early_error_no_abort(output, msg); - rustc_errors::FatalError.raise(); + early_error_handler(output).struct_fatal(msg).emit() } pub fn early_warn(output: config::ErrorOutputType, msg: &str) { - let emitter: Box<dyn Emitter + sync::Send> = match output { - config::ErrorOutputType::HumanReadable(kind) => { - let (short, color_config) = kind.unzip(); - Box::new(EmitterWriter::stderr(color_config, None, short, false, None, false)) - } - config::ErrorOutputType::Json { pretty, json_rendered } => { - Box::new(JsonEmitter::basic(pretty, json_rendered, None, false)) - } - }; - let handler = rustc_errors::Handler::with_emitter(true, None, emitter); - handler.struct_warn(msg).emit(); + early_error_handler(output).struct_warn(msg).emit() } |
