pub struct DiagCtxt { /* private fields */ }Expand description
A handler that deals with errors and other compiler output.
Certain errors (fatal, bug) may cause immediate exit, others log errors for later reporting.
Implementations§
Source§impl DiagCtxt
impl DiagCtxt
Sourcepub fn new(emitter: Box<dyn Emitter + Send>) -> DiagCtxt
pub fn new(emitter: Box<dyn Emitter + Send>) -> DiagCtxt
Creates a new DiagCtxt with the given diagnostics emitter.
Sourcepub fn new_early() -> DiagCtxt
pub fn new_early() -> DiagCtxt
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>>) -> DiagCtxt
pub fn with_test_emitter(source_map: Option<Arc<SourceMap>>) -> DiagCtxt
Creates a new DiagCtxt with a test emitter.
Sourcepub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> DiagCtxt
pub fn with_stderr_emitter(source_map: Option<Arc<SourceMap>>) -> DiagCtxt
Creates a new DiagCtxt with a stderr emitter.
Sourcepub fn with_stderr_emitter_and_color(
source_map: Option<Arc<SourceMap>>,
color_choice: ColorChoice,
) -> DiagCtxt
pub fn with_stderr_emitter_and_color( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> DiagCtxt
Creates a new DiagCtxt with a stderr emitter and a color choice.
Sourcepub fn with_silent_emitter(fatal_note: Option<String>) -> DiagCtxt
pub fn with_silent_emitter(fatal_note: Option<String>) -> DiagCtxt
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,
) -> DiagCtxt
pub fn with_buffer_emitter( source_map: Option<Arc<SourceMap>>, color_choice: ColorChoice, ) -> DiagCtxt
Creates a new DiagCtxt with a human emitter that emits diagnostics to a local buffer.
Sourcepub fn from_opts(opts: &Opts) -> DiagCtxt
pub fn from_opts(opts: &Opts) -> DiagCtxt
Creates a new DiagCtxt from the given options.
This is the default DiagCtxt used by the Session if one is not provided manually.
It looks at the following options:
error_formatcolorunstable.ui_testingunstable.track_diagnosticsno_warningserror_format_humandiagnostic_width
The default is human emitter to stderr.
See also DiagCtxtFlags::update_from_opts.
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 set_emitter(
&self,
emitter: Box<dyn Emitter + Send>,
) -> Box<dyn Emitter + Send>
pub fn set_emitter( &self, emitter: Box<dyn Emitter + Send>, ) -> Box<dyn Emitter + Send>
Sets the inner emitter. Returns the previous emitter.
Sourcepub fn wrap_emitter(
&self,
f: impl FnOnce(Box<dyn Emitter + Send>) -> Box<dyn Emitter + Send>,
)
pub fn wrap_emitter( &self, f: impl FnOnce(Box<dyn Emitter + Send>) -> Box<dyn Emitter + Send>, )
Wraps the current emitter with the given closure.
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 with_flags(self, f: impl FnOnce(&mut DiagCtxtFlags)) -> DiagCtxt
pub fn with_flags(self, f: impl FnOnce(&mut DiagCtxtFlags)) -> DiagCtxt
Sets flags.
Sourcepub fn set_flags(&self, f: impl FnOnce(&mut DiagCtxtFlags))
pub fn set_flags(&self, f: impl FnOnce(&mut DiagCtxtFlags))
Sets flags.
Sourcepub fn set_flags_mut(&mut self, f: impl FnOnce(&mut DiagCtxtFlags))
pub fn set_flags_mut(&mut self, f: impl FnOnce(&mut DiagCtxtFlags))
Sets flags.
Sourcepub fn disable_warnings(self) -> DiagCtxt
pub fn disable_warnings(self) -> DiagCtxt
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 warn_count(&self) -> usize
pub fn warn_count(&self) -> usize
Returns the number of warnings that have been emitted, including duplicates.
Sourcepub fn note_count(&self) -> usize
pub fn note_count(&self) -> usize
Returns the number of notes that have been emitted, including duplicates.
Sourcepub fn emitted_diagnostics_result(
&self,
) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>>
pub fn emitted_diagnostics_result( &self, ) -> Option<Result<EmittedDiagnostics, EmittedDiagnostics>>
Returns the emitted diagnostics as a result. Can be empty.
Returns None if the underlying emitter is not a human buffer emitter created with
with_buffer_emitter.
Results Ok if there are no errors, Err otherwise.
§Examples
Print diagnostics to stdout if there are no errors, otherwise propagate with ?:
println!("{}", dcx.emitted_diagnostics_result().unwrap()?);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<(), ErrorGuaranteed>
pub fn print_error_count(&self) -> Result<(), ErrorGuaranteed>
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>(
&self,
level: Level,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>where
G: EmissionGuarantee,
pub fn diag<G>(
&self,
level: Level,
msg: impl Into<DiagMsg>,
) -> DiagBuilder<'_, G>where
G: EmissionGuarantee,
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.
Trait Implementations§
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