pub struct DiagCtxt { /* private fields */ }Expand description
A handler deals with errors and other compiler output. Certain errors (fatal, bug, unimpl) may cause immediate exit, others log errors for later reporting.
Implementations§
Source§impl DiagCtxt
impl DiagCtxt
Sourcepub fn new(emitter: Box<DynEmitter>) -> Self
pub fn new(emitter: Box<DynEmitter>) -> Self
Creates a new DiagCtxt with the given diagnostics emitter.
Sourcepub fn new_early() -> Self
pub fn new_early() -> Self
Creates a new DiagCtxt with a stderr emitter for emitting one-off/early fatal errors that
contain no source information.
Sourcepub fn with_test_emitter(source_map: Option<Arc<SourceMap>>) -> Self
pub fn with_test_emitter(source_map: Option<Arc<SourceMap>>) -> Self
Creates a new DiagCtxt with a test emitter.
Sourcepub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> Self
pub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> Self
Creates a new DiagCtxt with a stderr emitter.
Sourcepub fn with_stderr_emitter_and_color(
source_map: Option<Arc<SourceMap>>,
color_choice: ColorChoice,
) -> Self
pub fn with_stderr_emitter_and_color( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> Self
Creates a new DiagCtxt with a stderr emitter and a color choice.
Sourcepub fn with_silent_emitter(fatal_note: Option<String>) -> Self
pub fn with_silent_emitter(fatal_note: Option<String>) -> Self
Creates a new DiagCtxt with a silent emitter.
Fatal diagnostics will still be emitted, optionally with the given note.
Sourcepub fn with_buffer_emitter(
source_map: Option<Arc<SourceMap>>,
color_choice: ColorChoice,
) -> Self
pub fn with_buffer_emitter( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> Self
Creates a new DiagCtxt with a human emitter that emits diagnostics to a local buffer.
Sourcepub fn make_silent(&self, fatal_note: Option<String>, emit_fatal: bool)
pub fn make_silent(&self, fatal_note: Option<String>, emit_fatal: bool)
Sets the emitter to SilentEmitter.
Sourcepub fn source_map(&self) -> Option<Arc<SourceMap>>
pub fn source_map(&self) -> Option<Arc<SourceMap>>
Gets the source map associated with this context.
Sourcepub fn source_map_mut(&mut self) -> Option<&Arc<SourceMap>>
pub fn source_map_mut(&mut self) -> Option<&Arc<SourceMap>>
Gets the source map associated with this context.
Sourcepub fn set_flags(self, f: impl FnOnce(&mut DiagCtxtFlags)) -> Self
pub fn set_flags(self, f: impl FnOnce(&mut DiagCtxtFlags)) -> Self
Sets whether to include created and emitted locations in diagnostics.
Sourcepub fn disable_warnings(self) -> Self
pub fn disable_warnings(self) -> Self
Disables emitting warnings.
Sourcepub fn track_diagnostics(&self) -> bool
pub fn track_diagnostics(&self) -> bool
Returns true if diagnostics are being tracked.
Sourcepub fn emit_diagnostic(&self, diagnostic: Diag) -> Result<(), ErrorGuaranteed>
pub fn emit_diagnostic(&self, diagnostic: Diag) -> Result<(), ErrorGuaranteed>
Emits the given diagnostic with this context.
Sourcepub fn err_count(&self) -> usize
pub fn err_count(&self) -> usize
Returns the number of errors that have been emitted, including duplicates.
Sourcepub fn has_errors(&self) -> Result<(), ErrorGuaranteed>
pub fn has_errors(&self) -> Result<(), ErrorGuaranteed>
Returns Err if any errors have been emitted.
Sourcepub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics>
pub fn emitted_diagnostics(&self) -> Option<EmittedDiagnostics>
Returns the emitted diagnostics. Can be empty.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Sourcepub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>>
pub fn emitted_errors(&self) -> Option<Result<(), EmittedDiagnostics>>
Returns Err with the printed diagnostics if any errors have been emitted.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Sourcepub fn print_error_count(&self) -> Result
pub fn print_error_count(&self) -> Result
Emits a diagnostic if any warnings or errors have been emitted.
Source§impl DiagCtxt
Diag constructors.
impl DiagCtxt
Diag constructors.
Note that methods returning a DiagBuilder must also marked with #[track_caller].
Sourcepub fn diag<G: EmissionGuarantee>(
&self,
level: Level,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>
pub fn diag<G: EmissionGuarantee>( &self, level: Level, msg: impl Into<DiagMsg>, ) -> DiagBuilder<'_, G>
Creates a builder at the given level with the given msg.
Sourcepub fn bug(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, BugAbort>
pub fn bug(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, BugAbort>
Creates a builder at the Bug level with the given msg.
Sourcepub fn fatal(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, FatalAbort>
pub fn fatal(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, FatalAbort>
Creates a builder at the Fatal level with the given msg.
Sourcepub fn err(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ErrorGuaranteed>
pub fn err(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ErrorGuaranteed>
Creates a builder at the Error level with the given msg.
Sourcepub fn warn(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()>
pub fn warn(&self, msg: impl Into<DiagMsg>) -> DiagBuilder<'_, ()>
Creates a builder at the Warning level with the given msg.
Attempting to .emit() the builder will only emit if can_emit_warnings is true.
Auto Trait Implementations§
impl !Freeze for DiagCtxt
impl !RefUnwindSafe for DiagCtxt
impl Send for DiagCtxt
impl Sync for DiagCtxt
impl Unpin for DiagCtxt
impl !UnwindSafe for DiagCtxt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more