diff options
| author | Ralf Jung <post@ralfj.de> | 2025-08-25 07:39:19 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-25 07:39:19 +0000 |
| commit | dd801475461bc579232e82db7ea5573e8ebc6506 (patch) | |
| tree | 7ef1c1f5acf3a267d9a288380957f2a0ec69156b /compiler/rustc_errors/src/diagnostic.rs | |
| parent | 7f6f741ebaa6a396fee50b107a0dbfadc08d6a6c (diff) | |
| parent | ca89652f896dad0213e060ce9f6787c72e36a0e9 (diff) | |
Merge pull request #4542 from rust-lang/rustup-2025-08-25
Automatic Rustup
Diffstat (limited to 'compiler/rustc_errors/src/diagnostic.rs')
| -rw-r--r-- | compiler/rustc_errors/src/diagnostic.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 43ce886975c..96a4ed3218f 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -577,6 +577,29 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { self.level = Level::DelayedBug; } + /// Make emitting this diagnostic fatal + /// + /// Changes the level of this diagnostic to Fatal, and importantly also changes the emission guarantee. + /// This is sound for errors that would otherwise be printed, but now simply exit the process instead. + /// This function still gives an emission guarantee, the guarantee is now just that it exits fatally. + /// For delayed bugs this is different, since those are buffered. If we upgrade one to fatal, another + /// might now be ignored. + #[rustc_lint_diagnostics] + #[track_caller] + pub fn upgrade_to_fatal(mut self) -> Diag<'a, FatalAbort> { + assert!( + matches!(self.level, Level::Error), + "upgrade_to_fatal: cannot upgrade {:?} to Fatal: not an error", + self.level + ); + self.level = Level::Fatal; + + // Take is okay since we immediately rewrap it in another diagnostic. + // i.e. we do emit it despite defusing the original diagnostic's drop bomb. + let diag = self.diag.take(); + Diag { dcx: self.dcx, diag, _marker: PhantomData } + } + with_fn! { with_span_label, /// Appends a labeled span to the diagnostic. /// |
