DiagnosticsHandler

Struct DiagnosticsHandler 

Source
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

Source

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.

Source

pub fn lookup_file_id(&self, filename: impl Into<FileName>) -> Option<SourceId>

Get the SourceId corresponding to the given filename

Source

pub fn has_errors(&self) -> bool

Returns true if the DiagnosticsHandler has emitted any error diagnostics

Source

pub fn abort_if_errors(&self)

Triggers a panic if the DiagnosticsHandler has emitted any error diagnostics

Source

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

Source

pub fn error(&self, error: impl ToString)

Report an error diagnostic

Source

pub fn warn(&self, warning: impl ToString)

Report a warning diagnostic

If warnings_as_errors is set, it produces an error diagnostic instead.

Source

pub fn info(&self, message: impl ToString)

Emits an informational diagnostic

Source

pub fn debug(&self, message: impl ToString)

Emits a debug diagnostic

Source

pub fn note(&self, message: impl ToString)

Emits a note diagnostic

Source

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

Source

pub fn success(&self, prefix: &str, message: impl ToString)

Prints a success message with the given prefix

Source

pub fn failed(&self, prefix: &str, message: impl ToString)

Prints an error message with the given prefix

Source

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.

Source

pub fn emit(&self, diagnostic: impl ToDiagnostic)

Emits the given diagnostic

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.