pub struct DiagnosticsHandler { /* private fields */ }Expand description
DiagnosticsHandler acts as the nexus point for configuring and emitting diagnostics. It puts together many of the pieces provided by this crate to provide a useful and convenient interface for handling diagnostics throughout a compiler.
In order to construct a DiagnosticsHandler, you will need a CodeMap, an Emitter, and a DiagnosticsConfig describing how the handler should behave.
DiagnosticsHandler is a thread-safe structure, and is intended to be passed around freely as needed throughout your project.
Implementations§
Source§impl DiagnosticsHandler
impl DiagnosticsHandler
Sourcepub fn new(
config: DiagnosticsConfig,
codemap: Arc<CodeMap>,
emitter: Arc<dyn Emitter>,
) -> Self
pub fn new( config: DiagnosticsConfig, codemap: Arc<CodeMap>, emitter: Arc<dyn Emitter>, ) -> Self
Create a new DiagnosticsHandler from the given DiagnosticsConfig, CodeMap, and Emitter implementation.
Sourcepub fn lookup_file_id(&self, filename: impl Into<FileName>) -> Option<SourceId>
pub fn lookup_file_id(&self, filename: impl Into<FileName>) -> Option<SourceId>
Get the SourceId corresponding to the given filename
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if the DiagnosticsHandler has emitted any error diagnostics
Sourcepub fn abort_if_errors(&self)
pub fn abort_if_errors(&self)
Triggers a panic if the DiagnosticsHandler has emitted any error diagnostics
Sourcepub fn fatal(&self, err: impl ToString) -> FatalError
pub fn fatal(&self, err: impl ToString) -> FatalError
Emits an error message and produces a FatalError object which can be used to terminate execution immediately
Sourcepub fn warn(&self, warning: impl ToString)
pub fn warn(&self, warning: impl ToString)
Report a warning diagnostic
If warnings_as_errors is set, it produces an error diagnostic instead.
Sourcepub fn notice(&self, prefix: &str, message: impl ToString)
pub fn notice(&self, prefix: &str, message: impl ToString)
Prints a warning-like message with the given prefix
NOTE: This does not get promoted to an error if warnings-as-errors is set, as it is intended for informational purposes, not issues with the code being compiled
Sourcepub fn success(&self, prefix: &str, message: impl ToString)
pub fn success(&self, prefix: &str, message: impl ToString)
Prints a success message with the given prefix
Sourcepub fn failed(&self, prefix: &str, message: impl ToString)
pub fn failed(&self, prefix: &str, message: impl ToString)
Prints an error message with the given prefix
Sourcepub fn diagnostic(&self, severity: Severity) -> InFlightDiagnostic<'_>
pub fn diagnostic(&self, severity: Severity) -> InFlightDiagnostic<'_>
Starts building an InFlightDiagnostic for rich compiler diagnostics.
The caller is responsible for dropping/emitting the diagnostic using the InFlightDiagnostic API.
Sourcepub fn emit(&self, diagnostic: impl ToDiagnostic)
pub fn emit(&self, diagnostic: impl ToDiagnostic)
Emits the given diagnostic